use of org.hibernate.persister.entity.PropertyMapping in project hibernate-orm by hibernate.
the class AbstractEmptinessExpression method getQueryableCollection.
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);
}
}
use of org.hibernate.persister.entity.PropertyMapping in project hibernate-orm by hibernate.
the class EntityQuerySpaceImpl method makeCompositeIdentifierQuerySpace.
@Override
public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() {
final String compositeQuerySpaceUid = getUid() + "-id";
final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace(compositeQuerySpaceUid, new CompositePropertyMapping((CompositeType) getEntityPersister().getIdentifierType(), (PropertyMapping) getEntityPersister(), getEntityPersister().getIdentifierPropertyName()), canJoinsBeRequired());
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin(this, EntityPersister.ENTITY_ID, rhs, canJoinsBeRequired(), (CompositeType) persister.getIdentifierType());
internalGetJoins().add(join);
return rhs;
}
use of org.hibernate.persister.entity.PropertyMapping 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.copyForCollectionProperty().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.entity.PropertyMapping in project hibernate-orm by hibernate.
the class FromElementType method toColumns.
String[] toColumns(String tableAlias, String path, boolean inSelect, boolean forceAlias) {
checkInitialized();
PropertyMapping propertyMapping = getPropertyMapping(path);
if (!inSelect && queryableCollection != null && CollectionProperties.isCollectionProperty(path)) {
// this is hacky, but really this is difficult to handle given the current codebase.
if (persister != propertyMapping) {
// DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfCollectionPropertiesInHql( path, fromElement.getClassAlias() );
return getCollectionPropertyReference(path).toColumns(tableAlias);
}
}
if (forceAlias) {
return propertyMapping.toColumns(tableAlias, path);
}
if (fromElement.getWalker().getStatementType() == HqlSqlTokenTypes.SELECT) {
return propertyMapping.toColumns(tableAlias, path);
}
if (fromElement.getWalker().isSubQuery()) {
// 2) otherwise (not correlated), use the given alias
if (isCorrelation()) {
if (isMultiTable() || isInsertQuery()) {
return propertyMapping.toColumns(tableAlias, path);
}
return propertyMapping.toColumns(extractTableName(), path);
}
return propertyMapping.toColumns(tableAlias, path);
}
if (fromElement.getWalker().getCurrentTopLevelClauseType() == HqlSqlTokenTypes.SELECT) {
return propertyMapping.toColumns(tableAlias, path);
}
if (isManipulationQuery() && isMultiTable() && inWhereClause()) {
// and safer to do so to protect from same-named columns
return propertyMapping.toColumns(tableAlias, path);
}
String[] columns = propertyMapping.toColumns(path);
LOG.tracev("Using non-qualified column reference [{0} -> ({1})]", path, ArrayHelper.toString(columns));
return columns;
}
use of org.hibernate.persister.entity.PropertyMapping in project hibernate-orm by hibernate.
the class FromElementType method getPropertyType.
/**
* 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;
// 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;
}
Aggregations