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 JdbcMapping jdbcMapping;
|
||||||
private final BasicValueConverter valueConverter;
|
private final BasicValueConverter valueConverter;
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public BasicValuedSingularAttributeMapping(
|
public BasicValuedSingularAttributeMapping(
|
||||||
String attributeName,
|
String attributeName,
|
||||||
int stateArrayPosition,
|
int stateArrayPosition,
|
||||||
|
@ -119,15 +120,11 @@ public class BasicValuedSingularAttributeMapping extends AbstractSingularAttribu
|
||||||
tableReference,
|
tableReference,
|
||||||
getMappedColumnExpression()
|
getMappedColumnExpression()
|
||||||
),
|
),
|
||||||
sqlAstProcessingState -> tableGroup.resolveColumnReference(
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
getContainingTableExpression(),
|
|
||||||
getMappedColumnExpression(),
|
getMappedColumnExpression(),
|
||||||
() -> new ColumnReference(
|
tableReference.getIdentificationVariable(),
|
||||||
getMappedColumnExpression(),
|
jdbcMapping,
|
||||||
tableReference.getIdentificationVariable(),
|
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
||||||
jdbcMapping,
|
|
||||||
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
valueConverter == null ? getMappedTypeDescriptor().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
|
valueConverter == null ? getMappedTypeDescriptor().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class EmbeddedAttributeMapping
|
||||||
private final String tableExpression;
|
private final String tableExpression;
|
||||||
private final String[] attrColumnNames;
|
private final String[] attrColumnNames;
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public EmbeddedAttributeMapping(
|
public EmbeddedAttributeMapping(
|
||||||
String name,
|
String name,
|
||||||
int stateArrayPosition,
|
int stateArrayPosition,
|
||||||
|
@ -187,15 +188,11 @@ public class EmbeddedAttributeMapping
|
||||||
tableReference,
|
tableReference,
|
||||||
attrColumnExpr
|
attrColumnExpr
|
||||||
),
|
),
|
||||||
sqlAstProcessingState -> tableGroup.resolveColumnReference(
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
getContainingTableExpression(),
|
|
||||||
attrColumnExpr,
|
attrColumnExpr,
|
||||||
() -> new ColumnReference(
|
tableReference.getIdentificationVariable(),
|
||||||
attrColumnExpr,
|
jdbcMapping,
|
||||||
tableReference.getIdentificationVariable(),
|
sqlAstCreationState.getCreationContext().getSessionFactory()
|
||||||
jdbcMapping,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,9 @@
|
||||||
package org.hibernate.sql.ast.tree.from;
|
package org.hibernate.sql.ast.tree.from;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.query.sqm.sql.SqlExpressionResolver;
|
|
||||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -28,7 +24,6 @@ public abstract class AbstractColumnReferenceQualifier implements ColumnReferenc
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// TableReference handling
|
// TableReference handling
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableReference resolveTableReference(String tableExpression, Supplier<TableReference> creator) {
|
public TableReference resolveTableReference(String tableExpression, Supplier<TableReference> creator) {
|
||||||
final TableReference existing = resolveTableReference( tableExpression );
|
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 + "`" );
|
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, Supplier<TableReference> creator);
|
||||||
TableReference resolveTableReference(String tableExpression);
|
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.EmbeddableValuedModelPart;
|
||||||
import org.hibernate.metamodel.mapping.ModelPartContainer;
|
import org.hibernate.metamodel.mapping.ModelPartContainer;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -127,16 +126,4 @@ public class CompositeTableGroup implements VirtualTableGroup {
|
||||||
return underlyingTableGroup.resolveTableReference( tableExpression );
|
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.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstWalker;
|
import org.hibernate.sql.ast.spi.SqlAstWalker;
|
||||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||||
|
@ -72,27 +71,6 @@ public class TableReference implements SqlAstNode, ColumnReferenceQualifier {
|
||||||
return null;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getTableExpression() + "(" + getIdentificationVariable() + ')';
|
return getTableExpression() + "(" + getIdentificationVariable() + ')';
|
||||||
|
|
Loading…
Reference in New Issue