Java Code Examples for org.hibernate.type.Type.isAssociationType()

The following are Jave code examples for showing how to use isAssociationType() of the org.hibernate.type.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 6 votes
@Override
public void finishingCollectionElements(CollectionElementDefinition elementDefinition) {
	final Type elementType = elementDefinition.getType();

	if ( elementType.isAnyType() ) {
		// nothing to do because the element graph was not pushed in #startingCollectionElement..
	}
	else if ( elementType.isComponentType() || elementType.isAssociationType()) {
		// pop it from the stack
		final ExpandingFetchSource popped = popFromStack();

		// validation
		if ( ! CollectionFetchableElement.class.isInstance( popped ) ) {
			throw new WalkingException( "Mismatched FetchSource from stack on pop" );
		}
	}

	log.tracef(
			"%s Finished collection element graph : %s",
			StringHelper.repeat( "<<", fetchSourceStack.size() ),
			elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);
}
 
Example 2
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 6 votes
@Override
public boolean startingAttribute(AttributeDefinition attributeDefinition) {
	log.tracef(
			"%s Starting attribute %s",
			StringHelper.repeat( ">>", fetchSourceStack.size() ),
			attributeDefinition
	);

	final Type attributeType = attributeDefinition.getType();

	final boolean isComponentType = attributeType.isComponentType();
	final boolean isAssociationType = attributeType.isAssociationType();
	final boolean isBasicType = ! ( isComponentType || isAssociationType );
	currentPropertyPath = currentPropertyPath.append( attributeDefinition.getName() );
	if ( isBasicType ) {
		return true;
	}
	else if ( isAssociationType ) {
		// also handles any type attributes...
		return handleAssociationAttribute( (AssociationAttributeDefinition) attributeDefinition );
	}
	else {
		return handleCompositeAttribute( attributeDefinition );
	}
}
 
