Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95bb4a7

Browse files
minor changes to AbstractEntityPersister
1 parent 1337186 commit 95bb4a7

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

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

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.hibernate.dialect.lock.LockingStrategy;
4444
import org.hibernate.engine.FetchTiming;
4545
import org.hibernate.engine.OptimisticLockStyle;
46-
import org.hibernate.engine.internal.CacheHelper;
4746
import org.hibernate.engine.internal.ImmutableEntityEntryFactory;
4847
import org.hibernate.engine.internal.MutableEntityEntryFactory;
4948
import org.hibernate.engine.profile.internal.FetchProfileAffectee;
@@ -68,7 +67,6 @@
6867
import org.hibernate.generator.internal.VersionGeneration;
6968
import org.hibernate.generator.values.GeneratedValues;
7069
import org.hibernate.generator.values.GeneratedValuesMutationDelegate;
71-
import org.hibernate.generator.values.internal.GeneratedValuesHelper;
7270
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
7371
import org.hibernate.id.IdentifierGenerator;
7472
import org.hibernate.id.OptimizableGenerator;
@@ -257,12 +255,14 @@
257255
import static java.util.Collections.emptySet;
258256
import static java.util.Collections.unmodifiableList;
259257
import static org.hibernate.boot.model.internal.SoftDeleteHelper.resolveSoftDeleteMapping;
258+
import static org.hibernate.engine.internal.CacheHelper.fromSharedCache;
260259
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
261260
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
262261
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfPersistentAttributeInterceptable;
263262
import static org.hibernate.generator.EventType.FORCE_INCREMENT;
264263
import static org.hibernate.generator.EventType.INSERT;
265264
import static org.hibernate.generator.EventType.UPDATE;
265+
import static org.hibernate.generator.values.internal.GeneratedValuesHelper.getGeneratedValuesDelegate;
266266
import static org.hibernate.internal.util.ReflectHelper.isAbstractClass;
267267
import static org.hibernate.internal.util.StringHelper.isEmpty;
268268
import static org.hibernate.internal.util.StringHelper.qualify;
@@ -284,6 +284,7 @@
284284
import static org.hibernate.internal.util.collections.CollectionHelper.toSmallList;
285285
import static org.hibernate.loader.ast.internal.MultiKeyLoadHelper.supportsSqlArrayType;
286286
import static org.hibernate.metamodel.RepresentationMode.POJO;
287+
import static org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor.getGeneratedAttributes;
287288
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildBasicAttributeMapping;
288289
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildEncapsulatedCompositeIdentifierMapping;
289290
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping;
@@ -667,25 +668,25 @@ else if ( selectable instanceof Column column ) {
667668
names.add( prop.getName() );
668669
types.add( prop.getType() );
669670

670-
final String[] cols = new String[ prop.getColumnSpan() ];
671-
final String[] readers = new String[ prop.getColumnSpan() ];
672-
final String[] readerTemplates = new String[ prop.getColumnSpan() ];
673-
final String[] forms = new String[ prop.getColumnSpan() ];
671+
final int columnSpan = prop.getColumnSpan();
672+
final String[] columnNames = new String[columnSpan];
673+
final String[] readers = new String[columnSpan];
674+
final String[] readerTemplates = new String[columnSpan];
675+
final String[] formulaTemplates = new String[columnSpan];
674676

675677
final var selectables = prop.getSelectables();
676678
for ( int i = 0; i < selectables.size(); i++ ) {
677679
final var selectable = selectables.get(i);
678680
if ( selectable instanceof Formula ) {
679-
final String template = selectable.getTemplate( dialect, typeConfiguration );
680-
forms[i] = template;
681+
formulaTemplates[i] = selectable.getTemplate( dialect, typeConfiguration );
681682
final String formulaAlias = selectable.getAlias( dialect );
682683
if ( prop.isSelectable() && !formulaAliases.contains( formulaAlias ) ) {
683684
formulaAliases.add( formulaAlias );
684685
}
685686
}
686687
else if ( selectable instanceof Column column ) {
687-
final String colName = column.getQuotedName(dialect);
688-
cols[i] = colName;
688+
final String quotedColumnName = column.getQuotedName(dialect);
689+
columnNames[i] = quotedColumnName;
689690
final String columnAlias = selectable.getAlias( dialect, prop.getValue().getTable() );
690691
if ( prop.isSelectable() && !aliases.contains( columnAlias ) ) {
691692
aliases.add( columnAlias );
@@ -695,14 +696,14 @@ else if ( selectable instanceof Column column ) {
695696
if ( thisClassProperties.contains( prop )
696697
? persistentClass.hasSubclasses()
697698
: persistentClass.isDefinedOnMultipleSubclasses( column ) ) {
698-
sharedColumnNames.add( colName );
699+
sharedColumnNames.add( quotedColumnName );
699700
}
700701
}
701702
}
702-
propColumns.add( cols );
703+
propColumns.add( columnNames );
703704
propColumnReaders.add( readers );
704705
propColumnReaderTemplates.add( readerTemplates );
705-
templates.add( forms );
706+
templates.add( formulaTemplates );
706707

707708
joinedFetchesList.add( prop.getValue().getFetchMode() );
708709
}
@@ -1470,7 +1471,7 @@ && isLazyPropertiesCacheable() ) {
14701471
session.getFactory(),
14711472
session.getTenantIdentifier()
14721473
);
1473-
final Object structuredEntry = CacheHelper.fromSharedCache( session, cacheKey, this, cacheAccess );
1474+
final Object structuredEntry = fromSharedCache( session, cacheKey, this, cacheAccess );
14741475
if ( structuredEntry != null ) {
14751476
final var cacheEntry = (CacheEntry) getCacheEntryStructure().destructure( structuredEntry, factory );
14761477
final Object initializedValue = initializeLazyPropertiesFromCache( fieldName, entity, session, entry, cacheEntry );
@@ -3131,24 +3132,25 @@ protected boolean shouldInnerJoinSubclassTable(int subclassTableNumber, Set<Stri
31313132
return !isInverseTable( subclassTableNumber )
31323133
&& !isNullableTable( subclassTableNumber );
31333134
}
3134-
3135-
// otherwise we have a subclass table and need to look a little deeper...
3136-
3137-
// IMPL NOTE: By default, 'includeSubclasses' indicates that all subclasses should be joined and that each
3138-
// subclass ought to be joined by outer join. However, 'TREAT AS' always requires that an inner join be used,
3139-
// so we give 'TREAT AS' higher precedence...
3140-
3141-
return isSubclassTableIndicatedByTreatAsDeclarations( subclassTableNumber, treatAsDeclarations );
3135+
else {
3136+
// otherwise we have a subclass table and need to look a little deeper...
3137+
// IMPL NOTE: By default, 'includeSubclasses' indicates that all subclasses should be joined and that
3138+
// each subclass ought to be joined by outer join. However, 'TREAT AS' always requires that an inner
3139+
// join be used, so we give 'TREAT AS' higher precedence.
3140+
return isSubclassTableIndicatedByTreatAsDeclarations( subclassTableNumber, treatAsDeclarations );
3141+
}
31423142
}
31433143

31443144
protected boolean isSubclassTableIndicatedByTreatAsDeclarations(int subclassTableNumber, Set<String> treatAsDeclarations) {
31453145
return false;
31463146
}
31473147

31483148
/**
3149-
* Post-construct is a callback for AbstractEntityPersister subclasses to call after they are all done with their
3150-
* constructor processing. It allows AbstractEntityPersister to extend its construction after all subclass-specific
3151-
* details have been handled.
3149+
* Post-construct is a callback for {@code AbstractEntityPersister}
3150+
* subclasses to call after they are all done with their constructor
3151+
* processing. It allows {@code AbstractEntityPersister} to extend
3152+
* its construction after subclass-specific details have all been
3153+
* taken care of.
31523154
*
31533155
* @param mapping The mapping
31543156
*
@@ -3174,11 +3176,11 @@ private void doLateInit() {
31743176

31753177
final List<AttributeMapping> insertGeneratedAttributes =
31763178
hasInsertGeneratedProperties()
3177-
? GeneratedValuesProcessor.getGeneratedAttributes( this, INSERT )
3179+
? getGeneratedAttributes( this, INSERT )
31783180
: emptyList();
31793181
final List<AttributeMapping> updateGeneratedAttributes =
31803182
hasUpdateGeneratedProperties()
3181-
? GeneratedValuesProcessor.getGeneratedAttributes( this, UPDATE )
3183+
? getGeneratedAttributes( this, UPDATE )
31823184
: emptyList();
31833185

31843186
insertGeneratedProperties = initInsertGeneratedProperties( insertGeneratedAttributes );
@@ -3192,10 +3194,12 @@ private void doLateInit() {
31923194
}
31933195

31943196
if ( hasInsertGeneratedProperties() ) {
3195-
insertGeneratedValuesProcessor = createGeneratedValuesProcessor( INSERT, insertGeneratedAttributes );
3197+
insertGeneratedValuesProcessor =
3198+
createGeneratedValuesProcessor( INSERT, insertGeneratedAttributes );
31963199
}
31973200
if ( hasUpdateGeneratedProperties() ) {
3198-
updateGeneratedValuesProcessor = createGeneratedValuesProcessor( UPDATE, updateGeneratedAttributes );
3201+
updateGeneratedValuesProcessor =
3202+
createGeneratedValuesProcessor( UPDATE, updateGeneratedAttributes );
31993203
}
32003204

32013205
insertCoordinator = buildInsertCoordinator();
@@ -3212,11 +3216,11 @@ protected GeneratedValuesMutationDelegate createInsertDelegate() {
32123216
final var generator = (OnExecutionGenerator) getGenerator();
32133217
return generator.getGeneratedIdentifierDelegate( this );
32143218
}
3215-
return GeneratedValuesHelper.getGeneratedValuesDelegate( this, INSERT );
3219+
return getGeneratedValuesDelegate( this, INSERT );
32163220
}
32173221

32183222
protected GeneratedValuesMutationDelegate createUpdateDelegate() {
3219-
return GeneratedValuesHelper.getGeneratedValuesDelegate( this, UPDATE );
3223+
return getGeneratedValuesDelegate( this, UPDATE );
32203224
}
32213225

32223226
private static class TableMappingBuilder {
@@ -3378,12 +3382,12 @@ protected EntityTableMapping[] buildTableMappings() {
33783382
}
33793383
} );
33803384

3381-
final EntityTableMapping[] list = new EntityTableMapping[tableBuilderMap.size()];
3385+
final varentityTableMappings = new EntityTableMapping[tableBuilderMap.size()];
33823386
int i = 0;
3383-
for ( Map.Entry<String, TableMappingBuilder> entry : tableBuilderMap.entrySet() ) {
3384-
list[i++] = entry.getValue().build();
3387+
for ( var entry : tableBuilderMap.entrySet() ) {
3388+
entityTableMappings[i++] = entry.getValue().build();
33853389
}
3386-
return list;
3390+
return entityTableMappings;
33873391
}
33883392

33893393
/**
@@ -3427,8 +3431,7 @@ protected InsertCoordinator buildInsertCoordinator() {
34273431
protected UpdateCoordinator buildUpdateCoordinator() {
34283432
// we only have updates to issue for entities with one or more singular attributes
34293433
for ( int i = 0; i < attributeMappings.size(); i++ ) {
3430-
final AttributeMapping attributeMapping = attributeMappings.get( i );
3431-
if ( attributeMapping instanceof SingularAttributeMapping ) {
3434+
if ( attributeMappings.get( i ) instanceof SingularAttributeMapping ) {
34323435
return new UpdateCoordinatorStandard( this, factory );
34333436
}
34343437
}
@@ -3439,8 +3442,7 @@ protected UpdateCoordinator buildUpdateCoordinator() {
34393442
protected UpdateCoordinator buildMergeCoordinator() {
34403443
// we only have updates to issue for entities with one or more singular attributes
34413444
for ( int i = 0; i < attributeMappings.size(); i++ ) {
3442-
final AttributeMapping attributeMapping = attributeMappings.get( i );
3443-
if ( attributeMapping instanceof SingularAttributeMapping ) {
3445+
if ( attributeMappings.get( i ) instanceof SingularAttributeMapping ) {
34443446
return new MergeCoordinator( this, factory );
34453447
}
34463448
}
@@ -3449,12 +3451,9 @@ protected UpdateCoordinator buildMergeCoordinator() {
34493451
}
34503452

34513453
protected DeleteCoordinator buildDeleteCoordinator() {
3452-
if ( softDeleteMapping == null ) {
3453-
return new DeleteCoordinatorStandard( this, factory );
3454-
}
3455-
else {
3456-
return new DeleteCoordinatorSoft( this, factory );
3457-
}
3454+
return softDeleteMapping == null
3455+
? new DeleteCoordinatorStandard( this, factory )
3456+
: new DeleteCoordinatorSoft( this, factory );
34583457
}
34593458

34603459
@Override
@@ -3523,7 +3522,7 @@ protected SingleIdEntityLoader<?> determineLoaderToUse(SharedSessionContractImpl
35233522
return getSingleIdLoader();
35243523
}
35253524

3526-
final LoadQueryInfluencers influencers = session.getLoadQueryInfluencers();
3525+
final var influencers = session.getLoadQueryInfluencers();
35273526
if ( isAffectedByInfluencers( influencers, true ) ) {
35283527
return buildSingleIdEntityLoader( influencers, lockOptions );
35293528
}
@@ -3877,15 +3876,14 @@ public Boolean isTransient(Object entity, SharedSessionContractImplementor sessi
38773876
if ( persistenceContext.hasLoadContext()
38783877
&& !persistenceContext.getLoadContexts().isLoadingFinished() ) {
38793878
// check if we're currently loading this entity instance, the version
3880-
// will be null but the entity cannot be considered transient
3879+
// will be null, but the entity cannot be considered transient
38813880
final var holder = persistenceContext.getEntityHolder( new EntityKey( id, this ) );
38823881
if ( holder != null && holder.isEventuallyInitialized() && holder.getEntity() == entity ) {
38833882
return false;
38843883
}
38853884
}
38863885
}
3887-
final var identifierGenerator = getGenerator();
3888-
if ( identifierGenerator != null ) {
3886+
if ( getGenerator() != null ) {
38893887
final Boolean unsaved = identifierMapping.getUnsavedStrategy().isUnsaved( id );
38903888
if ( unsaved != null && !unsaved ) {
38913889
throw new PropertyValueException(
@@ -3909,10 +3907,10 @@ public Boolean isTransient(Object entity, SharedSessionContractImplementor sessi
39093907

39103908
// check to see if it is in the second-level cache
39113909
if ( session.getCacheMode().isGetEnabled() && canReadFromCache() ) {
3912-
final var cache = getCacheAccessStrategy();
39133910
final Object cacheKey =
3914-
cache.generateCacheKey( id, this, session.getFactory(), session.getTenantIdentifier() );
3915-
final Object cacheEntry = CacheHelper.fromSharedCache( session, cacheKey, this, getCacheAccessStrategy() );
3911+
getCacheAccessStrategy()
3912+
.generateCacheKey( id, this, session.getFactory(), session.getTenantIdentifier() );
3913+
final Object cacheEntry = fromSharedCache( session, cacheKey, this, getCacheAccessStrategy() );
39163914
if ( cacheEntry != null ) {
39173915
return false;
39183916
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /