⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hbmbinder.java

📁 介绍了hibernate的入门有一些基本常用的事例
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			component.setComponentClassName( component.getOwner().getClassName() );		}		else {			// todo : again, how *should* this work for non-pojo entities?			Class reflectedClass = reflectedPropertyClass( ownerClassName, parentProperty );			if ( reflectedClass != null )				component.setComponentClassName( reflectedClass.getName() );		}		String nodeName = node.attributeValue( "node" );		if ( nodeName == null ) nodeName = node.attributeValue( "name" );		component.setNodeName( nodeName );		Iterator iter = node.elementIterator();		while ( iter.hasNext() ) {			Element subnode = (Element) iter.next();			String name = subnode.getName();			String propertyName = getPropertyName( subnode );			String subpath = propertyName == null ? null : StringHelper				.qualify( path, propertyName );			CollectionType collectType = CollectionType.collectionTypeFromString( name );			Value value = null;			if ( collectType != null ) {				Collection collection = collectType.create(					subnode,					subpath,					component.getOwner(),					mappings );				mappings.addCollection( collection );				value = collection;			}			else if ( "many-to-one".equals( name ) || "key-many-to-one".equals( name ) ) {				value = new ManyToOne( component.getTable() );				bindManyToOne( subnode, (ManyToOne) value, propertyName, isNullable, mappings );			}			else if ( "one-to-one".equals( name ) ) {				value = new OneToOne( component.getTable(), component.getOwner().getKey() );				bindOneToOne( subnode, (OneToOne) value, isNullable, mappings );			}			else if ( "any".equals( name ) ) {				value = new Any( component.getTable() );				bindAny( subnode, (Any) value, isNullable, mappings );			}			else if ( "property".equals( name ) || "key-property".equals( name ) ) {				value = new SimpleValue( component.getTable() );				bindSimpleValue( subnode, (SimpleValue) value, isNullable, propertyName, mappings );			}			else if ( "component".equals( name )				|| "dynamic-component".equals( name )				|| "nested-composite-element".equals( name ) ) {				value = new Component( component ); // a nested composite element				bindComponent(					subnode,					(Component) value,					component.getComponentClassName(),					propertyName,					subpath,					isNullable,					isEmbedded,					mappings,					inheritedMetas );			}			else if ( "parent".equals( name ) ) {				component.setParentProperty( propertyName );			}			if ( value != null ) {				component.addProperty( createProperty( value, propertyName, component					.getComponentClassName(), subnode, mappings, inheritedMetas ) );			}		}		if ( "true".equals( node.attributeValue( "unique" ) ) ) {			iter = component.getColumnIterator();			ArrayList cols = new ArrayList();			while ( iter.hasNext() )				cols.add( iter.next() );			component.getOwner().getTable().createUniqueKey( cols );		}	}	private static String getTypeFromXML(Element node) throws MappingException {		// TODO: handle TypeDefs		Attribute typeNode = node.attribute( "type" );		if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any		if ( typeNode == null ) return null; // we will have to use reflection		return typeNode.getValue();	}	private static void initOuterJoinFetchSetting(Element node, Fetchable model) {		Attribute fetchNode = node.attribute( "fetch" );		final FetchMode fetchStyle;		if ( fetchNode == null ) {			Attribute jfNode = node.attribute( "outer-join" );			if ( jfNode == null ) {				if ( "many-to-many".equals( node.getName() ) ) {					// default to join for the "second join" of the many-to-many					fetchStyle = FetchMode.JOIN;				}				else if ( "one-to-one".equals( node.getName() ) ) {					// one-to-one constrained=false cannot be proxied,					// so default to join					fetchStyle = ( (OneToOne) model ).isConstrained()						? FetchMode.DEFAULT						: FetchMode.JOIN;				}				else {					fetchStyle = FetchMode.DEFAULT;				}			}			else {				// use old (HB 2.1) defaults if outer-join is specified				String eoj = jfNode.getValue();				if ( "auto".equals( eoj ) ) {					fetchStyle = FetchMode.DEFAULT;				}				else {					fetchStyle = "true".equals( eoj ) ? FetchMode.JOIN : FetchMode.SELECT;				}			}		}		else {			fetchStyle = "join".equals( fetchNode.getValue() ) ? FetchMode.JOIN : FetchMode.SELECT;		}		model.setFetchMode( fetchStyle );	}	private static void makeIdentifier(Element node, SimpleValue model, Mappings mappings) {		// GENERATOR		Element subnode = node.element( "generator" );		if ( subnode != null ) {			model.setIdentifierGeneratorStrategy( subnode.attributeValue( "class" ) );			Properties params = new Properties();			if ( mappings.getSchemaName() != null ) {				params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );			}			if ( mappings.getCatalogName() != null ) {				params.setProperty( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );			}			Iterator iter = subnode.elementIterator( "param" );			while ( iter.hasNext() ) {				Element childNode = (Element) iter.next();				params.setProperty( childNode.attributeValue( "name" ), childNode.getText() );			}			model.setIdentifierGeneratorProperties( params );		}		model.getTable().setIdentifierValue( model );		// ID UNSAVED-VALUE		Attribute nullValueNode = node.attribute( "unsaved-value" );		if ( nullValueNode != null ) {			model.setNullValue( nullValueNode.getValue() );		}		else {			if ( "assigned".equals( model.getIdentifierGeneratorStrategy() ) ) {				model.setNullValue( "undefined" );			}			else {				model.setNullValue( null );			}		}	}	private static final void makeVersion(Element node, SimpleValue model) {		// VERSION UNSAVED-VALUE		Attribute nullValueNode = node.attribute( "unsaved-value" );		if ( nullValueNode != null ) {			model.setNullValue( nullValueNode.getValue() );		}		else {			model.setNullValue( "undefined" );		}	}	protected static void createClassProperties(Element node, PersistentClass persistentClass,			Mappings mappings, java.util.Map inheritedMetas) throws MappingException {		String entityName = persistentClass.getEntityName();		Table table = persistentClass.getTable();		Iterator iter = node.elementIterator();		while ( iter.hasNext() ) {			Element subnode = (Element) iter.next();			String name = subnode.getName();			String propertyName = subnode.attributeValue( "name" );			CollectionType collectType = CollectionType.collectionTypeFromString( name );			Value value = null;			if ( collectType != null ) {				Collection collection = collectType.create(					subnode,					propertyName,					persistentClass,					mappings );				mappings.addCollection( collection );				value = collection;			}			else if ( "many-to-one".equals( name ) ) {				value = new ManyToOne( table );				bindManyToOne( subnode, (ManyToOne) value, propertyName, true, mappings );			}			else if ( "any".equals( name ) ) {				value = new Any( table );				bindAny( subnode, (Any) value, true, mappings );			}			else if ( "one-to-one".equals( name ) ) {				OneToOne oneToOne = new OneToOne( table, persistentClass.getKey() );				bindOneToOne( subnode, oneToOne, true, mappings );				value = oneToOne;			}			else if ( "property".equals( name ) ) {				value = new SimpleValue( table );				bindSimpleValue( subnode, (SimpleValue) value, true, propertyName, mappings );			}			else if ( "component".equals( name )				|| "dynamic-component".equals( name )				|| "properties".equals( name ) ) {				String subpath = StringHelper.qualify( entityName, propertyName );				value = new Component( persistentClass );				bindComponent(					subnode,					(Component) value,					persistentClass.getClassName(),					propertyName,					subpath,					true,					"properties".equals( name ),					mappings,					inheritedMetas );			}			else if ( "query-list".equals( name ) ) {				value = new QueryList( table );				( (QueryList) value ).setQueryName( subnode.attributeValue( "query-ref" ) );			}			else if ( "join".equals( name ) ) {				Join join = new Join();				join.setPersistentClass( persistentClass );				bindJoin( subnode, join, mappings, inheritedMetas );				persistentClass.addJoin( join );			}			else if ( "subclass".equals( name ) ) {				handleSubclass( persistentClass, mappings, subnode, inheritedMetas );			}			else if ( "joined-subclass".equals( name ) ) {				handleJoinedSubclass( persistentClass, mappings, subnode, inheritedMetas );			}			else if ( "union-subclass".equals( name ) ) {				handleUnionSubclass( persistentClass, mappings, subnode, inheritedMetas );			}			else if ( "filter".equals( name ) ) {				parseFilter( subnode, persistentClass, mappings );			}			if ( value != null ) {				persistentClass.addProperty( createProperty( value, propertyName, persistentClass					.getClassName(), subnode, mappings, inheritedMetas ) );			}		}	}	private static Property createProperty(final Value value, final String propertyName,			final String className, final Element subnode, final Mappings mappings,			java.util.Map inheritedMetas) throws MappingException {		value.setTypeUsingReflection( className, propertyName );		// this is done here 'cos we might only know the type here (ugly!)		// TODO: improve this a lot:		if ( value instanceof ToOne ) {			ToOne toOne = (ToOne) value;			String propertyRef = toOne.getReferencedPropertyName();			if ( propertyRef != null ) {				mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef );			}		}		else if ( value instanceof Collection ) {			Collection coll = (Collection) value;			String propertyRef = coll.getReferencedPropertyName();			// not necessarily a *unique* property reference			if ( propertyRef != null ) {				mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );			}		}		value.createForeignKey();		Property prop = new Property();		prop.setValue( value );		bindProperty( subnode, prop, mappings, inheritedMetas );		return prop;	}	private static void handleUnionSubclass(PersistentClass model, Mappings mappings,			Element subnode, java.util.Map inheritedMetas) throws MappingException {		UnionSubclass subclass = new UnionSubclass( model );		bindUnionSubclass( subnode, subclass, mappings, inheritedMetas );		model.addSubclass( subclass );		mappings.addClass( subclass );	}	private static void handleJoinedSubclass(PersistentClass model, Mappings mappings,			Element subnode, java.util.Map inheritedMetas) throws MappingException {		JoinedSubclass subclass = new JoinedSubclass( model );		bindJoinedSubclass( subnode, subclass, mappings, inheritedMetas );		model.addSubclass( subclass );		mappings.addClass( subclass );	}	private static void handleSubclass(PersistentClass model, Mappings mappings, Element subnode,			java.util.Map inheritedMetas) throws MappingException {		Subclass subclass = new SingleTableSubclass( model );		bindSubclass( subnode, subclass, mappings, inheritedMetas );		model.addSubclass( subclass );		mappings.addClass( subclass );	}	/**	 * Called for Lists, arrays, primitive arrays	 */	public static void bindListSecondPass(Element node, List list, java.util.Map classes,			Mappings mappings, java.util.Map inheritedMetas) throws MappingException {		bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas );		Element subnode = node.element( "list-index" );		if ( subnode == null ) subnode = node.element( "index" );		SimpleValue iv = new SimpleValue( list.getCollectionTable() );		bindSimpleValue(			subnode,			iv,			list.isOneToMany(),			IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,			mappings );		iv.setTypeName( "integer" );		list.setIndex( iv );		String baseIndex = subnode.attributeValue( "base" );		if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) );		list.setIndexNodeName( subnode.attributeValue("node") );		if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {			String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();			PersistentClass referenced = mappings.getClass( entityName );			IndexBackref ib = new IndexBackref();			ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" );			ib.setUpdateable( false );			ib.setSelectable( false );			ib.setCollectionRole( list.getRole() );			ib.setValue( list.getIndex() );			// ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()			// ).setNullable(false);			referenced.addProperty( ib );		}	}	public static void bindIdentifierCollectionSecondPass(Element node,			IdentifierCollection collection, java.util.Map persistentClasses, Mappings mappings,			java.util.Map inheritedMetas) throws MappingException {		bindCollectionSecondPass( nod

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -