Move more tests and fix subselect support
This commit is contained in:
parent
b9814f5cef
commit
eecda61ceb
|
@ -256,12 +256,12 @@ public class FirebirdSqlAstTranslator<T extends JdbcOperation> extends AbstractS
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visitJdbcLiteral(JdbcLiteral jdbcLiteral) {
|
||||
public void visitJdbcLiteral(JdbcLiteral<?> jdbcLiteral) {
|
||||
visitLiteral( jdbcLiteral );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQueryLiteral(QueryLiteral queryLiteral) {
|
||||
public void visitQueryLiteral(QueryLiteral<?> queryLiteral) {
|
||||
visitLiteral( queryLiteral );
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.hibernate.query.ComparisonOperator;
|
|||
import org.hibernate.query.EntityIdentifierNavigablePath;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.AliasCollector;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
|
||||
|
@ -935,9 +936,11 @@ public class LoaderSelectBuilder {
|
|||
|
||||
final NavigablePath rootNavigablePath = new NavigablePath( loadable.getRootPathName() );
|
||||
|
||||
// We need to initialize the acronymMap based on subselect.getLoadingSqlAst() to avoid alias collisions
|
||||
final Map<String, TableReference> tableReferences = AliasCollector.getTableReferences( subselect.getLoadingSqlAst() );
|
||||
final LoaderSqlAstCreationState sqlAstCreationState = new LoaderSqlAstCreationState(
|
||||
rootQuerySpec,
|
||||
new SqlAliasBaseManager(),
|
||||
new SqlAliasBaseManager( tableReferences.keySet() ),
|
||||
new SimpleFromClauseAccessImpl(),
|
||||
lockOptions,
|
||||
this::visitFetches,
|
||||
|
|
|
@ -402,7 +402,13 @@ public abstract class SimpleValue implements KeyValue {
|
|||
if ( rootClass != null ) {
|
||||
params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
|
||||
params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName() );
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, getTable().getName() );
|
||||
// The table name is not really a good default for subselect entities, so use the JPA entity name which is short
|
||||
if ( getTable().isSubselect() ) {
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, rootClass.getJpaEntityName() );
|
||||
}
|
||||
else {
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, getTable().getName() );
|
||||
}
|
||||
|
||||
final StringBuilder tables = new StringBuilder();
|
||||
final Iterator<Table> itr = rootClass.getIdentityTables().iterator();
|
||||
|
|
|
@ -66,9 +66,11 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
|
|||
MappingModelCreationProcess creationProcess) {
|
||||
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
|
||||
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = sessionFactory.getSqlStringGenerationContext();
|
||||
final Dialect dialect = sqlStringGenerationContext.getDialect();
|
||||
final String tableName = sqlStringGenerationContext.format( bootValueMapping.getTable().getQualifiedTableName() );
|
||||
final Dialect dialect = sessionFactory.getSqlStringGenerationContext().getDialect();
|
||||
final String tableName = MappingModelCreationHelper.getTableIdentifierExpression(
|
||||
bootValueMapping.getTable(),
|
||||
creationProcess
|
||||
);
|
||||
|
||||
assert bootValueMapping.getColumnSpan() == 2;
|
||||
final Iterator<Selectable> columnIterator = bootValueMapping.getColumnIterator();
|
||||
|
|
|
@ -338,7 +338,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
|
|||
columnExpression = selectable.getText( dialect );
|
||||
}
|
||||
if ( selectable instanceof Column ) {
|
||||
containingTableExpression = getTableIdentifierExpression(
|
||||
containingTableExpression = MappingModelCreationHelper.getTableIdentifierExpression(
|
||||
( (Column) selectable ).getValue().getTable(),
|
||||
creationProcess
|
||||
);
|
||||
|
@ -557,13 +557,6 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
|
|||
return true;
|
||||
}
|
||||
|
||||
private static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) {
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = creationProcess.getCreationContext()
|
||||
.getSessionFactory()
|
||||
.getSqlStringGenerationContext();
|
||||
return sqlStringGenerationContext.format( table.getQualifiedTableName() );
|
||||
}
|
||||
|
||||
private boolean initColumnMappings() {
|
||||
this.selectableMappings = SelectableMappingsImpl.from( this );
|
||||
return true;
|
||||
|
|
|
@ -682,7 +682,7 @@ public class EntityCollectionPart
|
|||
fetched,
|
||||
sourceAlias,
|
||||
primaryTableReference,
|
||||
false,
|
||||
true,
|
||||
sqlAliasBase,
|
||||
(tableExpression) -> getEntityMappingType().containsTableReference( tableExpression ),
|
||||
(tableExpression, tg) -> getEntityMappingType().createTableReferenceJoin(
|
||||
|
|
|
@ -476,7 +476,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
|
|||
throw new IllegalAttributeType( "An IdClass cannot define <any/> attributes : " + attributeName );
|
||||
}
|
||||
},
|
||||
(column, jdbcEnvironment) -> getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),
|
||||
(column, jdbcEnvironment) -> MappingModelCreationHelper.getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),
|
||||
this::addAttribute,
|
||||
() -> {
|
||||
// We need the attribute mapping types to finish initialization first before we can build the column mappings
|
||||
|
@ -489,13 +489,6 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
|
|||
);
|
||||
}
|
||||
|
||||
private static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) {
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = creationProcess.getCreationContext()
|
||||
.getSessionFactory()
|
||||
.getSqlStringGenerationContext();
|
||||
return sqlStringGenerationContext.format( table.getQualifiedTableName() );
|
||||
}
|
||||
|
||||
private boolean initColumnMappings() {
|
||||
this.selectableMappings = SelectableMappingsImpl.from( this );
|
||||
return true;
|
||||
|
|
|
@ -644,8 +644,9 @@ public class MappingModelCreationHelper {
|
|||
);
|
||||
final String mapKeyTableExpression;
|
||||
if ( bootValueMapping instanceof Map && ( (Map) bootValueMapping ).getMapKeyPropertyName() != null ) {
|
||||
mapKeyTableExpression = sqlStringGenerationContext.format(
|
||||
( (Map) bootValueMapping ).getIndex().getTable().getQualifiedTableName()
|
||||
mapKeyTableExpression = getTableIdentifierExpression(
|
||||
( (Map) bootValueMapping ).getIndex().getTable(),
|
||||
creationProcess
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -1279,11 +1280,16 @@ public class MappingModelCreationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) {
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = creationProcess.getCreationContext()
|
||||
.getSessionFactory()
|
||||
.getSqlStringGenerationContext();
|
||||
return sqlStringGenerationContext.format( table.getQualifiedTableName() );
|
||||
public static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) {
|
||||
return getTableIdentifierExpression( table, creationProcess.getCreationContext().getSessionFactory() );
|
||||
}
|
||||
|
||||
public static String getTableIdentifierExpression(Table table, SessionFactoryImplementor sessionFactory) {
|
||||
if ( table.getSubselect() != null ) {
|
||||
return "( " + table.getSubselect() + " )";
|
||||
}
|
||||
|
||||
return sessionFactory.getSqlStringGenerationContext().format( table.getQualifiedTableName() );
|
||||
}
|
||||
|
||||
private static CollectionPart interpretMapKey(
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.mapping.OneToOne;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Selectable;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.mapping.ToOne;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.metamodel.mapping.AssociationKey;
|
||||
|
@ -271,8 +272,7 @@ public class ToOneAttributeMapping
|
|||
isKeyTableNullable = true;
|
||||
}
|
||||
else {
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = declaringEntityPersister.getFactory().getSqlStringGenerationContext();
|
||||
final String targetTableName = sqlStringGenerationContext.format( manyToOne.getTable().getQualifiedTableName() );
|
||||
final String targetTableName = MappingModelCreationHelper.getTableIdentifierExpression( manyToOne.getTable(), declaringEntityPersister.getFactory() );
|
||||
if ( CollectionPart.Nature.fromNameExact( navigableRole.getParent().getLocalName() ) != null ) {
|
||||
final PluralAttributeMapping pluralAttribute = (PluralAttributeMapping) declaringEntityPersister.resolveSubPart(
|
||||
navigableRole.getParent().getParent()
|
||||
|
@ -496,7 +496,7 @@ public class ToOneAttributeMapping
|
|||
this.isConstrained = original.isConstrained;
|
||||
}
|
||||
|
||||
private boolean equal(Iterator<Selectable> lhsColumns, Iterator<Selectable> rhsColumns) {
|
||||
private static boolean equal(Iterator<Selectable> lhsColumns, Iterator<Selectable> rhsColumns) {
|
||||
boolean hasNext;
|
||||
do {
|
||||
final Selectable lhs = lhsColumns.next();
|
||||
|
@ -1490,7 +1490,7 @@ public class ToOneAttributeMapping
|
|||
fetched,
|
||||
sourceAlias,
|
||||
primaryTableReference,
|
||||
false,
|
||||
true,
|
||||
sqlAliasBase,
|
||||
(tableExpression) -> getEntityMappingType().containsTableReference( tableExpression ),
|
||||
(tableExpression, tg) -> getEntityMappingType().createTableReferenceJoin(
|
||||
|
|
|
@ -371,7 +371,7 @@ public class VirtualIdEmbeddable extends AbstractEmbeddableMapping implements Id
|
|||
throw new IllegalAttributeType( "A \"virtual id\" cannot define <any/> attributes : " + attributeName );
|
||||
}
|
||||
},
|
||||
(column, jdbcEnvironment) -> getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),
|
||||
(column, jdbcEnvironment) -> MappingModelCreationHelper.getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),
|
||||
this::addAttribute,
|
||||
() -> {
|
||||
// We need the attribute mapping types to finish initialization first before we can build the column mappings
|
||||
|
@ -384,13 +384,6 @@ public class VirtualIdEmbeddable extends AbstractEmbeddableMapping implements Id
|
|||
);
|
||||
}
|
||||
|
||||
private static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) {
|
||||
final SqlStringGenerationContext sqlStringGenerationContext = creationProcess.getCreationContext()
|
||||
.getSessionFactory()
|
||||
.getSqlStringGenerationContext();
|
||||
return sqlStringGenerationContext.format( table.getQualifiedTableName() );
|
||||
}
|
||||
|
||||
private boolean initColumnMappings() {
|
||||
this.selectableMappings = SelectableMappingsImpl.from( this );
|
||||
return true;
|
||||
|
|
|
@ -79,6 +79,7 @@ import org.hibernate.mapping.Value;
|
|||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
|
||||
import org.hibernate.metamodel.mapping.internal.PluralAttributeMappingImpl;
|
||||
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
|
@ -689,11 +690,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
|
||||
protected String determineTableName(Table table) {
|
||||
if ( table.getSubselect() != null ) {
|
||||
return "( " + table.getSubselect() + " )";
|
||||
}
|
||||
|
||||
return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() );
|
||||
return MappingModelCreationHelper.getTableIdentifierExpression( table, factory );
|
||||
}
|
||||
|
||||
// private class ColumnMapperImpl implements ColumnMapper {
|
||||
|
|
|
@ -5337,11 +5337,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
protected String determineTableName(Table table) {
|
||||
if ( table.getSubselect() != null ) {
|
||||
return "( " + table.getSubselect() + " )";
|
||||
}
|
||||
|
||||
return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() );
|
||||
return MappingModelCreationHelper.getTableIdentifierExpression( table, factory );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -143,9 +143,9 @@ public interface SqlAstWalker {
|
|||
|
||||
void visitParameter(JdbcParameter jdbcParameter);
|
||||
|
||||
void visitJdbcLiteral(JdbcLiteral jdbcLiteral);
|
||||
void visitJdbcLiteral(JdbcLiteral<?> jdbcLiteral);
|
||||
|
||||
void visitQueryLiteral(QueryLiteral queryLiteral);
|
||||
void visitQueryLiteral(QueryLiteral<?> queryLiteral);
|
||||
|
||||
void visitUnaryOperationExpression(UnaryOperation unaryOperationExpression);
|
||||
|
||||
|
|
|
@ -4174,12 +4174,12 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visitJdbcLiteral(JdbcLiteral jdbcLiteral) {
|
||||
public void visitJdbcLiteral(JdbcLiteral<?> jdbcLiteral) {
|
||||
visitLiteral( jdbcLiteral );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQueryLiteral(QueryLiteral queryLiteral) {
|
||||
public void visitQueryLiteral(QueryLiteral<?> queryLiteral) {
|
||||
visitLiteral( queryLiteral );
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,468 @@
|
|||
/*
|
||||
* 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.sql.ast.spi;
|
||||
|
||||
import org.hibernate.query.sqm.tree.expression.Conversion;
|
||||
import org.hibernate.sql.ast.SqlAstWalker;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.cte.CteStatement;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.AggregateFunctionExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.Any;
|
||||
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CaseSimpleExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CastTarget;
|
||||
import org.hibernate.sql.ast.tree.expression.Collate;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Distinct;
|
||||
import org.hibernate.sql.ast.tree.expression.Duration;
|
||||
import org.hibernate.sql.ast.tree.expression.DurationUnit;
|
||||
import org.hibernate.sql.ast.tree.expression.EntityTypeLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.Every;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.ExtractUnit;
|
||||
import org.hibernate.sql.ast.tree.expression.Format;
|
||||
import org.hibernate.sql.ast.tree.expression.FunctionExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.Over;
|
||||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.SelfRenderingExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlSelectionExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
import org.hibernate.sql.ast.tree.expression.Star;
|
||||
import org.hibernate.sql.ast.tree.expression.Summarization;
|
||||
import org.hibernate.sql.ast.tree.expression.TrimSpecification;
|
||||
import org.hibernate.sql.ast.tree.expression.UnaryOperation;
|
||||
import org.hibernate.sql.ast.tree.from.FromClause;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableReferenceJoin;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.Values;
|
||||
import org.hibernate.sql.ast.tree.predicate.BetweenPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.ExistsPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.FilterPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.GroupedPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.InListPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Junction;
|
||||
import org.hibernate.sql.ast.tree.predicate.LikePredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.NegatedPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.NullnessPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.SelfRenderingPredicate;
|
||||
import org.hibernate.sql.ast.tree.select.QueryGroup;
|
||||
import org.hibernate.sql.ast.tree.select.QueryPart;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.ast.tree.select.SelectClause;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.ast.tree.select.SortSpecification;
|
||||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
|
||||
/**
|
||||
* A simple walker that checks for aggregate functions.
|
||||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
public class AbstractSqlAstWalker implements SqlAstWalker {
|
||||
|
||||
@Override
|
||||
public void visitAny(Any any) {
|
||||
any.getSubquery().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEvery(Every every) {
|
||||
every.getSubquery().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelfRenderingExpression(SelfRenderingExpression expression) {
|
||||
if ( expression instanceof FunctionExpression ) {
|
||||
final FunctionExpression functionExpression = (FunctionExpression) expression;
|
||||
for ( SqlAstNode argument : functionExpression.getArguments() ) {
|
||||
argument.accept( this );
|
||||
}
|
||||
if ( expression instanceof AggregateFunctionExpression ) {
|
||||
final AggregateFunctionExpression aggregateFunctionExpression = (AggregateFunctionExpression) expression;
|
||||
if ( aggregateFunctionExpression.getFilter() != null ) {
|
||||
aggregateFunctionExpression.getFilter().accept( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSortSpecification(SortSpecification sortSpecification) {
|
||||
sortSpecification.getSortExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelectClause(SelectClause selectClause) {
|
||||
for ( SqlSelection sqlSelection : selectClause.getSqlSelections() ) {
|
||||
sqlSelection.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSqlSelection(SqlSelection sqlSelection) {
|
||||
sqlSelection.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
|
||||
arithmeticExpression.getLeftHandOperand().accept( this );
|
||||
arithmeticExpression.getRightHandOperand().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression) {
|
||||
for ( CaseSearchedExpression.WhenFragment whenFragment : caseSearchedExpression.getWhenFragments() ) {
|
||||
whenFragment.getPredicate().accept( this );
|
||||
whenFragment.getResult().accept( this );
|
||||
}
|
||||
if ( caseSearchedExpression.getOtherwise() != null ) {
|
||||
caseSearchedExpression.getOtherwise().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression) {
|
||||
caseSimpleExpression.getFixture().accept( this );
|
||||
for ( CaseSimpleExpression.WhenFragment whenFragment : caseSimpleExpression.getWhenFragments() ) {
|
||||
whenFragment.getCheckValue().accept( this );
|
||||
whenFragment.getResult().accept( this );
|
||||
}
|
||||
if ( caseSimpleExpression.getOtherwise() != null ) {
|
||||
caseSimpleExpression.getOtherwise().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTuple(SqlTuple tuple) {
|
||||
for ( Expression expression : tuple.getExpressions() ) {
|
||||
expression.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCollate(Collate collate) {
|
||||
collate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitUnaryOperationExpression(UnaryOperation unaryOperationExpression) {
|
||||
unaryOperationExpression.getOperand().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModifiedSubQueryExpression(ModifiedSubQueryExpression expression) {
|
||||
expression.getSubQuery().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
|
||||
booleanExpressionPredicate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBetweenPredicate(BetweenPredicate betweenPredicate) {
|
||||
betweenPredicate.getExpression().accept( this );
|
||||
betweenPredicate.getLowerBound().accept( this );
|
||||
betweenPredicate.getUpperBound().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitGroupedPredicate(GroupedPredicate groupedPredicate) {
|
||||
groupedPredicate.getSubPredicate().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJunction(Junction junction) {
|
||||
for ( Predicate predicate : junction.getPredicates() ) {
|
||||
predicate.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLikePredicate(LikePredicate likePredicate) {
|
||||
likePredicate.getMatchExpression().accept( this );
|
||||
if ( likePredicate.getEscapeCharacter() != null ) {
|
||||
likePredicate.getEscapeCharacter().accept( this );
|
||||
}
|
||||
likePredicate.getPattern().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNegatedPredicate(NegatedPredicate negatedPredicate) {
|
||||
negatedPredicate.getPredicate().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNullnessPredicate(NullnessPredicate nullnessPredicate) {
|
||||
nullnessPredicate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitRelationalPredicate(ComparisonPredicate comparisonPredicate) {
|
||||
comparisonPredicate.getLeftHandExpression().accept( this );
|
||||
comparisonPredicate.getRightHandExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelfRenderingPredicate(SelfRenderingPredicate selfRenderingPredicate) {
|
||||
selfRenderingPredicate.getSelfRenderingExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOver(Over over) {
|
||||
over.getExpression().accept( this );
|
||||
for ( Expression partition : over.getPartitions() ) {
|
||||
partition.accept( this );
|
||||
}
|
||||
for ( SortSpecification sortSpecification : over.getOrderList() ) {
|
||||
sortSpecification.accept( this );
|
||||
}
|
||||
if ( over.getStartExpression() != null ) {
|
||||
over.getStartExpression().accept( this );
|
||||
}
|
||||
if ( over.getEndExpression() != null ) {
|
||||
over.getEndExpression().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelectStatement(SelectStatement statement) {
|
||||
for ( CteStatement cteStatement : statement.getCteStatements() ) {
|
||||
cteStatement.getCteDefinition().accept( this );
|
||||
}
|
||||
statement.getQueryPart().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDeleteStatement(DeleteStatement statement) {
|
||||
for ( CteStatement cteStatement : statement.getCteStatements() ) {
|
||||
cteStatement.getCteDefinition().accept( this );
|
||||
}
|
||||
statement.getRestriction().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitUpdateStatement(UpdateStatement statement) {
|
||||
for ( CteStatement cteStatement : statement.getCteStatements() ) {
|
||||
cteStatement.getCteDefinition().accept( this );
|
||||
}
|
||||
for ( Assignment assignment : statement.getAssignments() ) {
|
||||
assignment.accept( this );
|
||||
}
|
||||
statement.getRestriction().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInsertStatement(InsertStatement statement) {
|
||||
for ( CteStatement cteStatement : statement.getCteStatements() ) {
|
||||
cteStatement.getCteDefinition().accept( this );
|
||||
}
|
||||
if ( statement.getSourceSelectStatement() != null ) {
|
||||
statement.getSourceSelectStatement().accept( this );
|
||||
}
|
||||
else if ( statement.getValuesList() != null ) {
|
||||
for ( Values values : statement.getValuesList() ) {
|
||||
for ( Expression expression : values.getExpressions() ) {
|
||||
expression.accept( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssignment(Assignment assignment) {
|
||||
assignment.getAssignedValue().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQueryGroup(QueryGroup queryGroup) {
|
||||
for ( QueryPart queryPart : queryGroup.getQueryParts() ) {
|
||||
queryPart.accept( this );
|
||||
}
|
||||
visitOffsetFetchClause( queryGroup );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQuerySpec(QuerySpec querySpec) {
|
||||
querySpec.getSelectClause().accept( this );
|
||||
querySpec.getFromClause().accept( this );
|
||||
if ( querySpec.getWhereClauseRestrictions() != null ) {
|
||||
querySpec.getWhereClauseRestrictions().accept( this );
|
||||
}
|
||||
for ( Expression groupByClauseExpression : querySpec.getGroupByClauseExpressions() ) {
|
||||
groupByClauseExpression.accept( this );
|
||||
}
|
||||
if ( querySpec.getHavingClauseRestrictions() != null ) {
|
||||
querySpec.getHavingClauseRestrictions().accept( this );
|
||||
}
|
||||
visitOffsetFetchClause( querySpec );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDistinct(Distinct distinct) {
|
||||
distinct.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOffsetFetchClause(QueryPart querySpec) {
|
||||
if ( querySpec.getSortSpecifications() != null ) {
|
||||
for ( SortSpecification sortSpecification : querySpec.getSortSpecifications() ) {
|
||||
sortSpecification.accept( this );
|
||||
}
|
||||
}
|
||||
if ( querySpec.getOffsetClauseExpression() != null ) {
|
||||
querySpec.getOffsetClauseExpression().accept( this );
|
||||
}
|
||||
if ( querySpec.getFetchClauseExpression() != null ) {
|
||||
querySpec.getFetchClauseExpression().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDuration(Duration duration) {
|
||||
duration.getMagnitude().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConversion(Conversion conversion) {
|
||||
conversion.getDuration().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
inListPredicate.getTestExpression().accept( this );
|
||||
for ( Expression listExpression : inListPredicate.getListExpressions() ) {
|
||||
listExpression.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInSubQueryPredicate(InSubQueryPredicate inSubQueryPredicate) {
|
||||
inSubQueryPredicate.getTestExpression().accept( this );
|
||||
inSubQueryPredicate.getSubQuery().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExistsPredicate(ExistsPredicate existsPredicate) {
|
||||
existsPredicate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSummarization(Summarization every) {
|
||||
for ( Expression grouping : every.getGroupings() ) {
|
||||
grouping.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSqlSelectionExpression(SqlSelectionExpression expression) {
|
||||
expression.accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTableReferenceJoin(TableReferenceJoin tableReferenceJoin) {
|
||||
tableReferenceJoin.getJoinedTableReference().accept( this );
|
||||
if ( tableReferenceJoin.getPredicate() != null ) {
|
||||
tableReferenceJoin.getPredicate().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFromClause(FromClause fromClause) {
|
||||
for ( TableGroup root : fromClause.getRoots() ) {
|
||||
root.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTableGroup(TableGroup tableGroup) {
|
||||
tableGroup.getPrimaryTableReference().accept( this );
|
||||
for ( TableReferenceJoin tableReferenceJoin : tableGroup.getTableReferenceJoins() ) {
|
||||
tableReferenceJoin.accept( this );
|
||||
}
|
||||
for ( TableGroupJoin tableGroupJoin : tableGroup.getTableGroupJoins() ) {
|
||||
tableGroupJoin.accept( this );
|
||||
}
|
||||
for ( TableGroupJoin nestedTableGroupJoin : tableGroup.getNestedTableGroupJoins() ) {
|
||||
nestedTableGroupJoin.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTableGroupJoin(TableGroupJoin tableGroupJoin) {
|
||||
tableGroupJoin.getJoinedGroup().accept( this );
|
||||
if ( tableGroupJoin.getPredicate() != null ) {
|
||||
tableGroupJoin.getPredicate().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitColumnReference(ColumnReference columnReference) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExtractUnit(ExtractUnit extractUnit) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormat(Format format) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitStar(Star star) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTrimSpecification(TrimSpecification trimSpecification) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCastTarget(CastTarget castTarget) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDurationUnit(DurationUnit durationUnit) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFilterPredicate(FilterPredicate filterPredicate) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameter(JdbcParameter jdbcParameter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJdbcLiteral(JdbcLiteral<?> jdbcLiteral) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQueryLiteral(QueryLiteral<?> queryLiteral) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEntityTypeLiteral(EntityTypeLiteral expression) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTableReference(TableReference tableReference) {
|
||||
}
|
||||
}
|
|
@ -8,23 +8,17 @@
|
|||
package org.hibernate.sql.ast.spi;
|
||||
|
||||
import org.hibernate.query.sqm.tree.expression.Conversion;
|
||||
import org.hibernate.sql.ast.SqlAstWalker;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.AggregateFunctionExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.Any;
|
||||
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CaseSimpleExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CastTarget;
|
||||
import org.hibernate.sql.ast.tree.expression.Collate;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Distinct;
|
||||
import org.hibernate.sql.ast.tree.expression.Duration;
|
||||
import org.hibernate.sql.ast.tree.expression.DurationUnit;
|
||||
import org.hibernate.sql.ast.tree.expression.EntityTypeLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.Every;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.ExtractUnit;
|
||||
import org.hibernate.sql.ast.tree.expression.Format;
|
||||
import org.hibernate.sql.ast.tree.expression.FunctionExpression;
|
||||
|
@ -35,37 +29,23 @@ import org.hibernate.sql.ast.tree.expression.Over;
|
|||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.SelfRenderingExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlSelectionExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
import org.hibernate.sql.ast.tree.expression.Star;
|
||||
import org.hibernate.sql.ast.tree.expression.Summarization;
|
||||
import org.hibernate.sql.ast.tree.expression.TrimSpecification;
|
||||
import org.hibernate.sql.ast.tree.expression.UnaryOperation;
|
||||
import org.hibernate.sql.ast.tree.from.FromClause;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableReferenceJoin;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.ast.tree.predicate.BetweenPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.ExistsPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.FilterPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.GroupedPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.InListPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Junction;
|
||||
import org.hibernate.sql.ast.tree.predicate.LikePredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.NegatedPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.NullnessPredicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.sql.ast.tree.predicate.SelfRenderingPredicate;
|
||||
import org.hibernate.sql.ast.tree.select.QueryGroup;
|
||||
import org.hibernate.sql.ast.tree.select.QueryPart;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.ast.tree.select.SelectClause;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.ast.tree.select.SortSpecification;
|
||||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
|
||||
|
@ -74,7 +54,7 @@ import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
|||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
class AggregateFunctionChecker implements SqlAstWalker {
|
||||
public class AggregateFunctionChecker extends AbstractSqlAstWalker {
|
||||
|
||||
private static final AggregateFunctionChecker INSTANCE = new AggregateFunctionChecker();
|
||||
|
||||
|
@ -91,16 +71,6 @@ class AggregateFunctionChecker implements SqlAstWalker {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAny(Any any) {
|
||||
throw new AggregateFunctionException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEvery(Every every) {
|
||||
throw new AggregateFunctionException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelfRenderingExpression(SelfRenderingExpression expression) {
|
||||
if ( expression instanceof AggregateFunctionExpression ) {
|
||||
|
@ -113,134 +83,27 @@ class AggregateFunctionChecker implements SqlAstWalker {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSortSpecification(SortSpecification sortSpecification) {
|
||||
sortSpecification.getSortExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelectClause(SelectClause selectClause) {
|
||||
for ( SqlSelection sqlSelection : selectClause.getSqlSelections() ) {
|
||||
sqlSelection.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSqlSelection(SqlSelection sqlSelection) {
|
||||
sqlSelection.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
|
||||
arithmeticExpression.getLeftHandOperand().accept( this );
|
||||
arithmeticExpression.getRightHandOperand().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression) {
|
||||
for ( CaseSearchedExpression.WhenFragment whenFragment : caseSearchedExpression.getWhenFragments() ) {
|
||||
whenFragment.getPredicate().accept( this );
|
||||
whenFragment.getResult().accept( this );
|
||||
}
|
||||
if ( caseSearchedExpression.getOtherwise() != null ) {
|
||||
caseSearchedExpression.getOtherwise().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression) {
|
||||
caseSimpleExpression.getFixture().accept( this );
|
||||
for ( CaseSimpleExpression.WhenFragment whenFragment : caseSimpleExpression.getWhenFragments() ) {
|
||||
whenFragment.getCheckValue().accept( this );
|
||||
whenFragment.getResult().accept( this );
|
||||
}
|
||||
if ( caseSimpleExpression.getOtherwise() != null ) {
|
||||
caseSimpleExpression.getOtherwise().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTuple(SqlTuple tuple) {
|
||||
for ( Expression expression : tuple.getExpressions() ) {
|
||||
expression.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCollate(Collate collate) {
|
||||
collate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitUnaryOperationExpression(UnaryOperation unaryOperationExpression) {
|
||||
unaryOperationExpression.getOperand().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModifiedSubQueryExpression(ModifiedSubQueryExpression expression) {
|
||||
expression.getSubQuery().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
|
||||
booleanExpressionPredicate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBetweenPredicate(BetweenPredicate betweenPredicate) {
|
||||
betweenPredicate.getExpression().accept( this );
|
||||
betweenPredicate.getLowerBound().accept( this );
|
||||
betweenPredicate.getUpperBound().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitGroupedPredicate(GroupedPredicate groupedPredicate) {
|
||||
groupedPredicate.getSubPredicate().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJunction(Junction junction) {
|
||||
for ( Predicate predicate : junction.getPredicates() ) {
|
||||
predicate.accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLikePredicate(LikePredicate likePredicate) {
|
||||
likePredicate.getMatchExpression().accept( this );
|
||||
if ( likePredicate.getEscapeCharacter() != null ) {
|
||||
likePredicate.getEscapeCharacter().accept( this );
|
||||
}
|
||||
likePredicate.getPattern().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNegatedPredicate(NegatedPredicate negatedPredicate) {
|
||||
negatedPredicate.getPredicate().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNullnessPredicate(NullnessPredicate nullnessPredicate) {
|
||||
nullnessPredicate.getExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitRelationalPredicate(ComparisonPredicate comparisonPredicate) {
|
||||
comparisonPredicate.getLeftHandExpression().accept( this );
|
||||
comparisonPredicate.getRightHandExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSelfRenderingPredicate(SelfRenderingPredicate selfRenderingPredicate) {
|
||||
selfRenderingPredicate.getSelfRenderingExpression().accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOver(Over over) {
|
||||
over.getExpression().accept( this );
|
||||
// Only need to visit the expression over which the window is created as the window definition can't have aggregates
|
||||
// If the expression is an aggregate function, this means the aggregate is used as window function, which is fine
|
||||
// We only care about actually aggregating functions, which might be an argument of this function though
|
||||
if ( over.getExpression() instanceof AggregateFunctionExpression ) {
|
||||
final AggregateFunctionExpression aggregate = (AggregateFunctionExpression) over.getExpression();
|
||||
for ( SqlAstNode argument : aggregate.getArguments() ) {
|
||||
argument.accept( this );
|
||||
}
|
||||
if ( aggregate.getFilter() != null ) {
|
||||
aggregate.getFilter().accept( this );
|
||||
}
|
||||
}
|
||||
else {
|
||||
over.getExpression().accept( this );
|
||||
}
|
||||
}
|
||||
|
||||
// --- to ignore ---
|
||||
// There is no need to look into the following AST nodes as the aggregate check is only for the top level
|
||||
|
||||
@Override
|
||||
public void visitSelectStatement(SelectStatement statement) {
|
||||
|
@ -322,6 +185,18 @@ class AggregateFunctionChecker implements SqlAstWalker {
|
|||
public void visitInSubQueryPredicate(InSubQueryPredicate inSubQueryPredicate) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModifiedSubQueryExpression(ModifiedSubQueryExpression expression) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAny(Any any) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEvery(Every every) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExistsPredicate(ExistsPredicate existsPredicate) {
|
||||
}
|
||||
|
@ -335,11 +210,11 @@ class AggregateFunctionChecker implements SqlAstWalker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visitJdbcLiteral(JdbcLiteral jdbcLiteral) {
|
||||
public void visitJdbcLiteral(JdbcLiteral<?> jdbcLiteral) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitQueryLiteral(QueryLiteral queryLiteral) {
|
||||
public void visitQueryLiteral(QueryLiteral<?> queryLiteral) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.sql.ast.spi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
|
||||
/**
|
||||
* A simple walker that checks for aggregate functions.
|
||||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
public class AliasCollector extends AbstractSqlAstWalker {
|
||||
|
||||
private final Map<String, TableReference> tableReferenceMap = new HashMap<>();
|
||||
|
||||
public static Map<String, TableReference> getTableReferences(SqlAstNode node) {
|
||||
final AliasCollector aliasCollector = new AliasCollector();
|
||||
node.accept( aliasCollector );
|
||||
return aliasCollector.tableReferenceMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTableReference(TableReference tableReference) {
|
||||
tableReferenceMap.put( tableReference.getIdentificationVariable(), tableReference );
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ package org.hibernate.sql.ast.spi;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Helper used in creating unique SQL table aliases for a SQL AST
|
||||
|
@ -16,7 +17,30 @@ import java.util.Map;
|
|||
*/
|
||||
public class SqlAliasBaseManager implements SqlAliasBaseGenerator {
|
||||
// work dictionary used to map an acronym to the number of times it has been used.
|
||||
private Map<String,Integer> acronymCountMap = new HashMap<>();
|
||||
private final Map<String, Integer> acronymCountMap;
|
||||
|
||||
public SqlAliasBaseManager() {
|
||||
acronymCountMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public SqlAliasBaseManager(Set<String> usedAcronyms) {
|
||||
acronymCountMap = new HashMap<>( usedAcronyms.size() );
|
||||
for ( String acronym : usedAcronyms ) {
|
||||
// Everything after the last underscore is the table index
|
||||
final int underscoreIndex = acronym.lastIndexOf('_');
|
||||
for ( int i = underscoreIndex - 1; i >= 0; i-- ) {
|
||||
if ( !Character.isDigit( acronym.charAt( i ) ) ) {
|
||||
final String stem = acronym.substring( 0, i + 1 );
|
||||
final int acronymValue = Integer.parseInt( acronym.substring( i + 1, underscoreIndex ) );
|
||||
final Integer acronymCount = acronymCountMap.get( stem );
|
||||
if ( acronymCount == null || acronymCount < acronymValue ) {
|
||||
acronymCountMap.put( stem, acronymValue );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlAliasBase createSqlAliasBase(String stem) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Embeddable;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
||||
|
@ -14,6 +14,6 @@ import org.hibernate.boot.MetadataSources;
|
|||
public abstract class BaseHbmBindingTests extends BaseNamingTests {
|
||||
@Override
|
||||
protected void applySources(MetadataSources metadataSources) {
|
||||
metadataSources.addResource( "org/hibernate/test/namingstrategy/complete/Mappings.hbm.xml" );
|
||||
metadataSources.addResource( "org/hibernate/orm/test/namingstrategy/complete/Mappings.hbm.xml" );
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Entity;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.namingstrategy.complete">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.namingstrategy.complete">
|
||||
|
||||
<class name="Customer">
|
||||
<id name="id">
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
<set name="registeredTrademarks">
|
||||
<key/>
|
||||
<element/>
|
||||
<element type="string"/>
|
||||
</set>
|
||||
|
||||
<set name="addresses">
|
||||
|
@ -75,6 +75,6 @@
|
|||
<property name="code"/>
|
||||
</natural-id>
|
||||
<property name="city"/>
|
||||
<property name="state" type="EnumeratedType"/>
|
||||
<property name="state"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import java.util.Date;
|
||||
import jakarta.persistence.Basic;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Entity;
|
|
@ -9,4 +9,4 @@
|
|||
* Defines tests of the "main" NamingStrategies, mainly so that we can leverage this
|
||||
* in the 5.0 work to assert that the same names are produced.
|
||||
*/
|
||||
package org.hibernate.test.namingstrategy.complete;
|
||||
package org.hibernate.orm.test.namingstrategy.complete;
|
|
@ -54,7 +54,7 @@ public class SynchronizeTableNamingTest {
|
|||
@Test
|
||||
public void testHbmXmlHandling() {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addResource( "org/hibernate/test/namingstrategy/synchronizedTables/mapping.hbm.xml" )
|
||||
.addResource( "org/hibernate/orm/test/namingstrategy/synchronizedTables/mapping.hbm.xml" )
|
||||
.getMetadataBuilder()
|
||||
.applyPhysicalNamingStrategy( TestingPhysicalNamingStrategy.INSTANCE )
|
||||
.build();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subclassfilter;
|
||||
package org.hibernate.orm.test.subclassfilter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -30,6 +30,12 @@ import static org.junit.Assert.assertEquals;
|
|||
*/
|
||||
@RequiresDialectFeature(DialectChecks.SupportsTemporaryTable.class)
|
||||
public class JoinedSubclassFilterTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "org/hibernate/orm/test/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] getMappings() {
|
||||
return new String[] { "subclassfilter/joined-subclass.hbm.xml" };
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Alien.java 7203 2005-06-19 02:01:05Z oneovthafew $
|
||||
package org.hibernate.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
|
||||
/**
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
import java.util.Set;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Being.java 7203 2005-06-19 02:01:05Z oneovthafew $
|
||||
package org.hibernate.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
|
||||
/**
|
|
@ -26,12 +26,14 @@
|
|||
-->
|
||||
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.subselect"
|
||||
package="org.hibernate.orm.test.subselect"
|
||||
default-access="field">
|
||||
|
||||
<class name="Human" table="humans">
|
||||
<id name="id" unsaved-value="0" column="bid">
|
||||
<generator class="enhanced-sequence"/>
|
||||
<generator class="enhanced-sequence">
|
||||
<param name="sequence_name">Being_SEQ</param>
|
||||
</generator>
|
||||
</id>
|
||||
|
||||
<property name="name"
|
||||
|
@ -51,7 +53,9 @@
|
|||
|
||||
<class name="Alien" table="aliens">
|
||||
<id name="id" unsaved-value="0" column="bid">
|
||||
<generator class="enhanced-sequence"/>
|
||||
<generator class="enhanced-sequence">
|
||||
<param name="sequence_name">Being_SEQ</param>
|
||||
</generator>
|
||||
</id>
|
||||
|
||||
<property name="identity"
|
|
@ -10,7 +10,7 @@
|
|||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.subselect"
|
||||
package="org.hibernate.orm.test.subselect"
|
||||
default-access="field">
|
||||
|
||||
<class name="Author" table="author">
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
|
@ -4,17 +4,21 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class EmployeeGroupId
|
||||
implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column(name = "group_name")
|
||||
private String groupName;
|
||||
@Column(name = "dept_name")
|
||||
private String departmentName;
|
||||
|
||||
@SuppressWarnings("unused")
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Human.java 7203 2005-06-19 02:01:05Z oneovthafew $
|
||||
package org.hibernate.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
|
||||
/**
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||
|
@ -23,6 +23,13 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
@TestForIssue(jiraKey = "")
|
||||
public class SetSubselectTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "org/hibernate/orm/test/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] {"subselect/Book.hbm.xml"};
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect;
|
||||
package org.hibernate.orm.test.subselect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -24,6 +24,13 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class SubselectTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "org/hibernate/orm/test/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "subselect/Beings.hbm.xml" };
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.subselect.join">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.subselect.join">
|
||||
|
||||
<class name="SubselectInJoinedTableTest$Order" table="`ORDER`" lazy="false">
|
||||
<id name="orderId" column="id" type="java.lang.Long"/>
|
|
@ -4,7 +4,7 @@
|
|||
* 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.test.subselect.join;
|
||||
package org.hibernate.orm.test.subselect.join;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -19,6 +19,10 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SubselectInJoinedTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "org/hibernate/orm/test/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getMappings() {
|
Loading…
Reference in New Issue