Skip to content

Commit 510fe81

Browse files
gavinkingsebersole
authored andcommitted
eliminate casts to AbstractEntityPersister
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 4a7651b commit 510fe81

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
@@ -217,7 +217,7 @@ private void addCollectionKey(
217217
final CollectionPersister collectionPersister = pluralAttributeMapping.getCollectionDescriptor();
218218
final CollectionKey collectionKey = new CollectionKey(
219219
collectionPersister,
220-
( (AbstractEntityPersister) getPersister() ).getCollectionKey(
220+
AbstractEntityPersister.getCollectionKey(
221221
collectionPersister,
222222
getInstance(),
223223
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
@@ -60,7 +60,6 @@
6060
import org.hibernate.metamodel.mapping.VirtualModelPart;
6161
import org.hibernate.metamodel.model.domain.NavigableRole;
6262
import org.hibernate.persister.collection.AbstractCollectionPersister;
63-
import org.hibernate.persister.entity.AbstractEntityPersister;
6463
import org.hibernate.persister.entity.EntityNameUse;
6564
import org.hibernate.persister.entity.EntityPersister;
6665
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
@@ -360,12 +359,11 @@ && equal( join.getKey(), manyToOne ) ) {
360359
isKeyTableNullable = !persister.getTableName().equals( targetTableName );
361360
}
362361
else {
363-
final AbstractEntityPersister persister = (AbstractEntityPersister) declaringEntityPersister;
364362
final int tableIndex = ArrayHelper.indexOf(
365-
persister.getTableNames(),
363+
declaringEntityPersister.getTableNames(),
366364
targetTableName
367365
);
368-
isKeyTableNullable = persister.isNullableTable( tableIndex );
366+
isKeyTableNullable = declaringEntityPersister.isNullableTable( tableIndex );
369367
}
370368
}
371369
isOptional = ( (ManyToOne) bootValue ).isIgnoreNotFound();
@@ -728,8 +726,8 @@ private static boolean equal(Value lhsValue, Value rhsValue) {
728726
}
729727

730728
static String findMapsIdPropertyName(EntityMappingType entityMappingType, String referencedPropertyName) {
731-
final AbstractEntityPersister persister = (AbstractEntityPersister) entityMappingType.getEntityPersister();
732-
if ( Arrays.equals( persister.getKeyColumnNames(), persister.getPropertyColumnNames( referencedPropertyName ) ) ) {
729+
final EntityPersister persister = entityMappingType.getEntityPersister();
730+
if ( Arrays.equals( persister.getIdentifierColumnNames(), persister.getPropertyColumnNames( referencedPropertyName ) ) ) {
733731
return persister.getIdentifierPropertyName();
734732
}
735733
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
@@ -249,7 +249,6 @@
249249
import org.hibernate.sql.ast.tree.from.TableGroup;
250250
import org.hibernate.sql.ast.tree.from.TableReference;
251251
import org.hibernate.sql.ast.tree.from.TableReferenceJoin;
252-
import org.hibernate.sql.ast.tree.insert.InsertSelectStatement;
253252
import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
254253
import org.hibernate.sql.ast.tree.predicate.InListPredicate;
255254
import org.hibernate.sql.ast.tree.predicate.Junction;
@@ -520,7 +519,7 @@ public AbstractEntityPersister(
520519
assert javaType != null;
521520
this.implementsLifecycle = Lifecycle.class.isAssignableFrom( javaType.getJavaTypeClass() );
522521

523-
concreteProxy = isPolymorphic()
522+
concreteProxy = entityMetamodel.isPolymorphic()
524523
&& ( getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() || hasProxy() )
525524
&& persistentClass.isConcreteProxy();
526525

@@ -935,8 +934,6 @@ private boolean shouldStoreDiscriminatorInShallowQueryCacheLayout(CacheLayout en
935934
return queryCacheLayout == CacheLayout.SHALLOW_WITH_DISCRIMINATOR;
936935
}
937936

938-
public abstract String getSubclassTableName(int j);
939-
940937
protected abstract String[] getSubclassTableNames();
941938

942939
protected abstract String[] getSubclassTableKeyColumns(int j);
@@ -959,37 +956,12 @@ protected boolean isClassOrSuperclassJoin(int j) {
959956
return isClassOrSuperclassTable( j );
960957
}
961958

962-
public abstract int getSubclassTableSpan();
963-
964-
public abstract int getTableSpan();
965-
966-
public abstract boolean hasDuplicateTables();
967-
968-
/**
969-
* @deprecated Only ever used from places where we really want to use<ul>
970-
* <li>{@link SelectStatement} (select generator)</li>
971-
* <li>{@link InsertSelectStatement}</li>
972-
* <li>{@link org.hibernate.sql.ast.tree.update.UpdateStatement}</li>
973-
* <li>{@link org.hibernate.sql.ast.tree.delete.DeleteStatement}</li>
974-
* </ul>
975-
*/
976-
@Deprecated( since = "6.2" )
977-
public abstract String getTableName(int j);
978-
979-
public abstract String[] getKeyColumns(int j);
980-
981959
public abstract boolean isPropertyOfTable(int property, int j);
982960

983961
protected abstract int[] getPropertyTableNumbers();
984962

985963
private static final String DISCRIMINATOR_ALIAS = "clazz_";
986964

987-
/**
988-
* The name of the table to use when performing mutations (INSERT,UPDATE,DELETE)
989-
* for the given attribute
990-
*/
991-
public abstract String getAttributeMutationTableName(int i);
992-
993965
@Override
994966
public String getDiscriminatorColumnName() {
995967
return DISCRIMINATOR_ALIAS;
@@ -1009,10 +981,12 @@ public String getDiscriminatorFormulaTemplate() {
1009981
return null;
1010982
}
1011983

984+
@Override
1012985
public boolean isInverseTable(int j) {
1013986
return false;
1014987
}
1015988

989+
@Override
1016990
public boolean isNullableTable(int j) {
1017991
return false;
1018992
}
@@ -1026,6 +1000,7 @@ public boolean isSubclassEntityName(String entityName) {
10261000
return entityMetamodel.getSubclassEntityNames().contains( entityName );
10271001
}
10281002

1003+
@Override
10291004
public boolean isSharedColumn(String columnExpression) {
10301005
return sharedColumnNames.contains( columnExpression );
10311006
}
@@ -1080,6 +1055,7 @@ public boolean hasRowId() {
10801055
return rowIdName != null;
10811056
}
10821057

1058+
@Override
10831059
public String[] getTableNames() {
10841060
final String[] tableNames = new String[getTableSpan()];
10851061
for ( int i = 0; i < tableNames.length; i++ ) {
@@ -1396,7 +1372,7 @@ protected TableReferenceJoin generateTableReferenceJoin(
13961372
generateJoinPredicate(
13971373
lhs,
13981374
joinedTableReference,
1399-
getKeyColumnNames(),
1375+
getIdentifierColumnNames(),
14001376
targetColumns,
14011377
creationState
14021378
)
@@ -1547,7 +1523,7 @@ public Object initializeLazyProperty(String fieldName, Object entity, SharedSess
15471523

15481524
}
15491525

1550-
public Object getCollectionKey(
1526+
public static Object getCollectionKey(
15511527
CollectionPersister persister,
15521528
Object owner,
15531529
EntityEntry ownerEntry,
@@ -2267,20 +2243,20 @@ public boolean hasFormulaProperties() {
22672243
return hasFormulaProperties;
22682244
}
22692245

2270-
@Override
22712246
public FetchMode getFetchMode(int i) {
22722247
return subclassPropertyFetchModeClosure[i];
22732248
}
22742249

2275-
@Override
22762250
public Type getSubclassPropertyType(int i) {
22772251
return subclassPropertyTypeClosure[i];
22782252
}
22792253

2254+
@Override
22802255
public int countSubclassProperties() {
22812256
return subclassPropertyTypeClosure.length;
22822257
}
22832258

2259+
@Override
22842260
public String[] getSubclassPropertyColumnNames(int i) {
22852261
return subclassPropertyColumnNameClosure[i];
22862262
}
@@ -2639,17 +2615,6 @@ public String getSelectByUniqueKeyString(String[] propertyNames, String[] column
26392615
return select.toStatementString();
26402616
}
26412617

2642-
@Internal
2643-
public boolean hasLazyDirtyFields(int[] dirtyFields) {
2644-
final boolean[] propertyLaziness = getPropertyLaziness();
2645-
for ( int i = 0; i < dirtyFields.length; i++ ) {
2646-
if ( propertyLaziness[dirtyFields[i]] ) {
2647-
return true;
2648-
}
2649-
}
2650-
return false;
2651-
}
2652-
26532618
@Override
26542619
public GeneratedValuesMutationDelegate getInsertDelegate() {
26552620
return insertDelegate;
@@ -2660,34 +2625,25 @@ public GeneratedValuesMutationDelegate getUpdateDelegate() {
26602625
return updateDelegate;
26612626
}
26622627

2663-
protected EntityTableMapping[] getTableMappings() {
2628+
@Override
2629+
public EntityTableMapping[] getTableMappings() {
26642630
return tableMappings;
26652631
}
26662632

2667-
public EntityTableMapping getTableMapping(int i) {
2633+
protected EntityTableMapping getTableMapping(int i) {
26682634
return tableMappings[i];
26692635
}
26702636

26712637
/**
26722638
* Unfortunately we cannot directly use `SelectableMapping#getContainingTableExpression()`
26732639
* as that blows up for attributes declared on super-type for union-subclass mappings
26742640
*/
2641+
@Override
26752642
public String physicalTableNameForMutation(SelectableMapping selectableMapping) {
26762643
assert !selectableMapping.isFormula();
26772644
return selectableMapping.getContainingTableExpression();
26782645
}
26792646

2680-
public EntityTableMapping getPhysicalTableMappingForMutation(SelectableMapping selectableMapping) {
2681-
final String tableNameForMutation = physicalTableNameForMutation( selectableMapping );
2682-
for ( int i = 0; i < tableMappings.length; i++ ) {
2683-
if ( tableNameForMutation.equals( tableMappings[i].getTableName() ) ) {
2684-
return tableMappings[i];
2685-
}
2686-
}
2687-
2688-
throw new IllegalArgumentException( "Unable to resolve TableMapping for selectable - " + selectableMapping );
2689-
}
2690-
26912647
@Override
26922648
public EntityMappingType getTargetPart() {
26932649
return this;
@@ -2855,7 +2811,7 @@ public TableGroup createRootTableGroup(
28552811
joinedTableReference,
28562812
needsDiscriminator()
28572813
? getRootTableKeyColumnNames()
2858-
: getKeyColumnNames(),
2814+
: getIdentifierColumnNames(),
28592815
getSubclassTableKeyColumns( i ),
28602816
creationState
28612817
)
@@ -3242,8 +3198,6 @@ protected GeneratedValuesMutationDelegate createUpdateDelegate() {
32423198
return GeneratedValuesHelper.getGeneratedValuesDelegate( this, UPDATE );
32433199
}
32443200

3245-
public abstract String[][] getContraintOrderedTableKeyColumnClosure();
3246-
32473201
private static class TableMappingBuilder {
32483202
private final String tableName;
32493203
private final int relativePosition;
@@ -3478,9 +3432,11 @@ protected DeleteCoordinator buildDeleteCoordinator() {
34783432
}
34793433
}
34803434

3435+
@Override
34813436
public void addDiscriminatorToInsertGroup(MutationGroupBuilder insertGroupBuilder) {
34823437
}
34833438

3439+
@Override
34843440
public void addSoftDeleteToInsertGroup(MutationGroupBuilder insertGroupBuilder) {
34853441
if ( softDeleteMapping != null ) {
34863442
final TableInsertBuilder insertBuilder = insertGroupBuilder.getTableDetailsBuilder( getIdentifierTableName() );
@@ -3787,10 +3743,6 @@ public final String getEntityName() {
37873743
return entityMetamodel.getName();
37883744
}
37893745

3790-
public boolean isPolymorphic() {
3791-
return entityMetamodel.isPolymorphic();
3792-
}
3793-
37943746
@Override
37953747
public boolean isInherited() {
37963748
return entityMetamodel.isInherited();
@@ -4029,10 +3981,6 @@ public EntityMappingType resolveConcreteProxyTypeForId(Object id, SharedSessionC
40293981
return concreteTypeLoader.getConcreteType( id, session );
40303982
}
40313983

4032-
public String[] getKeyColumnNames() {
4033-
return getIdentifierColumnNames();
4034-
}
4035-
40363984
/**
40373985
* {@inheritDoc}
40383986
*
@@ -4151,6 +4099,7 @@ public boolean[] getPropertyCheckability() {
41514099
return entityMetamodel.getPropertyCheckability();
41524100
}
41534101

4102+
@Override
41544103
public boolean[] getNonLazyPropertyUpdateability() {
41554104
return entityMetamodel.getNonlazyPropertyUpdateability();
41564105
}
@@ -4398,6 +4347,7 @@ && hasSubclasses()
43984347
return this;
43994348
}
44004349

4350+
@Override
44014351
public boolean hasMultipleTables() {
44024352
return false;
44034353
}
@@ -4621,7 +4571,12 @@ public BytecodeEnhancementMetadata getBytecodeEnhancementMetadata() {
46214571
return entityMetamodel.getBytecodeEnhancementMetadata();
46224572
}
46234573

4624-
public int determineTableNumberForColumn(String columnName) {
4574+
@Override
4575+
public String getTableNameForColumn(String columnName) {
4576+
return getTableName( determineTableNumberForColumn( columnName ) );
4577+
}
4578+
4579+
protected int determineTableNumberForColumn(String columnName) {
46254580
return 0;
46264581
}
46274582

0 commit comments

Comments
 (0)