Java Code Examples for org.hibernate.type.AssociationType#getLHSPropertyName()

The following examples show how to use org.hibernate.type.AssociationType#getLHSPropertyName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join
 *
 * @param associationType The association type for the association that represents the join
 * @param columnQualifier The left-hand side table alias
 * @param propertyIndex The index of the property that represents the association/join
 * @param begin The index for any nested (composites) attributes
 * @param lhsPersister The persister for the left-hand side of the association/join
 * @param mapping The mapping (typically the SessionFactory).
 *
 * @return The qualified column names.
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType associationType,
		String columnQualifier,
		int propertyIndex,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( associationType.useLHSPrimaryKey() ) {
		return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		final String propertyName = associationType.getLHSPropertyName();
		if ( propertyName == null ) {
			return ArrayHelper.slice(
					toColumns( lhsPersister, columnQualifier, propertyIndex ),
					begin,
					associationType.getColumnSpan( mapping )
			);
		}
		else {
			//bad cast
			return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName );
		}
	}
}
 
Example 2
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Warning:
 * When there are duplicated property names in the subclasses
 * of the class, this method may return the wrong table
 * number for the duplicated subclass property (note that
 * SingleTableEntityPersister defines an overloaded form
 * which takes the entity name.
 */
public int getSubclassPropertyTableNumber(String propertyPath) {
	String rootPropertyName = StringHelper.root(propertyPath);
	Type type = propertyMapping.toType(rootPropertyName);
	if ( type.isAssociationType() ) {
		AssociationType assocType = ( AssociationType ) type;
		if ( assocType.useLHSPrimaryKey() ) {
			// performance op to avoid the array search
			return 0;
		}
		else if ( type.isCollectionType() ) {
			// properly handle property-ref-based associations
			rootPropertyName = assocType.getLHSPropertyName();
		}
	}
	//Enable for HHH-440, which we don't like:
	/*if ( type.isComponentType() && !propertyName.equals(rootPropertyName) ) {
		String unrooted = StringHelper.unroot(propertyName);
		int idx = ArrayHelper.indexOf( getSubclassColumnClosure(), unrooted );
		if ( idx != -1 ) {
			return getSubclassColumnTableNumberClosure()[idx];
		}
	}*/
	int index = ArrayHelper.indexOf( getSubclassPropertyNameClosure(), rootPropertyName); //TODO: optimize this better!
	return index==-1 ? 0 : getSubclassPropertyTableNumber(index);
}
 
Example 3
Source File: JoinHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Get the aliased columns of the owning entity which are to 
 * be used in the join
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType type, 
		String alias, 
		int property, 
		int begin, 
		OuterJoinLoadable lhsPersister,
		Mapping mapping
) {
	if ( type.useLHSPrimaryKey() ) {
		return StringHelper.qualify( alias, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		String propertyName = type.getLHSPropertyName();
		if (propertyName==null) {
			return ArrayHelper.slice( 
					lhsPersister.toColumns(alias, property), 
					begin, 
					type.getColumnSpan(mapping) 
				);
		}
		else {
			return ( (PropertyMapping) lhsPersister ).toColumns(alias, propertyName); //bad cast
		}
	}
}
 
Example 4
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Warning:
 * When there are duplicated property names in the subclasses
 * of the class, this method may return the wrong table
 * number for the duplicated subclass property (note that
 * SingleTableEntityPersister defines an overloaded form
 * which takes the entity name.
 */
public int getSubclassPropertyTableNumber(String propertyPath) {
	String rootPropertyName = StringHelper.root( propertyPath );
	Type type = propertyMapping.toType( rootPropertyName );
	if ( type.isAssociationType() ) {
		AssociationType assocType = (AssociationType) type;
		if ( assocType.useLHSPrimaryKey() ) {
			// performance op to avoid the array search
			return 0;
		}
		else if ( type.isCollectionType() ) {
			// properly handle property-ref-based associations
			rootPropertyName = assocType.getLHSPropertyName();
		}
	}
	//Enable for HHH-440, which we don't like:
	/*if ( type.isComponentType() && !propertyName.equals(rootPropertyName) ) {
		String unrooted = StringHelper.unroot(propertyName);
		int idx = ArrayHelper.indexOf( getSubclassColumnClosure(), unrooted );
		if ( idx != -1 ) {
			return getSubclassColumnTableNumberClosure()[idx];
		}
	}*/
	int index = ArrayHelper.indexOf(
			getSubclassPropertyNameClosure(),
			rootPropertyName
	); //TODO: optimize this better!
	return index == -1 ? 0 : getSubclassPropertyTableNumber( index );
}
 
Example 5
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the columns of the owning entity which are to be used in the join
 *
 * @param type The type representing the join
 * @param property The property index for the association type
 * @param begin ?
 * @param lhsPersister The persister for the left-hand-side of the join
 * @param mapping The mapping object (typically the SessionFactory)
 *
 * @return The columns for the left-hand-side of the join
 */
public static String[] getLHSColumnNames(
		AssociationType type,
		int property,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( type.useLHSPrimaryKey() ) {
		//return lhsPersister.getSubclassPropertyColumnNames(property);
		return lhsPersister.getIdentifierColumnNames();
	}
	else {
		final String propertyName = type.getLHSPropertyName();
		if ( propertyName == null ) {
			//slice, to get the columns for this component
			//property
			return ArrayHelper.slice(
					property < 0
							? lhsPersister.getIdentifierColumnNames()
							: lhsPersister.getSubclassPropertyColumnNames( property ),
					begin,
					type.getColumnSpan( mapping )
			);
		}
		else {
			//property-refs for associations defined on a
			//component are not supported, so no need to slice
			return lhsPersister.getPropertyColumnNames( propertyName );
		}
	}
}
 
Example 6
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the name of the table that is the left-hand-side of the join.  Usually this is the
 * name of the main table from the left-hand-side persister.  But that is not the case with property-refs.
 *
 * @param type The type representing the join
 * @param propertyIndex The property index for the type
 * @param lhsPersister The persister for the left-hand-side of the join
 *
 * @return The table name
 */
public static String getLHSTableName(
		AssociationType type,
		int propertyIndex,
		OuterJoinLoadable lhsPersister) {
	if ( type.useLHSPrimaryKey() || propertyIndex < 0 ) {
		return lhsPersister.getTableName();
	}
	else {
		final String propertyName = type.getLHSPropertyName();
		if ( propertyName == null ) {
			//if there is no property-ref, assume the join
			//is to the subclass table (ie. the table of the
			//subclass that the association belongs to)
			return lhsPersister.getSubclassPropertyTableName( propertyIndex );
		}
		else {
			//handle a property-ref
			String propertyRefTable = lhsPersister.getPropertyTableName( propertyName );
			if ( propertyRefTable == null ) {
				//it is possible that the tree-walking in OuterJoinLoader can get to
				//an association defined by a subclass, in which case the property-ref
				//might refer to a property defined on a subclass of the current class
				//in this case, the table name is not known - this temporary solution 
				//assumes that the property-ref refers to a property of the subclass
				//table that the association belongs to (a reasonable guess)
				//TODO: fix this, add: OuterJoinLoadable.getSubclassPropertyTableName(String propertyName)
				propertyRefTable = lhsPersister.getSubclassPropertyTableName( propertyIndex );
			}
			return propertyRefTable;
		}
	}
}
 
Example 7
Source File: JoinHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the columns of the owning entity which are to 
 * be used in the join
 */
public static String[] getLHSColumnNames(
		AssociationType type, 
		int property, 
		int begin, 
		OuterJoinLoadable lhsPersister,
		Mapping mapping
) {
	if ( type.useLHSPrimaryKey() ) {
		//return lhsPersister.getSubclassPropertyColumnNames(property);
		return lhsPersister.getIdentifierColumnNames();
	}
	else {
		String propertyName = type.getLHSPropertyName();
		if (propertyName==null) {
			//slice, to get the columns for this component
			//property
			return ArrayHelper.slice( 
					lhsPersister.getSubclassPropertyColumnNames(property),
					begin, 
					type.getColumnSpan(mapping) 
				);
		}
		else {
			//property-refs for associations defined on a
			//component are not supported, so no need to slice
			return lhsPersister.getPropertyColumnNames(propertyName);
		}
	}
}
 
Example 8
Source File: JoinHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getLHSTableName(
	AssociationType type, 
	int property, 
	OuterJoinLoadable lhsPersister
) {
	if ( type.useLHSPrimaryKey() ) {
		return lhsPersister.getTableName();
	}
	else {
		String propertyName = type.getLHSPropertyName();
		if (propertyName==null) {
			//if there is no property-ref, assume the join
			//is to the subclass table (ie. the table of the
			//subclass that the association belongs to)
			return lhsPersister.getSubclassPropertyTableName(property);
		}
		else {
			//handle a property-ref
			String propertyRefTable = lhsPersister.getPropertyTableName(propertyName);
			if (propertyRefTable==null) {
				//it is possible that the tree-walking in OuterJoinLoader can get to
				//an association defined by a subclass, in which case the property-ref
				//might refer to a property defined on a subclass of the current class
				//in this case, the table name is not known - this temporary solution 
				//assumes that the property-ref refers to a property of the subclass
				//table that the association belongs to (a reasonable guess)
				//TODO: fix this, add: OuterJoinLoadable.getSubclassPropertyTableName(String propertyName)
				propertyRefTable = lhsPersister.getSubclassPropertyTableName(property);
			}
			return propertyRefTable;
		}
	}
}