use of org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath 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));
}
Aggregations