Skip to content

Commit f03d67b

Browse files
committed
eliminate casts to AbstractEntityPersister
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 530d913 commit f03d67b

36 files changed

+543
-270
lines changed

hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private void addCollectionKey(
212212
final CollectionPersister collectionPersister = pluralAttributeMapping.getCollectionDescriptor();
213213
final CollectionKey collectionKey = new CollectionKey(
214214
collectionPersister,
215-
( (AbstractEntityPersister) getPersister() ).getCollectionKey(
215+
AbstractEntityPersister.getCollectionKey(
216216
collectionPersister,
217217
getInstance(),
218218
persistenceContext.getEntry( getInstance() ),

hibernate-core/src/main/java/org/hibernate/event/internal/WrapVisitor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ else if ( attributeInterceptor != null
115115
&& ((LazyAttributeLoadingInterceptor)attributeInterceptor).isAttributeLoaded( persister.getAttributeMapping().getAttributeName() ) ) {
116116
final EntityEntry entry = persistenceContext.getEntry( entity );
117117
if ( entry.isExistsInDatabase() ) {
118-
final AbstractEntityPersister entityDescriptor =
119-
(AbstractEntityPersister) persister.getOwnerEntityPersister();
120-
final Object key = entityDescriptor.getCollectionKey(
118+
final Object key = AbstractEntityPersister.getCollectionKey(
121119
persister,
122120
entity,
123121
entry,

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.hibernate.metamodel.mapping.VirtualModelPart;
6060
import org.hibernate.metamodel.model.domain.NavigableRole;
6161
import org.hibernate.persister.collection.AbstractCollectionPersister;
62-
import org.hibernate.persister.entity.AbstractEntityPersister;
6362
import org.hibernate.persister.entity.EntityNameUse;
6463
import org.hibernate.persister.entity.EntityPersister;
6564
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
@@ -358,12 +357,11 @@ && equal( join.getKey(), manyToOne ) ) {
358357
isKeyTableNullable = !persister.getTableName().equals( targetTableName );
359358
}
360359
else {
361-
final AbstractEntityPersister persister = (AbstractEntityPersister) declaringEntityPersister;
362360
final int tableIndex = ArrayHelper.indexOf(
363-
persister.getTableNames(),
361+
declaringEntityPersister.getTableNames(),
364362
targetTableName
365363
);
366-
isKeyTableNullable = persister.isNullableTable( tableIndex );
364+
isKeyTableNullable = declaringEntityPersister.isNullableTable( tableIndex );
367365
}
368366
}
369367
isOptional = ( (ManyToOne) bootValue ).isIgnoreNotFound();
@@ -723,8 +721,8 @@ private static boolean equal(Value lhsValue, Value rhsValue) {
723721
}
724722

725723
static String findMapsIdPropertyName(EntityMappingType entityMappingType, String referencedPropertyName) {
726-
final AbstractEntityPersister persister = (AbstractEntityPersister) entityMappingType.getEntityPersister();
727-
if ( Arrays.equals( persister.getKeyColumnNames(), persister.getPropertyColumnNames( referencedPropertyName ) ) ) {
724+
final EntityPersister persister = entityMappingType.getEntityPersister();
725+
if ( Arrays.equals( persister.getIdentifierColumnNames(), persister.getPropertyColumnNames( referencedPropertyName ) ) ) {
728726
return persister.getIdentifierPropertyName();
729727
}
730728
return null;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.hibernate.metamodel.mapping.ModelPartContainer;
1212
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
1313
import org.hibernate.metamodel.mapping.ordering.TranslationContext;
14-
import org.hibernate.persister.entity.AbstractEntityPersister;
14+
import org.hibernate.persister.entity.EntityPersister;
1515
import org.hibernate.query.NullPrecedence;
1616
import org.hibernate.query.SortDirection;
1717
import org.hibernate.sql.ast.spi.SqlAstCreationState;
@@ -119,11 +119,9 @@ TableReference getTableReference(TableGroup tableGroup) {
119119

120120
final MappingType elementMappingType = pluralAttribute.getElementDescriptor().getPartMappingType();
121121

122-
if ( elementMappingType instanceof AbstractEntityPersister ) {
123-
final AbstractEntityPersister abstractEntityPersister = (AbstractEntityPersister) elementMappingType;
124-
final int tableNumber = abstractEntityPersister.determineTableNumberForColumn( columnExpression );
125-
final String tableName = abstractEntityPersister.getTableName( tableNumber );
126-
122+
if ( elementMappingType instanceof EntityPersister) {
123+
final EntityPersister entityPersister = (EntityPersister) elementMappingType;
124+
final String tableName = entityPersister.getTableNameForColumn( columnExpression );
127125
return tableGroup.getTableReference( tableGroup.getNavigablePath(), tableName );
128126
}
129127
else {

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 24 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@
250250
import org.hibernate.sql.ast.tree.from.TableGroup;
251251
import org.hibernate.sql.ast.tree.from.TableReference;
252252
import org.hibernate.sql.ast.tree.from.TableReferenceJoin;
253-
import org.hibernate.sql.ast.tree.insert.InsertSelectStatement;
254253
import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
255254
import org.hibernate.sql.ast.tree.predicate.InListPredicate;
256255
import org.hibernate.sql.ast.tree.predicate.Junction;
@@ -511,7 +510,7 @@ public AbstractEntityPersister(
511510
assert javaType != null;
512511
this.implementsLifecycle = Lifecycle.class.isAssignableFrom( javaType.getJavaTypeClass() );
513512

514-
concreteProxy = isPolymorphic()
513+
concreteProxy = entityMetamodel.isPolymorphic()
515514
&& ( getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() || hasProxy() )
516515
&& persistentClass.isConcreteProxy();
517516

@@ -924,8 +923,6 @@ private boolean shouldStoreDiscriminatorInShallowQueryCacheLayout(CacheLayout en
924923
return queryCacheLayout == CacheLayout.SHALLOW_WITH_DISCRIMINATOR;
925924
}
926925

927-
public abstract String getSubclassTableName(int j);
928-
929926
protected abstract String[] getSubclassTableNames();
930927

931928
protected abstract String[] getSubclassTableKeyColumns(int j);
@@ -948,37 +945,12 @@ protected boolean isClassOrSuperclassJoin(int j) {
948945
return isClassOrSuperclassTable( j );
949946
}
950947

951-
public abstract int getSubclassTableSpan();
952-
953-
public abstract int getTableSpan();
954-
955-
public abstract boolean hasDuplicateTables();
956-
957-
/**
958-
* @deprecated Only ever used from places where we really want to use<ul>
959-
* <li>{@link SelectStatement} (select generator)</li>
960-
* <li>{@link InsertSelectStatement}</li>
961-
* <li>{@link org.hibernate.sql.ast.tree.update.UpdateStatement}</li>
962-
* <li>{@link org.hibernate.sql.ast.tree.delete.DeleteStatement}</li>
963-
* </ul>
964-
*/
965-
@Deprecated( since = "6.2" )
966-
public abstract String getTableName(int j);
967-
968-
public abstract String[] getKeyColumns(int j);
969-
970948
public abstract boolean isPropertyOfTable(int property, int j);
971949

972950
protected abstract int[] getPropertyTableNumbers();
973951

974952
private static final String DISCRIMINATOR_ALIAS = "clazz_";
975953

976-
/**
977-
* The name of the table to use when performing mutations (INSERT,UPDATE,DELETE)
978-
* for the given attribute
979-
*/
980-
public abstract String getAttributeMutationTableName(int i);
981-
982954
@Override
983955
public String getDiscriminatorColumnName() {
984956
return DISCRIMINATOR_ALIAS;
@@ -998,10 +970,12 @@ public String getDiscriminatorFormulaTemplate() {
998970
return null;
999971
}
1000972

973+
@Override
1001974
public boolean isInverseTable(int j) {
1002975
return false;
1003976
}
1004977

978+
@Override
1005979
public boolean isNullableTable(int j) {
1006980
return false;
1007981
}
@@ -1015,6 +989,7 @@ public boolean isSubclassEntityName(String entityName) {
1015989
return entityMetamodel.getSubclassEntityNames().contains( entityName );
1016990
}
1017991

992+
@Override
1018993
public boolean isSharedColumn(String columnExpression) {
1019994
return sharedColumnNames.contains( columnExpression );
1020995
}
@@ -1069,6 +1044,7 @@ public boolean hasRowId() {
10691044
return rowIdName != null;
10701045
}
10711046

1047+
@Override
10721048
public String[] getTableNames() {
10731049
final String[] tableNames = new String[getTableSpan()];
10741050
for ( int i = 0; i < tableNames.length; i++ ) {
@@ -1373,7 +1349,7 @@ protected TableReferenceJoin generateTableReferenceJoin(
13731349
generateJoinPredicate(
13741350
lhs,
13751351
joinedTableReference,
1376-
getKeyColumnNames(),
1352+
getIdentifierColumnNames(),
13771353
targetColumns,
13781354
creationState
13791355
)
@@ -1524,7 +1500,7 @@ public Object initializeLazyProperty(String fieldName, Object entity, SharedSess
15241500

15251501
}
15261502

1527-
public Object getCollectionKey(
1503+
public static Object getCollectionKey(
15281504
CollectionPersister persister,
15291505
Object owner,
15301506
EntityEntry ownerEntry,
@@ -2244,20 +2220,20 @@ public boolean hasFormulaProperties() {
22442220
return hasFormulaProperties;
22452221
}
22462222

2247-
@Override
22482223
public FetchMode getFetchMode(int i) {
22492224
return subclassPropertyFetchModeClosure[i];
22502225
}
22512226

2252-
@Override
22532227
public Type getSubclassPropertyType(int i) {
22542228
return subclassPropertyTypeClosure[i];
22552229
}
22562230

2231+
@Override
22572232
public int countSubclassProperties() {
22582233
return subclassPropertyTypeClosure.length;
22592234
}
22602235

2236+
@Override
22612237
public String[] getSubclassPropertyColumnNames(int i) {
22622238
return subclassPropertyColumnNameClosure[i];
22632239
}
@@ -2607,17 +2583,6 @@ public String getSelectByUniqueKeyString(String[] propertyNames, String[] column
26072583
return select.toStatementString();
26082584
}
26092585

2610-
@Internal
2611-
public boolean hasLazyDirtyFields(int[] dirtyFields) {
2612-
final boolean[] propertyLaziness = getPropertyLaziness();
2613-
for ( int i = 0; i < dirtyFields.length; i++ ) {
2614-
if ( propertyLaziness[dirtyFields[i]] ) {
2615-
return true;
2616-
}
2617-
}
2618-
return false;
2619-
}
2620-
26212586
@Override
26222587
public GeneratedValuesMutationDelegate getInsertDelegate() {
26232588
return insertDelegate;
@@ -2628,34 +2593,25 @@ public GeneratedValuesMutationDelegate getUpdateDelegate() {
26282593
return updateDelegate;
26292594
}
26302595

2631-
protected EntityTableMapping[] getTableMappings() {
2596+
@Override
2597+
public EntityTableMapping[] getTableMappings() {
26322598
return tableMappings;
26332599
}
26342600

2635-
public EntityTableMapping getTableMapping(int i) {
2601+
protected EntityTableMapping getTableMapping(int i) {
26362602
return tableMappings[i];
26372603
}
26382604

26392605
/**
26402606
* Unfortunately we cannot directly use `SelectableMapping#getContainingTableExpression()`
26412607
* as that blows up for attributes declared on super-type for union-subclass mappings
26422608
*/
2609+
@Override
26432610
public String physicalTableNameForMutation(SelectableMapping selectableMapping) {
26442611
assert !selectableMapping.isFormula();
26452612
return selectableMapping.getContainingTableExpression();
26462613
}
26472614

2648-
public EntityTableMapping getPhysicalTableMappingForMutation(SelectableMapping selectableMapping) {
2649-
final String tableNameForMutation = physicalTableNameForMutation( selectableMapping );
2650-
for ( int i = 0; i < tableMappings.length; i++ ) {
2651-
if ( tableNameForMutation.equals( tableMappings[i].getTableName() ) ) {
2652-
return tableMappings[i];
2653-
}
2654-
}
2655-
2656-
throw new IllegalArgumentException( "Unable to resolve TableMapping for selectable - " + selectableMapping );
2657-
}
2658-
26592615
@Override
26602616
public EntityMappingType getTargetPart() {
26612617
return this;
@@ -2823,7 +2779,7 @@ public TableGroup createRootTableGroup(
28232779
joinedTableReference,
28242780
needsDiscriminator()
28252781
? getRootTableKeyColumnNames()
2826-
: getKeyColumnNames(),
2782+
: getIdentifierColumnNames(),
28272783
getSubclassTableKeyColumns( i ),
28282784
creationState
28292785
)
@@ -3200,8 +3156,6 @@ protected GeneratedValuesMutationDelegate createUpdateDelegate() {
32003156
return GeneratedValuesHelper.getGeneratedValuesDelegate( this, UPDATE );
32013157
}
32023158

3203-
public abstract String[][] getContraintOrderedTableKeyColumnClosure();
3204-
32053159
private static class TableMappingBuilder {
32063160
private final String tableName;
32073161
private final int relativePosition;
@@ -3436,9 +3390,11 @@ protected DeleteCoordinator buildDeleteCoordinator() {
34363390
}
34373391
}
34383392

3393+
@Override
34393394
public void addDiscriminatorToInsertGroup(MutationGroupBuilder insertGroupBuilder) {
34403395
}
34413396

3397+
@Override
34423398
public void addSoftDeleteToInsertGroup(MutationGroupBuilder insertGroupBuilder) {
34433399
if ( softDeleteMapping != null ) {
34443400
final TableInsertBuilder insertBuilder = insertGroupBuilder.getTableDetailsBuilder( getIdentifierTableName() );
@@ -3755,10 +3711,6 @@ public final String getEntityName() {
37553711
return entityMetamodel.getName();
37563712
}
37573713

3758-
public boolean isPolymorphic() {
3759-
return entityMetamodel.isPolymorphic();
3760-
}
3761-
37623714
@Override
37633715
public boolean isInherited() {
37643716
return entityMetamodel.isInherited();
@@ -3997,10 +3949,6 @@ public EntityMappingType resolveConcreteProxyTypeForId(Object id, SharedSessionC
39973949
return concreteTypeLoader.getConcreteType( id, session );
39983950
}
39993951

4000-
public String[] getKeyColumnNames() {
4001-
return getIdentifierColumnNames();
4002-
}
4003-
40043952
/**
40053953
* {@inheritDoc}
40063954
*
@@ -4119,6 +4067,7 @@ public boolean[] getPropertyCheckability() {
41194067
return entityMetamodel.getPropertyCheckability();
41204068
}
41214069

4070+
@Override
41224071
public boolean[] getNonLazyPropertyUpdateability() {
41234072
return entityMetamodel.getNonlazyPropertyUpdateability();
41244073
}
@@ -4366,6 +4315,7 @@ && hasSubclasses()
43664315
return this;
43674316
}
43684317

4318+
@Override
43694319
public boolean hasMultipleTables() {
43704320
return false;
43714321
}
@@ -4589,7 +4539,12 @@ public BytecodeEnhancementMetadata getBytecodeEnhancementMetadata() {
45894539
return entityMetamodel.getBytecodeEnhancementMetadata();
45904540
}
45914541

4592-
public int determineTableNumberForColumn(String columnName) {
4542+
@Override
4543+
public String getTableNameForColumn(String columnName) {
4544+
return getTableName( determineTableNumberForColumn( columnName ) );
4545+
}
4546+
4547+
protected int determineTableNumberForColumn(String columnName) {
45934548
return 0;
45944549
}
45954550

0 commit comments

Comments
 (0)