Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jul 16, 2024
1 parent 60e98c1 commit efdc714
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 296 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ org.gradle.java.installations.auto-download=false
#enableSonatypeOpenSourceSnapshotsRep = true

# Enable the maven local repository (for local development when needed) when present (value ignored)
#enableMavenLocalRepo = true
enableMavenLocalRepo = true

# Override default Hibernate ORM version
#hibernateOrmVersion = 7.0.0.Alpha2
hibernateOrmVersion = 7.0.0-SNAPSHOT

# Override default Hibernate ORM Gradle plugin version
# Using the stable version because I don't know how to configure the build to download the snapshot version from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.PropertyValueException;
import org.hibernate.TransientObjectException;
import org.hibernate.action.internal.AbstractEntityInsertAction;
import org.hibernate.action.internal.BulkOperationCleanupAction;
import org.hibernate.action.internal.EntityDeleteAction;
import org.hibernate.action.internal.UnresolvedEntityInsertActions;
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.action.spi.Executable;
import org.hibernate.cache.CacheException;
import org.hibernate.engine.internal.NonNullableTransientDependencies;
import org.hibernate.engine.spi.ActionQueue;
import org.hibernate.engine.spi.ComparableExecutable;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.ExecutableList;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
Expand All @@ -59,7 +61,6 @@

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture;
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;

