Search in sources :

Example 16 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class EntityLoadQueryDetails method applyRootReturnFilterRestrictions.

protected void applyRootReturnFilterRestrictions(SelectStatementBuilder selectStatementBuilder) {
    final Queryable rootQueryable = (Queryable) getRootEntityReturn().getEntityPersister();
    selectStatementBuilder.appendRestrictions(rootQueryable.filterFragment(entityReferenceAliases.getTableAlias(), Collections.emptyMap()));
}
Also used : Queryable(org.hibernate.persister.entity.Queryable)

Example 17 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class QueryTranslatorImpl method buildAppropriateStatementExecutor.

private StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker) {
    final Statement statement = (Statement) walker.getAST();
    if (walker.getStatementType() == HqlSqlTokenTypes.DELETE) {
        final FromElement fromElement = walker.getFinalFromClause().getFromElement();
        final Queryable persister = fromElement.getQueryable();
        if (persister.isMultiTable()) {
            return new MultiTableDeleteExecutor(walker);
        } else {
            return new DeleteExecutor(walker, persister);
        }
    } else if (walker.getStatementType() == HqlSqlTokenTypes.UPDATE) {
        final FromElement fromElement = walker.getFinalFromClause().getFromElement();
        final Queryable persister = fromElement.getQueryable();
        if (persister.isMultiTable()) {
            // TODO : decide if it is better performance-wise to doAfterTransactionCompletion that check, or to simply use the MultiTableUpdateDelegate
            return new MultiTableUpdateExecutor(walker);
        } else {
            return new BasicExecutor(walker, persister);
        }
    } else if (walker.getStatementType() == HqlSqlTokenTypes.INSERT) {
        return new BasicExecutor(walker, ((InsertStatement) statement).getIntoClause().getQueryable());
    } else {
        throw new QueryException("Unexpected statement type");
    }
}
Also used : MultiTableDeleteExecutor(org.hibernate.hql.internal.ast.exec.MultiTableDeleteExecutor) DeleteExecutor(org.hibernate.hql.internal.ast.exec.DeleteExecutor) QueryException(org.hibernate.QueryException) Statement(org.hibernate.hql.internal.ast.tree.Statement) InsertStatement(org.hibernate.hql.internal.ast.tree.InsertStatement) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) Queryable(org.hibernate.persister.entity.Queryable) MultiTableUpdateExecutor(org.hibernate.hql.internal.ast.exec.MultiTableUpdateExecutor) BasicExecutor(org.hibernate.hql.internal.ast.exec.BasicExecutor) MultiTableDeleteExecutor(org.hibernate.hql.internal.ast.exec.MultiTableDeleteExecutor) InsertStatement(org.hibernate.hql.internal.ast.tree.InsertStatement)

Example 18 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class DotNode method dereferenceCollection.

private void dereferenceCollection(CollectionType collectionType, boolean implicitJoin, boolean indexed, String classAlias, AST parent) throws SemanticException {
    dereferenceType = DereferenceType.COLLECTION;
    String role = collectionType.getRole();
    //foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
    boolean isSizeProperty = getNextSibling() != null && CollectionProperties.isAnyCollectionProperty(getNextSibling().getText());
    if (isSizeProperty) {
        //yuck!
        indexed = true;
    }
    QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
    String propName = getPath();
    FromClause currentFromClause = getWalker().getCurrentFromClause();
    // If the lhs of the join is a "component join", we need to go back to the
    // first non-component-join as the origin to properly link aliases and
    // join columns
    FromElement lhsFromElement = getLhs().getFromElement();
    while (lhsFromElement != null && ComponentJoin.class.isInstance(lhsFromElement)) {
        lhsFromElement = lhsFromElement.getOrigin();
    }
    if (lhsFromElement == null) {
        throw new QueryException("Unable to locate appropriate lhs");
    }
    // in all other cases, we should use the table alias
    if (getWalker().getStatementType() != SqlTokenTypes.SELECT) {
        if (isFromElementUpdateOrDeleteRoot(lhsFromElement)) {
            // at this point we know we have the 2 conditions above,
            // lets see if we have the mentioned "multi-table" caveat...
            boolean useAlias = false;
            if (getWalker().getStatementType() != SqlTokenTypes.INSERT) {
                final Queryable persister = lhsFromElement.getQueryable();
                if (persister.isMultiTable()) {
                    useAlias = true;
                }
            }
            if (!useAlias) {
                final String lhsTableName = lhsFromElement.getQueryable().getTableName();
                columns = getFromElement().toColumns(lhsTableName, propertyPath, false, true);
            }
        }
    }
    // We do not look for an existing join on the same path, because
    // it makes sense to join twice on the same collection role
    FromElementFactory factory = new FromElementFactory(currentFromClause, lhsFromElement, propName, classAlias, getColumns(), implicitJoin);
    FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, indexed);
    LOG.debugf("dereferenceCollection() : Created new FROM element for %s : %s", propName, elem);
    setImpliedJoin(elem);
    // This 'dot' expression now refers to the resulting from element.
    setFromElement(elem);
    if (isSizeProperty) {
        elem.setText("");
        elem.setUseWhereFragment(false);
    }
    if (!implicitJoin) {
        EntityPersister entityPersister = elem.getEntityPersister();
        if (entityPersister != null) {
            getWalker().addQuerySpaces(entityPersister.getQuerySpaces());
        }
    }
    // Always add the collection's query spaces.
    getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) QueryException(org.hibernate.QueryException) Queryable(org.hibernate.persister.entity.Queryable) QueryableCollection(org.hibernate.persister.collection.QueryableCollection)

