lots more cleanups to persisters

This commit is contained in:
Gavin 2022-12-25 03:29:14 +01:00 committed by Gavin King
parent 5f0b27fb6a
commit 8162bd5152
10 changed files with 504 additions and 703 deletions

View File

@ -19,11 +19,6 @@ public class Oracle12cIdentityColumnSupport extends IdentityColumnSupportImpl {
return true;
}
@Override
public boolean supportsInsertSelectIdentity() {
return true;
}
@Override
public String getIdentityColumnString(int type) {
return "generated as identity";

View File

@ -1481,8 +1481,7 @@ public class ToOneAttributeMapping
navigablePath,
this,
tableGroupToUse,
null,
creationState
null
);
entityResult.afterInitialize( entityResult, creationState );
//noinspection unchecked

View File

@ -47,7 +47,6 @@ import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.mapping.TableDetails;
import org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl;
import org.hibernate.metamodel.mapping.internal.CaseStatementDiscriminatorMappingImpl;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -65,10 +64,12 @@ import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.entity.internal.EntityResultJoinedSubclassImpl;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.CompositeType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;
import org.jboss.logging.Logger;
import static java.util.Collections.emptyMap;
@ -79,6 +80,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.linkedMap
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
import static org.hibernate.jdbc.Expectations.appropriateExpectation;
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildEncapsulatedCompositeIdentifierMapping;
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping;
import static org.hibernate.persister.entity.DiscriminatorHelper.NOT_NULL_DISCRIMINATOR;
import static org.hibernate.persister.entity.DiscriminatorHelper.NULL_DISCRIMINATOR;
@ -189,8 +191,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class );
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
final SqmFunctionRegistry sqmFunctionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
final TypeConfiguration typeConfiguration = factory.getTypeConfiguration();
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
// DISCRIMINATOR
@ -215,9 +218,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
else {
explicitDiscriminatorColumnName = null;
discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS;
discriminatorType = factory.getTypeConfiguration()
.getBasicTypeRegistry()
.resolve( StandardBasicTypes.INTEGER );
discriminatorType = basicTypeRegistry.resolve( StandardBasicTypes.INTEGER );
try {
discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLString = discriminatorValue.toString();
@ -230,9 +231,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
else {
explicitDiscriminatorColumnName = null;
discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS;
discriminatorType = factory.getTypeConfiguration()
.getBasicTypeRegistry()
.resolve( StandardBasicTypes.INTEGER );
discriminatorType = basicTypeRegistry.resolve( StandardBasicTypes.INTEGER );
discriminatorValue = null;
discriminatorSQLString = null;
forceDiscriminator = false;
@ -246,30 +245,26 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
final int idColumnSpan = getIdentifierColumnSpan();
ArrayList<String> tableNames = new ArrayList<>();
ArrayList<String[]> keyColumns = new ArrayList<>();
ArrayList<String[]> keyColumnReaders = new ArrayList<>();
ArrayList<String[]> keyColumnReaderTemplates = new ArrayList<>();
ArrayList<Boolean> cascadeDeletes = new ArrayList<>();
List<Table> tableClosure = persistentClass.getTableClosure();
List<KeyValue> keyClosure = persistentClass.getKeyClosure();
final ArrayList<String> tableNames = new ArrayList<>();
final ArrayList<String[]> keyColumns = new ArrayList<>();
final ArrayList<String[]> keyColumnReaders = new ArrayList<>();
final ArrayList<String[]> keyColumnReaderTemplates = new ArrayList<>();
final ArrayList<Boolean> cascadeDeletes = new ArrayList<>();
final List<Table> tableClosure = persistentClass.getTableClosure();
final 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];
List<Column> columns = key.getColumns();
final String[] keyCols = new String[idColumnSpan];
final String[] keyColReaders = new String[idColumnSpan];
final String[] keyColReaderTemplates = new String[idColumnSpan];
final List<Column> columns = key.getColumns();
for ( int k = 0; k < idColumnSpan; k++ ) {
Column column = columns.get(k);
final Column column = columns.get(k);
keyCols[k] = column.getQuotedName( dialect );
keyColReaders[k] = column.getReadExpr( dialect );
keyColReaderTemplates[k] = column.getTemplate(
dialect,
factory.getTypeConfiguration(),
sqmFunctionRegistry
);
keyColReaderTemplates[k] = column.getTemplate( dialect, typeConfiguration, functionRegistry );
}
keyColumns.add( keyCols );
keyColumnReaders.add( keyColReaders );
@ -284,31 +279,27 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
isNullableTable = new boolean[tableSpan];
isInverseTable = new boolean[tableSpan];
List<Join> joinClosure = persistentClass.getJoinClosure();
final List<Join> joinClosure = persistentClass.getJoinClosure();
for ( int i = 0; i < joinClosure.size(); i++ ) {
Join join = joinClosure.get(i);
final Join join = joinClosure.get(i);
isNullableTable[i] = join.isOptional();
isInverseTable[i] = join.isInverse();
tableNames.add( determineTableName( join.getTable() ) );
KeyValue key = join.getKey();
int joinIdColumnSpan = key.getColumnSpan();
final KeyValue key = join.getKey();
final int joinIdColumnSpan = key.getColumnSpan();
String[] keyCols = new String[joinIdColumnSpan];
String[] keyColReaders = new String[joinIdColumnSpan];
String[] keyColReaderTemplates = new String[joinIdColumnSpan];
final String[] keyCols = new String[joinIdColumnSpan];
final String[] keyColReaders = new String[joinIdColumnSpan];
final String[] keyColReaderTemplates = new String[joinIdColumnSpan];
List<Column> columns = key.getColumns();
final List<Column> columns = key.getColumns();
for ( int k = 0; k < joinIdColumnSpan; k++ ) {
Column column = columns.get(k);
final Column column = columns.get(k);
keyCols[k] = column.getQuotedName( dialect );
keyColReaders[k] = column.getReadExpr( dialect );
keyColReaderTemplates[k] = column.getTemplate(
dialect,
factory.getTypeConfiguration(),
sqmFunctionRegistry
);
keyColReaderTemplates[k] = column.getTemplate( dialect, typeConfiguration, functionRegistry );
}
keyColumns.add( keyCols );
keyColumnReaders.add( keyColReaders );
@ -319,18 +310,18 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
hasDuplicateTables = new HashSet<>( tableNames ).size() == tableNames.size();
naturalOrderTableNames = toStringArray( tableNames );
naturalOrderTableKeyColumns = to2DStringArray( keyColumns );
String[][] naturalOrderTableKeyColumnReaders = to2DStringArray(keyColumnReaders);
String[][] naturalOrderTableKeyColumnReaderTemplates = to2DStringArray(keyColumnReaderTemplates);
final String[][] naturalOrderTableKeyColumnReaders = to2DStringArray( keyColumnReaders );
final String[][] naturalOrderTableKeyColumnReaderTemplates = to2DStringArray( keyColumnReaderTemplates );
naturalOrderCascadeDeleteEnabled = ArrayHelper.toBooleanArray( cascadeDeletes );
ArrayList<String> subclassTableNames = new ArrayList<>();
ArrayList<Boolean> isConcretes = new ArrayList<>();
// ArrayList<Boolean> isDeferreds = new ArrayList<>();
// ArrayList<Boolean> isLazies = new ArrayList<>();
ArrayList<Boolean> isInverses = new ArrayList<>();
ArrayList<Boolean> isNullables = new ArrayList<>();
final ArrayList<String> subclassTableNames = new ArrayList<>();
final ArrayList<Boolean> isConcretes = new ArrayList<>();
// final ArrayList<Boolean> isDeferreds = new ArrayList<>();
// final ArrayList<Boolean> isLazies = new ArrayList<>();
final ArrayList<Boolean> isInverses = new ArrayList<>();
final ArrayList<Boolean> isNullables = new ArrayList<>();
keyColumns = new ArrayList<>();
final ArrayList<String[]> allKeyColumns = new ArrayList<>();
for ( Table table : persistentClass.getSubclassTableClosure() ) {
isConcretes.add( persistentClass.isClassOrSuperclassTable( table ) );
// isDeferreds.add( false );
@ -339,36 +330,34 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
isNullables.add( false );
final String tableName = determineTableName( table );
subclassTableNames.add( tableName );
String[] key = new String[idColumnSpan];
List<Column> columns = table.getPrimaryKey().getColumnsInOriginalOrder();
final String[] key = new String[idColumnSpan];
final List<Column> columns = table.getPrimaryKey().getColumnsInOriginalOrder();
for ( int k = 0; k < idColumnSpan; k++ ) {
key[k] = columns.get(k).getQuotedName( dialect );
}
keyColumns.add( key );
allKeyColumns.add( key );
}
//Add joins
for ( Join join : persistentClass.getSubclassJoinClosure() ) {
final Table joinTable = join.getTable();
isConcretes.add( persistentClass.isClassOrSuperclassTable( joinTable ) );
// isDeferreds.add( join.isSequentialSelect() );
isInverses.add( join.isInverse() );
isNullables.add( join.isOptional() );
// isLazies.add( join.isLazy() );
String joinTableName = determineTableName( joinTable );
final String joinTableName = determineTableName( joinTable );
subclassTableNames.add( joinTableName );
String[] key = new String[idColumnSpan];
List<Column> columns = joinTable.getPrimaryKey().getColumnsInOriginalOrder();
final String[] key = new String[idColumnSpan];
final List<Column> columns = joinTable.getPrimaryKey().getColumnsInOriginalOrder();
for ( int k = 0; k < idColumnSpan; k++ ) {
key[k] = columns.get(k).getQuotedName( dialect );
}
keyColumns.add( key );
allKeyColumns.add( key );
}
String[] naturalOrderSubclassTableNameClosure = toStringArray( subclassTableNames );
String[][] naturalOrderSubclassTableKeyColumnClosure = to2DStringArray( keyColumns );
final String[] naturalOrderSubclassTableNameClosure = toStringArray( subclassTableNames );
final String[][] naturalOrderSubclassTableKeyColumnClosure = to2DStringArray( allKeyColumns );
isClassOrSuperclassTable = ArrayHelper.toBooleanArray( isConcretes );
// subclassTableSequentialSelect = ArrayHelper.toBooleanArray( isDeferreds );
// subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
@ -383,15 +372,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
constraintOrderedKeyColumnNames[currentPosition] = naturalOrderSubclassTableKeyColumnClosure[i];
}
/*
* Suppose an entity Client extends Person, mapped to the tableNames CLIENT and PERSON respectively.
* For the Client entity:
* naturalOrderTableNames -> PERSON, CLIENT; this reflects the sequence in which the tableNames are
* added to the meta-data when the annotated entities are processed.
* However, in some instances, for example when generating joins, the CLIENT table needs to be
* the first table as it will the driving table.
* tableNames -> CLIENT, PERSON
*/
// Suppose an entity Client extends Person, mapped to the tableNames CLIENT and PERSON respectively.
// For the Client entity:
// naturalOrderTableNames -> PERSON, CLIENT; this reflects the sequence in which the tableNames are
// added to the meta-data when the annotated entities are processed.
// However, in some instances, for example when generating joins, the CLIENT table needs to be
// the first table as it will the driving table.
// tableNames -> CLIENT, PERSON
this.tableNames = reverse( naturalOrderTableNames, coreTableSpan );
tableKeyColumns = reverse( naturalOrderTableKeyColumns, coreTableSpan );
@ -400,10 +387,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
subclassTableNameClosure = reverse( naturalOrderSubclassTableNameClosure, coreTableSpan );
subclassTableKeyColumnClosure = reverse( naturalOrderSubclassTableKeyColumnClosure, coreTableSpan );
spaces = ArrayHelper.join(
this.tableNames,
toStringArray( persistentClass.getSynchronizedTables() )
);
spaces = ArrayHelper.join( this.tableNames, toStringArray( persistentClass.getSynchronizedTables() ) );
// Custom sql
customSQLInsert = new String[tableSpan];
@ -417,38 +401,38 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
updateExpectations = new Expectation[tableSpan];
deleteExpectations = new Expectation[tableSpan];
PersistentClass pc = persistentClass;
PersistentClass currentClass = persistentClass;
int jk = coreTableSpan - 1;
while ( pc != null ) {
while ( currentClass != null ) {
isNullableTable[jk] = false;
isInverseTable[jk] = false;
customSQLInsert[jk] = pc.getCustomSQLInsert();
insertCallable[jk] = customSQLInsert[jk] != null && pc.isCustomInsertCallable();
customSQLInsert[jk] = currentClass.getCustomSQLInsert();
insertCallable[jk] = customSQLInsert[jk] != null && currentClass.isCustomInsertCallable();
insertExpectations[jk] = appropriateExpectation(
pc.getCustomSQLInsertCheckStyle() == null
currentClass.getCustomSQLInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[jk], insertCallable[jk] )
: pc.getCustomSQLInsertCheckStyle()
: currentClass.getCustomSQLInsertCheckStyle()
);
customSQLUpdate[jk] = pc.getCustomSQLUpdate();
updateCallable[jk] = customSQLUpdate[jk] != null && pc.isCustomUpdateCallable();
customSQLUpdate[jk] = currentClass.getCustomSQLUpdate();
updateCallable[jk] = customSQLUpdate[jk] != null && currentClass.isCustomUpdateCallable();
updateExpectations[jk] = appropriateExpectation(
pc.getCustomSQLUpdateCheckStyle() == null
currentClass.getCustomSQLUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] )
: pc.getCustomSQLUpdateCheckStyle()
: currentClass.getCustomSQLUpdateCheckStyle()
);
customSQLDelete[jk] = pc.getCustomSQLDelete();
deleteCallable[jk] = customSQLDelete[jk] != null && pc.isCustomDeleteCallable();
customSQLDelete[jk] = currentClass.getCustomSQLDelete();
deleteCallable[jk] = customSQLDelete[jk] != null && currentClass.isCustomDeleteCallable();
deleteExpectations[jk] = appropriateExpectation(
pc.getCustomSQLDeleteCheckStyle() == null
currentClass.getCustomSQLDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] )
: pc.getCustomSQLDeleteCheckStyle()
: currentClass.getCustomSQLDeleteCheckStyle()
);
jk--;
pc = pc.getSuperclass();
currentClass = currentClass.getSuperclass();
}
if ( jk != -1 ) {
@ -488,14 +472,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
// PROPERTIES
int hydrateSpan = getPropertySpan();
final int hydrateSpan = getPropertySpan();
naturalOrderPropertyTableNumbers = new int[hydrateSpan];
// propertyTableNumbers = new int[hydrateSpan];
List<Property> propertyClosure = persistentClass.getPropertyClosure();
final List<Property> propertyClosure = persistentClass.getPropertyClosure();
for ( int i = 0; i < propertyClosure.size(); i++ ) {
String tableName = propertyClosure.get(i).getValue().getTable().getQualifiedName(
factory.getSqlStringGenerationContext()
);
final String tableName =
propertyClosure.get(i).getValue().getTable()
.getQualifiedName( factory.getSqlStringGenerationContext() );
// propertyTableNumbers[i] = getTableId( tableName, this.tableNames );
naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames );
}
@ -504,16 +488,15 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
//TODO: code duplication with SingleTableEntityPersister
ArrayList<Integer> columnTableNumbers = new ArrayList<>();
// ArrayList<Integer> formulaTableNumbers = new ArrayList<>();
ArrayList<Integer> propTableNumbers = new ArrayList<>();
ArrayList<String> columns = new ArrayList<>();
final ArrayList<Integer> columnTableNumbers = new ArrayList<>();
// final ArrayList<Integer> formulaTableNumbers = new ArrayList<>();
final ArrayList<Integer> propTableNumbers = new ArrayList<>();
final ArrayList<String> columns = new ArrayList<>();
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
String tableName = property.getValue().getTable().getQualifiedName(
factory.getSqlStringGenerationContext()
);
Integer tableNumber = getTableId( tableName, subclassTableNameClosure );
final String tableName = property.getValue().getTable().
getQualifiedName( factory.getSqlStringGenerationContext() );
final Integer tableNumber = getTableId( tableName, subclassTableNameClosure );
propTableNumbers.add( tableNumber );
for ( Selectable selectable : property.getSelectables() ) {
@ -535,9 +518,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// SUBCLASSES
int subclassSpan = persistentClass.getSubclassSpan() + 1;
final int subclassSpan = persistentClass.getSubclassSpan() + 1;
// subclassClosure = new String[subclassSpan];
int subclassSpanMinusOne = subclassSpan - 1;
final int subclassSpanMinusOne = subclassSpan - 1;
// subclassClosure[subclassSpanMinusOne] = getEntityName();
if ( !persistentClass.isPolymorphic() ) {
subclassNameByTableName = emptyMap();
@ -555,7 +538,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
discriminatorColumnNameByTableName = linkedMapOfSize( subclassSpan + 1 );
subclassNameByTableName = mapOfSize( subclassSpan + 1 );
Table table = persistentClass.getTable();
final Table table = persistentClass.getTable();
discriminatorValues = new String[subclassSpan];
discriminatorAbstract = new boolean[subclassSpan];
initDiscriminatorProperties( dialect, subclassSpanMinusOne, table, discriminatorValue, isAbstract( persistentClass) );
@ -567,11 +550,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
);
notNullColumnTableNumbers[subclassSpanMinusOne] = id;
notNullColumnNames = new String[subclassSpan];
notNullColumnNames[subclassSpanMinusOne] = subclassTableKeyColumnClosure[id][0]; //( (Column) model.getTable().getPrimaryKey().getColumnIterator().next() ).getName();
notNullColumnNames[subclassSpanMinusOne] = subclassTableKeyColumnClosure[id][0];
List<Subclass> subclasses = persistentClass.getSubclasses();
final List<Subclass> subclasses = persistentClass.getSubclasses();
for ( int k = 0; k < subclasses.size(); k++ ) {
Subclass subclass = subclasses.get(k);
final Subclass subclass = subclasses.get(k);
// subclassClosure[k] = subclass.getEntityName();
final Table subclassTable = subclass.getTable();
subclassNameByTableName.put( subclassTable.getName(), subclass.getEntityName() );
@ -584,12 +567,12 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
: subclass.getSubclassId();
initDiscriminatorProperties( dialect, k, subclassTable, discriminatorValue, isAbstract( subclass ) );
subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() );
int tableId = getTableId(
final int tableId = getTableId(
subclassTable.getQualifiedName( factory.getSqlStringGenerationContext() ),
subclassTableNameClosure
);
notNullColumnTableNumbers[k] = tableId;
notNullColumnNames[k] = subclassTableKeyColumnClosure[tableId][0]; //( (Column) sc.getTable().getPrimaryKey().getColumnIterator().next() ).getName();
notNullColumnNames[k] = subclassTableKeyColumnClosure[tableId][0];
}
}
}
@ -1208,7 +1191,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
scale = null;
}
else {
Column column = bootEntityDescriptor.getIdentifier().getColumns().get( 0 );
final Column column = bootEntityDescriptor.getIdentifier().getColumns().get( 0 );
columnDefinition = column.getSqlType();
length = column.getLength();
precision = column.getPrecision();
@ -1280,7 +1263,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
PersistentClass bootEntityDescriptor) {
assert declaredAttributeMappings != null;
return MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping(
return buildNonEncapsulatedCompositeIdentifierMapping(
this,
getTableName(),
tableKeyColumns[0],
@ -1302,10 +1285,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
@Override
public TableDetails getIdentifierTableDetails() {
final EntityMappingType superMappingType = getSuperMappingType();
if ( superMappingType == null ) {
return getMappedTableDetails();
}
return getRootEntityDescriptor().getIdentifierTableDetails();
return superMappingType == null
? getMappedTableDetails()
: getRootEntityDescriptor().getIdentifierTableDetails();
}
@Override
@ -1319,8 +1301,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
navigablePath,
this,
tableGroup,
resultVariable,
creationState
resultVariable
);
entityResultJoinedSubclass.afterInitialize( entityResultJoinedSubclass, creationState );
//noinspection unchecked
@ -1338,14 +1319,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
final MappingMetamodelImplementor metamodel = getFactory().getRuntimeMetamodels().getMappingMetamodel();
for ( String treatedEntityName : treatedEntityNames ) {
final JoinedSubclassEntityPersister subPersister =
final JoinedSubclassEntityPersister persister =
(JoinedSubclassEntityPersister) metamodel.findEntityDescriptor( treatedEntityName );
final String[] subclassTableNames = subPersister.getSubclassTableNames();
final String[] subclassTableNames = persister.getSubclassTableNames();
// For every treated entity name, we collect table names that are needed by all treated entity names
// In mathematical terms, sharedSuperclassTables will be the "intersection" of the table names of all treated entities
if ( sharedSuperclassTables.isEmpty() ) {
for ( int i = 0; i < subclassTableNames.length; i++ ) {
if ( subPersister.isClassOrSuperclassTable[i] ) {
if ( persister.isClassOrSuperclassTable[i] ) {
sharedSuperclassTables.add( subclassTableNames[i] );
}
}
@ -1357,7 +1338,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// Table references not appearing in this set can later be pruned away
// todo (6.0): no need to resolve all table references, only the ones needed for cardinality
for ( String subclassTableName : subclassTableNames ) {
retainedTableReferences.add(tableGroup.resolveTableReference(null, subclassTableName, false));
final TableReference tableReference =
tableGroup.resolveTableReference( null, subclassTableName, false );
retainedTableReferences.add( tableReference );
}
}
final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();
@ -1373,21 +1356,16 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
for ( TableReferenceJoin oldJoin : oldJoins ) {
final NamedTableReference joinedTableReference = oldJoin.getJoinedTableReference();
if ( retainedTableReferences.contains( joinedTableReference ) ) {
if ( oldJoin.getJoinType() != SqlAstJoinType.INNER
&& sharedSuperclassTables.contains( joinedTableReference.getTableExpression() ) ) {
tableReferenceJoins.add(
new TableReferenceJoin( true, joinedTableReference, oldJoin.getPredicate() )
);
}
else {
tableReferenceJoins.add( oldJoin );
}
final TableReferenceJoin join = oldJoin.getJoinType() != SqlAstJoinType.INNER
&& sharedSuperclassTables.contains( joinedTableReference.getTableExpression() )
? new TableReferenceJoin(true, joinedTableReference, oldJoin.getPredicate())
: oldJoin;
tableReferenceJoins.add( join );
}
}
}
else {
tableReferenceJoins
.removeIf( join -> !retainedTableReferences.contains( join.getJoinedTableReference() ) );
tableReferenceJoins.removeIf( join -> !retainedTableReferences.contains( join.getJoinedTableReference() ) );
}
}

View File

@ -46,6 +46,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;
import static org.hibernate.internal.util.collections.ArrayHelper.to2DStringArray;
import static org.hibernate.internal.util.collections.ArrayHelper.toBooleanArray;
@ -74,7 +75,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final int joinSpan;
private final boolean hasDuplicateTables;
/**
* todo (6.2) - this assumes duplicates are included which we are trying to do away wi
*/
@ -145,6 +145,8 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
final Dialect dialect = factory.getJdbcServices().getDialect();
final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
final TypeConfiguration typeConfiguration = factory.getTypeConfiguration();
// CLASS + TABLE
@ -203,7 +205,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
// JOINS
List<Join> joinClosure = persistentClass.getJoinClosure();
final List<Join> joinClosure = persistentClass.getJoinClosure();
boolean hasDuplicateTableName = false;
for ( int j = 1; j - 1 < joinClosure.size(); j++ ) {
Join join = joinClosure.get( j - 1 );
@ -240,7 +242,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
keyColumnNames[j] = new String[join.getKey().getColumnSpan()];
List<Column> columns = join.getKey().getColumns();
final List<Column> columns = join.getKey().getColumns();
for ( int i = 0; i < columns.size(); i++ ) {
keyColumnNames[j][i] = columns.get( i ).getQuotedName( dialect );
}
@ -254,21 +256,18 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
constraintOrderedKeyColumnNames[position] = keyColumnNames[i];
}
spaces = ArrayHelper.join(
qualifiedTableNames,
toStringArray( persistentClass.getSynchronizedTables() )
);
spaces = ArrayHelper.join( qualifiedTableNames, toStringArray( persistentClass.getSynchronizedTables() ) );
// final boolean lazyAvailable = isInstrumented();
ArrayList<String> subclassTables = new ArrayList<>();
ArrayList<String[]> joinKeyColumns = new ArrayList<>();
ArrayList<Boolean> isConcretes = new ArrayList<>();
ArrayList<Boolean> isClassOrSuperclassJoins = new ArrayList<>();
// ArrayList<Boolean> isDeferreds = new ArrayList<>();
ArrayList<Boolean> isInverses = new ArrayList<>();
ArrayList<Boolean> isNullables = new ArrayList<>();
// ArrayList<Boolean> isLazies = new ArrayList<>();
final ArrayList<String> subclassTables = new ArrayList<>();
final ArrayList<String[]> joinKeyColumns = new ArrayList<>();
final ArrayList<Boolean> isConcretes = new ArrayList<>();
final ArrayList<Boolean> isClassOrSuperclassJoins = new ArrayList<>();
// final ArrayList<Boolean> isDeferreds = new ArrayList<>();
final ArrayList<Boolean> isInverses = new ArrayList<>();
final ArrayList<Boolean> isNullables = new ArrayList<>();
// final ArrayList<Boolean> isLazies = new ArrayList<>();
subclassTables.add( qualifiedTableNames[0] );
joinKeyColumns.add( getIdentifierColumnNames() );
isConcretes.add( true );
@ -291,7 +290,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
subclassTables.add( joinTableName );
final String[] keyCols = new String[join.getKey().getColumnSpan()];
List<Column> columns = join.getKey().getColumns();
final List<Column> columns = join.getKey().getColumns();
for ( int i = 0; i < columns.size(); i++ ) {
keyCols[i] = columns.get( i ).getQuotedName( dialect );
}
@ -316,19 +315,14 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
forceDiscriminator = persistentClass.isForceDiscriminator();
final Selectable selectable = discriminator.getSelectables().get( 0 );
SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
discriminatorType = DiscriminatorHelper.getDiscriminatorType( persistentClass );
discriminatorValue = DiscriminatorHelper.getDiscriminatorValue( persistentClass );
discriminatorSQLValue = DiscriminatorHelper.getDiscriminatorSQLValue( persistentClass, dialect );
discriminatorInsertable = isDiscriminatorInsertable( persistentClass );
if ( discriminator.hasFormula() ) {
Formula formula = (Formula) selectable;
final Formula formula = (Formula) selectable;
// discriminatorFormula = formula.getFormula();
discriminatorFormulaTemplate = formula.getTemplate(
dialect,
factory.getTypeConfiguration(),
functionRegistry
);
discriminatorFormulaTemplate = formula.getTemplate( dialect, typeConfiguration, functionRegistry );
discriminatorColumnName = null;
discriminatorColumnReaders = null;
discriminatorColumnReaderTemplate = null;
@ -338,11 +332,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
final Column column = (Column) selectable;
discriminatorColumnName = column.getQuotedName( dialect );
discriminatorColumnReaders = column.getReadExpr( dialect );
discriminatorColumnReaderTemplate = column.getTemplate(
dialect,
factory.getTypeConfiguration(),
functionRegistry
);
discriminatorColumnReaderTemplate = column.getTemplate( dialect, typeConfiguration, functionRegistry );
discriminatorAlias = column.getAlias( dialect, persistentClass.getRootTable() );
// discriminatorFormula = null;
discriminatorFormulaTemplate = null;
@ -372,21 +362,20 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
//TODO: code duplication with JoinedSubclassEntityPersister
// ArrayList<Integer> columnJoinNumbers = new ArrayList<>();
// ArrayList<Integer> formulaJoinedNumbers = new ArrayList<>();
ArrayList<Integer> propertyJoinNumbers = new ArrayList<>();
// final ArrayList<Integer> columnJoinNumbers = new ArrayList<>();
// final ArrayList<Integer> formulaJoinedNumbers = new ArrayList<>();
final ArrayList<Integer> propertyJoinNumbers = new ArrayList<>();
// final HashMap<String, Integer> propertyTableNumbersByNameAndSubclassLocal = new HashMap<>();
final Map<Object, String> subclassesByDiscriminatorValueLocal = new HashMap<>();
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
Integer join = persistentClass.getJoinNumber( property );
propertyJoinNumbers.add( join );
propertyJoinNumbers.add( persistentClass.getJoinNumber( property ) );
}
subclassPropertyTableNumberClosure = toIntArray( propertyJoinNumbers );
int subclassSpan = persistentClass.getSubclassSpan() + 1;
final int subclassSpan = persistentClass.getSubclassSpan() + 1;
subclassClosure = new String[subclassSpan];
subclassClosure[0] = getEntityName();
if ( persistentClass.isPolymorphic() ) {

View File

@ -35,7 +35,6 @@ import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.JoinedList;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jdbc.Expectations;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Subclass;
@ -63,6 +62,10 @@ import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.type.BasicType;
import org.hibernate.type.StandardBasicTypes;
import static org.hibernate.internal.util.collections.ArrayHelper.to2DStringArray;
import static org.hibernate.internal.util.collections.ArrayHelper.toStringArray;
import static org.hibernate.jdbc.Expectations.appropriateExpectation;
/**
* An {@link EntityPersister} implementing the
* {@link jakarta.persistence.InheritanceType#TABLE_PER_CLASS}
@ -133,7 +136,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
: persistentClass.getCustomSQLInsertCheckStyle();
customSQLInsert = new String[] {sql};
insertCallable = new boolean[] {callable};
insertExpectations = new Expectation[] { Expectations.appropriateExpectation( checkStyle ) };
insertExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };
sql = persistentClass.getCustomSQLUpdate();
callable = sql != null && persistentClass.isCustomUpdateCallable();
@ -144,7 +147,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
: persistentClass.getCustomSQLUpdateCheckStyle();
customSQLUpdate = new String[] {sql};
updateCallable = new boolean[] {callable};
updateExpectations = new Expectation[] { Expectations.appropriateExpectation( checkStyle ) };
updateExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };
sql = persistentClass.getCustomSQLDelete();
callable = sql != null && persistentClass.isCustomDeleteCallable();
@ -155,21 +158,16 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
: persistentClass.getCustomSQLDeleteCheckStyle();
customSQLDelete = new String[] {sql};
deleteCallable = new boolean[] {callable};
deleteExpectations = new Expectation[] { Expectations.appropriateExpectation( checkStyle ) };
deleteExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };
discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
discriminatorType = factory.getTypeConfiguration()
.getBasicTypeRegistry()
.resolve( StandardBasicTypes.INTEGER );
discriminatorType = factory.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER );
// PROPERTIES
// SUBCLASSES
subclassByDiscriminatorValue.put(
persistentClass.getSubclassId(),
persistentClass.getEntityName()
);
subclassByDiscriminatorValue.put( persistentClass.getSubclassId(), persistentClass.getEntityName() );
if ( persistentClass.isPolymorphic() ) {
for ( Subclass subclass : persistentClass.getSubclasses() ) {
subclassByDiscriminatorValue.put( subclass.getSubclassId(), subclass.getEntityName() );
@ -192,7 +190,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
for ( Table table : persistentClass.getSubclassTableClosure() ) {
subclassTables.add( determineTableName( table ) );
}
subclassSpaces = ArrayHelper.toStringArray( subclassTables );
subclassSpaces = toStringArray( subclassTables );
subquery = generateSubquery( persistentClass, creationContext.getMetadata() );
final List<String> tableExpressions = new ArrayList<>( subclassSpaces.length * 2 );
@ -208,17 +206,17 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
tableExpressions.add( generateSubquery( subPersistentClass, creationContext.getMetadata() ) );
}
}
subclassTableExpressions = ArrayHelper.toStringArray( tableExpressions );
subclassTableExpressions = toStringArray( tableExpressions );
if ( hasMultipleTables() ) {
int idColumnSpan = getIdentifierColumnSpan();
ArrayList<String> tableNames = new ArrayList<>();
ArrayList<String[]> keyColumns = new ArrayList<>();
final int idColumnSpan = getIdentifierColumnSpan();
final ArrayList<String> tableNames = new ArrayList<>();
final ArrayList<String[]> keyColumns = new ArrayList<>();
for ( Table table : persistentClass.getSubclassTableClosure() ) {
if ( !table.isAbstractUnionTable() ) {
tableNames.add( determineTableName( table ) );
String[] key = new String[idColumnSpan];
List<Column> columns = table.getPrimaryKey().getColumnsInOriginalOrder();
final String[] key = new String[idColumnSpan];
final List<Column> columns = table.getPrimaryKey().getColumnsInOriginalOrder();
for ( int k = 0; k < idColumnSpan; k++ ) {
key[k] = columns.get(k).getQuotedName( dialect );
}
@ -226,8 +224,8 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
}
}
constraintOrderedTableNames = ArrayHelper.toStringArray( tableNames );
constraintOrderedKeyColumnNames = ArrayHelper.to2DStringArray( keyColumns );
constraintOrderedTableNames = toStringArray( tableNames );
constraintOrderedKeyColumnNames = to2DStringArray( keyColumns );
}
else {
constraintOrderedTableNames = new String[] { tableName };
@ -428,7 +426,6 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
for ( int i = 0; i < constraintOrderedTableNames.length; i++ ) {
final String tableName = constraintOrderedTableNames[i];
final int tablePosition = i;
consumer.consume(
tableName,
() -> columnConsumer -> columnConsumer.accept( tableName, constraintOrderedKeyColumnNames[tablePosition] )
@ -441,7 +438,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
consumer.consume(
tableName,
0,
() -> (columnConsumer) -> columnConsumer.accept( tableName, getIdentifierMapping(), getIdentifierColumnNames() )
() -> columnConsumer -> columnConsumer.accept( tableName, getIdentifierMapping(), getIdentifierColumnNames() )
);
}

View File

@ -47,8 +47,7 @@ public class EntityFetchJoinedImpl extends AbstractNonLazyEntityFetch {
navigablePath,
toOneMapping,
tableGroup,
null,
creationState
null
);
this.entityResult.afterInitialize( this, creationState );
@ -69,8 +68,7 @@ public class EntityFetchJoinedImpl extends AbstractNonLazyEntityFetch {
navigablePath,
collectionPart,
tableGroup,
null,
creationState
null
);
this.entityResult.afterInitialize( this, creationState );

View File

@ -7,7 +7,6 @@
package org.hibernate.sql.results.graph.entity.internal;
import org.hibernate.LockMode;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.tree.from.TableGroup;
@ -15,13 +14,11 @@ import org.hibernate.sql.ast.tree.from.TableGroupJoin;
import org.hibernate.sql.ast.tree.from.TableGroupProducer;
import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.Initializer;
import org.hibernate.sql.results.graph.entity.AbstractEntityResultGraphNode;
import org.hibernate.sql.results.graph.entity.EntityInitializer;
import org.hibernate.sql.results.graph.entity.EntityResult;
/**
@ -38,18 +35,7 @@ public class EntityResultImpl extends AbstractEntityResultGraphNode implements E
NavigablePath navigablePath,
EntityValuedModelPart entityValuedModelPart,
TableGroup tableGroup,
String resultVariable,
DomainResultCreationState creationState) {
this( navigablePath, entityValuedModelPart, tableGroup, resultVariable, null, creationState );
}
public EntityResultImpl(
NavigablePath navigablePath,
EntityValuedModelPart entityValuedModelPart,
TableGroup tableGroup,
String resultVariable,
EntityMappingType targetType,
DomainResultCreationState creationState) {
String resultVariable) {
super( entityValuedModelPart, navigablePath );
this.tableGroup = tableGroup;
this.resultVariable = resultVariable;

View File

@ -11,22 +11,20 @@ import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.sql.results.graph.Initializer;
import org.hibernate.sql.results.graph.entity.EntityInitializer;
/**
* @author Andrea Boriero
*/
public class EntityResultJoinedSubclassImpl extends EntityResultImpl {
public EntityResultJoinedSubclassImpl(
NavigablePath navigablePath,
EntityValuedModelPart entityValuedModelPart,
TableGroup tableGroup,
String resultVariable,
DomainResultCreationState creationState) {
super( navigablePath, entityValuedModelPart, tableGroup, resultVariable, creationState );
String resultVariable) {
super( navigablePath, entityValuedModelPart, tableGroup, resultVariable );
}
@Override

View File

@ -16,7 +16,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.hibernate.MappingException;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.SQLDelete;
@ -392,20 +391,11 @@ public class DefaultCatalogAndSchemaTest {
verifyOnlyQualifier( insertSqls, SqlType.RUNTIME, jpaEntityName, expectedQualifier );
try {
verifyOnlyQualifierOptional( persister.getIdentitySelectString(), SqlType.RUNTIME,
jpaEntityName, expectedQualifier );
}
catch (MappingException e) {
if ( e.getMessage().contains( "does not support identity key generation" ) ) {
// For some reason Oracle12cIdentityColumnSupport#supportsInsertSelectIdentity() returns true,
// but getIdentitySelectString is not implemented, resulting in runtime exceptions.
// Whatever, we'll just ignore this for now.
}
else {
throw e;
}
String identitySelectString = persister.getIdentitySelectString();
if ( identitySelectString != null ) {
verifyOnlyQualifierOptional( identitySelectString, SqlType.RUNTIME, jpaEntityName, expectedQualifier );
}
final MutationOperationGroup staticSqlUpdateGroup = persister.getUpdateCoordinator().getStaticUpdateGroup();
final String[] sqlUpdateStrings = new String[staticSqlUpdateGroup.getNumberOfOperations()];
staticSqlUpdateGroup.forEachOperation( (tablePosition, operation) -> {