Search in sources :

Example 21 with Queryable

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

the class MapEntryNode method determineKeySelectExpressions.

private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator(0);
    appendSelectExpressions(collectionPersister.getIndexColumnNames(), selections, aliasGenerator);
    Type keyType = collectionPersister.getIndexType();
    if (keyType.isEntityType()) {
        MapKeyEntityFromElement mapKeyEntityFromElement = findOrAddMapKeyEntityFromElement(collectionPersister);
        Queryable keyEntityPersister = mapKeyEntityFromElement.getQueryable();
        SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(mapKeyEntityFromElement.getTableAlias(), null, false);
        appendSelectExpressions(fragment, selections, aliasGenerator);
    }
}
Also used : 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)

Example 22 with Queryable

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

the class HqlSqlWalker method prepareVersioned.

@Override
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
    UpdateStatement updateStatement = (UpdateStatement) updateNode;
    FromClause fromClause = updateStatement.getFromClause();
    if (versioned != null) {
        // Make sure that the persister is versioned
        Queryable persister = fromClause.getFromElement().getQueryable();
        if (!persister.isVersioned()) {
            throw new SemanticException("increment option specified for update of non-versioned entity");
        }
        VersionType versionType = persister.getVersionType();
        if (versionType instanceof UserVersionType) {
            throw new SemanticException("user-defined version types not supported for increment option");
        }
        AST eq = getASTFactory().create(HqlSqlTokenTypes.EQ, "=");
        AST versionPropertyNode = generateVersionPropertyNode(persister);
        eq.setFirstChild(versionPropertyNode);
        AST versionIncrementNode = null;
        if (isTimestampBasedVersion(versionType)) {
            versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PARAM, "?");
            ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(versionType);
            ((ParameterNode) versionIncrementNode).setHqlParameterSpecification(paramSpec);
            parameters.add(0, paramSpec);
        } else {
            // Not possible to simply re-use the versionPropertyNode here as it causes
            // OOM errors due to circularity :(
            versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PLUS, "+");
            versionIncrementNode.setFirstChild(generateVersionPropertyNode(persister));
            versionIncrementNode.addChild(getASTFactory().create(HqlSqlTokenTypes.IDENT, "1"));
        }
        eq.addChild(versionIncrementNode);
        evaluateAssignment(eq, persister, 0);
        AST setClause = updateStatement.getSetClause();
        AST currentFirstSetElement = setClause.getFirstChild();
        setClause.setFirstChild(eq);
        eq.setNextSibling(currentFirstSetElement);
    }
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) UserVersionType(org.hibernate.usertype.UserVersionType) AST(antlr.collections.AST) CollectionFilterKeyParameterSpecification(org.hibernate.param.CollectionFilterKeyParameterSpecification) ParameterSpecification(org.hibernate.param.ParameterSpecification) PositionalParameterSpecification(org.hibernate.param.PositionalParameterSpecification) VersionTypeSeedParameterSpecification(org.hibernate.param.VersionTypeSeedParameterSpecification) NamedParameterSpecification(org.hibernate.param.NamedParameterSpecification) VersionTypeSeedParameterSpecification(org.hibernate.param.VersionTypeSeedParameterSpecification) ParameterNode(org.hibernate.hql.internal.ast.tree.ParameterNode) FromClause(org.hibernate.hql.internal.ast.tree.FromClause) Queryable(org.hibernate.persister.entity.Queryable) UserVersionType(org.hibernate.usertype.UserVersionType) VersionType(org.hibernate.type.VersionType) SemanticException(antlr.SemanticException)

Example 23 with Queryable

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

the class HqlSqlWalker method evaluateAssignment.

@Override
protected void evaluateAssignment(AST eq) throws SemanticException {
    prepareLogicOperator(eq);
    Queryable persister = getCurrentFromClause().getFromElement().getQueryable();
    evaluateAssignment(eq, persister, -1);
}
Also used : Queryable(org.hibernate.persister.entity.Queryable)

Example 24 with Queryable

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

the class FromElementFactory method createEntityAssociation.

private FromElement createEntityAssociation(String role, String roleAlias, JoinType joinType) throws SemanticException {
    FromElement elem;
    Queryable entityPersister = (Queryable) queryableCollection.getElementPersister();
    String associatedEntityName = entityPersister.getEntityName();
    // Get the class name of the associated entity.
    if (queryableCollection.isOneToMany()) {
        LOG.debugf("createEntityAssociation() : One to many - path = %s role = %s associatedEntityName = %s", path, role, associatedEntityName);
        JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
        elem = createJoin(associatedEntityName, roleAlias, joinSequence, (EntityType) queryableCollection.getElementType(), false);
    } else {
        LOG.debugf("createManyToMany() : path = %s role = %s associatedEntityName = %s", path, role, associatedEntityName);
        elem = createManyToMany(role, associatedEntityName, roleAlias, entityPersister, (EntityType) queryableCollection.getElementType(), joinType);
        fromClause.getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
    }
    elem.setCollectionTableAlias(roleAlias);
    return elem;
}
Also used : EntityType(org.hibernate.type.EntityType) Queryable(org.hibernate.persister.entity.Queryable) JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 25 with Queryable

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

the class CustomLoader method determineAppropriateOwnerPersister.

private Queryable determineAppropriateOwnerPersister(NonScalarReturn ownerDescriptor) {
    String entityName = null;
    if (ownerDescriptor instanceof RootReturn) {
        entityName = ((RootReturn) ownerDescriptor).getEntityName();
    } else if (ownerDescriptor instanceof CollectionReturn) {
        CollectionReturn collRtn = (CollectionReturn) ownerDescriptor;
        String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty();
        CollectionPersister persister = getFactory().getMetamodel().collectionPersister(role);
        EntityType ownerType = (EntityType) persister.getElementType();
        entityName = ownerType.getAssociatedEntityName(getFactory());
    } else if (ownerDescriptor instanceof FetchReturn) {
        FetchReturn fetchRtn = (FetchReturn) ownerDescriptor;
        Queryable persister = determineAppropriateOwnerPersister(fetchRtn.getOwner());
        Type ownerType = persister.getPropertyType(fetchRtn.getOwnerProperty());
        if (ownerType.isEntityType()) {
            entityName = ((EntityType) ownerType).getAssociatedEntityName(getFactory());
        } else if (ownerType.isCollectionType()) {
            Type ownerCollectionElementType = ((CollectionType) ownerType).getElementType(getFactory());
            if (ownerCollectionElementType.isEntityType()) {
                entityName = ((EntityType) ownerCollectionElementType).getAssociatedEntityName(getFactory());
            }
        }
    }
    if (entityName == null) {
        throw new HibernateException("Could not determine fetch owner : " + ownerDescriptor);
    }
    return (Queryable) getFactory().getMetamodel().entityPersister(entityName);
}
Also used : EntityType(org.hibernate.type.EntityType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) HibernateException(org.hibernate.HibernateException) 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