move subclassColumnClosure down to the only subclass that uses it

This commit is contained in:
Gavin King 2022-01-29 17:46:42 +01:00
parent 135216b0a9
commit 48dc4662ef
2 changed files with 47 additions and 47 deletions

View File

@ -359,7 +359,7 @@ public abstract class AbstractEntityPersister
private final CascadeStyle[] subclassPropertyCascadeStyleClosure;
//information about all columns/formulas in class hierarchy
private final String[] subclassColumnClosure; //only used by JoinedSubclassEntityPersister! TODO: MOVE IT DOWN!
// private final String[] subclassColumnClosure;
// private final boolean[] subclassColumnLazyClosure;
private final String[] subclassColumnAliasClosure;
private final boolean[] subclassColumnSelectableClosure;
@ -705,12 +705,10 @@ public abstract class AbstractEntityPersister
this.entityMetamodel = new EntityMetamodel( bootDescriptor, this, creationContext );
if ( entityMetamodel.isMutable() ) {
this.entityEntryFactory = MutableEntityEntryFactory.INSTANCE;
}
else {
this.entityEntryFactory = ImmutableEntityEntryFactory.INSTANCE;
}
this.entityEntryFactory = entityMetamodel.isMutable()
? MutableEntityEntryFactory.INSTANCE
: ImmutableEntityEntryFactory.INSTANCE;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this.representationStrategy = creationContext.getBootstrapContext().getRepresentationStrategySelector()
@ -719,7 +717,6 @@ public abstract class AbstractEntityPersister
this.javaType = representationStrategy.getLoadJavaType();
assert javaType != null;
final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class );
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
@ -777,12 +774,9 @@ public abstract class AbstractEntityPersister
// VERSION
if ( bootDescriptor.isVersioned() ) {
versionColumnName = bootDescriptor.getVersion().getColumns().get(0).getQuotedName( dialect );
}
else {
versionColumnName = null;
}
versionColumnName = bootDescriptor.isVersioned()
? bootDescriptor.getVersion().getColumns().get(0).getQuotedName(dialect)
: null;
//WHERE STRING
@ -846,14 +840,15 @@ public abstract class AbstractEntityPersister
colAliases[k] = selectable.getAlias( dialect, prop.getValue().getTable() );
if ( selectable.isFormula() ) {
foundFormula = true;
( (Formula) selectable ).setFormula( substituteBrackets( ( (Formula) selectable ).getFormula() ) );
Formula formula = (Formula) selectable;
formula.setFormula( substituteBrackets( formula.getFormula() ) );
formulaTemplates[k] = selectable.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
}
else {
Column col = (Column) selectable;
colNames[k] = col.getQuotedName( dialect );
// colReaderTemplates[k] = col.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
colWriters[k] = col.getWriteExpr();
Column column = (Column) selectable;
colNames[k] = column.getQuotedName( dialect );
// colReaderTemplates[k] = column.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
colWriters[k] = column.getWriteExpr();
}
k++;
}
@ -863,7 +858,7 @@ public abstract class AbstractEntityPersister
propertyColumnWriters[i] = colWriters;
propertyColumnAliases[i] = colAliases;
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
final boolean lazy = !EnhancementHelper.includeInBaseFetchGroup(
prop,
entityMetamodel.isInstrumented(),
entityName -> {
@ -905,7 +900,7 @@ public abstract class AbstractEntityPersister
// SUBCLASS PROPERTY CLOSURE
ArrayList<String> columns = new ArrayList<>();
// ArrayList<String> columns = new ArrayList<>();
// ArrayList<Boolean> columnsLazy = new ArrayList<>();
// ArrayList<String> columnReaderTemplates = new ArrayList<>();
ArrayList<String> aliases = new ArrayList<>();
@ -968,19 +963,21 @@ public abstract class AbstractEntityPersister
// formulasLazy.add( lazy );
}
else {
Column col = (Column) selectable;
String colName = col.getQuotedName( dialect );
Column column = (Column) selectable;
String colName = column.getQuotedName( dialect );
// colnos[l] = columns.size(); //before add :-)
// formnos[l] = -1;
columns.add( colName );
// columns.add( colName );
cols[l] = colName;
aliases.add( selectable.getAlias( dialect, prop.getValue().getTable() ) );
// columnsLazy.add( lazy );
columnSelectables.add( prop.isSelectable() );
readers[l] = col.getReadExpr( dialect );
String readerTemplate = col.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
readerTemplates[l] = readerTemplate;
readers[l] = column.getReadExpr( dialect );
readerTemplates[l] = column.getTemplate(
dialect,
factory.getQueryEngine().getSqmFunctionRegistry()
);
// columnReaderTemplates.add( readerTemplate );
}
l++;
@ -995,7 +992,7 @@ public abstract class AbstractEntityPersister
joinedFetchesList.add( prop.getValue().getFetchMode() );
cascades.add( prop.getCascadeStyle() );
}
subclassColumnClosure = ArrayHelper.toStringArray( columns );
// subclassColumnClosure = ArrayHelper.toStringArray( columns );
subclassColumnAliasClosure = ArrayHelper.toStringArray( aliases );
// subclassColumnLazyClosure = ArrayHelper.toBooleanArray( columnsLazy );
subclassColumnSelectableClosure = ArrayHelper.toBooleanArray( columnSelectables );
@ -2509,11 +2506,6 @@ public abstract class AbstractEntityPersister
return ArrayHelper.toIntArray( fields );
}
@Deprecated //TODO: REMOVE THIS
protected String[] getSubclassColumnClosure() {
return subclassColumnClosure;
}
protected String[] getSubclassColumnAliasClosure() {
return subclassColumnAliasClosure;
}