Example 3
Project: lams   File: AbstractEntityPersister.java   View Source Code Vote up 6 votes
/**
 * 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 4
Project: lams   File: PropertyFactory.java   View Source Code Vote up 6 votes
private static NonIdentifierAttributeNature decode(Type type) {
	if ( type.isAssociationType() ) {
		AssociationType associationType = (AssociationType) type;

		if ( type.isComponentType() ) {
			// an any type is both an association and a composite...
			return NonIdentifierAttributeNature.ANY;
		}

		return type.isCollectionType()
				? NonIdentifierAttributeNature.COLLECTION
				: NonIdentifierAttributeNature.ENTITY;
	}
	else {
		if ( type.isComponentType() ) {
			return NonIdentifierAttributeNature.COMPOSITE;
		}

		return NonIdentifierAttributeNature.BASIC;
	}
}
 
Example 5
Project: lams   File: MapEntryNode.java   View Source Code Vote up 6 votes
private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
	AliasGenerator aliasGenerator = new LocalAliasGenerator( 0 );
	appendSelectExpressions( collectionPersister.getIndexColumnNames(), selections, aliasGenerator );
	Type keyType = collectionPersister.getIndexType();
	if ( keyType.isAssociationType() ) {
		EntityType entityType = (EntityType) keyType;
		Queryable keyEntityPersister = (Queryable) sfi().getEntityPersister(
				entityType.getAssociatedEntityName( sfi() )
		);
		SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(
				collectionTableAlias(),
				null,
				false
		);
		appendSelectExpressions( fragment, selections, aliasGenerator );
	}
}
 
Example 6
Project: lams   File: MapEntryNode.java   View Source Code Vote up 6 votes
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
	AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 );
	appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator );
	Type valueType = collectionPersister.getElementType();
	if ( valueType.isAssociationType() ) {
		EntityType valueEntityType = (EntityType) valueType;
		Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(
				valueEntityType.getAssociatedEntityName( sfi() )
		);
		SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(
				elementTableAlias(),
				null,
				false
		);
		appendSelectExpressions( fragment, selections, aliasGenerator );
	}
}
 
Example 7
Project: lams   File: Example.java   View Source Code Vote up 5 votes
@SuppressWarnings("SimplifiableIfStatement")
private boolean isPropertyIncluded(Object value, String name, Type type) {
	if ( excludedProperties.contains( name ) ) {
		// was explicitly excluded
		return false;
	}

	if ( type.isAssociationType() ) {
		// associations are implicitly excluded
		return false;
	}

	return selector.include( value, name, type );
}
 
Example 8
Project: lams   File: LoadQueryJoinAndFetchProcessor.java   View Source Code Vote up 5 votes
private AssociationType getJoinedAssociationTypeOrNull(Join join) {

		if ( !JoinDefinedByMetadata.class.isInstance( join ) ) {
			return null;
		}
		final Type joinedType = ( (JoinDefinedByMetadata) join ).getJoinedPropertyType();
		return joinedType.isAssociationType()
				? (AssociationType) joinedType
				: null;
	}
 
Example 9
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 5 votes
@Override
public void startingCollectionElements(CollectionElementDefinition elementDefinition) {
	final Type elementType = elementDefinition.getType();
	log.tracef(
			"%s Starting collection element graph : %s",
			StringHelper.repeat( ">>", fetchSourceStack.size() ),
			elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);

	final CollectionReference collectionReference = currentCollection();
	final CollectionFetchableElement elementGraph = collectionReference.getElementGraph();

	if ( elementType.isAssociationType() || elementType.isComponentType() ) {
		if ( elementGraph == null ) {
			throw new IllegalStateException(
					"CollectionReference did not return an expected element graph : " +
							elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
		if ( !elementType.isAnyType() ) {
			pushToStack( (ExpandingFetchSource) elementGraph );
		}
	}
	else {
		if ( elementGraph != null ) {
			throw new IllegalStateException(
					"CollectionReference returned an unexpected element graph : " +
							elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
	}
}
 
Example 10
Project: lams   File: IdentNode.java   View Source Code Vote up 5 votes
private DereferenceType resolveAsNakedPropertyRef() {
	FromElement fromElement = locateSingleFromElement();
	if (fromElement == null) {
		return DereferenceType.UNKNOWN;
	}
	Queryable persister = fromElement.getQueryable();
	if (persister == null) {
		return DereferenceType.UNKNOWN;
	}
	Type propertyType = getNakedPropertyType(fromElement);
	if (propertyType == null) {
		// assume this ident's text does *not* refer to a property on the given persister
		return DereferenceType.UNKNOWN;
	}

	if ((propertyType.isComponentType() || propertyType.isAssociationType() )) {
		return DereferenceType.COMPONENT_REF;
	}

	setFromElement(fromElement);
	String property = getText();
	String[] columns = getWalker().isSelectStatement()
			? persister.toColumns(fromElement.getTableAlias(), property)
			: persister.toColumns(property);
	String text = StringHelper.join(", ", columns);
	setText(columns.length == 1 ? text : "(" + text + ")");
	setType(SqlTokenTypes.SQL_TOKEN);

	// these pieces are needed for usage in select clause
	super.setDataType(propertyType);
	nakedPropertyRef = true;

	return DereferenceType.PROPERTY_REF;
}
 
Example 11
Project: lams   File: MetamodelGraphWalker.java   View Source Code Vote up 5 votes
private void visitCollectionIndex(CollectionDefinition collectionDefinition) {
	final CollectionIndexDefinition collectionIndexDefinition = collectionDefinition.getIndexDefinition();
	if ( collectionIndexDefinition == null ) {
		return;
	}

	strategy.startingCollectionIndex( collectionIndexDefinition );

	log.debug( "Visiting index for collection :  " + currentPropertyPath.getFullPath() );
	currentPropertyPath = currentPropertyPath.append( "<index>" );

	try {
		final Type collectionIndexType = collectionIndexDefinition.getType();
		if ( collectionIndexType.isAnyType() ) {
			visitAnyDefinition( collectionIndexDefinition.toAnyMappingDefinition() );
		}
		else if ( collectionIndexType.isComponentType() ) {
			visitCompositeDefinition( collectionIndexDefinition.toCompositeDefinition() );
		}
		else if ( collectionIndexType.isAssociationType() ) {
			visitEntityDefinition( collectionIndexDefinition.toEntityDefinition() );
		}
	}
	finally {
		currentPropertyPath = currentPropertyPath.getParent();
	}

	strategy.finishingCollectionIndex( collectionIndexDefinition );
}
 
Example 12
Project: lams   File: PropertyFactory.java   View Source Code Vote up 5 votes
@Deprecated
public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) {
	final Type type = property.getValue().getType();

	// we need to dirty check collections, since they can cause an owner
	// version number increment

	// we need to dirty check many-to-ones with not-found="ignore" in order
	// to update the cache (not the database), since in this case a null
	// entity reference can lose information

	boolean alwaysDirtyCheck = type.isAssociationType() &&
			( (AssociationType) type ).isAlwaysDirtyChecked();

	return new StandardProperty(
			property.getName(),
			type,
			lazyAvailable && property.isLazy(),
			property.isInsertable(),
			property.isUpdateable(),
			property.getValueGenerationStrategy(),
			property.isOptional(),
			alwaysDirtyCheck || property.isUpdateable(),
			property.isOptimisticLocked(),
			property.getCascadeStyle(),
			property.getValue().getFetchMode()
	);
}
 
Example 13
Project: lams   File: JoinWalker.java   View Source Code Vote up 4 votes
/**
 * For a collection role, return a list of associations to be fetched by outerjoin
 */
