From 076a0aa25a75571dd78a840cb9588035f3e65864 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 28 Aug 2020 13:11:22 +0100 Subject: [PATCH] fix compilation errors after merging master --- .../ast/exec/IdSubselectUpdateExecutor.java | 120 ------------------ .../hql/internal/ast/exec/InsertExecutor.java | 59 --------- .../ast/exec/SimpleUpdateExecutor.java | 69 ---------- 3 files changed, 248 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/IdSubselectUpdateExecutor.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/InsertExecutor.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/SimpleUpdateExecutor.java diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/IdSubselectUpdateExecutor.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/IdSubselectUpdateExecutor.java deleted file mode 100644 index 38dade2b2f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/IdSubselectUpdateExecutor.java +++ /dev/null @@ -1,120 +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 . - */ -package org.hibernate.hql.internal.ast.exec; - -import antlr.RecognitionException; -import org.hibernate.AssertionFailure; -import org.hibernate.HibernateException; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.hql.internal.ast.HqlSqlWalker; -import org.hibernate.hql.internal.ast.QuerySyntaxException; -import org.hibernate.hql.internal.ast.SqlGenerator; -import org.hibernate.hql.internal.ast.tree.AssignmentSpecification; -import org.hibernate.hql.internal.ast.tree.UpdateStatement; -import org.hibernate.param.ParameterSpecification; -import org.hibernate.persister.entity.Queryable; -import org.hibernate.sql.Update; - -import java.util.List; -import java.util.stream.IntStream; - -import static org.hibernate.hql.spi.id.AbstractTableBasedBulkIdHandler.generateIdSelect; - -/** - * Executes HQL bulk updates against a single table, using a subselect - * against multiple tables to collect ids, which is needed when the - * where condition of the query touches columns from multiple tables. - * - * @author Gavin King - */ -public class IdSubselectUpdateExecutor extends BasicExecutor { - - private final Queryable persister; - private final String sql; - private final List parameterSpecifications; - - public Queryable getPersister() { - return persister; - } - @Override - public String getSql() { - return sql; - } - - @Override - public List getParameterSpecifications() { - return parameterSpecifications; - } - - public IdSubselectUpdateExecutor(HqlSqlWalker walker) { - persister = walker.getFinalFromClause().getFromElement().getQueryable(); - - Dialect dialect = walker.getDialect(); - UpdateStatement updateStatement = (UpdateStatement) walker.getAST(); - List assignments = walker.getAssignmentSpecifications(); - - String whereClause; - if ( updateStatement.getWhereClause().getNumberOfChildren() == 0 ) { - whereClause = ""; - } - else { - try { - SqlGenerator gen = new SqlGenerator( walker.getSessionFactoryHelper().getFactory() ); - gen.whereClause( updateStatement.getWhereClause() ); - gen.getParseErrorHandler().throwQueryException(); - whereClause = gen.getSQL().substring( 7 ); // strip the " where " - } - catch ( RecognitionException e ) { - throw new HibernateException( "Unable to generate id select for DML operation", e ); - } - } - String tableAlias = updateStatement.getFromClause().getFromElement().getTableAlias(); - String idSelect = generateIdSelect( tableAlias, whereClause, dialect, persister ); - - String[] tableNames = persister.getConstraintOrderedTableNameClosure(); - String[][] columnNames = persister.getContraintOrderedTableKeyColumnClosure(); - - int[] affectedTables = - IntStream.range( 0, tableNames.length ).filter( - table -> assignments.stream().anyMatch( - assign -> assign.affectsTable( tableNames[table] ) - ) - ).toArray(); - if ( affectedTables.length > 1 ) { - throw new AssertionFailure("more than one affected table"); - } - int affectedTable = affectedTables[0]; - - String tableName = tableNames[affectedTable]; - String idColumnNames = String.join( ", ", columnNames[affectedTable] ); - Update update = new Update( dialect ).setTableName( tableName ); - if ( dialect instanceof MySQLDialect) { - //MySQL needs an extra subselect to hack the query optimizer - String selectedIdColumns = String.join( ", ", persister.getIdentifierColumnNames() ); - update.setWhere( "(" + idColumnNames + ") in (select " + selectedIdColumns + " from (" + idSelect + ") as ht_ids)" ); - } - else { - update.setWhere( "(" + idColumnNames + ") in (" + idSelect + ")" ); - } - for ( AssignmentSpecification assignment: assignments ) { - update.appendAssignmentFragment( assignment.getSqlAssignmentFragment() ); - } - sql = update.toStatementString(); - - // now collect the parameters from the whole query - // parameters included in the list - try { - SqlGenerator gen = new SqlGenerator( walker.getSessionFactoryHelper().getFactory() ); - gen.statement( walker.getAST() ); - parameterSpecifications = gen.getCollectedParameters(); - } - catch ( RecognitionException e ) { - throw QuerySyntaxException.convert( e ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/InsertExecutor.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/InsertExecutor.java deleted file mode 100644 index bdff7a5275..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/InsertExecutor.java +++ /dev/null @@ -1,59 +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 . - */ -package org.hibernate.hql.internal.ast.exec; - -import antlr.RecognitionException; -import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes; -import org.hibernate.hql.internal.ast.HqlSqlWalker; -import org.hibernate.hql.internal.ast.QuerySyntaxException; -import org.hibernate.hql.internal.ast.SqlGenerator; -import org.hibernate.hql.internal.ast.tree.InsertStatement; -import org.hibernate.hql.internal.ast.tree.Statement; -import org.hibernate.param.ParameterSpecification; -import org.hibernate.persister.entity.Queryable; - -import java.util.List; - -/** - * Executes HQL insert statements. - * - * @author Gavin King - */ -public class InsertExecutor extends BasicExecutor { - private final Queryable persister; - private final String sql; - private final List parameterSpecifications; - - @Override - public Queryable getPersister() { - return persister; - } - - @Override - public String getSql() { - return sql; - } - - @Override - public List getParameterSpecifications() { - return parameterSpecifications; - } - - public InsertExecutor(HqlSqlWalker walker) { - persister = ( (InsertStatement) walker.getAST() ).getIntoClause().getQueryable(); - try { - SqlGenerator gen = new SqlGenerator( walker.getSessionFactoryHelper().getFactory() ); - gen.statement( walker.getAST() ); - sql = gen.getSQL(); - gen.getParseErrorHandler().throwQueryException(); - parameterSpecifications = gen.getCollectedParameters(); - } - catch ( RecognitionException e ) { - throw QuerySyntaxException.convert( e ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/SimpleUpdateExecutor.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/SimpleUpdateExecutor.java deleted file mode 100644 index 4c7407c1bd..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/exec/SimpleUpdateExecutor.java +++ /dev/null @@ -1,69 +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 . - */ -package org.hibernate.hql.internal.ast.exec; - -import antlr.RecognitionException; -import org.hibernate.AssertionFailure; -import org.hibernate.hql.internal.ast.HqlSqlWalker; -import org.hibernate.hql.internal.ast.QuerySyntaxException; -import org.hibernate.hql.internal.ast.SqlGenerator; -import org.hibernate.param.ParameterSpecification; -import org.hibernate.persister.entity.Queryable; - -import java.util.List; - -/** - * Executes HQL bulk updates against a single table, where the - * query only touches columns from the table it's updating, and - * so we don't need to use a subselect. - * - * @author Gavin King - */ -public class SimpleUpdateExecutor extends BasicExecutor { - - private final Queryable persister; - private final String sql; - private final List parameterSpecifications; - - @Override - public Queryable getPersister() { - return persister; - } - - @Override - public String getSql() { - return sql; - } - - @Override - public List getParameterSpecifications() { - return parameterSpecifications; - } - - public SimpleUpdateExecutor(HqlSqlWalker walker) { - persister = walker.getFinalFromClause().getFromElement().getQueryable(); - - if ( persister.isMultiTable() && walker.getQuerySpaces().size() > 1 ) { - throw new AssertionFailure("not a simple update"); - } - - try { - SqlGenerator gen = new SqlGenerator( walker.getSessionFactoryHelper().getFactory() ); - gen.statement( walker.getAST() ); - gen.getParseErrorHandler().throwQueryException(); - // workaround for a problem where HqlSqlWalker actually generates - // broken SQL with undefined aliases in the where clause, because - // that is what MultiTableUpdateExecutor is expecting to get - String alias = walker.getFinalFromClause().getFromElement().getTableAlias(); - sql = gen.getSQL().replace( alias + ".", "" ); - parameterSpecifications = gen.getCollectedParameters(); - } - catch ( RecognitionException e ) { - throw QuerySyntaxException.convert( e ); - } - } -}