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

📄 hbmbinder.java

📁 hibernate-3.0.5 中文文档
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		else {			return mappings.getNamingStrategy().tableName( tableNameNode.getValue() );		}	}	public static void bindJoinedSubclass(Element node, JoinedSubclass joinedSubclass,			Mappings mappings, java.util.Map inheritedMetas) throws MappingException {		bindClass( node, joinedSubclass, mappings, inheritedMetas );		inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from																	// <joined-subclass>		// joined subclasses		if ( joinedSubclass.getEntityPersisterClass() == null ) {			joinedSubclass.getRootClass().setEntityPersisterClass(				JoinedSubclassEntityPersister.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.addTable( 			schema, 			catalog, 			getClassTableName( joinedSubclass, node, mappings ), 			getSubselect( node ), 			false );		joinedSubclass.setTable( mytable );		bindComment(mytable, node);		log.info( "Mapping joined-subclass: "			+ joinedSubclass.getEntityName()			+ " -> "			+ joinedSubclass.getTable().getName() );		// KEY		Element keyNode = node.element( "key" );		SimpleValue key = new DependantValue( mytable, joinedSubclass.getIdentifier() );		joinedSubclass.setKey( key );		key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );		bindSimpleValue( keyNode, key, false, joinedSubclass.getEntityName(), mappings );		// model.getKey().setType( new Type( model.getIdentifier() ) );		joinedSubclass.createPrimaryKey();		joinedSubclass.createForeignKey();		// CHECK		Attribute chNode = node.attribute( "check" );		if ( chNode != null ) mytable.addCheckConstraint( chNode.getValue() );		// properties		createClassProperties( node, joinedSubclass, mappings, inheritedMetas );	}	private static void bindJoin(Element node, Join join, Mappings mappings,			java.util.Map inheritedMetas) throws MappingException {		PersistentClass persistentClass = join.getPersistentClass();		String path = persistentClass.getEntityName();		// TABLENAME		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, 			getClassTableName( persistentClass, node, mappings ), 			getSubselect( node ), 			false );		join.setTable( table );		bindComment(table, node);		Attribute fetchNode = node.attribute( "fetch" );		if ( fetchNode != null )			join.setSequentialSelect( "select".equals( fetchNode.getValue() ) );		Attribute invNode = node.attribute( "inverse" );		if ( invNode != null ) join.setInverse( "true".equals( invNode.getValue() ) );		Attribute nullNode = node.attribute( "optional" );		if ( nullNode != null ) join.setOptional( "true".equals( nullNode.getValue() ) );		log.info( "Mapping class join: "			+ persistentClass.getEntityName()			+ " -> "			+ join.getTable().getName() );		// KEY		Element keyNode = node.element( "key" );		SimpleValue key = new DependantValue( table, persistentClass.getIdentifier() );		join.setKey( key );		key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );		bindSimpleValue( keyNode, key, false, persistentClass.getEntityName(), mappings );		// join.getKey().setType( new Type( lazz.getIdentifier() ) );		join.createPrimaryKey();		join.createForeignKey();		// PROPERTIES		Iterator iter = node.elementIterator();		while ( iter.hasNext() ) {			Element subnode = (Element) iter.next();			String name = subnode.getName();			String propertyName = subnode.attributeValue( "name" );			Value value = null;			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 ( "property".equals( name ) ) {				value = new SimpleValue( table );				bindSimpleValue( subnode, (SimpleValue) value, true, propertyName, mappings );			}			else if ( "component".equals( name ) || "dynamic-component".equals( name ) ) {				String subpath = StringHelper.qualify( path, propertyName );				value = new Component( join );				bindComponent(					subnode,					(Component) value,					join.getPersistentClass().getClassName(),					propertyName,					subpath,					true,					false,					mappings,					inheritedMetas );			}			if ( value != null ) {				Property prop = createProperty( value, propertyName, persistentClass					.getEntityName(), subnode, mappings, inheritedMetas );				prop.setOptional( join.isOptional() );				join.addProperty( prop );			}		}		// CUSTOM SQL		handleCustomSQL( node, join );	}	public static void bindColumns(final Element node, final SimpleValue simpleValue,			final boolean isNullable, final boolean autoColumn, final String propertyPath,			final Mappings mappings) throws MappingException {		Table table = simpleValue.getTable();		// COLUMN(S)		Attribute columnAttribute = node.attribute( "column" );		if ( columnAttribute == null ) {			Iterator iter = node.elementIterator();			int count = 0;			while ( iter.hasNext() ) {				Element columnElement = (Element) iter.next();				if ( columnElement.getName().equals( "column" ) ) {					Column column = new Column();					column.setValue( simpleValue );					column.setTypeIndex( count++ );					bindColumn( columnElement, column, isNullable );					column.setName( mappings.getNamingStrategy().columnName(						columnElement.attributeValue( "name" ) ) );					if ( table != null ) table.addColumn( column ); // table=null -> an association																	// - fill it in later					simpleValue.addColumn( column );					// column index					bindIndex( columnElement.attribute( "index" ), table, column );					bindIndex( node.attribute( "index" ), table, column );					//column unique-key					bindUniqueKey( columnElement.attribute( "unique-key" ), table, column );					bindUniqueKey( node.attribute( "unique-key" ), table, column );				}				else if ( columnElement.getName().equals( "formula" ) ) {					Formula formula = new Formula();					formula.setFormula( columnElement.getText() );					simpleValue.addFormula( formula );				}			}		}		else {			if ( node.elementIterator( "column" ).hasNext() ) {				throw new MappingException(					"column attribute may not be used together with <column> subelement" );			}			if ( node.elementIterator( "formula" ).hasNext() ) {				throw new MappingException(					"column attribute may not be used together with <formula> subelement" );			}			Column column = new Column();			column.setValue( simpleValue );			bindColumn( node, column, isNullable );			column.setName( mappings.getNamingStrategy().columnName( columnAttribute.getValue() ) );			if ( table != null ) table.addColumn( column ); // table=null -> an association - fill															// it in later			simpleValue.addColumn( column );			bindIndex( node.attribute( "index" ), table, column );			bindUniqueKey( node.attribute( "unique-key" ), table, column );		}		if ( autoColumn && simpleValue.getColumnSpan() == 0 ) {			Column col = new Column();			col.setValue( simpleValue );			bindColumn( node, col, isNullable );			col.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) );			simpleValue.getTable().addColumn( col );			simpleValue.addColumn( col );			bindIndex( node.attribute( "index" ), table, col );			bindUniqueKey( node.attribute( "unique-key" ), table, col );		}	}	private static void bindIndex(Attribute indexAttribute, Table table, Column column) {		if ( indexAttribute != null && table != null ) {			StringTokenizer tokens = new StringTokenizer( indexAttribute.getValue(), ", " );			while ( tokens.hasMoreTokens() ) {				table.getOrCreateIndex( tokens.nextToken() ).addColumn( column );			}		}	}	private static void bindUniqueKey(Attribute uniqueKeyAttribute, Table table, Column column) {		if ( uniqueKeyAttribute != null && table != null ) {			StringTokenizer tokens = new StringTokenizer( uniqueKeyAttribute.getValue(), ", " );			while ( tokens.hasMoreTokens() ) {				table.getOrCreateUniqueKey( tokens.nextToken() ).addColumn( column );			}		}	}	// automatically makes a column with the default name if none is specifed by XML	public static void bindSimpleValue(Element node, SimpleValue simpleValue, boolean isNullable,			String path, Mappings mappings) throws MappingException {		bindSimpleValueType( node, simpleValue, mappings );		bindColumnsOrFormula( node, simpleValue, path, isNullable, mappings );		Attribute fkNode = node.attribute( "foreign-key" );		if ( fkNode != null ) simpleValue.setForeignKeyName( fkNode.getValue() );	}	private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings)			throws MappingException {		String typeName = null;		Properties parameters = new Properties();		Attribute typeNode = node.attribute( "type" );		if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any		if ( typeNode != null ) typeName = typeNode.getValue();		Element typeChild = node.element( "type" );		if ( typeName == null && typeChild != null ) {			typeName = typeChild.attribute( "name" ).getValue();			Iterator typeParameters = typeChild.elementIterator( "param" );			while ( typeParameters.hasNext() ) {				Element paramElement = (Element) typeParameters.next();				parameters.setProperty( paramElement.attributeValue( "name" ), paramElement					.getTextTrim() );			}		}		TypeDef typeDef = mappings.getTypeDef( typeName );		if ( typeDef != null ) {			typeName = typeDef.getTypeClass();			// parameters on the property mapping should			// override parameters in the typedef			Properties allParameters = new Properties();			allParameters.putAll( typeDef.getParameters() );			allParameters.putAll( parameters );			parameters = allParameters;		}		if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters );		if ( typeName != null ) simpleValue.setTypeName( typeName );	}	public static void bindProperty(Element node, Property property, Mappings mappings,			java.util.Map inheritedMetas) throws MappingException {				String propName = node.attributeValue( "name" );		property.setName( propName );		String nodeName = node.attributeValue( "node" );		if (nodeName==null) nodeName = propName;		property.setNodeName( nodeName );				// TODO:		//Type type = model.getValue().getType(); 		//if (type==null) throw new MappingException(		//"Could not determine a property type for: " + model.getName() );				Attribute accessNode = node.attribute( "access" );		if ( accessNode != null ) {			property.setPropertyAccessorName( accessNode.getValue() );		}		else if ( node.getName().equals( "properties" ) ) {			property.setPropertyAccessorName( "embedded" );		}		else {			property.setPropertyAccessorName( mappings.getDefaultAccess() );		}		Attribute cascadeNode = node.attribute( "cascade" );		property.setCascade( cascadeNode == null ? mappings.getDefaultCascade() : cascadeNode			.getValue() );		Attribute updateNode = node.attribute( "update" );		property.setUpdateable( updateNode == null || "true".equals( updateNode.getValue() ) );		Attribute insertNode = node.attribute( "insert" );		property.setInsertable( insertNode == null || "true".equals( insertNode.getValue() ) );		Attribute lockNode = node.attribute( "optimistic-lock" );		property.setOptimisticLocked( lockNode == null || "true".equals( lockNode.getValue() ) );		boolean isLazyable = "property".equals( node.getName() )			|| "component".equals( node.getName() )			|| "many-to-one".equals( node.getName() )			|| "one-to-one".equals( node.getName() )			|| "any".equals( node.getName() );		if ( isLazyable ) {			Attribute lazyNode = node.attribute( "lazy" );			property.setLazy( lazyNode != null && "true".equals( lazyNode.getValue() ) );		}		if ( log.isDebugEnabled() ) {			String msg = "Mapped property: " + property.getName();			String columns = columns( property.getValue() );			if ( columns.length() > 0 ) msg += " -> " + columns;			// TODO: this fails if we run with debug on!			// if ( model.getType()!=null ) msg += ", type: " + model.getType().getName();			log.debug( msg );		}		property.setMetaAttributes( getMetas( node, inheritedMetas ) );	}	private static String columns(Value val) {		StringBuffer columns = new StringBuffer();		Iterator iter = val.getColumnIterator();		while ( iter.hasNext() ) {			columns.append( ( (Selectable) iter.next() ).getText() );			if ( iter.hasNext() ) columns.append( ", " );		}		return columns.toString();	}	/**	 * Called for all collections	 */	public static void bindCollection(Element node, Collection collection, String className,			String path, Mappings mappings) throws MappingException {		// ROLENAME		collection.setRole( StringHelper.qualify( className, path ) );		Attribute inverseNode = node.attribute( "inverse" );

⌨️ 快捷键说明

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