📄 hbmbinder.java
字号:
if ( inverseNode != null ) { collection.setInverse( "true".equals( inverseNode.getValue() ) ); } Attribute olNode = node.attribute( "optimistic-lock" ); collection.setOptimisticLocked( olNode == null || "true".equals( olNode.getValue() ) ); Attribute orderNode = node.attribute( "order-by" ); if ( orderNode != null ) { if ( Environment.jvmSupportsLinkedHashCollections() || ( collection instanceof Bag ) ) { collection.setOrderBy( orderNode.getValue() ); } else { log.warn( "Attribute \"order-by\" ignored in JDK1.3 or less" ); } } Attribute whereNode = node.attribute( "where" ); if ( whereNode != null ) { collection.setWhere( whereNode.getValue() ); } Attribute batchNode = node.attribute( "batch-size" ); if ( batchNode != null ) { collection.setBatchSize( Integer.parseInt( batchNode.getValue() ) ); } String nodeName = node.attributeValue( "node" ); if ( nodeName == null ) nodeName = node.attributeValue( "name" ); collection.setNodeName( nodeName ); String embed = node.attributeValue( "embed-xml" ); collection.setEmbedded( embed==null || "true".equals(embed) ); // PERSISTER Attribute persisterNode = node.attribute( "persister" ); if ( persisterNode != null ) { try { collection.setCollectionPersisterClass( ReflectHelper.classForName( persisterNode .getValue() ) ); } catch (ClassNotFoundException cnfe) { throw new MappingException( "Could not find collection persister class: " + persisterNode.getValue() ); } } Attribute typeNode = node.attribute( "collection-type" ); if ( typeNode != null ) collection.setTypeName( typeNode.getValue() ); // FETCH STRATEGY initOuterJoinFetchSetting( node, collection ); if ( "subselect".equals( node.attributeValue("fetch") ) ) { collection.setSubselectLoadable(true); collection.getOwner().setSubselectLoadableCollections(true); } initLaziness( node, collection, mappings, "true", mappings.isDefaultLazy() ); Element oneToManyNode = node.element( "one-to-many" ); if ( oneToManyNode != null ) { OneToMany oneToMany = new OneToMany( collection.getOwner() ); collection.setElement( oneToMany ); bindOneToMany( oneToManyNode, oneToMany, mappings ); // we have to set up the table later!! yuck } else { // TABLE Attribute tableNode = node.attribute( "table" ); String tableName; if ( tableNode != null ) { tableName = mappings.getNamingStrategy().tableName( tableNode.getValue() ); } else { tableName = mappings.getNamingStrategy().propertyToTableName( className, path ); } 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 table = mappings.addTable( schema, catalog, tableName, getSubselect( node ), false ); collection.setCollectionTable( table ); bindComment(table, node); log.info( "Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName() ); } // SORT Attribute sortedAtt = node.attribute( "sort" ); // unsorted, natural, comparator.class.name if ( sortedAtt == null || sortedAtt.getValue().equals( "unsorted" ) ) { collection.setSorted( false ); } else { collection.setSorted( true ); String comparatorClassName = sortedAtt.getValue(); if ( !comparatorClassName.equals( "natural" ) ) { try { collection.setComparator( (Comparator) ReflectHelper.classForName( comparatorClassName ).newInstance() ); } catch (Exception e) { throw new MappingException( "Could not instantiate comparator class: " + comparatorClassName ); } } } // ORPHAN DELETE (used for programmer error detection) Attribute cascadeAtt = node.attribute( "cascade" ); if ( cascadeAtt != null && cascadeAtt.getValue().indexOf( "delete-orphan" ) >= 0 ) { collection.setOrphanDelete( true ); } // CUSTOM SQL handleCustomSQL( node, collection ); // set up second pass if ( collection instanceof List ) { mappings.addSecondPass( new ListSecondPass( node, mappings, (List) collection ) ); } else if ( collection instanceof Map ) { mappings.addSecondPass( new MapSecondPass( node, mappings, (Map) collection ) ); } else if ( collection instanceof IdentifierCollection ) { mappings.addSecondPass( new IdentifierCollectionSecondPass( node, mappings, (IdentifierCollection) collection ) ); } else { mappings.addSecondPass( new CollectionSecondPass( node, mappings, collection ) ); } Iterator iter = node.elementIterator( "filter" ); while ( iter.hasNext() ) { final Element filter = (Element) iter.next(); parseFilter( filter, collection, mappings ); } Iterator tables = node.elementIterator( "synchronize" ); while ( tables.hasNext() ) { collection.getSynchronizedTables().add( ( (Element) tables.next() ).attributeValue( "table" ) ); } Element element = node.element( "loader" ); if ( element != null ) { collection.setLoaderName( element.attributeValue( "query-ref" ) ); } collection.setReferencedPropertyName( node.element( "key" ).attributeValue( "property-ref" ) ); } private static void initLaziness( Element node, Fetchable fetchable, Mappings mappings, String proxyVal, boolean defaultLazy ) { Attribute lazyNode = node.attribute( "lazy" ); boolean isLazyTrue = lazyNode == null ? defaultLazy && fetchable.isLazy() : //fetch="join" overrides default laziness proxyVal.equals( lazyNode.getValue() ); //fetch="join" overrides default laziness fetchable.setLazy( isLazyTrue ); } private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path, boolean isNullable, Mappings mappings) { Attribute formulaNode = node.attribute( "formula" ); if ( formulaNode != null ) { Formula f = new Formula(); f.setFormula( formulaNode.getText() ); simpleValue.addFormula( f ); } else { bindColumns( node, simpleValue, isNullable, true, path, mappings ); } } private static void bindComment(Table table, Element node) { Element comment = node.element("comment"); if (comment!=null) table.setComment( comment.getTextTrim() ); } public static void bindManyToOne(Element node, ManyToOne manyToOne, String path, boolean isNullable, Mappings mappings) throws MappingException { bindColumnsOrFormula( node, manyToOne, path, isNullable, mappings ); initOuterJoinFetchSetting( node, manyToOne ); initLaziness( node, manyToOne, mappings, "proxy", true ); Attribute ukName = node.attribute( "property-ref" ); if ( ukName != null ) manyToOne.setReferencedPropertyName( ukName.getValue() ); manyToOne.setReferencedEntityName( getEntityName( node, mappings ) ); String embed = node.attributeValue( "embed-xml" ); manyToOne.setEmbedded( embed == null || "true".equals( embed ) ); String notFound = node.attributeValue( "not-found" ); manyToOne.setIgnoreNotFound( "ignore".equals( notFound ) ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() ); } public static void bindAny(Element node, Any any, boolean isNullable, Mappings mappings) throws MappingException { any.setIdentifierType( getTypeFromXML( node ) ); Attribute metaAttribute = node.attribute( "meta-type" ); if ( metaAttribute != null ) { any.setMetaType( metaAttribute.getValue() ); Iterator iter = node.elementIterator( "meta-value" ); if ( iter.hasNext() ) { HashMap values = new HashMap(); org.hibernate.type.Type metaType = TypeFactory.heuristicType( any.getMetaType() ); while ( iter.hasNext() ) { Element metaValue = (Element) iter.next(); try { Object value = ( (DiscriminatorType) metaType ).stringToObject( metaValue .attributeValue( "value" ) ); String entityName = getClassName( metaValue.attribute( "class" ), mappings ); values.put( value, entityName ); } catch (ClassCastException cce) { throw new MappingException( "meta-type was not a DiscriminatorType: " + metaType.getName() ); } catch (Exception e) { throw new MappingException( "could not interpret meta-value", e ); } } any.setMetaValues( values ); } } bindColumns( node, any, isNullable, false, null, mappings ); } public static void bindOneToOne(Element node, OneToOne oneToOne, boolean isNullable, Mappings mappings) throws MappingException { bindColumns( node, oneToOne, isNullable, false, null, mappings ); Attribute constrNode = node.attribute( "constrained" ); boolean constrained = constrNode != null && constrNode.getValue().equals( "true" ); oneToOne.setConstrained( constrained ); oneToOne.setForeignKeyType( constrained ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ); initOuterJoinFetchSetting( node, oneToOne ); initLaziness( node, oneToOne, mappings, "proxy", true ); oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() ); Attribute ukName = node.attribute( "property-ref" ); if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() ); oneToOne.setPropertyName( node.attributeValue( "name" ) ); oneToOne.setReferencedEntityName( getEntityName( node, mappings ) ); } public static void bindOneToMany(Element node, OneToMany oneToMany, Mappings mappings) throws MappingException { oneToMany.setReferencedEntityName( getEntityName( node, mappings ) ); String embed = node.attributeValue( "embed-xml" ); oneToMany.setEmbedded( embed == null || "true".equals( embed ) ); String notFound = node.attributeValue( "not-found" ); oneToMany.setIgnoreNotFound( "ignore".equals( notFound ) ); } public static void bindColumn(Element node, Column column, boolean isNullable) { Attribute lengthNode = node.attribute( "length" ); if ( lengthNode != null ) column.setLength( Integer.parseInt( lengthNode.getValue() ) ); Attribute scalNode = node.attribute( "scale" ); if ( scalNode != null ) column.setScale( Integer.parseInt( scalNode.getValue() ) ); Attribute precNode = node.attribute( "precision" ); if ( precNode != null ) column.setPrecision( Integer.parseInt( precNode.getValue() ) ); Attribute nullNode = node.attribute( "not-null" ); column.setNullable( nullNode == null ? isNullable : nullNode.getValue().equals( "false" ) ); Attribute unqNode = node.attribute( "unique" ); if ( unqNode != null ) column.setUnique( unqNode.getValue().equals( "true" ) ); column.setCheckConstraint( node.attributeValue( "check" ) ); Attribute typeNode = node.attribute( "sql-type" ); if ( typeNode != null ) column.setSqlType( typeNode.getValue() ); Element comment = node.element("comment"); if (comment!=null) column.setComment( comment.getTextTrim() ); } /** * Called for arrays and primitive arrays */ public static void bindArray(Element node, Array array, String prefix, String path, Mappings mappings) throws MappingException { bindCollection( node, array, prefix, path, mappings ); Attribute att = node.attribute( "element-class" ); if ( att != null ) array.setElementClassName( getClassName( att, mappings ) ); } private static Class reflectedPropertyClass(String className, String propertyName) throws MappingException { if ( className == null ) return null; return ReflectHelper.reflectedPropertyClass( className, propertyName ); } public static void bindComposite(Element node, Component component, String path, boolean isNullable, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindComponent( node, component, null, null, path, isNullable, false, mappings, inheritedMetas ); } public static void bindCompositeId(Element node, Component component, PersistentClass persistentClass, String propertyName, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { component.setKey( true ); String path = StringHelper.qualify( persistentClass.getEntityName(), propertyName == null ? "id" : propertyName ); bindComponent( node, component, persistentClass.getClassName(), propertyName, path, false, node.attribute( "class" ) == null && propertyName == null, mappings, inheritedMetas );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -