Search in sources :

Example 1 with EntityVersionMapping

use of org.hibernate.metamodel.mapping.EntityVersionMapping in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method addVersionedAssignment.

public void addVersionedAssignment(Consumer<Assignment> assignmentConsumer, SqmUpdateStatement<?> sqmStatement) {
    if (!sqmStatement.isVersioned()) {
        return;
    }
    final EntityPersister persister = creationContext.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(sqmStatement.getTarget().getEntityName());
    if (!persister.isVersioned()) {
        throw new SemanticException("increment option specified for update of non-versioned entity");
    }
    final BasicType<?> versionType = persister.getVersionType();
    if (versionType instanceof UserVersionType) {
        throw new SemanticException("user-defined version types not supported for increment option");
    }
    final EntityVersionMapping versionMapping = persister.getVersionMapping();
    final List<ColumnReference> targetColumnReferences = BasicValuedPathInterpretation.from((SqmBasicValuedSimplePath<?>) sqmStatement.getRoot().get(versionMapping.getPartName()), this, this, jpaQueryComplianceEnabled).getColumnReferences();
    assert targetColumnReferences.size() == 1;
    final ColumnReference versionColumn = targetColumnReferences.get(0);
    final Expression value;
    if (versionMapping.getJdbcMapping().getJdbcType().isTemporal()) {
        value = new VersionTypeSeedParameterSpecification(versionType, persister.getVersionJavaType());
    } else {
        value = new BinaryArithmeticExpression(versionColumn, ADD, new QueryLiteral<>(1, versionType), versionType);
    }
    assignmentConsumer.accept(new Assignment(versionColumn, value));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) UserVersionType(org.hibernate.usertype.UserVersionType) VersionTypeSeedParameterSpecification(org.hibernate.sql.exec.internal.VersionTypeSeedParameterSpecification) SqmBasicValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath) Assignment(org.hibernate.sql.ast.tree.update.Assignment) SqmAssignment(org.hibernate.query.sqm.tree.update.SqmAssignment) QueryLiteral(org.hibernate.sql.ast.tree.expression.QueryLiteral) ConvertedQueryLiteral(org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) SemanticException(org.hibernate.query.SemanticException) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Aggregations

EntityVersionMapping (org.hibernate.metamodel.mapping.EntityVersionMapping)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 SingleTableEntityPersister (org.hibernate.persister.entity.SingleTableEntityPersister)1 SemanticException (org.hibernate.query.SemanticException)1 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)1 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)1 SqmBasicValuedSimplePath (org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath)1 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)1 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)1 SqmAssignment (org.hibernate.query.sqm.tree.update.SqmAssignment)1 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)1 CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)1 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)1 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)1 ConvertedQueryLiteral (org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral)1 Expression (org.hibernate.sql.ast.tree.expression.Expression)1 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)1 QueryLiteral (org.hibernate.sql.ast.tree.expression.QueryLiteral)1 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)1