private void walkCollectionTree(
		final QueryableCollection persister,
		final String alias,
		final PropertyPath path,
		final int currentDepth)	throws MappingException {

	if ( persister.isOneToMany() ) {
		walkEntityTree(
				(OuterJoinLoadable) persister.getElementPersister(),
				alias,
				path,
				currentDepth
			);
	}
	else {
		Type type = persister.getElementType();
		if ( type.isAssociationType() ) {
			// a many-to-many;
			// decrement currentDepth here to allow join across the association table
			// without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit)
			AssociationType associationType = (AssociationType) type;
			String[] aliasedLhsColumns = persister.getElementColumnNames(alias);
			String[] lhsColumns = persister.getElementColumnNames();
			// if the current depth is 0, the root thing being loaded is the
			// many-to-many collection itself.  Here, it is alright to use
			// an inner join...
			boolean useInnerJoin = currentDepth == 0;
			final JoinType joinType = getJoinType(
					associationType,
					persister.getFetchMode(),
					path,
					persister.getTableName(),
					lhsColumns,
					!useInnerJoin,
					currentDepth - 1, 
					null //operations which cascade as far as the collection also cascade to collection elements
			);
			addAssociationToJoinTreeIfNecessary(
					associationType,
					aliasedLhsColumns,
					alias,
					path,
					currentDepth - 1,
					joinType
				);
		}
		else if ( type.isComponentType() ) {
			walkCompositeElementTree(
					(CompositeType) type,
					persister.getElementColumnNames(),
					persister,
					alias,
					path,
					currentDepth
				);
		}
	}

}
 
Example 14
Project: lams   File: JoinWalker.java   View Source Code Vote up 4 votes
/**
 * Walk the association tree for an entity, adding associations which should
 * be join fetched to the {@link #associations} inst var.  This form is the
 * entry point into the walking for a given entity, starting the recursive
 * calls into {@link #walkEntityTree(org.hibernate.persister.entity.OuterJoinLoadable, String, PropertyPath ,int)}.
 *
 * @param persister The persister representing the entity to be walked.
 * @param alias The (root) alias to use for this entity/persister.
 * @param path The property path to the entity being walked
 * @param currentDepth The current join depth
 * @throws org.hibernate.MappingException ???
 */
