Search in sources :

Example 1 with CollectionPropertyMapping

use of org.hibernate.persister.collection.CollectionPropertyMapping in project hibernate-orm by hibernate.

the class FromElementType method getCollectionPropertyReference.

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.copy().setUseThetaStyle(true), enabledFilters, collectionPropertyMapping.toColumns(tableAlias, propertyName));
            LOG.debugf("toColumns(%s,%s) : subquery = %s", tableAlias, propertyName, subquery);
            return new String[] { "(" + subquery + ")" };
        }
    };
}
Also used : QueryException(org.hibernate.QueryException) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping) Map(java.util.Map)

Example 2 with CollectionPropertyMapping

use of org.hibernate.persister.collection.CollectionPropertyMapping in project hibernate-orm by hibernate.

the class PathExpressionParser method addFromCollection.

public String addFromCollection(QueryTranslatorImpl q) throws QueryException {
    Type collectionElementType = getPropertyType();
    if (collectionElementType == null) {
        throw new QueryException("must specify 'elements' for collection valued property in from clause: " + path);
    }
    if (collectionElementType.isEntityType()) {
        // an association
        QueryableCollection collectionPersister = q.getCollectionPersister(collectionRole);
        Queryable entityPersister = (Queryable) collectionPersister.getElementPersister();
        String clazz = entityPersister.getEntityName();
        final String elementName;
        if (collectionPersister.isOneToMany()) {
            elementName = collectionName;
            //allow index() function:
            q.decoratePropertyMapping(elementName, collectionPersister);
        } else {
            //many-to-many
            q.addCollection(collectionName, collectionRole);
            elementName = q.createNameFor(clazz);
            addJoin(elementName, (AssociationType) collectionElementType);
        }
        q.addFrom(elementName, clazz, joinSequence);
        currentPropertyMapping = new CollectionPropertyMapping(collectionPersister);
        return elementName;
    } else {
        // collections of values
        q.addFromCollection(collectionName, collectionRole, joinSequence);
        return collectionName;
    }
}
Also used : JoinType(org.hibernate.sql.JoinType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) Queryable(org.hibernate.persister.entity.Queryable) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping)

Example 3 with CollectionPropertyMapping

use of org.hibernate.persister.collection.CollectionPropertyMapping in project hibernate-orm by hibernate.

the class PathExpressionParser method dereferenceCollection.

private void dereferenceCollection(String propertyName, String role, QueryTranslatorImpl q) throws QueryException {
    collectionRole = role;
    QueryableCollection collPersister = q.getCollectionPersister(role);
    String name = q.createNameForCollection(role);
    addJoin(name, collPersister.getCollectionType());
    //if ( collPersister.hasWhere() ) join.addCondition( collPersister.getSQLWhereString(name) );
    collectionName = name;
    collectionOwnerName = currentName;
    currentName = name;
    currentProperty = propertyName;
    componentPath.setLength(0);
    currentPropertyMapping = new CollectionPropertyMapping(collPersister);
}
Also used : QueryableCollection(org.hibernate.persister.collection.QueryableCollection) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping)

Aggregations

CollectionPropertyMapping (org.hibernate.persister.collection.CollectionPropertyMapping)3 QueryException (org.hibernate.QueryException)2 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)2 Map (java.util.Map)1 PropertyMapping (org.hibernate.persister.entity.PropertyMapping)1 Queryable (org.hibernate.persister.entity.Queryable)1 JoinType (org.hibernate.sql.JoinType)1 AssociationType (org.hibernate.type.AssociationType)1 CollectionType (org.hibernate.type.CollectionType)1 EntityType (org.hibernate.type.EntityType)1 Type (org.hibernate.type.Type)1