Further improvements
This commit is contained in:
parent
352970604d
commit
bbe8783887
|
@ -1 +1 @@
|
|||
hibernateVersion=6.0.0-SNAPSHOT
|
||||
hibernateVersion=6.0.0.BENCHMARK
|
|
@ -85,10 +85,6 @@ public class SqlAstProcessingStateImpl
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// SqlExpressionResolver
|
||||
|
||||
protected Map<Expression, SqlSelection> sqlSelectionMap() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression resolveSqlExpression(
|
||||
String key,
|
||||
|
@ -104,38 +100,9 @@ public class SqlAstProcessingStateImpl
|
|||
expressionMap.put( key, expression );
|
||||
}
|
||||
|
||||
return normalize( expression );
|
||||
}
|
||||
|
||||
protected Expression normalize(Expression expression) {
|
||||
final Clause currentClause = currentClauseAccess.get();
|
||||
if ( sqlSelectionMap() != null && ( currentClause == Clause.ORDER || currentClause == Clause.GROUP ) ) {
|
||||
// see if this (Sql)Expression is used as a selection, and if so
|
||||
// wrap the (Sql)Expression in a special wrapper with access to both
|
||||
// the (Sql)Expression and the SqlSelection.
|
||||
//
|
||||
// This is used for databases which prefer to use the position of a
|
||||
// selected expression (within the select-clause) as the
|
||||
// order-by, group-by or having expression
|
||||
final SqlSelection selection = sqlSelectionMap().get( expression );
|
||||
if ( selection != null ) {
|
||||
return new SqlSelectionExpression( selection );
|
||||
}
|
||||
}
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Expression resolveSqlExpression(NonQualifiableSqlExpressible sqlSelectable) {
|
||||
// final Expression expression = normalize( sqlSelectable.createExpression() );
|
||||
// final Consumer<Expression> expressionConsumer = resolvedExpressionConsumerAccess.get();
|
||||
// if ( expressionConsumer != null ) {
|
||||
// expressionConsumer.accept( expression );
|
||||
// }
|
||||
// return expression;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public SqlSelection resolveSqlSelection(
|
||||
Expression expression,
|
||||
|
|
|
@ -62,16 +62,11 @@ public class SqlAstQueryPartProcessingStateImpl
|
|||
public QueryPart getInflightQueryPart() {
|
||||
return queryPart;
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// SqlExpressionResolver
|
||||
|
||||
private Map<Expression, SqlSelection> sqlSelectionMap;
|
||||
private Map<FetchParent, Map<Expression, SqlSelection>> fetchParentSqlSelectionMap;
|
||||
|
||||
@Override
|
||||
protected Map<Expression, SqlSelection> sqlSelectionMap() {
|
||||
return sqlSelectionMap;
|
||||
}
|
||||
private Map<?, ?> sqlSelectionMap;
|
||||
|
||||
@Override
|
||||
public SqlSelection resolveSqlSelection(
|
||||
|
@ -79,42 +74,49 @@ public class SqlAstQueryPartProcessingStateImpl
|
|||
JavaType<?> javaType,
|
||||
FetchParent fetchParent,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
final SqlSelection existing;
|
||||
if ( sqlSelectionMap == null ) {
|
||||
sqlSelectionMap = new HashMap<>();
|
||||
existing = null;
|
||||
}
|
||||
else {
|
||||
existing = sqlSelectionMap.get( expression );
|
||||
}
|
||||
|
||||
if ( existing != null && deduplicateSelectionItems ) {
|
||||
return existing;
|
||||
}
|
||||
final Map<Expression, SqlSelection> fetchParentSelections;
|
||||
if ( !deduplicateSelectionItems && fetchParent != null ) {
|
||||
// De-duplicate selection items within the root of a fetch parent
|
||||
final FetchParent root = fetchParent.getRoot();
|
||||
if ( fetchParentSqlSelectionMap == null ) {
|
||||
fetchParentSqlSelectionMap = new HashMap<>();
|
||||
fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() );
|
||||
final Map<Expression, SqlSelection> selectionMap;
|
||||
if ( deduplicateSelectionItems ) {
|
||||
final SqlSelection existing;
|
||||
if ( sqlSelectionMap == null ) {
|
||||
sqlSelectionMap = new HashMap<>();
|
||||
existing = null;
|
||||
}
|
||||
else {
|
||||
existing = (SqlSelection) sqlSelectionMap.get( expression );
|
||||
}
|
||||
|
||||
if ( existing != null ) {
|
||||
return existing;
|
||||
}
|
||||
//noinspection unchecked
|
||||
selectionMap = (Map<Expression, SqlSelection>) sqlSelectionMap;
|
||||
}
|
||||
else if ( fetchParent != null ) {
|
||||
// De-duplicate selection items within the root of a fetch parent
|
||||
final Map<FetchParent, Map<Expression, SqlSelection>> fetchParentSqlSelectionMap;
|
||||
final FetchParent root = fetchParent.getRoot();
|
||||
if ( sqlSelectionMap == null ) {
|
||||
sqlSelectionMap = fetchParentSqlSelectionMap = new HashMap<>();
|
||||
fetchParentSqlSelectionMap.put( root, selectionMap = new HashMap<>() );
|
||||
}
|
||||
else {
|
||||
//noinspection unchecked
|
||||
fetchParentSqlSelectionMap = (Map<FetchParent, Map<Expression, SqlSelection>>) sqlSelectionMap;
|
||||
final Map<Expression, SqlSelection> map = fetchParentSqlSelectionMap.get( root );
|
||||
if ( map == null ) {
|
||||
fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() );
|
||||
fetchParentSqlSelectionMap.put( root, selectionMap = new HashMap<>() );
|
||||
}
|
||||
else {
|
||||
fetchParentSelections = map;
|
||||
selectionMap = map;
|
||||
}
|
||||
}
|
||||
final SqlSelection sqlSelection = fetchParentSelections.get( expression );
|
||||
final SqlSelection sqlSelection = selectionMap.get( expression );
|
||||
if ( sqlSelection != null ) {
|
||||
return sqlSelection;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fetchParentSelections = null;
|
||||
selectionMap = null;
|
||||
}
|
||||
|
||||
final SelectClause selectClause = ( (QuerySpec) queryPart ).getSelectClause();
|
||||
|
@ -128,10 +130,8 @@ public class SqlAstQueryPartProcessingStateImpl
|
|||
|
||||
selectClause.addSqlSelection( sqlSelection );
|
||||
|
||||
sqlSelectionMap.put( expression, sqlSelection );
|
||||
|
||||
if ( fetchParentSelections != null ) {
|
||||
fetchParentSelections.put( expression, sqlSelection );
|
||||
if ( selectionMap != null ) {
|
||||
selectionMap.put( expression, sqlSelection );
|
||||
}
|
||||
|
||||
return sqlSelection;
|
||||
|
|
|
@ -1596,11 +1596,13 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
|||
|
||||
private boolean hasDuplicateSelectItems(QuerySpec querySpec) {
|
||||
final List<SqlSelection> sqlSelections = querySpec.getSelectClause().getSqlSelections();
|
||||
final Map<Expression, Void> map = new IdentityHashMap<>( sqlSelections.size() );
|
||||
final Map<Expression, Boolean> map = new IdentityHashMap<>( sqlSelections.size() );
|
||||
for ( int i = 0; i < sqlSelections.size(); i++ ) {
|
||||
map.put( sqlSelections.get( i ).getExpression(), null );
|
||||
if ( map.put( sqlSelections.get( i ).getExpression(), Boolean.TRUE ) != null ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return map.size() != sqlSelections.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean supportsSimpleQueryGrouping() {
|
||||
|
|
Loading…
Reference in New Issue