📄 hbmbinder.java
字号:
} private static void bindCompositeId(Element idNode, RootClass entity, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { String propertyName = idNode.attributeValue( "name" ); Component id = new Component( entity ); entity.setIdentifier( id ); bindCompositeId( idNode, id, entity, propertyName, mappings, inheritedMetas ); if ( propertyName == null ) { entity.setEmbeddedIdentifier( id.isEmbedded() ); if ( id.isEmbedded() ) { // todo : what is the implication of this? id.setDynamic( !entity.hasPojoRepresentation() ); /* * Property prop = new Property(); prop.setName("id"); * prop.setPropertyAccessorName("embedded"); prop.setValue(id); * entity.setIdentifierProperty(prop); */ } } else { Property prop = new Property(); prop.setValue( id ); bindProperty( idNode, prop, mappings, inheritedMetas ); entity.setIdentifierProperty( prop ); } makeIdentifier( idNode, id, mappings ); if ( !id.isDynamic() ) { try { Class idClass = id.getComponentClass(); if ( idClass != null && !ReflectHelper.overridesEquals( idClass ) ) { throw new MappingException( "composite-id class must override equals(): " + id.getComponentClass().getName() ); } if ( !ReflectHelper.overridesHashCode( idClass ) ) { throw new MappingException( "composite-id class must override hashCode(): " + id.getComponentClass().getName() ); } if ( !Serializable.class.isAssignableFrom( idClass ) ) { throw new MappingException( "composite-id class must implement Serializable: " + id.getComponentClass().getName() ); } } catch (MappingException cnfe) { log.warn( "Could not perform validation checks for component as the class " + id.getComponentClassName() + " was not found" ); } } } private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings, String name, RootClass entity, java.util.Map inheritedMetas) { String propertyName = subnode.attributeValue( "name" ); SimpleValue val = new SimpleValue( table ); bindSimpleValue( subnode, val, false, propertyName, mappings ); if ( !val.isTypeSpecified() ) { val.setTypeName( "version".equals( name ) ? "integer" : "timestamp" ); } Property prop = new Property(); prop.setValue( val ); bindProperty( subnode, prop, mappings, inheritedMetas ); makeVersion( subnode, val ); entity.setVersion( prop ); entity.addProperty( prop ); } private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode, Mappings mappings) { SimpleValue discrim = new SimpleValue( table ); entity.setDiscriminator( discrim ); bindSimpleValue( subnode, discrim, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings ); if ( !discrim.isTypeSpecified() ) { discrim.setTypeName( "string" ); // ( (Column) discrim.getColumnIterator().next() ).setType(type); } entity.setPolymorphic( true ); if ( "true".equals( subnode.attributeValue( "force" ) ) ) entity.setForceDiscriminator( true ); if ( "false".equals( subnode.attributeValue( "insert" ) ) ) entity.setDiscriminatorInsertable( false ); } public static void bindClass(Element node, PersistentClass persistentClass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { // transfer an explicitly defined entity name // handle the lazy attribute Attribute lazyNode = node.attribute( "lazy" ); boolean lazy = lazyNode == null ? mappings.isDefaultLazy() : "true".equals( lazyNode .getValue() ); // go ahead and set the lazy here, since pojo.proxy can override it. persistentClass.setLazy( lazy ); String entityName = node.attributeValue( "entity-name" ); if ( entityName == null ) entityName = getClassName( node.attribute("name"), mappings ); if ( entityName==null ) { throw new MappingException( "Unable to determine entity name" ); } persistentClass.setEntityName( entityName ); bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas ); bindDom4jRepresentation( node, persistentClass, mappings, inheritedMetas ); bindMapRepresentation( node, persistentClass, mappings, inheritedMetas ); bindPersistentClassCommonValues( node, persistentClass, mappings, inheritedMetas ); } private static void bindPojoRepresentation(Element node, PersistentClass entity, Mappings mappings, java.util.Map metaTags) { String className = getClassName( node.attribute( "name" ), mappings ); String proxyName = getClassName( node.attribute( "proxy" ), mappings ); entity.setClassName( className ); if ( proxyName != null ) { entity.setProxyInterfaceName( proxyName ); entity.setLazy( true ); } else if ( entity.isLazy() ) { entity.setProxyInterfaceName( className ); } } private static void bindDom4jRepresentation(Element node, PersistentClass entity, Mappings mappings, java.util.Map inheritedMetas) { String nodeName = node.attributeValue( "node" ); if (nodeName==null) nodeName = StringHelper.unqualify( entity.getEntityName() ); entity.setNodeName(nodeName); } private static void bindMapRepresentation(Element node, PersistentClass entity, Mappings mappings, java.util.Map inheritedMetas) { // nothing to do } private static void bindPersistentClassCommonValues(Element node, PersistentClass entity, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { // DISCRIMINATOR Attribute discriminatorNode = node.attribute( "discriminator-value" ); entity.setDiscriminatorValue( ( discriminatorNode == null ) ? entity.getEntityName() : discriminatorNode.getValue() ); // DYNAMIC UPDATE Attribute dynamicNode = node.attribute( "dynamic-update" ); entity.setDynamicUpdate( ( dynamicNode == null ) ? false : "true".equals( dynamicNode .getValue() ) ); // DYNAMIC INSERT Attribute insertNode = node.attribute( "dynamic-insert" ); entity.setDynamicInsert( ( insertNode == null ) ? false : "true".equals( insertNode .getValue() ) ); // IMPORT mappings.addImport( entity.getEntityName(), entity.getEntityName() ); if ( mappings.isAutoImport() && entity.getEntityName().indexOf( '.' ) > 0 ) { mappings.addImport( entity.getEntityName(), StringHelper.unqualify( entity .getEntityName() ) ); } // BATCH SIZE Attribute batchNode = node.attribute( "batch-size" ); if ( batchNode != null ) entity.setBatchSize( Integer.parseInt( batchNode.getValue() ) ); // SELECT BEFORE UPDATE Attribute sbuNode = node.attribute( "select-before-update" ); if ( sbuNode != null ) entity.setSelectBeforeUpdate( "true".equals( sbuNode.getValue() ) ); // OPTIMISTIC LOCK MODE Attribute olNode = node.attribute( "optimistic-lock" ); entity.setOptimisticLockMode( getOptimisticLockMode( olNode ) ); entity.setMetaAttributes( getMetas( node, inheritedMetas ) ); // PERSISTER Attribute persisterNode = node.attribute( "persister" ); if ( persisterNode == null ) { // persister = SingleTableEntityPersister.class; } else { try { entity.setEntityPersisterClass( ReflectHelper.classForName( persisterNode .getValue() ) ); } catch (ClassNotFoundException cnfe) { throw new MappingException( "Could not find persister class: " + persisterNode.getValue() ); } } // CUSTOM SQL handleCustomSQL( node, entity ); Iterator tables = node.elementIterator( "synchronize" ); while ( tables.hasNext() ) { entity.addSynchronizedTable( ( (Element) tables.next() ).attributeValue( "table" ) ); } Attribute abstractNode = node.attribute( "abstract" ); if ( abstractNode != null ) entity.setAbstract( "true".equals( abstractNode.getValue() ) ); } private static void handleCustomSQL(Element node, PersistentClass model) throws MappingException { Element element = node.element( "sql-insert" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLInsert( element.getText(), callable ); } element = node.element( "sql-delete" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLDelete( element.getText(), callable ); } element = node.element( "sql-update" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLUpdate( element.getText(), callable ); } element = node.element( "loader" ); if ( element != null ) { model.setLoaderName( element.attributeValue( "query-ref" ) ); } } private static void handleCustomSQL(Element node, Join model) throws MappingException { Element element = node.element( "sql-insert" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLInsert( element.getText(), callable ); } element = node.element( "sql-delete" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLDelete( element.getText(), callable ); } element = node.element( "sql-update" ); if ( element != null ) { boolean callable = false; callable = isCallable( element ); model.setCustomSQLUpdate( element.getText(), callable ); } } private static void handleCustomSQL(Element node, Collection model) throws MappingException { Element element = node.element( "sql-insert" ); if ( element != null ) { boolean callable = false; callable = isCallable( element, true ); model.setCustomSQLInsert( element.getText(), callable ); } element = node.element( "sql-delete" ); if ( element != null ) { boolean callable = false; callable = isCallable( element, true ); model.setCustomSQLDelete( element.getText(), callable ); } element = node.element( "sql-update" ); if ( element != null ) { boolean callable = false; callable = isCallable( element, true ); model.setCustomSQLUpdate( element.getText(), callable ); } element = node.element( "sql-delete-all" ); if ( element != null ) { boolean callable = false; callable = isCallable( element, true ); model.setCustomSQLDeleteAll( element.getText(), callable ); } } private static boolean isCallable(Element e) throws MappingException { return isCallable( e, true ); } /** * @param element * @param supportsCallable * @return */ private static boolean isCallable(Element element, boolean supportsCallable) throws MappingException { Attribute attrib = element.attribute( "callable" ); if ( attrib != null && "true".equals( attrib.getValue() ) ) { if ( !supportsCallable ) { throw new MappingException( "callable attribute not supported yet!" ); } return true; } return false; } public static void bindUnionSubclass(Element node, UnionSubclass unionSubclass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindClass( node, unionSubclass, mappings, inheritedMetas ); inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass> if ( unionSubclass.getEntityPersisterClass() == null ) { unionSubclass.getRootClass().setEntityPersisterClass( UnionSubclassEntityPersister.class ); } Attribute schemaNode = node.attribute( "schema" ); String schema = schemaNode == null ? mappings.getSchemaName() : schemaNode.getValue(); Attribute catalogNode = node.attribute( "catalog" ); String catalog = catalogNode == null ? mappings.getCatalogName() : catalogNode.getValue(); Table mytable = mappings.addDenormalizedTable( schema, catalog, getClassTableName(unionSubclass, node, mappings ), unionSubclass.isAbstract(), getSubselect( node ), unionSubclass.getSuperclass().getTable() ); unionSubclass.setTable( mytable ); log.info( "Mapping union-subclass: " + unionSubclass.getEntityName() + " -> " + unionSubclass.getTable().getName() ); createClassProperties( node, unionSubclass, mappings, inheritedMetas ); } public static void bindSubclass(Element node, Subclass subclass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindClass( node, subclass, mappings, inheritedMetas ); inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass> if ( subclass.getEntityPersisterClass() == null ) { subclass.getRootClass().setEntityPersisterClass( SingleTableEntityPersister.class ); } log.info( "Mapping subclass: " + subclass.getEntityName() + " -> " + subclass.getTable().getName() ); // properties createClassProperties( node, subclass, mappings, inheritedMetas ); } private static String getClassTableName(PersistentClass model, Element node, Mappings mappings) { Attribute tableNameNode = node.attribute( "table" ); if ( tableNameNode == null ) { return mappings.getNamingStrategy().classToTableName( model.getEntityName() ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -