Working support for simple HQL DELETE -> execution!!
This commit is contained in:
parent
30ad3eabe5
commit
e6895c3d91
|
@ -166,6 +166,7 @@ import org.hibernate.property.access.spi.PropertyAccess;
|
|||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.query.ComparisonOperator;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.Alias;
|
||||
import org.hibernate.sql.Delete;
|
||||
|
@ -237,7 +238,7 @@ public abstract class AbstractEntityPersister
|
|||
private final MultiIdEntityLoader multiIdEntityLoader;
|
||||
private final NaturalIdLoader naturalIdLoader;
|
||||
|
||||
|
||||
private SqmMultiTableMutationStrategy sqmMultiTableMutationStrategy;
|
||||
|
||||
|
||||
|
||||
|
@ -6184,6 +6185,21 @@ public abstract class AbstractEntityPersister
|
|||
else {
|
||||
accessOptimizer = null;
|
||||
}
|
||||
|
||||
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
|
||||
|
||||
if ( isMultiTable() ) {
|
||||
sqmMultiTableMutationStrategy = null;
|
||||
//sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect().getFallbackSqmMutationStrategy( this )
|
||||
}
|
||||
else {
|
||||
sqmMultiTableMutationStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy() {
|
||||
return sqmMultiTableMutationStrategy;
|
||||
}
|
||||
|
||||
protected int getStateArrayInitialPosition(MappingModelCreationProcess creationProcess) {
|
||||
|
|
|
@ -166,7 +166,7 @@ public interface EntityPersister extends EntityDefinition, EntityValuedModelPart
|
|||
* has multiple tables. Returns {@code null} to indicate that the entity
|
||||
* does not define multiple tables
|
||||
*/
|
||||
default SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy(){
|
||||
default SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy() {
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ public class StandardSqlAstDeleteTranslator
|
|||
appendSql( "delete from " );
|
||||
appendSql( sqlAst.getTargetTable().getTableExpression() );
|
||||
|
||||
sqlAst.getRestriction().accept( this );
|
||||
if ( sqlAst.getRestriction() != null ) {
|
||||
sqlAst.getRestriction().accept( this );
|
||||
}
|
||||
|
||||
return new JdbcDelete() {
|
||||
@Override
|
||||
|
|
|
@ -45,6 +45,8 @@ public class StandardJdbcMutationExecutor implements JdbcMutationExecutor {
|
|||
|
||||
final String sql = jdbcMutation.getSql();
|
||||
try {
|
||||
jdbcServices.getSqlStatementLogger().logStatement( sql );
|
||||
|
||||
// prepare the query
|
||||
final PreparedStatement preparedStatement = statementCreator.apply( sql );
|
||||
|
||||
|
@ -64,9 +66,16 @@ public class StandardJdbcMutationExecutor implements JdbcMutationExecutor {
|
|||
executionContext
|
||||
);
|
||||
}
|
||||
int rows = preparedStatement.executeUpdate();
|
||||
expectationCheck.accept( rows, preparedStatement );
|
||||
return rows;
|
||||
|
||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementStart();
|
||||
try {
|
||||
int rows = preparedStatement.executeUpdate();
|
||||
expectationCheck.accept( rows, preparedStatement );
|
||||
return rows;
|
||||
}
|
||||
finally {
|
||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementEnd();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
logicalConnection.getResourceRegistry().release( preparedStatement );
|
||||
|
|
|
@ -97,7 +97,13 @@ public class DeferredResultSetAccess extends AbstractResultSetAccess {
|
|||
);
|
||||
}
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementStart();
|
||||
try {
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
}
|
||||
finally {
|
||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementEnd();
|
||||
}
|
||||
logicalConnection.getResourceRegistry().register( resultSet, preparedStatement );
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.orm.test.sql.exec;
|
||||
|
||||
import org.hibernate.orm.test.metamodel.mapping.PluralAttributeTests;
|
||||
|
||||
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||
@ServiceRegistry
|
||||
@SessionFactory( exportSchema = true )
|
||||
public class HqlDeleteExecutionTests {
|
||||
@Test
|
||||
public void testSimpleDelete(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> session.createQuery( "delete BasicEntity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue