Search in sources :

Example 1 with PropertyMapping

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);
    }
}
Also used : CollectionType(org.hibernate.type.CollectionType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) CollectionType(org.hibernate.type.CollectionType) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) MappingException(org.hibernate.MappingException)

Example 2 with PropertyMapping

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;
}
Also used : ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) CompositeType(org.hibernate.type.CompositeType)

Example 3 with PropertyMapping

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 + ")" };
        }
    };
}
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 4 with PropertyMapping

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;
}
Also used : PropertyMapping(org.hibernate.persister.entity.PropertyMapping) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping)

Example 5 with PropertyMapping

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;
}
Also used : EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping) MappingException(org.hibernate.MappingException)

Aggregations

PropertyMapping (org.hibernate.persister.entity.PropertyMapping)6 QueryException (org.hibernate.QueryException)3 CollectionPropertyMapping (org.hibernate.persister.collection.CollectionPropertyMapping)3 MappingException (org.hibernate.MappingException)2 Type (org.hibernate.type.Type)2 Map (java.util.Map)1 HibernateException (org.hibernate.HibernateException)1 ExpandingCompositeQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace)1 JoinDefinedByMetadata (org.hibernate.loader.plan.spi.JoinDefinedByMetadata)1 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)1 Queryable (org.hibernate.persister.entity.Queryable)1 CollectionType (org.hibernate.type.CollectionType)1 CompositeType (org.hibernate.type.CompositeType)1 EntityType (org.hibernate.type.EntityType)1