HHH-17279 Simplify SqmTranslatorFactory and SqlAstTranslatorFactory
This commit is contained in:
parent
cb6a78dc44
commit
3c36cfd747
|
@ -1,226 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
|
||||
*/
|
||||
package org.hibernate.query.sqm.internal;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.action.internal.BulkOperationCleanupAction;
|
||||
import org.hibernate.dialect.DmlTargetColumnQualifierSupport;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.MutableObject;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
|
||||
import org.hibernate.query.spi.DomainQueryExecutionContext;
|
||||
import org.hibernate.query.spi.NonSelectQueryPlan;
|
||||
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslation;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslator;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.tree.AbstractUpdateOrDeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractDeleteQueryPlan<S extends AbstractUpdateOrDeleteStatement, O extends JdbcOperationQueryMutation>
|
||||
implements NonSelectQueryPlan {
|
||||
private final EntityMappingType entityDescriptor;
|
||||
private final SqmDeleteStatement<?> sqmDelete;
|
||||
private final DomainParameterXref domainParameterXref;
|
||||
|
||||
private O jdbcOperation;
|
||||
|
||||
private SqmTranslation<DeleteStatement> sqmInterpretation;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
|
||||
public AbstractDeleteQueryPlan(
|
||||
EntityMappingType entityDescriptor,
|
||||
SqmDeleteStatement<?> sqmDelete,
|
||||
DomainParameterXref domainParameterXref) {
|
||||
assert entityDescriptor.getEntityName().equals( sqmDelete.getTarget().getEntityName() );
|
||||
|
||||
this.entityDescriptor = entityDescriptor;
|
||||
this.sqmDelete = sqmDelete;
|
||||
this.domainParameterXref = domainParameterXref;
|
||||
}
|
||||
|
||||
public EntityMappingType getEntityDescriptor() {
|
||||
return entityDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate(DomainQueryExecutionContext executionContext) {
|
||||
BulkOperationCleanupAction.schedule( executionContext.getSession(), sqmDelete );
|
||||
|
||||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
SqlAstTranslator<O> sqlAstTranslator = null;
|
||||
if ( jdbcOperation == null ) {
|
||||
sqlAstTranslator = createTranslator( executionContext );
|
||||
}
|
||||
|
||||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
sqmInterpretation.getFromClauseAccess()::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
return (MappingModelExpressible<T>) sqmInterpretation.getSqmParameterMappingModelTypeResolutions().get(parameter);
|
||||
}
|
||||
},
|
||||
session
|
||||
);
|
||||
|
||||
if ( jdbcOperation != null
|
||||
&& ! jdbcOperation.isCompatibleWith( jdbcParameterBindings, executionContext.getQueryOptions() ) ) {
|
||||
sqlAstTranslator = createTranslator( executionContext );
|
||||
}
|
||||
|
||||
if ( sqlAstTranslator != null ) {
|
||||
jdbcOperation = sqlAstTranslator.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
}
|
||||
|
||||
final boolean missingRestriction = sqmInterpretation.getSqlAst().getRestriction() == null;
|
||||
if ( missingRestriction ) {
|
||||
assert domainParameterXref.getSqmParameterCount() == 0;
|
||||
assert jdbcParamsXref.isEmpty();
|
||||
}
|
||||
|
||||
final SqmJdbcExecutionContextAdapter executionContextAdapter = SqmJdbcExecutionContextAdapter.usingLockingAndPaging( executionContext );
|
||||
|
||||
SqmMutationStrategyHelper.cleanUpCollectionTables(
|
||||
entityDescriptor,
|
||||
(tableReference, attributeMapping) -> {
|
||||
final TableGroup collectionTableGroup = new MutatingTableReferenceGroupWrapper(
|
||||
new NavigablePath( attributeMapping.getRootPathName() ),
|
||||
attributeMapping,
|
||||
(NamedTableReference) tableReference
|
||||
);
|
||||
|
||||
final MutableObject<Predicate> additionalPredicate = new MutableObject<>();
|
||||
attributeMapping.applyBaseRestrictions(
|
||||
p -> additionalPredicate.set( Predicate.combinePredicates( additionalPredicate.get(), p ) ),
|
||||
collectionTableGroup,
|
||||
factory.getJdbcServices().getDialect().getDmlTargetColumnQualifierSupport() == DmlTargetColumnQualifierSupport.TABLE_ALIAS,
|
||||
executionContext.getSession().getLoadQueryInfluencers().getEnabledFilters(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if ( missingRestriction ) {
|
||||
return additionalPredicate.get();
|
||||
}
|
||||
|
||||
final ForeignKeyDescriptor fkDescriptor = attributeMapping.getKeyDescriptor();
|
||||
final Expression fkColumnExpression = MappingModelCreationHelper.buildColumnReferenceExpression(
|
||||
collectionTableGroup,
|
||||
fkDescriptor.getKeyPart(),
|
||||
null,
|
||||
factory
|
||||
);
|
||||
|
||||
final QuerySpec matchingIdSubQuery = new QuerySpec( false );
|
||||
|
||||
final MutatingTableReferenceGroupWrapper tableGroup = new MutatingTableReferenceGroupWrapper(
|
||||
new NavigablePath( attributeMapping.getRootPathName() ),
|
||||
attributeMapping,
|
||||
sqmInterpretation.getSqlAst().getTargetTable()
|
||||
);
|
||||
final Expression fkTargetColumnExpression = MappingModelCreationHelper.buildColumnReferenceExpression(
|
||||
tableGroup,
|
||||
fkDescriptor.getTargetPart(),
|
||||
sqmInterpretation.getSqlExpressionResolver(),
|
||||
factory
|
||||
);
|
||||
matchingIdSubQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( 0, fkTargetColumnExpression ) );
|
||||
|
||||
matchingIdSubQuery.getFromClause().addRoot(
|
||||
tableGroup
|
||||
);
|
||||
|
||||
matchingIdSubQuery.applyPredicate( SqmMutationStrategyHelper.getIdSubqueryPredicate(
|
||||
sqmInterpretation.getSqlAst().getRestriction(),
|
||||
entityDescriptor,
|
||||
tableGroup,
|
||||
session
|
||||
) );
|
||||
|
||||
return Predicate.combinePredicates(
|
||||
additionalPredicate.get(),
|
||||
new InSubQueryPredicate( fkColumnExpression, matchingIdSubQuery, false )
|
||||
);
|
||||
},
|
||||
( missingRestriction ? JdbcParameterBindings.NO_BINDINGS : jdbcParameterBindings ),
|
||||
executionContextAdapter
|
||||
);
|
||||
|
||||
return jdbcServices.getJdbcMutationExecutor().execute(
|
||||
jdbcOperation,
|
||||
jdbcParameterBindings,
|
||||
sql -> session
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( sql ),
|
||||
(integer, preparedStatement) -> {},
|
||||
executionContextAdapter
|
||||
);
|
||||
}
|
||||
|
||||
protected SqlAstTranslator<O> createTranslator(DomainQueryExecutionContext executionContext) {
|
||||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
final SqmTranslator<DeleteStatement> translator = factory.getQueryEngine().getSqmTranslatorFactory().createSimpleDeleteTranslator(
|
||||
sqmDelete,
|
||||
executionContext.getQueryOptions(),
|
||||
domainParameterXref,
|
||||
executionContext.getQueryParameterBindings(),
|
||||
executionContext.getSession().getLoadQueryInfluencers(),
|
||||
factory
|
||||
);
|
||||
sqmInterpretation = translator.translate();
|
||||
|
||||
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmInterpretation::getJdbcParamsBySqmParam
|
||||
);
|
||||
|
||||
final S ast = buildAst( sqmInterpretation, executionContext );
|
||||
return createTranslator( ast, executionContext );
|
||||
}
|
||||
|
||||
protected abstract S buildAst(
|
||||
SqmTranslation<DeleteStatement> sqmInterpretation,
|
||||
DomainQueryExecutionContext executionContext);
|
||||
|
||||
protected abstract SqlAstTranslator<O> createTranslator(
|
||||
S ast,
|
||||
DomainQueryExecutionContext executionContext);
|
||||
}
|
|
@ -766,9 +766,7 @@ public class QuerySqmImpl<R>
|
|||
return new MultiTableDeleteQueryPlan( sqmDelete, domainParameterXref, multiTableStrategy );
|
||||
}
|
||||
else {
|
||||
return persister.getSoftDeleteMapping() != null
|
||||
? new SoftDeleteQueryPlan( persister, sqmDelete, domainParameterXref )
|
||||
: new SimpleDeleteQueryPlan( persister, sqmDelete, domainParameterXref );
|
||||
return new SimpleDeleteQueryPlan( persister, sqmDelete, domainParameterXref );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,42 +6,240 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.action.internal.BulkOperationCleanupAction;
|
||||
import org.hibernate.dialect.DmlTargetColumnQualifierSupport;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.MutableObject;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.mapping.SoftDeleteMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
|
||||
import org.hibernate.query.spi.DomainQueryExecutionContext;
|
||||
import org.hibernate.query.spi.NonSelectQueryPlan;
|
||||
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslation;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslator;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete;
|
||||
import org.hibernate.sql.ast.tree.AbstractUpdateOrDeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcLiteral;
|
||||
import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleDeleteQueryPlan extends AbstractDeleteQueryPlan<DeleteStatement, JdbcOperationQueryDelete> {
|
||||
public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
|
||||
private final EntityMappingType entityDescriptor;
|
||||
private final SqmDeleteStatement<?> sqmDelete;
|
||||
private final DomainParameterXref domainParameterXref;
|
||||
|
||||
private JdbcOperationQueryMutation jdbcOperation;
|
||||
|
||||
private SqmTranslation<? extends AbstractUpdateOrDeleteStatement> sqmInterpretation;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
|
||||
public SimpleDeleteQueryPlan(
|
||||
EntityMappingType entityDescriptor,
|
||||
SqmDeleteStatement<?> sqmDelete,
|
||||
DomainParameterXref domainParameterXref) {
|
||||
super( entityDescriptor, sqmDelete, domainParameterXref );
|
||||
assert entityDescriptor.getEntityName().equals( sqmDelete.getTarget().getEntityName() );
|
||||
|
||||
this.entityDescriptor = entityDescriptor;
|
||||
this.sqmDelete = sqmDelete;
|
||||
this.domainParameterXref = domainParameterXref;
|
||||
}
|
||||
|
||||
public EntityMappingType getEntityDescriptor() {
|
||||
return entityDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteStatement buildAst(
|
||||
SqmTranslation<DeleteStatement> sqmInterpretation,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
return sqmInterpretation.getSqlAst();
|
||||
public int executeUpdate(DomainQueryExecutionContext executionContext) {
|
||||
BulkOperationCleanupAction.schedule( executionContext.getSession(), sqmDelete );
|
||||
|
||||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
SqlAstTranslator<? extends JdbcOperationQueryMutation> sqlAstTranslator = null;
|
||||
if ( jdbcOperation == null ) {
|
||||
sqlAstTranslator = createTranslator( executionContext );
|
||||
}
|
||||
|
||||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
sqmInterpretation.getFromClauseAccess()::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
return (MappingModelExpressible<T>) sqmInterpretation.getSqmParameterMappingModelTypeResolutions().get(parameter);
|
||||
}
|
||||
},
|
||||
session
|
||||
);
|
||||
|
||||
if ( jdbcOperation != null
|
||||
&& ! jdbcOperation.isCompatibleWith( jdbcParameterBindings, executionContext.getQueryOptions() ) ) {
|
||||
sqlAstTranslator = createTranslator( executionContext );
|
||||
}
|
||||
|
||||
if ( sqlAstTranslator != null ) {
|
||||
jdbcOperation = sqlAstTranslator.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
}
|
||||
|
||||
final boolean missingRestriction = sqmInterpretation.getSqlAst().getRestriction() == null;
|
||||
if ( missingRestriction ) {
|
||||
assert domainParameterXref.getSqmParameterCount() == 0;
|
||||
assert jdbcParamsXref.isEmpty();
|
||||
}
|
||||
|
||||
final SqmJdbcExecutionContextAdapter executionContextAdapter = SqmJdbcExecutionContextAdapter.usingLockingAndPaging( executionContext );
|
||||
|
||||
SqmMutationStrategyHelper.cleanUpCollectionTables(
|
||||
entityDescriptor,
|
||||
(tableReference, attributeMapping) -> {
|
||||
final TableGroup collectionTableGroup = new MutatingTableReferenceGroupWrapper(
|
||||
new NavigablePath( attributeMapping.getRootPathName() ),
|
||||
attributeMapping,
|
||||
(NamedTableReference) tableReference
|
||||
);
|
||||
|
||||
final MutableObject<Predicate> additionalPredicate = new MutableObject<>();
|
||||
attributeMapping.applyBaseRestrictions(
|
||||
p -> additionalPredicate.set( Predicate.combinePredicates( additionalPredicate.get(), p ) ),
|
||||
collectionTableGroup,
|
||||
factory.getJdbcServices().getDialect().getDmlTargetColumnQualifierSupport() == DmlTargetColumnQualifierSupport.TABLE_ALIAS,
|
||||
executionContext.getSession().getLoadQueryInfluencers().getEnabledFilters(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if ( missingRestriction ) {
|
||||
return additionalPredicate.get();
|
||||
}
|
||||
|
||||
final ForeignKeyDescriptor fkDescriptor = attributeMapping.getKeyDescriptor();
|
||||
final Expression fkColumnExpression = MappingModelCreationHelper.buildColumnReferenceExpression(
|
||||
collectionTableGroup,
|
||||
fkDescriptor.getKeyPart(),
|
||||
null,
|
||||
factory
|
||||
);
|
||||
|
||||
final QuerySpec matchingIdSubQuery = new QuerySpec( false );
|
||||
|
||||
final MutatingTableReferenceGroupWrapper tableGroup = new MutatingTableReferenceGroupWrapper(
|
||||
new NavigablePath( attributeMapping.getRootPathName() ),
|
||||
attributeMapping,
|
||||
sqmInterpretation.getSqlAst().getTargetTable()
|
||||
);
|
||||
final Expression fkTargetColumnExpression = MappingModelCreationHelper.buildColumnReferenceExpression(
|
||||
tableGroup,
|
||||
fkDescriptor.getTargetPart(),
|
||||
sqmInterpretation.getSqlExpressionResolver(),
|
||||
factory
|
||||
);
|
||||
matchingIdSubQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( 0, fkTargetColumnExpression ) );
|
||||
|
||||
matchingIdSubQuery.getFromClause().addRoot(
|
||||
tableGroup
|
||||
);
|
||||
|
||||
matchingIdSubQuery.applyPredicate( SqmMutationStrategyHelper.getIdSubqueryPredicate(
|
||||
sqmInterpretation.getSqlAst().getRestriction(),
|
||||
entityDescriptor,
|
||||
tableGroup,
|
||||
session
|
||||
) );
|
||||
|
||||
return Predicate.combinePredicates(
|
||||
additionalPredicate.get(),
|
||||
new InSubQueryPredicate( fkColumnExpression, matchingIdSubQuery, false )
|
||||
);
|
||||
},
|
||||
( missingRestriction ? JdbcParameterBindings.NO_BINDINGS : jdbcParameterBindings ),
|
||||
executionContextAdapter
|
||||
);
|
||||
|
||||
return jdbcServices.getJdbcMutationExecutor().execute(
|
||||
jdbcOperation,
|
||||
jdbcParameterBindings,
|
||||
sql -> session
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( sql ),
|
||||
(integer, preparedStatement) -> {},
|
||||
executionContextAdapter
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlAstTranslator<JdbcOperationQueryDelete> createTranslator(
|
||||
DeleteStatement ast,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
protected SqlAstTranslator<? extends JdbcOperationQueryMutation> createTranslator(DomainQueryExecutionContext executionContext) {
|
||||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
final SqmTranslator<? extends MutationStatement> translator = factory.getQueryEngine().getSqmTranslatorFactory().createMutationTranslator(
|
||||
sqmDelete,
|
||||
executionContext.getQueryOptions(),
|
||||
domainParameterXref,
|
||||
executionContext.getQueryParameterBindings(),
|
||||
executionContext.getSession().getLoadQueryInfluencers(),
|
||||
factory
|
||||
);
|
||||
//noinspection unchecked
|
||||
sqmInterpretation = (SqmTranslation<? extends AbstractUpdateOrDeleteStatement>) translator.translate();
|
||||
|
||||
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmInterpretation::getJdbcParamsBySqmParam
|
||||
);
|
||||
final MutationStatement ast;
|
||||
if ( entityDescriptor.getSoftDeleteMapping() == null ) {
|
||||
ast = sqmInterpretation.getSqlAst();
|
||||
}
|
||||
else {
|
||||
final AbstractUpdateOrDeleteStatement sqlDeleteAst = sqmInterpretation.getSqlAst();
|
||||
final NamedTableReference targetTable = sqlDeleteAst.getTargetTable();
|
||||
final SoftDeleteMapping columnMapping = getEntityDescriptor().getSoftDeleteMapping();
|
||||
final ColumnReference columnReference = new ColumnReference( targetTable, columnMapping );
|
||||
//noinspection rawtypes,unchecked
|
||||
final JdbcLiteral jdbcLiteral = new JdbcLiteral( columnMapping.getDeletedLiteralValue(), columnMapping.getJdbcMapping() );
|
||||
final Assignment assignment = new Assignment( columnReference, jdbcLiteral );
|
||||
|
||||
ast = new UpdateStatement(
|
||||
targetTable,
|
||||
Collections.singletonList( assignment ),
|
||||
sqlDeleteAst.getRestriction()
|
||||
);
|
||||
}
|
||||
return factory.getJdbcServices()
|
||||
.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildDeleteTranslator( factory, ast );
|
||||
.buildMutationTranslator( factory, ast );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,12 +19,15 @@ import org.hibernate.query.spi.NonSelectQueryPlan;
|
|||
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslation;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslator;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
|
||||
|
@ -36,7 +39,7 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
private final DomainParameterXref domainParameterXref;
|
||||
private Map<SqmParameter<?>, MappingModelExpressible<?>> paramTypeResolutions;
|
||||
|
||||
private JdbcOperationQueryInsert jdbcInsert;
|
||||
private JdbcOperationQueryMutation jdbcInsert;
|
||||
private FromClauseAccess tableGroupAccess;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
|
||||
|
@ -47,12 +50,11 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
this.domainParameterXref = domainParameterXref;
|
||||
}
|
||||
|
||||
private SqlAstTranslator<JdbcOperationQueryInsert> createInsertTranslator(DomainQueryExecutionContext executionContext) {
|
||||
private SqlAstTranslator<? extends JdbcOperationQueryMutation> createInsertTranslator(DomainQueryExecutionContext executionContext) {
|
||||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
|
||||
final SqmTranslation<InsertStatement> sqmInterpretation =
|
||||
factory.getQueryEngine().getSqmTranslatorFactory()
|
||||
.createInsertTranslator(
|
||||
final SqmTranslation<? extends MutationStatement> sqmInterpretation = factory.getQueryEngine().getSqmTranslatorFactory()
|
||||
.createMutationTranslator(
|
||||
sqmInsert,
|
||||
executionContext.getQueryOptions(),
|
||||
domainParameterXref,
|
||||
|
@ -74,7 +76,7 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
return factory.getJdbcServices()
|
||||
.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildInsertTranslator( factory, sqmInterpretation.getSqlAst() );
|
||||
.buildMutationTranslator( factory, sqmInterpretation.getSqlAst() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +85,7 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
SqlAstTranslator<JdbcOperationQueryInsert> insertTranslator = null;
|
||||
SqlAstTranslator<? extends JdbcOperationQueryMutation> insertTranslator = null;
|
||||
if ( jdbcInsert == null ) {
|
||||
insertTranslator = createInsertTranslator( executionContext );
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
|||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
|
@ -35,7 +37,7 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
private final SqmUpdateStatement<?> sqmUpdate;
|
||||
private final DomainParameterXref domainParameterXref;
|
||||
|
||||
private JdbcOperationQueryUpdate jdbcUpdate;
|
||||
private JdbcOperationQueryMutation jdbcUpdate;
|
||||
private FromClauseAccess tableGroupAccess;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
private Map<SqmParameter<?>, MappingModelExpressible<?>> sqmParamMappingTypeResolutions;
|
||||
|
@ -53,7 +55,7 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
SqlAstTranslator<JdbcOperationQueryUpdate> updateTranslator = null;
|
||||
SqlAstTranslator<? extends JdbcOperationQueryMutation> updateTranslator = null;
|
||||
if ( jdbcUpdate == null ) {
|
||||
updateTranslator = createUpdateTranslator( executionContext );
|
||||
}
|
||||
|
@ -96,12 +98,12 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
);
|
||||
}
|
||||
|
||||
private SqlAstTranslator<JdbcOperationQueryUpdate> createUpdateTranslator(DomainQueryExecutionContext executionContext) {
|
||||
private SqlAstTranslator<? extends JdbcOperationQueryMutation> createUpdateTranslator(DomainQueryExecutionContext executionContext) {
|
||||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
|
||||
final SqmTranslation<UpdateStatement> sqmInterpretation =
|
||||
final SqmTranslation<? extends MutationStatement> sqmInterpretation =
|
||||
factory.getQueryEngine().getSqmTranslatorFactory()
|
||||
.createSimpleUpdateTranslator(
|
||||
.createMutationTranslator(
|
||||
sqmUpdate,
|
||||
executionContext.getQueryOptions(),
|
||||
domainParameterXref,
|
||||
|
@ -121,6 +123,6 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
this.sqmParamMappingTypeResolutions = sqmInterpretation.getSqmParameterMappingModelTypeResolutions();
|
||||
|
||||
return factory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( factory, sqmInterpretation.getSqlAst() );
|
||||
.buildMutationTranslator( factory, sqmInterpretation.getSqlAst() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
|
||||
*/
|
||||
package org.hibernate.query.sqm.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.SoftDeleteMapping;
|
||||
import org.hibernate.query.spi.DomainQueryExecutionContext;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslation;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcLiteral;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
|
||||
/**
|
||||
* NonSelectQueryPlan for handling DELETE queries against an entity with soft-delete
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SoftDeleteQueryPlan extends AbstractDeleteQueryPlan<UpdateStatement,JdbcOperationQueryUpdate> {
|
||||
public SoftDeleteQueryPlan(
|
||||
EntityMappingType entityDescriptor,
|
||||
SqmDeleteStatement<?> sqmDelete,
|
||||
DomainParameterXref domainParameterXref) {
|
||||
super( entityDescriptor, sqmDelete, domainParameterXref );
|
||||
assert entityDescriptor.getSoftDeleteMapping() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UpdateStatement buildAst(
|
||||
SqmTranslation<DeleteStatement> sqmInterpretation,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
final DeleteStatement sqlDeleteAst = sqmInterpretation.getSqlAst();
|
||||
final NamedTableReference targetTable = sqlDeleteAst.getTargetTable();
|
||||
final SoftDeleteMapping columnMapping = getEntityDescriptor().getSoftDeleteMapping();
|
||||
final ColumnReference columnReference = new ColumnReference( targetTable, columnMapping );
|
||||
//noinspection rawtypes,unchecked
|
||||
final JdbcLiteral jdbcLiteral = new JdbcLiteral( columnMapping.getDeletedLiteralValue(), columnMapping.getJdbcMapping() );
|
||||
final Assignment assignment = new Assignment( columnReference, jdbcLiteral );
|
||||
|
||||
return new UpdateStatement(
|
||||
targetTable,
|
||||
Collections.singletonList( assignment ),
|
||||
sqlDeleteAst.getRestriction()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlAstTranslator<JdbcOperationQueryUpdate> createTranslator(
|
||||
UpdateStatement sqlUpdateAst,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
return factory.getJdbcServices()
|
||||
.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( factory, sqlUpdateAst );
|
||||
}
|
||||
}
|
|
@ -174,7 +174,7 @@ public class SqmMutationStrategyHelper {
|
|||
jdbcServices.getJdbcMutationExecutor().execute(
|
||||
jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildDeleteTranslator( sessionFactory, sqlAstDelete )
|
||||
.buildMutationTranslator( sessionFactory, sqlAstDelete )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() ),
|
||||
jdbcParameterBindings,
|
||||
sql -> executionContext.getSession()
|
||||
|
|
|
@ -34,8 +34,7 @@ import org.hibernate.sql.ast.tree.update.Assignment;
|
|||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
||||
import org.hibernate.sql.exec.spi.JdbcMutationExecutor;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.StatementCreatorHelper;
|
||||
|
||||
|
@ -208,8 +207,8 @@ public class InlineDeleteHandler implements DeleteHandler {
|
|||
predicate
|
||||
);
|
||||
|
||||
final JdbcOperationQueryUpdate jdbcOperation = sqlAstTranslatorFactory
|
||||
.buildUpdateTranslator( sessionFactory, updateStatement )
|
||||
final JdbcOperationQueryMutation jdbcOperation = sqlAstTranslatorFactory
|
||||
.buildMutationTranslator( sessionFactory, updateStatement )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
jdbcMutationExecutor.execute(
|
||||
|
@ -249,7 +248,7 @@ public class InlineDeleteHandler implements DeleteHandler {
|
|||
|
||||
final DeleteStatement deleteStatement = new DeleteStatement( targetTableReference, matchingIdsPredicate );
|
||||
|
||||
final JdbcOperationQueryDelete jdbcOperation = sqlAstTranslatorFactory.buildDeleteTranslator( sessionFactory, deleteStatement )
|
||||
final JdbcOperationQueryMutation jdbcOperation = sqlAstTranslatorFactory.buildMutationTranslator( sessionFactory, deleteStatement )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
jdbcMutationExecutor.execute(
|
||||
|
|
|
@ -77,8 +77,7 @@ import org.hibernate.sql.ast.tree.update.Assignment;
|
|||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcMutationExecutor;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
|
@ -379,9 +378,9 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
final UpdateStatement sqlAst = new UpdateStatement( dmlTableReference, assignments, idListPredicate );
|
||||
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( sessionFactory, sqlAst )
|
||||
.buildMutationTranslator( sessionFactory, sqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
final int updateCount = jdbcServices.getJdbcMutationExecutor().execute(
|
||||
|
@ -550,9 +549,9 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
insertSqlAst.addTargetColumnReferences( targetColumnReferences.toArray( new ColumnReference[0] ) );
|
||||
insertSqlAst.setSourceSelectStatement( querySpec );
|
||||
|
||||
final JdbcOperationQueryInsert jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildInsertTranslator( sessionFactory, insertSqlAst )
|
||||
.buildMutationTranslator( sessionFactory, insertSqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
final int insertCount = jdbcServices.getJdbcMutationExecutor().execute(
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.hibernate.sql.ast.tree.predicate.Predicate;
|
|||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
|
@ -152,7 +153,7 @@ public final class ExecuteWithTemporaryTableHelper {
|
|||
}
|
||||
);
|
||||
}
|
||||
final JdbcOperationQueryInsert jdbcInsert = sqlAstTranslatorFactory.buildInsertTranslator( factory, temporaryTableInsert )
|
||||
final JdbcOperationQueryMutation jdbcInsert = sqlAstTranslatorFactory.buildMutationTranslator( factory, temporaryTableInsert )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
lockOptions.setLockMode( lockMode );
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
|||
import org.hibernate.sql.exec.internal.JdbcParameterImpl;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
|
@ -473,9 +474,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
)
|
||||
);
|
||||
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( sessionFactory, updateStatement )
|
||||
.buildMutationTranslator( sessionFactory, updateStatement )
|
||||
.translate( null, executionContext.getQueryOptions() );
|
||||
final JdbcParameterBindings updateBindings = new JdbcParameterBindingsImpl( 2 );
|
||||
if ( sessionUidColumn != null ) {
|
||||
|
@ -540,9 +541,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
}
|
||||
}
|
||||
|
||||
final JdbcOperationQueryInsert jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildInsertTranslator( sessionFactory, insertStatement )
|
||||
.buildMutationTranslator( sessionFactory, insertStatement )
|
||||
.translate( null, executionContext.getQueryOptions() );
|
||||
|
||||
if ( generator.generatedOnExecution() ) {
|
||||
|
@ -596,9 +597,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
)
|
||||
);
|
||||
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( sessionFactory, updateStatement )
|
||||
.buildMutationTranslator( sessionFactory, updateStatement )
|
||||
.translate( null, executionContext.getQueryOptions() );
|
||||
final JdbcParameterBindings updateBindings = new JdbcParameterBindingsImpl( 2 );
|
||||
|
||||
|
@ -740,9 +741,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
);
|
||||
}
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcOperationQueryInsert jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildInsertTranslator( sessionFactory, insertStatement )
|
||||
.buildMutationTranslator( sessionFactory, insertStatement )
|
||||
.translate( null, executionContext.getQueryOptions() );
|
||||
|
||||
jdbcServices.getJdbcMutationExecutor().execute(
|
||||
|
|
|
@ -58,7 +58,7 @@ import org.hibernate.sql.ast.tree.predicate.Predicate;
|
|||
import org.hibernate.sql.ast.tree.predicate.PredicateCollector;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
|
||||
import static org.hibernate.query.sqm.mutation.internal.MutationQueryLogging.MUTATION_QUERY_LOGGER;
|
||||
|
@ -434,9 +434,9 @@ public class RestrictedDeleteExecutionDelegate extends AbstractDeleteExecutionDe
|
|||
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
|
||||
final JdbcOperationQueryDelete jdbcDelete = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcDelete = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildDeleteTranslator( factory, sqlAst )
|
||||
.buildMutationTranslator( factory, sqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
return jdbcServices.getJdbcMutationExecutor().execute(
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec;
|
|||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
@ -413,9 +414,9 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
final JdbcServices jdbcServices = factory.getJdbcServices();
|
||||
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
final JdbcOperationQueryMutation jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildUpdateTranslator( factory, updateStatement )
|
||||
.buildMutationTranslator( factory, updateStatement )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
return jdbcServices.getJdbcMutationExecutor().execute(
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
|||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcMutationExecutor;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
@ -369,8 +370,8 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
insertSqlAst.addTargetColumnReferences( targetColumnReferences.toArray( new ColumnReference[0] ) );
|
||||
insertSqlAst.setSourceSelectStatement( insertSourceSelectQuerySpec );
|
||||
|
||||
final JdbcOperationQueryInsert jdbcInsert = sqlAstTranslatorFactory
|
||||
.buildInsertTranslator( sessionFactory, insertSqlAst )
|
||||
final JdbcOperationQueryMutation jdbcInsert = sqlAstTranslatorFactory
|
||||
.buildMutationTranslator( sessionFactory, insertSqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
return jdbcMutationExecutor.execute(
|
||||
|
@ -443,8 +444,8 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
new InSubQueryPredicate( keyExpression, idTableSubQuery, false )
|
||||
);
|
||||
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = sqlAstTranslatorFactory
|
||||
.buildUpdateTranslator( sessionFactory, sqlAst )
|
||||
final JdbcOperationQueryMutation jdbcUpdate = sqlAstTranslatorFactory
|
||||
.buildMutationTranslator( sessionFactory, sqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
final int updateCount = jdbcMutationExecutor.execute(
|
||||
|
|
|
@ -10,11 +10,13 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
|
|||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.spi.QueryParameterBindings;
|
||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||
import org.hibernate.query.sqm.tree.SqmDmlStatement;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
||||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
|
@ -34,28 +36,78 @@ public interface SqmTranslatorFactory {
|
|||
SqlAstCreationContext creationContext,
|
||||
boolean deduplicateSelectionItems);
|
||||
|
||||
SqmTranslator<DeleteStatement> createSimpleDeleteTranslator(
|
||||
SqmTranslator<? extends MutationStatement> createMutationTranslator(
|
||||
SqmDmlStatement<?> sqmDeleteStatement,
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
||||
QueryParameterBindings domainParameterBindings,
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SqlAstCreationContext creationContext);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #createMutationTranslator(SqmDmlStatement, QueryOptions, DomainParameterXref, QueryParameterBindings, LoadQueryInfluencers, SqlAstCreationContext)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqmTranslator<DeleteStatement> createSimpleDeleteTranslator(
|
||||
SqmDeleteStatement<?> sqmDeleteStatement,
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
||||
QueryParameterBindings domainParameterBindings,
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationContext creationContext) {
|
||||
//noinspection unchecked
|
||||
return (SqmTranslator<DeleteStatement>) createMutationTranslator(
|
||||
sqmDeleteStatement,
|
||||
queryOptions,
|
||||
domainParameterXref,
|
||||
domainParameterBindings,
|
||||
loadQueryInfluencers,
|
||||
creationContext
|
||||
);
|
||||
}
|
||||
|
||||
SqmTranslator<InsertStatement> createInsertTranslator(
|
||||
/**
|
||||
* @deprecated Use {@link #createMutationTranslator(SqmDmlStatement, QueryOptions, DomainParameterXref, QueryParameterBindings, LoadQueryInfluencers, SqlAstCreationContext)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqmTranslator<InsertStatement> createInsertTranslator(
|
||||
SqmInsertStatement<?> sqmInsertStatement,
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
||||
QueryParameterBindings domainParameterBindings,
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationContext creationContext) {
|
||||
//noinspection unchecked
|
||||
return (SqmTranslator<InsertStatement>) createMutationTranslator(
|
||||
sqmInsertStatement,
|
||||
queryOptions,
|
||||
domainParameterXref,
|
||||
domainParameterBindings,
|
||||
loadQueryInfluencers,
|
||||
creationContext
|
||||
);
|
||||
}
|
||||
|
||||
SqmTranslator<UpdateStatement> createSimpleUpdateTranslator(
|
||||
/**
|
||||
* @deprecated Use {@link #createMutationTranslator(SqmDmlStatement, QueryOptions, DomainParameterXref, QueryParameterBindings, LoadQueryInfluencers, SqlAstCreationContext)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqmTranslator<UpdateStatement> createSimpleUpdateTranslator(
|
||||
SqmUpdateStatement<?> sqmUpdateStatement,
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
||||
QueryParameterBindings queryParameterBindings,
|
||||
QueryParameterBindings domainParameterBindings,
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationContext creationContext) {
|
||||
//noinspection unchecked
|
||||
return (SqmTranslator<UpdateStatement>) createMutationTranslator(
|
||||
sqmUpdateStatement,
|
||||
queryOptions,
|
||||
domainParameterXref,
|
||||
domainParameterBindings,
|
||||
loadQueryInfluencers,
|
||||
creationContext
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,11 +11,13 @@ import org.hibernate.query.spi.QueryOptions;
|
|||
import org.hibernate.query.spi.QueryParameterBindings;
|
||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||
import org.hibernate.query.sqm.sql.internal.StandardSqmTranslator;
|
||||
import org.hibernate.query.sqm.tree.SqmDmlStatement;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
||||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
|
@ -48,6 +50,25 @@ public class StandardSqmTranslatorFactory implements SqmTranslatorFactory {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmTranslator<? extends MutationStatement> createMutationTranslator(
|
||||
SqmDmlStatement<?> sqmDeleteStatement,
|
||||
QueryOptions queryOptions,
|
||||
DomainParameterXref domainParameterXref,
|
||||
QueryParameterBindings domainParameterBindings,
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return new StandardSqmTranslator<>(
|
||||
sqmDeleteStatement,
|
||||
queryOptions,
|
||||
domainParameterXref,
|
||||
domainParameterBindings,
|
||||
loadQueryInfluencers,
|
||||
creationContext,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmTranslator<DeleteStatement> createSimpleDeleteTranslator(
|
||||
SqmDeleteStatement<?> sqmDeleteStatement,
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
package org.hibernate.sql.ast;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.model.ast.TableMutation;
|
||||
|
@ -30,19 +32,42 @@ public interface SqlAstTranslatorFactory {
|
|||
SqlAstTranslator<JdbcOperationQuerySelect> buildSelectTranslator(SessionFactoryImplementor sessionFactory, SelectStatement statement);
|
||||
|
||||
/**
|
||||
* Builds a single-use delete translator
|
||||
* Builds a single-use mutation translator
|
||||
*/
|
||||
SqlAstTranslator<JdbcOperationQueryDelete> buildDeleteTranslator(SessionFactoryImplementor sessionFactory, DeleteStatement statement);
|
||||
SqlAstTranslator<? extends JdbcOperationQueryMutation> buildMutationTranslator(SessionFactoryImplementor sessionFactory, MutationStatement statement);
|
||||
|
||||
/**
|
||||
* Builds a single-use delete translator
|
||||
*
|
||||
* @deprecated Use {@link #buildMutationTranslator(SessionFactoryImplementor, MutationStatement)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqlAstTranslator<JdbcOperationQueryDelete> buildDeleteTranslator(SessionFactoryImplementor sessionFactory, DeleteStatement statement) {
|
||||
//noinspection unchecked
|
||||
return (SqlAstTranslator<JdbcOperationQueryDelete>) buildMutationTranslator( sessionFactory, statement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a single-use insert-select translator
|
||||
*
|
||||
* @deprecated Use {@link #buildMutationTranslator(SessionFactoryImplementor, MutationStatement)} instead
|
||||
*/
|
||||
SqlAstTranslator<JdbcOperationQueryInsert> buildInsertTranslator(SessionFactoryImplementor sessionFactory, InsertStatement statement);
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqlAstTranslator<JdbcOperationQueryInsert> buildInsertTranslator(SessionFactoryImplementor sessionFactory, InsertStatement statement) {
|
||||
//noinspection unchecked
|
||||
return (SqlAstTranslator<JdbcOperationQueryInsert>) buildMutationTranslator( sessionFactory, statement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a single-use update translator
|
||||
*
|
||||
* @deprecated Use {@link #buildMutationTranslator(SessionFactoryImplementor, MutationStatement)} instead
|
||||
*/
|
||||
SqlAstTranslator<JdbcOperationQueryUpdate> buildUpdateTranslator(SessionFactoryImplementor sessionFactory, UpdateStatement statement);
|
||||
@Deprecated(forRemoval = true)
|
||||
default SqlAstTranslator<JdbcOperationQueryUpdate> buildUpdateTranslator(SessionFactoryImplementor sessionFactory, UpdateStatement statement) {
|
||||
//noinspection unchecked
|
||||
return (SqlAstTranslator<JdbcOperationQueryUpdate>) buildMutationTranslator( sessionFactory, statement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a single-use translator for dealing with model mutations
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.sql.ast.spi;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.Statement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
|
@ -17,6 +18,7 @@ import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
|||
import org.hibernate.sql.exec.spi.JdbcOperation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.model.ast.TableMutation;
|
||||
|
@ -34,6 +36,11 @@ public class StandardSqlAstTranslatorFactory implements SqlAstTranslatorFactory
|
|||
return buildTranslator( sessionFactory, statement );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlAstTranslator<? extends JdbcOperationQueryMutation> buildMutationTranslator(SessionFactoryImplementor sessionFactory, MutationStatement statement) {
|
||||
return buildTranslator( sessionFactory, statement );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlAstTranslator<JdbcOperationQueryDelete> buildDeleteTranslator(SessionFactoryImplementor sessionFactory, DeleteStatement statement) {
|
||||
return buildTranslator( sessionFactory, statement );
|
||||
|
|
Loading…
Reference in New Issue