Search in sources :

Example 1 with UpdateStatement

use of org.hibernate.hql.internal.ast.tree.UpdateStatement in project hibernate-orm by hibernate.

the class HqlSqlWalker method postProcessUpdate.

@Override
protected void postProcessUpdate(AST update) throws SemanticException {
    UpdateStatement updateStatement = (UpdateStatement) update;
    postProcessDML(updateStatement);
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement)

Example 2 with UpdateStatement

use of org.hibernate.hql.internal.ast.tree.UpdateStatement in project hibernate-orm by hibernate.

the class PersistentTableBulkIdStrategy method buildUpdateHandler.

@Override
public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) {
    final UpdateStatement updateStatement = (UpdateStatement) walker.getAST();
    final FromElement fromElement = updateStatement.getFromClause().getFromElement();
    final Queryable targetedPersister = fromElement.getQueryable();
    return new UpdateHandlerImpl(factory, walker, getIdTableInfo(targetedPersister));
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) Queryable(org.hibernate.persister.entity.Queryable)

Example 3 with UpdateStatement

use of org.hibernate.hql.internal.ast.tree.UpdateStatement in project hibernate-orm by hibernate.

the class LocalTemporaryTableBulkIdStrategy method buildUpdateHandler.

@Override
public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) {
    final UpdateStatement updateStatement = (UpdateStatement) walker.getAST();
    final FromElement fromElement = updateStatement.getFromClause().getFromElement();
    final Queryable targetedPersister = fromElement.getQueryable();
    final IdTableInfoImpl tableInfo = getIdTableInfo(targetedPersister);
    return new TableBasedUpdateHandlerImpl(factory, walker, tableInfo) {

        @Override
        protected void prepareForUse(Queryable persister, SharedSessionContractImplementor session) {
            Helper.INSTANCE.createTempTable(tableInfo, ddlTransactionHandling, session);
        }

        @Override
        protected void releaseFromUse(Queryable persister, SharedSessionContractImplementor session) {
            Helper.INSTANCE.releaseTempTable(tableInfo, afterUseAction, ddlTransactionHandling, session);
        }
    };
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) Queryable(org.hibernate.persister.entity.Queryable) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) TableBasedUpdateHandlerImpl(org.hibernate.hql.spi.id.TableBasedUpdateHandlerImpl)

Example 4 with UpdateStatement

use of org.hibernate.hql.internal.ast.tree.UpdateStatement in project hibernate-orm by hibernate.

the class GlobalTemporaryTableBulkIdStrategy method buildUpdateHandler.

@Override
public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) {
    final UpdateStatement updateStatement = (UpdateStatement) walker.getAST();
    final FromElement fromElement = updateStatement.getFromClause().getFromElement();
    final Queryable targetedPersister = fromElement.getQueryable();
    return new TableBasedUpdateHandlerImpl(factory, walker, getIdTableInfo(targetedPersister)) {

        @Override
        protected void releaseFromUse(Queryable persister, SharedSessionContractImplementor session) {
            if (afterUseAction == AfterUseAction.NONE) {
                return;
            }
            // clean up our id-table rows
            cleanUpRows(getIdTableInfo(persister).getQualifiedIdTableName(), session);
        }
    };
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) Queryable(org.hibernate.persister.entity.Queryable) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) TableBasedUpdateHandlerImpl(org.hibernate.hql.spi.id.TableBasedUpdateHandlerImpl)

Example 5 with UpdateStatement

use of org.hibernate.hql.internal.ast.tree.UpdateStatement 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)

Aggregations

UpdateStatement (org.hibernate.hql.internal.ast.tree.UpdateStatement)5 Queryable (org.hibernate.persister.entity.Queryable)4 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)3 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)2 TableBasedUpdateHandlerImpl (org.hibernate.hql.spi.id.TableBasedUpdateHandlerImpl)2 SemanticException (antlr.SemanticException)1 AST (antlr.collections.AST)1 FromClause (org.hibernate.hql.internal.ast.tree.FromClause)1 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)1 CollectionFilterKeyParameterSpecification (org.hibernate.param.CollectionFilterKeyParameterSpecification)1 NamedParameterSpecification (org.hibernate.param.NamedParameterSpecification)1 ParameterSpecification (org.hibernate.param.ParameterSpecification)1 PositionalParameterSpecification (org.hibernate.param.PositionalParameterSpecification)1 VersionTypeSeedParameterSpecification (org.hibernate.param.VersionTypeSeedParameterSpecification)1 VersionType (org.hibernate.type.VersionType)1 UserVersionType (org.hibernate.usertype.UserVersionType)1