From 5482c55e6c9dfa5f24e2b9b3baafa575a60a1ede Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 16 Oct 2019 10:30:17 -0500 Subject: [PATCH] remove caching of ColumnReferences inside ColumnReferenceQualifier - they are already cached as part of the SqlExpressionResolver, which has a broader scope and is therefore more efficient place --- .../BasicValuedSingularAttributeMapping.java | 13 ++++----- .../internal/EmbeddedAttributeMapping.java | 13 ++++----- .../AbstractColumnReferenceQualifier.java | 28 ------------------- .../tree/from/ColumnReferenceQualifier.java | 2 -- .../ast/tree/from/CompositeTableGroup.java | 13 --------- .../sql/ast/tree/from/TableReference.java | 22 --------------- 6 files changed, 10 insertions(+), 81 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java index 2aab74eb76..4a7c06e291 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java @@ -46,6 +46,7 @@ public class BasicValuedSingularAttributeMapping extends AbstractSingularAttribu private final JdbcMapping jdbcMapping; private final BasicValueConverter valueConverter; + @SuppressWarnings("WeakerAccess") public BasicValuedSingularAttributeMapping( String attributeName, int stateArrayPosition, @@ -119,15 +120,11 @@ public class BasicValuedSingularAttributeMapping extends AbstractSingularAttribu tableReference, getMappedColumnExpression() ), - sqlAstProcessingState -> tableGroup.resolveColumnReference( - getContainingTableExpression(), + sqlAstProcessingState -> new ColumnReference( getMappedColumnExpression(), - () -> new ColumnReference( - getMappedColumnExpression(), - tableReference.getIdentificationVariable(), - jdbcMapping, - creationState.getSqlAstCreationState().getCreationContext().getSessionFactory() - ) + tableReference.getIdentificationVariable(), + jdbcMapping, + creationState.getSqlAstCreationState().getCreationContext().getSessionFactory() ) ), valueConverter == null ? getMappedTypeDescriptor().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java index cc80aec3bf..932d6e041c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java @@ -58,6 +58,7 @@ public class EmbeddedAttributeMapping private final String tableExpression; private final String[] attrColumnNames; + @SuppressWarnings("WeakerAccess") public EmbeddedAttributeMapping( String name, int stateArrayPosition, @@ -187,15 +188,11 @@ public class EmbeddedAttributeMapping tableReference, attrColumnExpr ), - sqlAstProcessingState -> tableGroup.resolveColumnReference( - getContainingTableExpression(), + sqlAstProcessingState -> new ColumnReference( attrColumnExpr, - () -> new ColumnReference( - attrColumnExpr, - tableReference.getIdentificationVariable(), - jdbcMapping, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) + tableReference.getIdentificationVariable(), + jdbcMapping, + sqlAstCreationState.getCreationContext().getSessionFactory() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractColumnReferenceQualifier.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractColumnReferenceQualifier.java index ceb8c8865b..0f5749026b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractColumnReferenceQualifier.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractColumnReferenceQualifier.java @@ -7,13 +7,9 @@ package org.hibernate.sql.ast.tree.from; import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; import java.util.function.Supplier; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.query.sqm.sql.SqlExpressionResolver; -import org.hibernate.sql.ast.tree.expression.ColumnReference; /** * @author Steve Ebersole @@ -28,7 +24,6 @@ public abstract class AbstractColumnReferenceQualifier implements ColumnReferenc // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // TableReference handling - @Override public TableReference resolveTableReference(String tableExpression, Supplier creator) { final TableReference existing = resolveTableReference( tableExpression ); @@ -56,27 +51,4 @@ public abstract class AbstractColumnReferenceQualifier implements ColumnReferenc throw new IllegalStateException( "Could not resolve binding for table `" + tableExpression + "`" ); } - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // ColumnReference handling - - private final SortedMap columnReferenceMap = new TreeMap<>(); - - @Override - public ColumnReference resolveColumnReference( - String tableExpression, - String columnExpression, - Supplier creator) { - return columnReferenceMap.computeIfAbsent( - SqlExpressionResolver.createColumnReferenceKey( resolveTableReference( tableExpression ), columnExpression ), - s -> creator.get() - ); - } - - @Override - public ColumnReference resolveColumnReference(String tableExpression, String columnExpression) { - return columnReferenceMap.get( - SqlExpressionResolver.createColumnReferenceKey( resolveTableReference( tableExpression ), columnExpression ) - ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/ColumnReferenceQualifier.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/ColumnReferenceQualifier.java index 88ff70f60b..73410ef669 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/ColumnReferenceQualifier.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/ColumnReferenceQualifier.java @@ -17,6 +17,4 @@ public interface ColumnReferenceQualifier { TableReference resolveTableReference(String tableExpression, Supplier creator); TableReference resolveTableReference(String tableExpression); - ColumnReference resolveColumnReference(String tableExpression, String columnExpression, Supplier creator); - ColumnReference resolveColumnReference(String tableExpression, String columnExpression); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java index 77d91b90cb..638fa66c7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java @@ -17,7 +17,6 @@ import org.hibernate.LockMode; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; -import org.hibernate.sql.ast.tree.expression.ColumnReference; /** * @author Steve Ebersole @@ -127,16 +126,4 @@ public class CompositeTableGroup implements VirtualTableGroup { return underlyingTableGroup.resolveTableReference( tableExpression ); } - @Override - public ColumnReference resolveColumnReference( - String tableExpression, - String columnExpression, - Supplier creator) { - return underlyingTableGroup.resolveColumnReference( tableExpression, columnExpression, creator ); - } - - @Override - public ColumnReference resolveColumnReference(String tableExpression, String columnExpression) { - return underlyingTableGroup.resolveColumnReference( tableExpression, columnExpression ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java index 6cb68e8a29..d068a9cb5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java @@ -11,7 +11,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.Supplier; -import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.tree.SqlAstNode; @@ -72,27 +71,6 @@ public class TableReference implements SqlAstNode, ColumnReferenceQualifier { return null; } - @Override - public ColumnReference resolveColumnReference(String tableExpression, String columnExpression, Supplier creator) { - final ColumnReference existing = resolveColumnReference( tableExpression, columnExpression ); - if ( existing != null ) { - return existing; - } - - final ColumnReference columnReference = creator.get(); - columnReferenceResolutionMap.put( columnExpression, columnReference ); - return columnReference; - } - - @Override - public ColumnReference resolveColumnReference(String tableExpression, String columnExpression) { - if ( ! tableExpression.equals( getTableExpression() ) ) { - throw new HibernateException( "Attempt to resolve ColumnReference relative to a table other than the referenced table" ); - } - - return columnReferenceResolutionMap.get( columnExpression ); - } - @Override public String toString() { return getTableExpression() + "(" + getIdentificationVariable() + ')';