Example 19 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class FromElement method buildTypeDiscriminatorMetadata.

private TypeDiscriminatorMetadata buildTypeDiscriminatorMetadata() {
    final String aliasToUse = getTableAlias();
    Queryable queryable = getQueryable();
    if (queryable == null) {
        QueryableCollection collection = getQueryableCollection();
        if (!collection.getElementType().isEntityType()) {
            throw new QueryException("type discrimination cannot be applied to value collection [" + collection.getRole() + "]");
        }
        queryable = (Queryable) collection.getElementPersister();
    }
    handlePropertyBeingDereferenced(getDataType(), DISCRIMINATOR_PROPERTY_NAME);
    return new TypeDiscriminatorMetadataImpl(queryable.getTypeDiscriminatorMetadata(), aliasToUse);
}
Also used : QueryException(org.hibernate.QueryException) Queryable(org.hibernate.persister.entity.Queryable) QueryableCollection(org.hibernate.persister.collection.QueryableCollection)

Example 20 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class MapEntryNode method determineValueSelectExpressions.

private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator(1);
    appendSelectExpressions(collectionPersister.getElementColumnNames(), selections, aliasGenerator);
    Type valueType = collectionPersister.getElementType();
    if (valueType.isAssociationType()) {
        EntityType valueEntityType = (EntityType) valueType;
        Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(valueEntityType.getAssociatedEntityName(sfi()));
        SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(elementTableAlias(), null, false);
        appendSelectExpressions(fragment, selections, aliasGenerator);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) SelectFragment(org.hibernate.sql.SelectFragment) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) AliasGenerator(org.hibernate.sql.AliasGenerator) Queryable(org.hibernate.persister.entity.Queryable)

Aggregations

Queryable (org.hibernate.persister.entity.Queryable)34 QueryException (org.hibernate.QueryException)10 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)8 Type (org.hibernate.type.Type)7 CollectionType (org.hibernate.type.CollectionType)5 EntityType (org.hibernate.type.EntityType)5 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4 UpdateStatement (org.hibernate.hql.internal.ast.tree.UpdateStatement)4 DeleteStatement (org.hibernate.hql.internal.ast.tree.DeleteStatement)3 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 JoinType (org.hibernate.sql.JoinType)3 AST (antlr.collections.AST)2 InsertStatement (org.hibernate.hql.internal.ast.tree.InsertStatement)2 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)2 TableBasedDeleteHandlerImpl (org.hibernate.hql.spi.id.TableBasedDeleteHandlerImpl)2 TableBasedUpdateHandlerImpl (org.hibernate.hql.spi.id.TableBasedUpdateHandlerImpl)2 CollectionFilterKeyParameterSpecification (org.hibernate.param.CollectionFilterKeyParameterSpecification)2 NamedParameterSpecification (org.hibernate.param.NamedParameterSpecification)2 ParameterSpecification (org.hibernate.param.ParameterSpecification)2