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

📄 ejb3joincolumn.java

📁 hibernate3.2.6源码和jar包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//$Id: Ejb3JoinColumn.java 14389 2008-03-04 21:22:12Z epbernard $package org.hibernate.cfg;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.persistence.JoinColumn;import javax.persistence.PrimaryKeyJoinColumn;import org.hibernate.AnnotationException;import org.hibernate.MappingException;import org.hibernate.annotations.common.util.StringHelper;import org.hibernate.mapping.Column;import org.hibernate.mapping.Join;import org.hibernate.mapping.PersistentClass;import org.hibernate.mapping.SimpleValue;import org.hibernate.mapping.Table;import org.hibernate.mapping.Value;/** * Wrap state of an EJB3 @JoinColumn annotation * and build the Hibernate column mapping element * * @author Emmanuel Bernard */public class Ejb3JoinColumn extends Ejb3Column {	/**	 * property name repated to this column	 */	private String referencedColumn;	private String mappedBy;	//property name on the mapped by side if any	private String mappedByPropertyName;	//table name on the mapped by side if any	private String mappedByTableName;	private String mappedByEntityName;	//FIXME hacky solution to get the information at proeprty ref resolution	public String getManyToManyOwnerSideEntityName() {		return manyToManyOwnerSideEntityName;	}	public void setManyToManyOwnerSideEntityName(String manyToManyOwnerSideEntityName) {		this.manyToManyOwnerSideEntityName = manyToManyOwnerSideEntityName;	}	private String manyToManyOwnerSideEntityName;	public void setReferencedColumn(String referencedColumn) {		this.referencedColumn = referencedColumn;	}	public String getMappedBy() {		return mappedBy;	}	public void setMappedBy(String mappedBy) {		this.mappedBy = mappedBy;	}	//Due to @AnnotationOverride overriding rules, I don't want the constructor to be public	private Ejb3JoinColumn() {		setMappedBy( BinderHelper.ANNOTATION_STRING_DEFAULT );	}	//Due to @AnnotationOverride overriding rules, I don't want the constructor to be public	//TODO get rid of it and use setters	private Ejb3JoinColumn(			String sqlType,			String name,			boolean nullable,			boolean unique,			boolean insertable,			boolean updatable,			String referencedColumn,			String secondaryTable,			Map<String, Join> joins,			PropertyHolder propertyHolder,			String propertyName,			String mappedBy,			boolean isImplicit,			ExtendedMappings mappings	) {		super();		setImplicit( isImplicit );		setSqlType( sqlType );		setLogicalColumnName( name );		setNullable( nullable );		setUnique( unique );		setInsertable( insertable );		setUpdatable( updatable );		setSecondaryTableName( secondaryTable );		setPropertyHolder( propertyHolder );		setJoins( joins );		setMappings( mappings );		setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) );		bind();		this.referencedColumn = referencedColumn;		this.mappedBy = mappedBy;	}	public String getReferencedColumn() {		return referencedColumn;	}	public static Ejb3JoinColumn[] buildJoinColumns(			JoinColumn[] anns,			String mappedBy, Map<String, Join> joins,			PropertyHolder propertyHolder,			String propertyName,			ExtendedMappings mappings	) {		JoinColumn[] actualColumns = propertyHolder.getOverriddenJoinColumn(				StringHelper.qualify( propertyHolder.getPath(), propertyName )		);		if ( actualColumns == null ) actualColumns = anns;		if ( actualColumns == null || actualColumns.length == 0 ) {			return new Ejb3JoinColumn[] {					buildJoinColumn( (JoinColumn) null, mappedBy, joins, propertyHolder, propertyName, mappings )			};		}		else {			int size = actualColumns.length;			Ejb3JoinColumn[] result = new Ejb3JoinColumn[size];			for (int index = 0; index < size; index++) {				result[index] = buildJoinColumn(						actualColumns[index],						mappedBy,						joins,						propertyHolder,						propertyName,						mappings				);			}			return result;		}	}	/**	 * build join column for SecondaryTables	 */	private static Ejb3JoinColumn buildJoinColumn(			JoinColumn ann,			String mappedBy, Map<String, Join> joins,			PropertyHolder propertyHolder,			String propertyName,			ExtendedMappings mappings	) {		if ( ann != null ) {			if ( BinderHelper.isDefault( mappedBy ) ) {				throw new AnnotationException(						"Illegal attempt to define a @JoinColumn with a mappedBy association: "								+ BinderHelper.getRelativePath( propertyHolder, propertyName )				);			}			Ejb3JoinColumn joinColumn = new Ejb3JoinColumn();			joinColumn.setJoinAnnotation( ann, null );			joinColumn.setJoins( joins );			joinColumn.setPropertyHolder( propertyHolder );			joinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) );			joinColumn.setImplicit( false );			joinColumn.setMappings( mappings );			joinColumn.bind();			return joinColumn;		}		else {			Ejb3JoinColumn joinColumn = new Ejb3JoinColumn();			joinColumn.setMappedBy( mappedBy );			joinColumn.setJoins( joins );			joinColumn.setPropertyHolder( propertyHolder );			joinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) );			joinColumn.setImplicit( true );			joinColumn.setMappings( mappings );			joinColumn.bind();			return joinColumn;		}	}	//FIXME default name still useful in association table	public void setJoinAnnotation(JoinColumn annJoin, String defaultName) {		if ( annJoin == null ) {			setImplicit( true );		}		else {			setImplicit( false );			if ( !BinderHelper.isDefault( annJoin.columnDefinition() ) ) setSqlType( annJoin.columnDefinition() );			if ( !BinderHelper.isDefault( annJoin.name() ) ) setLogicalColumnName( annJoin.name() );			setNullable( annJoin.nullable() );			setUnique( annJoin.unique() );			setInsertable( annJoin.insertable() );			setUpdatable( annJoin.updatable() );			setReferencedColumn( annJoin.referencedColumnName() );			setSecondaryTableName( annJoin.table() );		}	}	/**	 * Build JoinColumn for a JOINED hierarchy	 */	public static Ejb3JoinColumn buildJoinColumn(			PrimaryKeyJoinColumn pkJoinAnn,			JoinColumn joinAnn,			Value identifier,			Map<String, Join> joins,			PropertyHolder propertyHolder, ExtendedMappings mappings	) {		Column col = (Column) identifier.getColumnIterator().next();		String defaultName = mappings.getLogicalColumnName( col.getName(), identifier.getTable() );		if ( pkJoinAnn != null || joinAnn != null ) {			String colName;			String columnDefinition;			String referencedColumnName;			if ( pkJoinAnn != null ) {				colName = pkJoinAnn.name();				columnDefinition = pkJoinAnn.columnDefinition();				referencedColumnName = pkJoinAnn.referencedColumnName();			}			else {				colName = joinAnn.name();				columnDefinition = joinAnn.columnDefinition();				referencedColumnName = joinAnn.referencedColumnName();			}			String sqlType = "".equals( columnDefinition ) ? null : columnDefinition;			String name = "".equals( colName ) ? defaultName : colName;			return new Ejb3JoinColumn(					sqlType,					name, false, false,					true, true,					referencedColumnName,					null, joins,					propertyHolder, null, null, false, mappings			);		}		else {			return new Ejb3JoinColumn(					(String) null, defaultName,					false, false, true, true, null, (String) null,					joins, propertyHolder, null, null, true, mappings			);		}	}	/**	 * Override persistent class on oneToMany Cases for late settings	 * Must only be used on second level pass binding	 */	public void setPersistentClass(PersistentClass persistentClass, Map<String, Join> joins) {		//FIXME shouldn't we deduce the classname from the persistentclasS?		this.propertyHolder = PropertyHolderBuilder.buildPropertyHolder( persistentClass, joins, getMappings() );	}	public static void checkIfJoinColumn(Object columns, PropertyHolder holder, PropertyData property) {		if ( !( columns instanceof Ejb3JoinColumn[] ) ) {			throw new AnnotationException(					"@Column cannot be used on an association property: "

⌨️ 快捷键说明

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