Expand Down Expand Up @@ -520,11 +521,21 @@ public CompletionStage<Void> executeInserts() {
*/
public CompletionStage<Void> executeActions() {
if ( hasUnresolvedEntityInsertActions() ) {
return failedFuture( new IllegalStateException( "About to execute actions, but there are unresolved entity insert actions." ) );
final AbstractEntityInsertAction insertAction = unresolvedInsertions
.getDependentEntityInsertActions()
.iterator()
.next();
final NonNullableTransientDependencies transientEntities = insertAction.findNonNullableTransientEntities();
final Object transientEntity = transientEntities.getNonNullableTransientEntities().iterator().next();
final String path = transientEntities.getNonNullableTransientPropertyPaths(transientEntity).iterator().next();
//TODO: should be TransientPropertyValueException
throw new TransientObjectException( "Persistent instance of '" + insertAction.getEntityName()
+ "' with id '" + insertAction.getId()
+ "' references an unsaved transient instance via attribute '" + path
+ "' (save the transient instance before flushing)" );
}

CompletionStage<Void> ret = voidFuture();

for ( OrderedActions action : ORDERED_OPERATIONS ) {
ret = ret.thenCompose( v -> executeActions( action.getActions( this ) ) );
}
Expand Down Expand Up @@ -738,26 +749,6 @@ public int numberOfInsertions() {
return insertions.size();
}

// public TransactionCompletionProcesses getTransactionCompletionProcesses() {
// return new TransactionCompletionProcesses( beforeTransactionProcesses(), afterTransactionProcesses() );
// }
//
// /**
// * Bind transaction completion processes to make them shared between primary and secondary session.
// * Transaction completion processes are always executed by transaction owner (primary session),
// * but can be registered using secondary session too.
// *
// * @param processes Transaction completion processes.
// * @param isTransactionCoordinatorShared Flag indicating shared transaction context.
// */
// public void setTransactionCompletionProcesses(
// TransactionCompletionProcesses processes,
// boolean isTransactionCoordinatorShared) {
// this.isTransactionCoordinatorShared = isTransactionCoordinatorShared;
// this.beforeTransactionProcesses = processes.beforeTransactionCompletionProcesses;
// this.afterTransactionProcesses = processes.afterTransactionCompletionProcesses;
// }

public void sortCollectionActions() {
if ( isOrderUpdatesEnabled() ) {
// sort the updates by fk
Expand Down Expand Up @@ -864,32 +855,6 @@ public void unScheduleDeletion(EntityEntry entry, Object rescuedEntity) {
throw new AssertionFailure( "Unable to perform un-delete for instance " + entry.getEntityName() );
}

// /**
// * Used by the owning session to explicitly control serialization of the action queue
// *
// * @param oos The stream to which the action queue should get written
// *
// * @throws IOException Indicates an error writing to the stream
// */
// public void serialize(ObjectOutputStream oos) throws IOException {
// LOG.trace( "Serializing action-queue" );
// if ( unresolvedInsertions == null ) {
// unresolvedInsertions = new UnresolvedEntityInsertActions();
// }
// unresolvedInsertions.serialize( oos );
//
// for ( ListProvider<?> p : EXECUTABLE_LISTS_MAP.values() ) {
// ExecutableList<?> l = p.get( this );
// if ( l == null ) {
// oos.writeBoolean( false );
// }
// else {
// oos.writeBoolean( true );
// l.writeExternal( oos );
// }
// }
// }

private abstract static class AbstractTransactionCompletionProcessQueue<T,U> {
final ReactiveSession session;

Expand Down Expand Up @@ -994,21 +959,6 @@ public CompletionStage<Void> afterTransactionCompletion(boolean success) {
}
}

// /**
// * Wrapper class allowing to bind the same transaction completion process queues in different sessions.
// */
// public static class TransactionCompletionProcesses {
// private final BeforeTransactionCompletionProcessQueue beforeTransactionCompletionProcesses;
// private final AfterTransactionCompletionProcessQueue afterTransactionCompletionProcesses;
//
// private TransactionCompletionProcesses(
// BeforeTransactionCompletionProcessQueue beforeTransactionCompletionProcessQueue,
// AfterTransactionCompletionProcessQueue afterTransactionCompletionProcessQueue) {
// this.beforeTransactionCompletionProcesses = beforeTransactionCompletionProcessQueue;
// this.afterTransactionCompletionProcesses = afterTransactionCompletionProcessQueue;
// }
// }

/**
* Order the {@link #insertions} queue such that we group inserts against the same entity together (without
* violating constraints). The original order is generated by cascade order, which in turn is based on the
Expand Down Expand Up @@ -1152,26 +1102,23 @@ public void sort(List<ReactiveEntityInsertActionHolder> insertions) {
*/
private void addParentChildEntityNames(ReactiveEntityInsertAction action, BatchIdentifier batchIdentifier) {
Object[] propertyValues = action.getState();
ClassMetadata classMetadata = action.getPersister().getClassMetadata();
if ( classMetadata != null ) {
Type[] propertyTypes = classMetadata.getPropertyTypes();
Type identifierType = classMetadata.getIdentifierType();

for ( int i = 0; i < propertyValues.length; i++ ) {
Object value = propertyValues[i];
if (value!=null) {
Type type = propertyTypes[i];
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, value );
}
Type[] propertyTypes = action.getPersister().getPropertyTypes();
Type identifierType = action.getPersister().getIdentifierType();

for ( int i = 0; i < propertyValues.length; i++ ) {
Object value = propertyValues[i];
if (value!=null) {
Type type = propertyTypes[i];
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, value );
}
}

if ( identifierType.isComponentType() ) {
CompositeType compositeType = (CompositeType) identifierType;
Type[] compositeIdentifierTypes = compositeType.getSubtypes();
if ( identifierType.isComponentType() ) {
CompositeType compositeType = (CompositeType) identifierType;
Type[] compositeIdentifierTypes = compositeType.getSubtypes();

for ( Type type : compositeIdentifierTypes ) {
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, null );
}
for ( Type type : compositeIdentifierTypes ) {
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, null );
}
}
}
Expand Down Expand Up @@ -1275,10 +1222,9 @@ public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof BatchIdentifier ) ) {
if ( !( o instanceof BatchIdentifier that ) ) {
return false;
}
BatchIdentifier that = (BatchIdentifier) o;
return Objects.equals( entityName, that.entityName );
}

Expand Down Expand Up @@ -1315,9 +1261,7 @@ boolean hasAnyChildEntityNames(BatchIdentifier batchIdentifier) {
/**
* Check if this {@link BatchIdentifier} has a parent or grandparent
* matching the given {@link BatchIdentifier reference.
*
* @param batchIdentifier {@link BatchIdentifier} reference
*
* @return this {@link BatchIdentifier} has a parent matching the given {@link BatchIdentifier reference
*/
boolean hasParent(BatchIdentifier batchIdentifier) {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit efdc714

Please sign in to comment.