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
This commit is contained in:
parent
4d32d3d763
commit
5482c55e6c
|
@ -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(),
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -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<TableReference> 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<String, ColumnReference> columnReferenceMap = new TreeMap<>();
|
||||
|
||||
@Override
|
||||
public ColumnReference resolveColumnReference(
|
||||
String tableExpression,
|
||||
String columnExpression,
|
||||
Supplier<ColumnReference> 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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,4 @@ public interface ColumnReferenceQualifier {
|
|||
TableReference resolveTableReference(String tableExpression, Supplier<TableReference> creator);
|
||||
TableReference resolveTableReference(String tableExpression);
|
||||
|
||||
ColumnReference resolveColumnReference(String tableExpression, String columnExpression, Supplier<ColumnReference> creator);
|
||||
ColumnReference resolveColumnReference(String tableExpression, String columnExpression);
|
||||
}
|
||||
|
|
|
@ -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<ColumnReference> creator) {
|
||||
return underlyingTableGroup.resolveColumnReference( tableExpression, columnExpression, creator );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnReference resolveColumnReference(String tableExpression, String columnExpression) {
|
||||
return underlyingTableGroup.resolveColumnReference( tableExpression, columnExpression );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ColumnReference> 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() + ')';
|
||||
|
|
Loading…
Reference in New Issue