private void walkEntityTree(
		final OuterJoinLoadable persister,
		final String alias,
		final PropertyPath path,
		final int currentDepth) throws MappingException {
	int n = persister.countSubclassProperties();
	for ( int i = 0; i < n; i++ ) {
		Type type = persister.getSubclassPropertyType(i);
		if ( type.isAssociationType() ) {
			walkEntityAssociationTree(
				( AssociationType ) type,
				persister,
				i,
				alias,
				path,
				persister.isSubclassPropertyNullable(i),
				currentDepth
			);
		}
		else if ( type.isComponentType() ) {
			walkComponentTree(
					( CompositeType ) type,
					i,
					0,
					persister,
					alias,
					path.append( persister.getSubclassPropertyName(i) ),
					currentDepth
			);
		}
	}

	// if the entity has a composite identifier, see if we need to handle
	// its sub-properties separately
	final Type idType = persister.getIdentifierType();
	if ( idType.isComponentType() ) {
		final CompositeType cidType = (CompositeType) idType;
		if ( cidType.isEmbedded() ) {
			// we have an embedded composite identifier.  Most likely we need to process the composite
			// properties separately, although there is an edge case where the identifier is really
			// a simple identifier (single value) wrapped in a JPA @IdClass or even in the case of a
			// a simple identifier (single value) wrapped in a Hibernate composite type.
			//
			// We really do not have a built-in method to determine that.  However, generally the
			// persister would report that there is single, physical identifier property which is
			// explicitly at odds with the notion of "embedded composite".  So we use that for now
			if ( persister.getEntityMetamodel().getIdentifierProperty().isEmbedded() ) {
				walkComponentTree(
						cidType,
						-1,
						0,
						persister,
						alias,
						path,
						currentDepth
				);
			}
		}
	}
}
 
Example 15
Project: lams   File: CriteriaQueryTranslator.java   View Source Code Vote up 4 votes
private CriteriaInfoProvider getPathInfo(String path) {
	StringTokenizer tokens = new StringTokenizer( path, "." );
	String componentPath = "";

	// start with the 'rootProvider'
	CriteriaInfoProvider provider = nameCriteriaInfoMap.get( rootEntityName );

	while ( tokens.hasMoreTokens() ) {
		componentPath += tokens.nextToken();
		final Type type = provider.getType( componentPath );
		if ( type.isAssociationType() ) {
			// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
			final AssociationType atype = (AssociationType) type;
			final CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null;
			final Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null;
			// is the association a collection of components or value-types? (i.e a colloction of valued types?)
			if ( ctype != null  && elementType.isComponentType() ) {
				provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) );
			}
			else if ( ctype != null && !elementType.isEntityType() ) {
				provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() );
			}
			else {
				provider = new EntityCriteriaInfoProvider(
						(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) )
				);
			}
			
			componentPath = "";
		}
		else if ( type.isComponentType() ) {
			if (!tokens.hasMoreTokens()) {
				throw new QueryException(
						"Criteria objects cannot be created directly on components.  Create a criteria on " +
								"owning entity and use a dotted property to access component property: " + path
				);
			}
			else {
				componentPath += '.';
			}
		}
		else {
			throw new QueryException( "not an association: " + componentPath );
		}
	}
	
	return provider;
}
 
