Java Code Examples for org.hibernate.persister.entity.PropertyMapping#toType()

The following examples show how to use org.hibernate.persister.entity.PropertyMapping#toType() . 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: AbstractEmptinessExpression.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected QueryableCollection getQueryableCollection(
		String entityName,
		String propertyName,
		SessionFactoryImplementor factory) throws HibernateException {
	final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
	final Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
				"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	final String role = ( (CollectionType) type ).getRole();
	try {
		return (QueryableCollection) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
Example 2
Source File: AbstractEmptinessExpression.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
	PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
	Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
		        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	String role = ( ( CollectionType ) type ).getRole();
	try {
		return ( QueryableCollection ) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
Example 3
Source File: FromElementType.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the type of a property, given it's name (the last part) and the full path.
 *
 * @param propertyName The last part of the full path to the property.
 * @return The type.
 * @0param propertyPath The full property path.
 */
public Type getPropertyType(String propertyName, String propertyPath) {
	checkInitialized();
	Type type = null;
	// If this is an entity and the property is the identifier property, then use getIdentifierType().
	//      Note that the propertyName.equals( propertyPath ) checks whether we have a component
	//      key reference, where the component class property name is the same as the
	//      entity id property name; if the two are not equal, this is the case and
	//      we'd need to "fall through" to using the property mapping.
	if ( persister != null && propertyName.equals( propertyPath ) && propertyName.equals( persister.getIdentifierPropertyName() ) ) {
		type = persister.getIdentifierType();
	}
	else {	// Otherwise, use the property mapping.
		PropertyMapping mapping = getPropertyMapping( propertyName );
		type = mapping.toType( propertyPath );
	}
	if ( type == null ) {
		throw new MappingException( "Property " + propertyName + " does not exist in " +
				( ( queryableCollection == null ) ? "class" : "collection" ) + " "
				+ ( ( queryableCollection == null ) ? fromElement.getClassName() : queryableCollection.getRole() ) );
	}
	return type;
}
 
Example 4
Source File: FromElementType.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the type of a property, given it's name (the last part) and the full path.
 *
 * @param propertyName The last part of the full path to the property.
 *
 * @return The type.
 *
 * @0param getPropertyPath The full property path.
 */
public Type getPropertyType(String propertyName, String propertyPath) {
	checkInitialized();
	Type type = null;
	// If this is an entity and the property is the identifier property, then use getIdentifierType().
	//      Note that the propertyName.equals( getPropertyPath ) checks whether we have a component
	//      key reference, where the component class property name is the same as the
	//      entity id property name; if the two are not equal, this is the case and
	//      we'd need to "fall through" to using the property mapping.
	if ( persister != null && propertyName.equals( propertyPath ) && propertyName.equals( persister.getIdentifierPropertyName() ) ) {
		type = persister.getIdentifierType();
	}
	else {    // Otherwise, use the property mapping.
		PropertyMapping mapping = getPropertyMapping( propertyName );
		type = mapping.toType( propertyPath );
	}
	if ( type == null ) {
		throw new MappingException(
				"Property " + propertyName + " does not exist in " +
						( ( queryableCollection == null ) ? "class" : "collection" ) + " "
						+ ( ( queryableCollection == null ) ?
						fromElement.getClassName() :
						queryableCollection.getRole() )
		);
	}
	return type;
}
 
Example 5
Source File: FromElementType.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public CollectionPropertyReference getCollectionPropertyReference(final String propertyName) {
	if ( queryableCollection == null ) {
		throw new QueryException( "Not a collection reference" );
	}

	final PropertyMapping collectionPropertyMapping;

	if ( queryableCollection.isManyToMany()
			&& queryableCollection.hasIndex()
			&& SPECIAL_MANY2MANY_TREATMENT_FUNCTION_NAMES.contains( propertyName ) ) {
		collectionPropertyMapping = new SpecialManyToManyCollectionPropertyMapping();
	}
	else if ( CollectionProperties.isCollectionProperty( propertyName ) ) {
		if ( this.collectionPropertyMapping == null ) {
			this.collectionPropertyMapping = new CollectionPropertyMapping( queryableCollection );
		}
		collectionPropertyMapping = this.collectionPropertyMapping;
	}
	else {
		collectionPropertyMapping = queryableCollection;
	}

	return new CollectionPropertyReference() {
		@Override
		public Type getType() {
			return collectionPropertyMapping.toType( propertyName );
		}

		@Override
		public String[] toColumns(final String tableAlias) {
			if ( propertyName.equalsIgnoreCase( "index" ) ) {
				return collectionPropertyMapping.toColumns( tableAlias, propertyName );
			}

			Map enabledFilters = fromElement.getWalker().getEnabledFilters();
			String subquery = CollectionSubqueryFactory.createCollectionSubquery(
					joinSequence.copyForCollectionProperty().setUseThetaStyle( true ),
					enabledFilters,
					collectionPropertyMapping.toColumns( tableAlias, propertyName )
			);
			LOG.debugf( "toColumns(%s,%s) : subquery = %s", tableAlias, propertyName, subquery );
			return new String[] {"(" + subquery + ")"};
		}
	};
}