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 + ")" };
}
};
}
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;
}
}
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);
}
Aggregations