Example 16
Project: lams   File: AbstractCollectionReference.java   View Source Code Vote up 4 votes
private CollectionFetchableIndex buildIndexGraph(
		ExpandingCollectionQuerySpace collectionQuerySpace,
		boolean shouldIncludeJoins) {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	if ( persister.hasIndex() ) {
		final Type type = persister.getIndexType();
		if ( type.isAssociationType() ) {
			if ( type.isEntityType() ) {
				final EntityPersister indexPersister = persister.getFactory().getEntityPersister(
						( (EntityType) type ).getAssociatedEntityName()
				);

				final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
						collectionQuerySpace,
						indexPersister,
						CollectionPropertyNames.COLLECTION_INDICES,
						(EntityType) persister.getIndexType(),
						collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
						collectionQuerySpace.canJoinsBeRequired(),
						shouldIncludeJoins
				);
				return new CollectionFetchableIndexEntityGraph( this, entityQuerySpace );
			}
			else if ( type.isAnyType() ) {
				return new CollectionFetchableIndexAnyGraph( this );
			}
		}
		else if ( type.isComponentType() ) {
			final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
					collectionQuerySpace,
					new CompositePropertyMapping(
							(CompositeType) persister.getIndexType(),
							(PropertyMapping) persister,
							""
					),
					CollectionPropertyNames.COLLECTION_INDICES,
					(CompositeType) persister.getIndexType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					shouldIncludeJoins
			);
			return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace );
		}
	}

	return null;
}
 
Example 17
Project: lams   File: AbstractCollectionReference.java   View Source Code Vote up 4 votes
private CollectionFetchableElement buildElementGraph(
		ExpandingCollectionQuerySpace collectionQuerySpace,
		boolean shouldIncludeJoins) {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	final Type type = persister.getElementType();
	if ( type.isAssociationType() ) {
		if ( type.isEntityType() ) {
			final EntityPersister elementPersister = persister.getFactory().getEntityPersister(
					( (EntityType) type ).getAssociatedEntityName()
			);
			final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
					collectionQuerySpace,
					elementPersister,
					CollectionPropertyNames.COLLECTION_ELEMENTS,
					(EntityType) persister.getElementType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					shouldIncludeJoins
			);
			return new CollectionFetchableElementEntityGraph( this, entityQuerySpace );
		}
		else if ( type.isAnyType() ) {
			return new CollectionFetchableElementAnyGraph( this );
		}
	}
	else if ( type.isComponentType() ) {
		final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
				collectionQuerySpace,
				new CompositePropertyMapping(
						(CompositeType) persister.getElementType(),
						(PropertyMapping) persister,
						""
				),
				CollectionPropertyNames.COLLECTION_ELEMENTS,
				(CompositeType) persister.getElementType(),
				collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
				collectionQuerySpace.canJoinsBeRequired(),
				shouldIncludeJoins
		);
		return new CollectionFetchableElementCompositeGraph( this, compositeQuerySpace );
	}

	return null;
}
 
Example 18
Project: lams   File: SingleTableEntityPersister.java   View Source Code Vote up 4 votes
private int getSubclassPropertyTableNumber(String propertyName, String entityName) {
	Type type = propertyMapping.toType(propertyName);
	if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) return 0;
	final Integer tabnum = (Integer) propertyTableNumbersByNameAndSubclass.get(entityName + '.' + propertyName);
	return tabnum==null ? 0 : tabnum;
}
 
