clean up looping, using indexed for instead of local var
This commit is contained in:
parent
5de6c703a8
commit
a7da40709c
|
@ -205,6 +205,7 @@ import org.hibernate.query.spi.NavigablePath;
|
|||
import org.hibernate.query.named.NamedQueryMemento;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.sql.internal.SQLQueryParser;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
|
@ -768,16 +769,15 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
multiIdEntityLoader = new MultiIdLoaderStandard<>( this, bootDescriptor, factory );
|
||||
|
||||
int i = 0;
|
||||
for ( Column column: bootDescriptor.getIdentifier().getColumns() ) {
|
||||
SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
|
||||
|
||||
List<Column> columns = bootDescriptor.getIdentifier().getColumns();
|
||||
for ( int i = 0; i < columns.size(); i++ ) {
|
||||
Column column = columns.get(i);
|
||||
rootTableKeyColumnNames[i] = column.getQuotedName( dialect );
|
||||
rootTableKeyColumnReaders[i] = column.getReadExpr( dialect );
|
||||
rootTableKeyColumnReaderTemplates[i] = column.getTemplate(
|
||||
dialect,
|
||||
factory.getQueryEngine().getSqmFunctionRegistry()
|
||||
);
|
||||
rootTableKeyColumnReaderTemplates[i] = column.getTemplate( dialect, functionRegistry );
|
||||
identifierAliases[i] = column.getAlias( dialect, bootDescriptor.getRootTable() );
|
||||
i++;
|
||||
}
|
||||
|
||||
// VERSION
|
||||
|
@ -805,7 +805,7 @@ public abstract class AbstractEntityPersister
|
|||
sqlWhereStringTemplate = Template.renderWhereStringTemplate(
|
||||
"(" + bootDescriptor.getWhere() + ")",
|
||||
dialect,
|
||||
factory.getQueryEngine().getSqmFunctionRegistry()
|
||||
functionRegistry
|
||||
);
|
||||
}
|
||||
// PROPERTIES
|
||||
|
@ -830,9 +830,10 @@ public abstract class AbstractEntityPersister
|
|||
ArrayList<String[]> lazyColAliases = new ArrayList<>();
|
||||
|
||||
final ArrayList<Integer> lobPropertiesLocalCollector = new ArrayList<>();
|
||||
i = 0;
|
||||
boolean foundFormula = false;
|
||||
for ( Property prop : bootDescriptor.getPropertyClosure() ) {
|
||||
List<Property> propertyClosure = bootDescriptor.getPropertyClosure();
|
||||
for ( int i = 0; i < propertyClosure.size(); i++ ) {
|
||||
Property prop = propertyClosure.get(i);
|
||||
thisClassProperties.add( prop );
|
||||
|
||||
int span = prop.getColumnSpan();
|
||||
|
@ -843,14 +844,15 @@ public abstract class AbstractEntityPersister
|
|||
// String[] colReaderTemplates = new String[span];
|
||||
String[] colWriters = new String[span];
|
||||
String[] formulaTemplates = new String[span];
|
||||
int k = 0;
|
||||
for ( Selectable selectable: prop.getSelectables() ) {
|
||||
List<Selectable> selectables = prop.getSelectables();
|
||||
for ( int k = 0; k < selectables.size(); k++ ) {
|
||||
Selectable selectable = selectables.get(k);
|
||||
colAliases[k] = selectable.getAlias( dialect, prop.getValue().getTable() );
|
||||
if ( selectable.isFormula() ) {
|
||||
foundFormula = true;
|
||||
Formula formula = (Formula) selectable;
|
||||
formula.setFormula( substituteBrackets( formula.getFormula() ) );
|
||||
formulaTemplates[k] = selectable.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
||||
formulaTemplates[k] = selectable.getTemplate( dialect, functionRegistry );
|
||||
}
|
||||
else {
|
||||
Column column = (Column) selectable;
|
||||
|
@ -858,7 +860,6 @@ public abstract class AbstractEntityPersister
|
|||
// colReaderTemplates[k] = column.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
||||
colWriters[k] = column.getWriteExpr();
|
||||
}
|
||||
k++;
|
||||
}
|
||||
propertyColumnNames[i] = colNames;
|
||||
propertyColumnFormulaTemplates[i] = formulaTemplates;
|
||||
|
@ -895,9 +896,6 @@ public abstract class AbstractEntityPersister
|
|||
if ( prop.isLob() && dialect.forceLobAsLastValue() ) {
|
||||
lobPropertiesLocalCollector.add( i );
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
this.lobProperties = CollectionHelper.toSmallList( lobPropertiesLocalCollector );
|
||||
hasFormulaProperties = foundFormula;
|
||||
|
@ -947,7 +945,6 @@ public abstract class AbstractEntityPersister
|
|||
// int[] colnos = new int[ prop.getColumnSpan() ];
|
||||
// int[] formnos = new int[ prop.getColumnSpan() ];
|
||||
|
||||
int l = 0;
|
||||
// final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
|
||||
// prop,
|
||||
// entityMetamodel.isInstrumented(),
|
||||
|
@ -959,36 +956,34 @@ public abstract class AbstractEntityPersister
|
|||
// },
|
||||
// sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled()
|
||||
// );
|
||||
for ( Selectable selectable : prop.getSelectables() ) {
|
||||
List<Selectable> selectables = prop.getSelectables();
|
||||
for ( int i = 0; i < selectables.size(); i++ ) {
|
||||
Selectable selectable = selectables.get(i);
|
||||
if ( selectable.isFormula() ) {
|
||||
String template = selectable.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
||||
String template = selectable.getTemplate( dialect, functionRegistry );
|
||||
// formnos[l] = formulaTemplates.size();
|
||||
// colnos[l] = -1;
|
||||
// formulaTemplates.add( template );
|
||||
forms[l] = template;
|
||||
forms[i] = template;
|
||||
// formulas.add( selectable.getText( dialect ) );
|
||||
formulaAliases.add( selectable.getAlias( dialect ) );
|
||||
// formulasLazy.add( lazy );
|
||||
}
|
||||
else {
|
||||
Column column = (Column) selectable;
|
||||
String colName = column.getQuotedName( dialect );
|
||||
String colName = column.getQuotedName(dialect);
|
||||
// colnos[l] = columns.size(); //before add :-)
|
||||
// formnos[l] = -1;
|
||||
// columns.add( colName );
|
||||
cols[l] = colName;
|
||||
cols[i] = colName;
|
||||
aliases.add( selectable.getAlias( dialect, prop.getValue().getTable() ) );
|
||||
// columnsLazy.add( lazy );
|
||||
columnSelectables.add( prop.isSelectable() );
|
||||
|
||||
readers[l] = column.getReadExpr( dialect );
|
||||
readerTemplates[l] = column.getTemplate(
|
||||
dialect,
|
||||
factory.getQueryEngine().getSqmFunctionRegistry()
|
||||
);
|
||||
readers[i] = column.getReadExpr( dialect );
|
||||
readerTemplates[i] = column.getTemplate( dialect, functionRegistry );
|
||||
// columnReaderTemplates.add( readerTemplate );
|
||||
}
|
||||
l++;
|
||||
}
|
||||
propColumns.add( cols );
|
||||
propColumnReaders.add( readers );
|
||||
|
|
|
@ -235,13 +235,12 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
ArrayList<String[]> keyColumnReaders = new ArrayList<>();
|
||||
ArrayList<String[]> keyColumnReaderTemplates = new ArrayList<>();
|
||||
ArrayList<Boolean> cascadeDeletes = new ArrayList<>();
|
||||
List<Table> tItr = persistentClass.getTableClosure();
|
||||
List<KeyValue> kItr = persistentClass.getKeyClosure();
|
||||
for ( int i = 0; i < tItr.size() && i < kItr.size(); i++ ) {
|
||||
final Table table = tItr.get(i);
|
||||
final KeyValue key = kItr.get(i);
|
||||
final String tableName = determineTableName( table );
|
||||
tableNames.add( tableName );
|
||||
List<Table> tableClosure = persistentClass.getTableClosure();
|
||||
List<KeyValue> keyClosure = persistentClass.getKeyClosure();
|
||||
for ( int i = 0; i < tableClosure.size() && i < keyClosure.size(); i++ ) {
|
||||
tableNames.add( determineTableName( tableClosure.get(i) ) );
|
||||
|
||||
final KeyValue key = keyClosure.get(i);
|
||||
String[] keyCols = new String[idColumnSpan];
|
||||
String[] keyColReaders = new String[idColumnSpan];
|
||||
String[] keyColReaderTemplates = new String[idColumnSpan];
|
||||
|
@ -265,14 +264,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
isNullableTable = new boolean[tableSpan];
|
||||
isInverseTable = new boolean[tableSpan];
|
||||
|
||||
int tableIndex = 0;
|
||||
for ( Join join : persistentClass.getJoinClosure() ) {
|
||||
isNullableTable[tableIndex] = join.isOptional();
|
||||
isInverseTable[tableIndex] = join.isInverse();
|
||||
List<Join> joinClosure = persistentClass.getJoinClosure();
|
||||
for ( int i = 0; i < joinClosure.size(); i++ ) {
|
||||
Join join = joinClosure.get(i);
|
||||
isNullableTable[i] = join.isOptional();
|
||||
isInverseTable[i] = join.isInverse();
|
||||
|
||||
Table table = join.getTable();
|
||||
final String tableName = determineTableName( table );
|
||||
tableNames.add( tableName );
|
||||
tableNames.add( determineTableName( join.getTable() ) );
|
||||
|
||||
KeyValue key = join.getKey();
|
||||
int joinIdColumnSpan = key.getColumnSpan();
|
||||
|
@ -292,8 +290,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
keyColumnReaders.add( keyColReaders );
|
||||
keyColumnReaderTemplates.add( keyColReaderTemplates );
|
||||
cascadeDeletes.add( key.isCascadeDeleteEnabled() && dialect.supportsCascadeDelete() );
|
||||
|
||||
tableIndex++;
|
||||
}
|
||||
|
||||
naturalOrderTableNames = ArrayHelper.toStringArray( tableNames );
|
||||
|
@ -450,14 +446,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
int hydrateSpan = getPropertySpan();
|
||||
naturalOrderPropertyTableNumbers = new int[hydrateSpan];
|
||||
propertyTableNumbers = new int[hydrateSpan];
|
||||
int i = 0;
|
||||
for ( Property property : persistentClass.getPropertyClosure() ) {
|
||||
String tableName = property.getValue().getTable().getQualifiedName(
|
||||
List<Property> propertyClosure = persistentClass.getPropertyClosure();
|
||||
for ( int i = 0; i < propertyClosure.size(); i++ ) {
|
||||
String tableName = propertyClosure.get(i).getValue().getTable().getQualifiedName(
|
||||
factory.getSqlStringGenerationContext()
|
||||
);
|
||||
propertyTableNumbers[i] = getTableId( tableName, this.tableNames );
|
||||
naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames );
|
||||
i++;
|
||||
}
|
||||
|
||||
// subclass closure properties
|
||||
|
@ -470,8 +465,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
ArrayList<String> columns = new ArrayList<>();
|
||||
|
||||
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
|
||||
Table table = property.getValue().getTable();
|
||||
String tableName = table.getQualifiedName(
|
||||
String tableName = property.getValue().getTable().getQualifiedName(
|
||||
factory.getSqlStringGenerationContext()
|
||||
);
|
||||
Integer tableNumber = getTableId( tableName, subclassTableNameClosure );
|
||||
|
|
|
@ -197,8 +197,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
|
||||
// JOINS
|
||||
|
||||
int j = 1;
|
||||
for ( Join join : persistentClass.getJoinClosure() ) {
|
||||
List<Join> joinClosure = persistentClass.getJoinClosure();
|
||||
for ( int j = 1; j-1 < joinClosure.size(); j++ ) {
|
||||
Join join = joinClosure.get(j-1);
|
||||
qualifiedTableNames[j] = determineTableName( join.getTable() );
|
||||
isInverseTable[j] = join.isInverse();
|
||||
isNullableTable[j] = join.isOptional();
|
||||
|
@ -221,12 +222,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
: join.getCustomSQLDeleteCheckStyle();
|
||||
|
||||
keyColumnNames[j] = new String[join.getKey().getColumnSpan()];
|
||||
int i = 0;
|
||||
for ( Column col : join.getKey().getColumns() ) {
|
||||
keyColumnNames[j][i++] = col.getQuotedName( dialect );
|
||||
}
|
||||
|
||||
j++;
|
||||
List<Column> columns = join.getKey().getColumns();
|
||||
for ( int i = 0; i < columns.size(); i++ ) {
|
||||
keyColumnNames[j][i] = columns.get(i).getQuotedName( dialect );
|
||||
}
|
||||
}
|
||||
|
||||
constraintOrderedTableNames = new String[qualifiedTableNames.length];
|
||||
|
@ -273,9 +273,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
subclassTables.add( joinTableName );
|
||||
|
||||
String[] keyCols = new String[join.getKey().getColumnSpan()];
|
||||
int i = 0;
|
||||
for ( Column col : join.getKey().getColumns() ) {
|
||||
keyCols[i++] = col.getQuotedName( dialect );
|
||||
List<Column> columns = join.getKey().getColumns();
|
||||
for ( int i = 0; i < columns.size(); i++ ) {
|
||||
Column col = columns.get(i);
|
||||
keyCols[i] = col.getQuotedName(dialect);
|
||||
}
|
||||
joinKeyColumns.add( keyCols );
|
||||
}
|
||||
|
@ -339,9 +340,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
// PROPERTIES
|
||||
|
||||
propertyTableNumbers = new int[getPropertySpan()];
|
||||
int i = 0;
|
||||
for ( Property property : persistentClass.getPropertyClosure() ) {
|
||||
propertyTableNumbers[i++] = persistentClass.getJoinNumber( property );
|
||||
List<Property> propertyClosure = persistentClass.getPropertyClosure();
|
||||
for ( int k = 0; k < propertyClosure.size(); k++ ) {
|
||||
propertyTableNumbers[k] = persistentClass.getJoinNumber( propertyClosure.get(k) );
|
||||
}
|
||||
|
||||
//TODO: code duplication with JoinedSubclassEntityPersister
|
||||
|
@ -397,9 +398,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
}
|
||||
|
||||
// SUBCLASSES
|
||||
int k = 1;
|
||||
for ( Subclass subclass : persistentClass.getSubclasses() ) {
|
||||
subclassClosure[k++] = subclass.getEntityName();
|
||||
List<Subclass> subclasses = persistentClass.getSubclasses();
|
||||
for ( int k = 0; k < subclasses.size(); k++ ) {
|
||||
Subclass subclass = subclasses.get(k);
|
||||
subclassClosure[k] = subclass.getEntityName();
|
||||
Object subclassDiscriminatorValue = DiscriminatorHelper.getDiscriminatorValue( subclass );
|
||||
addSubclassByDiscriminatorValue(
|
||||
subclassesByDiscriminatorValueLocal,
|
||||
|
@ -413,7 +415,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
: subclass.isAbstract();
|
||||
|
||||
if ( !subclassAbstract ) {
|
||||
values.add(subclassDiscriminatorValue);
|
||||
values.add( subclassDiscriminatorValue );
|
||||
sqlValues.add( DiscriminatorHelper.getDiscriminatorSQLValue( subclass, dialect, factory ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue