FileDocCategorySizeDatePackage
AbstractEmptinessExpression.javaAPI DocHibernate 3.2.53218Tue May 03 17:19:00 BST 2005org.hibernate.criterion

AbstractEmptinessExpression

public abstract class AbstractEmptinessExpression extends Object implements Criterion
Implementation of AbstractEmptinessExpression.
author
Steve Ebersole

Fields Summary
private static final org.hibernate.engine.TypedValue[]
NO_VALUES
protected final String
propertyName
Constructors Summary
protected AbstractEmptinessExpression(String propertyName)


	   
		this.propertyName = propertyName;
	
Methods Summary
protected abstract booleanexcludeEmpty()

protected org.hibernate.persister.collection.QueryableCollectiongetQueryableCollection(java.lang.String entityName, java.lang.String propertyName, org.hibernate.engine.SessionFactoryImplementor factory)

		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 );
		}
	
public final org.hibernate.engine.TypedValue[]getTypedValues(org.hibernate.Criteria criteria, CriteriaQuery criteriaQuery)

		return NO_VALUES;
	
public final java.lang.StringtoSqlString(org.hibernate.Criteria criteria, CriteriaQuery criteriaQuery)

		String entityName = criteriaQuery.getEntityName( criteria, propertyName );
		String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
		String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );

		SessionFactoryImplementor factory = criteriaQuery.getFactory();
		QueryableCollection collectionPersister = getQueryableCollection( entityName, actualPropertyName, factory );

		String[] collectionKeys = collectionPersister.getKeyColumnNames();
		String[] ownerKeys = ( ( Loadable ) factory.getEntityPersister( entityName ) ).getIdentifierColumnNames();

		String innerSelect = "(select 1 from " + collectionPersister.getTableName()
		        + " where "
		        + new ConditionFragment().setTableAlias( sqlAlias ).setCondition( ownerKeys, collectionKeys ).toFragmentString()
		        + ")";

		return excludeEmpty()
		        ? "exists " + innerSelect
		        : "not exists " + innerSelect;
	
public final java.lang.StringtoString()

		return propertyName + ( excludeEmpty() ? " is not empty" : " is empty" );