Example 19
Project: hibernate-ogm-ignite   File: IgnitePropertyHelper.java   View Source Code Vote up 4 votes
/**
	 * Returns the {@link PropertyIdentifier} for the given property path.
	 *
	 * In passing, it creates all the necessary aliases for embedded/associations.
	 *
	 * @param entityType the type of the entity
	 * @param propertyPath the path to the property without aliases
	 * @return the {@link PropertyIdentifier}
	 */
	public PropertyIdentifier getPropertyIdentifier(String entityType, List<String> propertyPath) {
		// we analyze the property path to find all the associations/embedded which are in the way and create proper
		// aliases for them
		String entityAlias = findAliasForType( entityType );

		String propertyEntityType = entityType;
		String propertyAlias = entityAlias;
		String propertyName;

		List<String> currentPropertyPath = new ArrayList<>();
		List<String> lastAssociationPath = Collections.emptyList();
		OgmEntityPersister currentPersister = getPersister( entityType );

		int requiredDepth = propertyPath.size();
		boolean isLastElementAssociation = false;
		int depth = 1;
		for ( String property : propertyPath ) {
			currentPropertyPath.add( property );
			Type currentPropertyType = getPropertyType( entityType, currentPropertyPath );

			// determine if the current property path is still part of requiredPropertyMatch
			boolean optionalMatch = depth > requiredDepth;

			if ( currentPropertyType.isAssociationType() ) {
				AssociationType associationPropertyType = (AssociationType) currentPropertyType;
				Joinable associatedJoinable = associationPropertyType.getAssociatedJoinable( getSessionFactory() );
				if ( associatedJoinable.isCollection()
						&& ( (OgmCollectionPersister) associatedJoinable ).getType().isComponentType() ) {
					// we have a collection of embedded
					throw new NotYetImplementedException();
//					propertyAlias = aliasResolver.createAliasForEmbedded( entityAlias, currentPropertyPath, optionalMatch );
				}
				else {
					propertyEntityType = associationPropertyType.getAssociatedEntityName( getSessionFactory() );
					currentPersister = getPersister( propertyEntityType );
					String targetNodeType = currentPersister.getEntityKeyMetadata().getTable();

					throw new NotYetImplementedException();
//					propertyAlias = aliasResolver.createAliasForAssociation( entityAlias, currentPropertyPath, targetNodeType, optionalMatch );
//					lastAssociationPath = new ArrayList<>( currentPropertyPath );
//					isLastElementAssociation = true;
				}
			}
			else if ( currentPropertyType.isComponentType()
					&& !isIdProperty( currentPersister, propertyPath.subList( lastAssociationPath.size(), propertyPath.size() ) ) ) {
				// we are in the embedded case and the embedded is not the id of the entity (the id is stored as normal
				// properties)
				throw new NotYetImplementedException();
//				propertyAlias = aliasResolver.createAliasForEmbedded( entityAlias, currentPropertyPath, optionalMatch );
			}
			else {
				isLastElementAssociation = false;
			}
			depth++;
		}
		if ( isLastElementAssociation ) {
			// even the last element is an association, we need to find a suitable identifier property
			propertyName = getSessionFactory().getEntityPersister( propertyEntityType ).getIdentifierPropertyName();
		}
		else {
			// the last element is a property so we can build the test with this property
			propertyName = getColumnName( propertyEntityType, propertyPath.subList( lastAssociationPath.size(), propertyPath.size() ) );
		}
		return new PropertyIdentifier( propertyAlias, propertyName );
	}
 
Example 20
Project: Layer-Query   File: CustomCriteriaQueryTranslator.java   View Source Code Vote up 4 votes
private CriteriaInfoProvider getPathInfo(String path) {
	StringTokenizer tokens = new StringTokenizer( path, "." );
	String componentPath = "";

	// start with the 'rootProvider'
	CriteriaInfoProvider provider = nameCriteriaInfoMap.get( rootEntityName );

	while ( tokens.hasMoreTokens() ) {
		componentPath += tokens.nextToken();
		final Type type = provider.getType( componentPath );
		if ( type.isAssociationType() ) {
			// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
			final AssociationType atype = (AssociationType) type;
			final CollectionType ctype = type.isCollectionType() ? (CollectionType) type : null;
			final Type elementType = ( ctype != null ) ? ctype.getElementType( sessionFactory ) : null;
			// is the association a collection of components or value-types? (i.e a colloction of valued types?)
			if ( ctype != null && elementType.isComponentType() ) {
				provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister( ctype.getRole() ) );
			}
			else if ( ctype != null && !elementType.isEntityType() ) {
				provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() );
			}
			else {
				provider = new EntityCriteriaInfoProvider(
						(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) )
				);
			}

			componentPath = "";
		}
		else if ( type.isComponentType() ) {
			if ( !tokens.hasMoreTokens() ) {
				throw new QueryException(
						"Criteria objects cannot be created directly on components.  Create a criteria on " +
								"owning entity and use a dotted property to access component property: " + path
				);
			}
			else {
				componentPath += '.';
			}
		}
		else {
			throw new QueryException( "not an association: " + componentPath );
		}
	}

	return provider;
}