Minor cleanups to SqlAstTranslators

- rename SqlAstInsertSelectTranslator to SqlAstInsertTranslator
- use simplified for loops
This commit is contained in:
gavinking 2020-02-16 13:46:10 +01:00 committed by Steve Ebersole
parent 0381da76b9
commit c787dae475
9 changed files with 30 additions and 36 deletions

View File

@ -17,7 +17,7 @@ import org.hibernate.query.sqm.sql.SqmInsertTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
import org.hibernate.sql.ast.SqlAstInsertSelectTranslator;
import org.hibernate.sql.ast.SqlAstInsertTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
@ -75,7 +75,7 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
final SqlAstInsertSelectTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildInsertTranslator( factory );
final SqlAstInsertTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildInsertTranslator( factory );
jdbcInsert = sqlAstTranslator.translate( sqmInterpretation.getSqlAst() );
}

View File

@ -23,7 +23,7 @@ import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.query.ComparisonOperator;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
import org.hibernate.sql.ast.SqlAstInsertSelectTranslator;
import org.hibernate.sql.ast.SqlAstInsertTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
@ -129,7 +129,7 @@ public final class ExecuteWithIdTableHelper {
final JdbcServices jdbcServices = factory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
final SqlAstInsertSelectTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildInsertTranslator( factory );
final SqlAstInsertTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildInsertTranslator( factory );
final JdbcInsert jdbcInsert = sqlAstTranslator.translate( idTableInsert );
return jdbcServices.getJdbcMutationExecutor().execute(

View File

@ -12,6 +12,6 @@ import org.hibernate.sql.exec.spi.JdbcInsert;
/**
* @author Steve Ebersole
*/
public interface SqlAstInsertSelectTranslator extends SqlAstTranslator {
public interface SqlAstInsertTranslator extends SqlAstTranslator {
JdbcInsert translate(InsertStatement sqlAst);
}

View File

@ -27,7 +27,7 @@ public interface SqlAstTranslatorFactory {
/**
* Builds a single-use insert-select translator
*/
SqlAstInsertSelectTranslator buildInsertTranslator(SessionFactoryImplementor sessionFactory);
SqlAstInsertTranslator buildInsertTranslator(SessionFactoryImplementor sessionFactory);
SqlAstUpdateTranslator buildUpdateTranslator(SessionFactoryImplementor sessionFactory);

View File

@ -71,8 +71,7 @@ public class StandardSqlAstDeleteTranslator extends AbstractSqlAstTranslator imp
String separator = "";
for ( int i = 0; i < sqlAst.getCteTable().getCteColumns().size(); i++ ) {
final CteColumn cteColumn = sqlAst.getCteTable().getCteColumns().get( i );
for ( CteColumn cteColumn : sqlAst.getCteTable().getCteColumns() ) {
appendSql( separator );
appendSql( cteColumn.getColumnExpression() );
separator = ", ";

View File

@ -10,7 +10,7 @@ import java.util.List;
import java.util.Set;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.sql.ast.SqlAstInsertSelectTranslator;
import org.hibernate.sql.ast.SqlAstInsertTranslator;
import org.hibernate.sql.ast.tree.cte.CteColumn;
import org.hibernate.sql.ast.tree.cte.CteStatement;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
@ -23,10 +23,10 @@ import org.hibernate.sql.exec.spi.JdbcParameterBinder;
/**
* @author Steve Ebersole
*/
public class StandardSqlAstInsertSelectTranslator
public class StandardSqlAstInsertTranslator
extends AbstractSqlAstTranslator
implements SqlAstInsertSelectTranslator {
public StandardSqlAstInsertSelectTranslator(SessionFactoryImplementor sessionFactory) {
implements SqlAstInsertTranslator {
public StandardSqlAstInsertTranslator(SessionFactoryImplementor sessionFactory) {
super( sessionFactory );
}
@ -43,16 +43,15 @@ public class StandardSqlAstInsertSelectTranslator
renderImplicitTargetColumnSpec();
}
else {
for ( int i = 0; i < targetColumnReferences.size(); i++ ) {
if ( firstPass ) {
for (ColumnReference targetColumnReference : targetColumnReferences) {
if (firstPass) {
firstPass = false;
}
else {
appendSql( ", " );
}
final ColumnReference columnReference = targetColumnReferences.get( i );
appendSql( columnReference.getColumnExpression() );
appendSql( targetColumnReference.getColumnExpression() );
}
}
@ -89,17 +88,17 @@ public class StandardSqlAstInsertSelectTranslator
return new JdbcInsert() {
@Override
public String getSql() {
return StandardSqlAstInsertSelectTranslator.this.getSql();
return StandardSqlAstInsertTranslator.this.getSql();
}
@Override
public List<JdbcParameterBinder> getParameterBinders() {
return StandardSqlAstInsertSelectTranslator.this.getParameterBinders();
return StandardSqlAstInsertTranslator.this.getParameterBinders();
}
@Override
public Set<String> getAffectedTableNames() {
return StandardSqlAstInsertSelectTranslator.this.getAffectedTableNames();
return StandardSqlAstInsertTranslator.this.getAffectedTableNames();
}
};
}
@ -118,8 +117,7 @@ public class StandardSqlAstInsertSelectTranslator
String separator = "";
for ( int i = 0; i < sqlAst.getCteTable().getCteColumns().size(); i++ ) {
final CteColumn cteColumn = sqlAst.getCteTable().getCteColumns().get( i );
for ( CteColumn cteColumn : sqlAst.getCteTable().getCteColumns() ) {
appendSql( separator );
appendSql( cteColumn.getColumnExpression() );
separator = ", ";
@ -136,17 +134,17 @@ public class StandardSqlAstInsertSelectTranslator
return new JdbcInsert() {
@Override
public String getSql() {
return StandardSqlAstInsertSelectTranslator.this.getSql();
return StandardSqlAstInsertTranslator.this.getSql();
}
@Override
public List<JdbcParameterBinder> getParameterBinders() {
return StandardSqlAstInsertSelectTranslator.this.getParameterBinders();
return StandardSqlAstInsertTranslator.this.getParameterBinders();
}
@Override
public Set<String> getAffectedTableNames() {
return StandardSqlAstInsertSelectTranslator.this.getAffectedTableNames();
return StandardSqlAstInsertTranslator.this.getAffectedTableNames();
}
};
}

View File

@ -46,8 +46,7 @@ public class StandardSqlAstSelectTranslator
String separator = "";
for ( int i = 0; i < sqlAst.getCteTable().getCteColumns().size(); i++ ) {
final CteColumn cteColumn = sqlAst.getCteTable().getCteColumns().get( i );
for ( CteColumn cteColumn : sqlAst.getCteTable().getCteColumns() ) {
appendSql( separator );
appendSql( cteColumn.getColumnExpression() );
separator = ", ";

View File

@ -8,7 +8,7 @@ package org.hibernate.sql.ast.spi;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
import org.hibernate.sql.ast.SqlAstInsertSelectTranslator;
import org.hibernate.sql.ast.SqlAstInsertTranslator;
import org.hibernate.sql.ast.SqlAstSelectTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.SqlAstUpdateTranslator;
@ -28,8 +28,8 @@ public class StandardSqlAstTranslatorFactory implements SqlAstTranslatorFactory
}
@Override
public SqlAstInsertSelectTranslator buildInsertTranslator(SessionFactoryImplementor sessionFactory) {
return new StandardSqlAstInsertSelectTranslator( sessionFactory );
public SqlAstInsertTranslator buildInsertTranslator(SessionFactoryImplementor sessionFactory) {
return new StandardSqlAstInsertTranslator( sessionFactory );
}
@Override

View File

@ -10,7 +10,6 @@ import java.util.List;
import java.util.Set;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.sql.ast.SqlAstUpdateTranslator;
import org.hibernate.sql.ast.tree.cte.CteStatement;
@ -26,7 +25,7 @@ import org.hibernate.sql.exec.spi.JdbcUpdate;
public class StandardSqlAstUpdateTranslator
extends AbstractSqlAstTranslator
implements SqlAstUpdateTranslator {
private final Dialect dialect;
// private final Dialect dialect;
public StandardSqlAstUpdateTranslator(SessionFactoryImplementor sessionFactory) {
super( sessionFactory );
@ -34,7 +33,7 @@ public class StandardSqlAstUpdateTranslator
// todo (6.0) : use the Dialect to determine how to handle column references
// - specifically should they use the table-alias, the table-expression
// or neither for its qualifier
dialect = getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect();
// dialect = getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect();
}
private String updatingTableAlias;
@ -48,7 +47,7 @@ public class StandardSqlAstUpdateTranslator
appendSql( " set " );
boolean firstPass = true;
for ( int i = 0; i < sqlAst.getAssignments().size(); i++ ) {
for ( Assignment assignment : sqlAst.getAssignments() ) {
if ( firstPass ) {
firstPass = false;
}
@ -56,15 +55,14 @@ public class StandardSqlAstUpdateTranslator
appendSql( ", " );
}
final Assignment assignment = sqlAst.getAssignments().get( i );
final List<ColumnReference> columnReferences = assignment.getAssignable().getColumnReferences();
if ( columnReferences.size() == 1 ) {
columnReferences.get( 0 ).accept( this );
}
else {
appendSql( " (" );
for ( int cri = 0; cri < columnReferences.size(); cri++ ) {
columnReferences.get( cri ).accept( this );
for (ColumnReference columnReference : columnReferences) {
columnReference.accept( this );
}
appendSql( ") " );
}