Skip to content

Commit e70d8e7

Browse files
committed
Rework type hierarchy of ReactiveEntityInsertAction
1 parent 24b1d4b commit e70d8e7

File tree

3 files changed

+92
-15
lines changed

3 files changed

+92
-15
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.hibernate.reactive.engine.impl.ReactiveEntityActionVetoException;
4545
import org.hibernate.reactive.engine.impl.ReactiveEntityDeleteAction;
4646
import org.hibernate.reactive.engine.impl.ReactiveEntityInsertAction;
47+
import org.hibernate.reactive.engine.impl.ReactiveEntityInsertActionHolder;
4748
import org.hibernate.reactive.engine.impl.ReactiveEntityRegularInsertAction;
4849
import org.hibernate.reactive.engine.impl.ReactiveEntityUpdateAction;
4950
import org.hibernate.reactive.engine.impl.ReactiveOrphanRemovalAction;
@@ -78,7 +79,7 @@ public class ReactiveActionQueue {
7879
// Object insertions, updates, and deletions have list semantics because
7980
// they must happen in the right order to respect referential
8081
// integrity
81-
private ExecutableList<ReactiveEntityInsertAction> insertions;
82+
private ExecutableList<ReactiveEntityInsertActionHolder> insertions;
8283
private ExecutableList<ReactiveEntityDeleteAction> deletions;
8384
private ExecutableList<ReactiveEntityUpdateAction> updates;
8485
// Actually the semantics of the next three are really "Bag"
@@ -281,7 +282,7 @@ private CompletionStage<Void> addResolvedEntityInsertAction(ReactiveEntityInsert
281282
else {
282283
LOG.trace( "Adding resolved non-early insert action." );
283284
OrderedActions.EntityInsertAction.ensureInitialized( this );
284-
this.insertions.add( insert );
285+
this.insertions.add( new ReactiveEntityInsertActionHolder( insert ) );
285286
ret = voidFuture();
286287
}
287288

@@ -1016,34 +1017,35 @@ public CompletionStage<Void> afterTransactionCompletion(boolean success) {
10161017
*
10171018
* @author Jay Erb
10181019
*/
1019-
private static class InsertActionSorter implements ExecutableList.Sorter<ReactiveEntityInsertAction> {
1020+
private static class InsertActionSorter implements ExecutableList.Sorter<ReactiveEntityInsertActionHolder> {
10201021
/**
10211022
* Singleton access
10221023
*/
10231024
public static final InsertActionSorter INSTANCE = new InsertActionSorter();
10241025
// the map of batch numbers to EntityInsertAction lists
1025-
private Map<BatchIdentifier, List<ReactiveEntityInsertAction>> actionBatches;
1026+
private Map<BatchIdentifier, List<ReactiveEntityInsertActionHolder>> actionBatches;
10261027

10271028
public InsertActionSorter() {
10281029
}
10291030

10301031
/**
10311032
* Sort the insert actions.
10321033
*/
1033-
public void sort(List<ReactiveEntityInsertAction> insertions) {
1034+
public void sort(List<ReactiveEntityInsertActionHolder> insertions) {
10341035
// optimize the hash size to eliminate a rehash.
10351036
this.actionBatches = new HashMap<>();
10361037

10371038
// the mapping of entity names to their latest batch numbers.
10381039
final List<BatchIdentifier> latestBatches = new ArrayList<>();
10391040

1040-
for ( ReactiveEntityInsertAction action : insertions ) {
1041+
for ( ReactiveEntityInsertActionHolder action : insertions ) {
1042+
final ReactiveEntityInsertAction actionDelegate = action.getDelegate();
10411043
BatchIdentifier batchIdentifier = new BatchIdentifier(
1042-
action.getEntityName(),
1043-
action.getSession()
1044+
actionDelegate.getEntityName(),
1045+
actionDelegate.getSession()
10441046
.getFactory()
10451047
.getMetamodel()
1046-
.entityPersister( action.getEntityName() )
1048+
.entityPersister( actionDelegate.getEntityName() )
10471049
.getRootEntityName()
10481050
);
10491051

@@ -1055,8 +1057,8 @@ public void sort(List<ReactiveEntityInsertAction> insertions) {
10551057
else {
10561058
latestBatches.add( batchIdentifier );
10571059
}
1058-
addParentChildEntityNames( action, batchIdentifier );
1059-
addToBatch( batchIdentifier, action );
1060+
addParentChildEntityNames( actionDelegate, batchIdentifier );
1061+
addToBatch( batchIdentifier, actionDelegate );
10601062
}
10611063
insertions.clear();
10621064

@@ -1233,10 +1235,10 @@ else if ( type.isComponentType() && value != null ) {
12331235
}
12341236

12351237
private void addToBatch(BatchIdentifier batchIdentifier, ReactiveEntityInsertAction action) {
1236-
List<ReactiveEntityInsertAction> actions = actionBatches
1238+
List<ReactiveEntityInsertActionHolder> actions = actionBatches
12371239
.computeIfAbsent( batchIdentifier, k -> new LinkedList<>() );
12381240

1239-
actions.add( action );
1241+
actions.add( new ReactiveEntityInsertActionHolder( action ) );
12401242
}
12411243

12421244
private static class BatchIdentifier {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.hibernate.LockMode;
1111
import org.hibernate.action.internal.AbstractEntityInsertAction;
12-
import org.hibernate.action.internal.ComparableEntityAction;
1312
import org.hibernate.engine.internal.NonNullableTransientDependencies;
1413
import org.hibernate.engine.internal.Nullability;
1514
import org.hibernate.engine.internal.Versioning;
@@ -29,7 +28,7 @@
2928
*
3029
* @see org.hibernate.action.internal.AbstractEntityInsertAction
3130
*/
32-
public interface ReactiveEntityInsertAction extends ReactiveExecutable, ComparableEntityAction {
31+
public interface ReactiveEntityInsertAction extends ReactiveExecutable {
3332
boolean isEarlyInsert();
3433
NonNullableTransientDependencies findNonNullableTransientEntities();
3534
SharedSessionContractImplementor getSession();
@@ -98,4 +97,8 @@ default CompletionStage<NonNullableTransientDependencies> reactiveFindNonNullabl
9897

9998
AbstractEntityInsertAction asAbstractEntityInsertAction();
10099

100+
default int compareActionTo(ReactiveEntityInsertAction delegate) {
101+
return asAbstractEntityInsertAction().compareTo( delegate.asAbstractEntityInsertAction() );
102+
}
103+
101104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Hibernate, Relational Persistence for Idiomatic Java
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Copyright: Red Hat Inc. and Hibernate Authors
5+
*/
6+
package org.hibernate.reactive.engine.impl;
7+
8+
import java.io.Serializable;
9+
import java.util.Objects;
10+
import java.util.concurrent.CompletionStage;
11+
12+
import org.hibernate.HibernateException;
13+
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
14+
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
15+
import org.hibernate.action.spi.Executable;
16+
import org.hibernate.event.spi.EventSource;
17+
import org.hibernate.reactive.engine.ReactiveExecutable;
18+
19+
public final class ReactiveEntityInsertActionHolder implements Executable, ReactiveExecutable, Comparable<ReactiveEntityInsertActionHolder>,
20+
Serializable {
21+
22+
private final ReactiveEntityInsertAction delegate;
23+
24+
public ReactiveEntityInsertActionHolder(ReactiveEntityInsertAction delegate) {
25+
Objects.requireNonNull( delegate );
26+
this.delegate = delegate;
27+
}
28+
29+
@Override
30+
public int compareTo(ReactiveEntityInsertActionHolder o) {
31+
return delegate.compareActionTo( o.delegate );
32+
}
33+
34+
@Override
35+
public Serializable[] getPropertySpaces() {
36+
return delegate.getPropertySpaces();
37+
}
38+
39+
@Override
40+
public void beforeExecutions() throws HibernateException {
41+
delegate.beforeExecutions();
42+
}
43+
44+
@Override
45+
public void execute() throws HibernateException {
46+
delegate.execute();
47+
}
48+
49+
@Override
50+
public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() {
51+
return delegate.getAfterTransactionCompletionProcess();
52+
}
53+
54+
@Override
55+
public BeforeTransactionCompletionProcess getBeforeTransactionCompletionProcess() {
56+
return delegate.getBeforeTransactionCompletionProcess();
57+
}
58+
59+
@Override
60+
public void afterDeserialize(EventSource session) {
61+
delegate.afterDeserialize( session );
62+
}
63+
64+
@Override
65+
public CompletionStage<Void> reactiveExecute() {
66+
return delegate.reactiveExecute();
67+
}
68+
69+
public ReactiveEntityInsertAction getDelegate() {
70+
return delegate;
71+
}
72+
}

0 commit comments

Comments
 (0)