Skip to content

Commit 900f1f4

Browse files
committed
[#1504] Clean up EntityTYpes
* Format code * Remove warnings
1 parent 936cf6d commit 900f1f4

File tree

1 file changed

+23
-17
lines changed
  • hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl

1 file changed

+23
-17
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/EntityTypes.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister;
2525
import org.hibernate.reactive.session.impl.ReactiveQueryExecutorLookup;
2626
import org.hibernate.reactive.session.impl.ReactiveSessionImpl;
27-
import org.hibernate.reactive.util.impl.CompletionStages;
2827
import org.hibernate.type.EntityType;
2928
import org.hibernate.type.ForeignKeyDirection;
3029
import org.hibernate.type.OneToOneType;
@@ -79,8 +78,11 @@ static boolean isNull(EntityType entityType, Object owner, SharedSessionContract
7978
OneToOneType type = (OneToOneType) entityType;
8079
String propertyName = type.getPropertyName();
8180
if ( propertyName != null ) {
82-
EntityPersister ownerPersister = session.getFactory().getMetamodel()
83-
.entityPersister( entityType.getAssociatedEntityName() );
81+
final EntityPersister ownerPersister = session.getFactory()
82+
.getRuntimeMetamodels()
83+
.getMappingMetamodel()
84+
.getEntityDescriptor( entityType.getAssociatedEntityName() );
85+
8486
Object id = session.getContextEntityIdentifier( owner );
8587
EntityKey entityKey = session.generateEntityKey( id, ownerPersister );
8688
return session.getPersistenceContextInternal().isPropertyNull( entityKey, propertyName );
@@ -183,7 +185,8 @@ public static CompletionStage<Object[]> replace(
183185
copyCache
184186
).thenCompose( copy -> {
185187
if ( copy instanceof CompletionStage ) {
186-
return ( (CompletionStage) copy ).thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
188+
return ( (CompletionStage<?>) copy )
189+
.thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
187190
}
188191
else {
189192
copied[i] = copy;
@@ -202,7 +205,7 @@ public static CompletionStage<Object[]> replace(
202205
final Type[] types,
203206
final SessionImplementor session,
204207
final Object owner,
205-
final Map copyCache,
208+
final Map<Object, Object> copyCache,
206209
final ForeignKeyDirection foreignKeyDirection) {
207210
Object[] copied = new Object[original.length];
208211
for ( int i = 0; i < types.length; i++ ) {
@@ -235,7 +238,7 @@ public static CompletionStage<Object[]> replace(
235238
foreignKeyDirection
236239
).thenCompose( copy -> {
237240
if ( copy instanceof CompletionStage ) {
238-
return ( (CompletionStage) copy ).thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
241+
return ( (CompletionStage<?>) copy ).thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
239242
}
240243
else {
241244
copied[i] = copy;
@@ -254,7 +257,7 @@ private static CompletionStage<Object> replace(
254257
Object target,
255258
SessionImplementor session,
256259
Object owner,
257-
Map copyCache,
260+
Map<Object, Object> copyCache,
258261
ForeignKeyDirection foreignKeyDirection)
259262
throws HibernateException {
260263
boolean include = entityType.isAssociationType()
@@ -274,7 +277,7 @@ private static CompletionStage<Object> replace(
274277
Object target,
275278
SessionImplementor session,
276279
Object owner,
277-
Map copyCache) {
280+
Map<Object, Object> copyCache) {
278281
if ( original == null ) {
279282
return nullFuture();
280283
}
@@ -320,11 +323,12 @@ private static CompletionStage<Object> resolveIdOrUniqueKey(
320323
Object original,
321324
SessionImplementor session,
322325
Object owner,
323-
Map copyCache) {
326+
Map<Object, Object> copyCache) {
324327
return getIdentifier( entityType, original, session )
325328
.thenCompose( id -> {
326329
if ( id == null ) {
327-
throw new AssertionFailure( "non-transient entity has a null id: " + original.getClass().getName() );
330+
throw new AssertionFailure( "non-transient entity has a null id: " + original.getClass()
331+
.getName() );
328332
}
329333
// For the special case of a @ManyToOne joined on a (non-primary) unique key,
330334
// the "id" class is actually the associated entity object itself, but treated
@@ -336,9 +340,8 @@ private static CompletionStage<Object> resolveIdOrUniqueKey(
336340
Object idOrUniqueKey = entityType.getIdentifierOrUniqueKeyType( session.getFactory() )
337341
.replace( fetched, null, session, owner, copyCache );
338342
if ( idOrUniqueKey instanceof CompletionStage ) {
339-
return ( (CompletionStage) idOrUniqueKey ).thenCompose(
340-
key -> resolve( entityType, key, owner, session )
341-
);
343+
return ( (CompletionStage<?>) idOrUniqueKey )
344+
.thenCompose( key -> resolve( entityType, key, owner, session ) );
342345
}
343346

344347
return resolve( entityType, idOrUniqueKey, owner, session );
@@ -361,8 +364,8 @@ private static CompletionStage<Object> getIdentifier(
361364
return nullFuture();
362365
}
363366

364-
if( value instanceof HibernateProxy ) {
365-
return getIdentifierFromHibernateProxy( entityType, (HibernateProxy)value, session );
367+
if ( value instanceof HibernateProxy ) {
368+
return getIdentifierFromHibernateProxy( entityType, (HibernateProxy) value, session );
366369
}
367370

368371
final LazyInitializer lazyInitializer = extractLazyInitializer( value );
@@ -399,7 +402,10 @@ else if ( isPersistentAttributeInterceptable( value ) ) {
399402

400403
}
401404

402-
private static CompletionStage<Object> getIdentifierFromHibernateProxy(EntityType entityType, HibernateProxy proxy, SharedSessionContractImplementor session) {
405+
private static CompletionStage<Object> getIdentifierFromHibernateProxy(
406+
EntityType entityType,
407+
HibernateProxy proxy,
408+
SharedSessionContractImplementor session) {
403409
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
404410
final String entityName = initializer.getEntityName();
405411
final Object identifier = initializer.getIdentifier();
@@ -421,7 +427,7 @@ private static CompletionStage<Object> getIdentifierFromHibernateProxy(EntityTyp
421427
}
422428
return completedFuture( propertyValue );
423429
}
424-
return CompletionStages.nullFuture();
430+
return nullFuture();
425431
} );
426432
}
427433

0 commit comments

Comments
 (0)