View File

@ -21,6 +21,8 @@ import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator;
@ -118,6 +120,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// subclasses and superclasses of this class
private final int[] subclassColumnTableNumberClosure;
// private final int[] subclassFormulaTableNumberClosure;
private final String[] subclassColumnClosure;
private final boolean[] subclassTableSequentialSelect;
// private final boolean[] subclassTableIsLazyClosure;
@ -176,8 +179,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
else {
final Column column = (Column) selectable;
explicitDiscriminatorColumnName = column.getQuotedName(factory.getJdbcServices().getDialect());
discriminatorAlias = column.getAlias(factory.getJdbcServices().getDialect(), persistentClass.getRootTable() );
explicitDiscriminatorColumnName = column.getQuotedName( factory.getJdbcServices().getDialect() );
discriminatorAlias = column.getAlias( factory.getJdbcServices().getDialect(), persistentClass.getRootTable() );
}
discriminatorType = (BasicType<?>) persistentClass.getDiscriminator().getType();
if ( persistentClass.isDiscriminatorValueNull() ) {
@ -480,9 +483,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
//TODO: code duplication with SingleTableEntityPersister
final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class );
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
ArrayList<Integer> columnTableNumbers = new ArrayList<>();
// ArrayList<Integer> formulaTableNumbers = new ArrayList<>();
ArrayList<Integer> propTableNumbers = new ArrayList<>();
ArrayList<String> columns = new ArrayList<>();
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
Table table = property.getValue().getTable();
@ -498,14 +505,16 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
else {
columnTableNumbers.add( tableNumber );
Column column = (Column) selectable;
columns.add( column.getQuotedName( dialect ) );
}
}
}
subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnTableNumbers );
subclassPropertyTableNumberClosure = ArrayHelper.toIntArray( propTableNumbers );
// subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaTableNumbers );
subclassColumnClosure = ArrayHelper.toStringArray( columns );
// SUBCLASSES
@ -596,9 +605,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
initDiscriminatorProperties( factory, k, table, discriminatorValue );
subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() );
int id = getTableId(
table.getQualifiedName(
factory.getSqlStringGenerationContext()
),
table.getQualifiedName( factory.getSqlStringGenerationContext() ),
subclassTableNameClosure
);
notNullColumnTableNumbers[k] = id;
@ -673,7 +680,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
*
* @return subclassNamesBySubclassTable
*/
private String[][] buildSubclassNamesBySubclassTableMapping(PersistentClass persistentClass, SessionFactoryImplementor factory) {
private String[][] buildSubclassNamesBySubclassTableMapping(
PersistentClass persistentClass,
SessionFactoryImplementor factory) {
// this value represents the number of subclasses (and not the class itself)
final int numberOfSubclassTables = subclassTableNameClosure.length - coreTableSpan;
if ( numberOfSubclassTables == 0 ) {
@ -1107,18 +1116,17 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return naturalOrderPropertyTableNumbers[i];
}
}
final String[] subclassColumnNameClosure = getSubclassColumnClosure();
for ( int i = 0, max = subclassColumnNameClosure.length; i < max; i++ ) {
final boolean quoted = subclassColumnNameClosure[i].startsWith( "\"" )
&& subclassColumnNameClosure[i].endsWith( "\"" );
for (int i = 0, max = subclassColumnClosure.length; i < max; i++ ) {
final boolean quoted = subclassColumnClosure[i].startsWith( "\"" )
&& subclassColumnClosure[i].endsWith( "\"" );
if ( quoted ) {
if ( subclassColumnNameClosure[i].equals( columnName ) ) {
if ( subclassColumnClosure[i].equals( columnName ) ) {
return subclassColumnTableNumberClosure[i];
}
}
else {
if ( subclassColumnNameClosure[i].equalsIgnoreCase( columnName ) ) {
if ( subclassColumnClosure[i].equalsIgnoreCase( columnName ) ) {
return subclassColumnTableNumberClosure[i];
}
}