Skip to content

generalize uses of SessionImplementor to SharedSessionContractImplementor #2244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.persister.collection.CollectionPersister;
Expand Down Expand Up @@ -58,7 +57,7 @@ public static CompletionStage<Object> replace(
CollectionType type,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection)
Expand All @@ -76,7 +75,7 @@ public static CompletionStage<Object> replace(
CollectionType type,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache) throws HibernateException {
if ( original == null ) {
Expand All @@ -96,7 +95,7 @@ else if ( !Hibernate.isInitialized( original ) ) {
*/
private static Object replaceNullOriginal(
Object target,
SessionImplementor session) {
SharedSessionContractImplementor session) {
if ( target == null ) {
return null;
}
Expand Down Expand Up @@ -132,7 +131,7 @@ private static Object replaceUninitializedOriginal(
CollectionType type,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Map<Object, Object> copyCache) {
final PersistentCollection<?> persistentCollection = (PersistentCollection<?>) original;
if ( persistentCollection.hasQueuedOperations() ) {
Expand Down Expand Up @@ -165,7 +164,7 @@ private static CompletionStage<Object> replaceOriginal(
CollectionType type,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache) {

Expand Down Expand Up @@ -211,7 +210,7 @@ private static CompletionStage<Object> replaceElements(
Object target,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
if ( type instanceof ArrayType ) {
return replaceArrayTypeElements( type, original, target, owner, copyCache, session );
}
Expand Down Expand Up @@ -246,7 +245,7 @@ private static CompletionStage<Object> replaceCollectionTypeElements(
final Collection<Object> result,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
result.clear();
// copy elements into newly empty target collection
final Type elemType = type.getElementType( session.getFactory() );
Expand All @@ -261,7 +260,7 @@ private static CompletionStage<Object> preserveSnapshotIfNecessary(
Collection<Object> result,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session,
SharedSessionContractImplementor session,
Type elemType) {
// if the original is a PersistentCollection, and that original
// was not flagged as dirty, then reset the target's dirty flag
Expand Down Expand Up @@ -293,7 +292,7 @@ private static CompletionStage<Object> replaceMapTypeElements(
Map<Object, Object> target,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final CollectionPersister persister =
session.getFactory().getRuntimeMetamodels().getMappingMetamodel()
.getCollectionDescriptor( type.getRole() );
Expand All @@ -320,7 +319,7 @@ private static CompletionStage<Object> replaceArrayTypeElements(
Object target,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final Object result;
final int length = Array.getLength( original );
if ( length != Array.getLength( target ) ) {
Expand All @@ -345,7 +344,7 @@ private static CompletionStage<Object> getReplace(
Type elemType,
Object o,
Object owner,
SessionImplementor session,
SharedSessionContractImplementor session,
Map<Object, Object> copyCache) {
return getReplace( elemType, o, null, owner, session, copyCache );
}
Expand All @@ -355,7 +354,7 @@ private static CompletionStage<Object> getReplace(
Object object,
Object target,
Object owner,
SessionImplementor session,
SharedSessionContractImplementor session,
Map<Object, Object> copyCache) {
return elemType instanceof EntityType entityType
? EntityTypes.replace( entityType, object, target, session, owner, copyCache )
Expand All @@ -371,7 +370,7 @@ private static CompletionStage<Void> preserveSnapshot(
Type elemType,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( result );
if ( ce != null ) {
return createSnapshot( original, result, elemType, owner, copyCache, session )
Expand All @@ -391,7 +390,7 @@ private static CompletionStage<Serializable> createSnapshot(
Type elemType,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final Serializable originalSnapshot = original.getStoredSnapshot();
if ( originalSnapshot instanceof List<?> list ) {
return createListSnapshot( list, elemType, owner, copyCache, session );
Expand All @@ -416,7 +415,7 @@ private static CompletionStage<Serializable> createArraySnapshot(
Type elemType,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
return loop( 0, array.length,
i -> getReplace( elemType, array[i], owner, session, copyCache )
.thenAccept( o -> array[i] = o )
Expand All @@ -432,7 +431,7 @@ private static <K,V> CompletionStage<Serializable> createMapSnapshot(
Type elemType,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final Map<?, ?> resultSnapshot = (Map<?, ?>) result.getStoredSnapshot();
final Map<K, V> targetMap =
map instanceof SortedMap<K, V> sortedMap
Expand All @@ -457,7 +456,7 @@ private static CompletionStage<Serializable> createListSnapshot(
Type elemType,
Object owner,
Map<Object, Object> copyCache,
SessionImplementor session) {
SharedSessionContractImplementor session) {
final ArrayList<Object> targetList = new ArrayList<>( list.size() );
return loop( list,
obj -> getReplace( elemType, obj, owner, session, copyCache )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
Expand Down Expand Up @@ -155,7 +154,7 @@ public static CompletionStage<Object[]> replace(
final Object[] original,
final Object[] target,
final Type[] types,
final SessionImplementor session,
final SharedSessionContractImplementor session,
final Object owner,
final Map<Object, Object> copyCache) {
Object[] copied = new Object[original.length];
Expand All @@ -171,7 +170,7 @@ public static CompletionStage<Object[]> replace(
final Object[] original,
final Object[] target,
final Type[] types,
final SessionImplementor session,
final SharedSessionContractImplementor session,
final Object owner,
final Map<Object, Object> copyCache,
final ForeignKeyDirection foreignKeyDirection) {
Expand All @@ -188,7 +187,7 @@ private static CompletionStage<Object> replace(
EntityType entityType,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection)
Expand All @@ -208,7 +207,7 @@ protected static CompletionStage<Object> replace(
EntityType entityType,
Object original,
Object target,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache) {
if ( original == null ) {
Expand Down Expand Up @@ -254,7 +253,7 @@ protected static CompletionStage<Object> replace(
private static CompletionStage<Object> resolveIdOrUniqueKey(
EntityType entityType,
Object original,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache) {
return getIdentifier( entityType, original, session )
Expand Down Expand Up @@ -289,7 +288,7 @@ private static CompletionStage<Object> resolveIdOrUniqueKey(
private static CompletionStage<Object> getIdentifier(
EntityType entityType,
Object value,
SessionImplementor session) {
SharedSessionContractImplementor session) {
if ( entityType.isReferenceToIdentifierProperty() ) {
// tolerates nulls
return getEntityIdentifierIfNotUnsaved( entityType.getAssociatedEntityName(), value, session );
Expand Down Expand Up @@ -358,7 +357,7 @@ private static CompletionStage<Object> getIdentifierFromHibernateProxy(
// an entity type, in which case we need to resolve its identifier
final AttributeMapping type = entityPersister.findAttributeMapping( uniqueKeyPropertyName );
if ( type.isEntityIdentifierMapping() ) {
propertyValue = getIdentifier( (EntityType) type, propertyValue, (SessionImplementor) session );
propertyValue = getIdentifier( (EntityType) type, propertyValue, session );
}
return propertyValue;
}
Expand Down Expand Up @@ -389,7 +388,7 @@ private static CompletionStage<Void> replace(
Object[] original,
Object[] target,
Type[] types,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache,
int i,
Expand Down Expand Up @@ -435,7 +434,7 @@ private static CompletionStage<Void> replace(
Object[] original,
Object[] target,
Type[] types,
SessionImplementor session,
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.entity.EntityPersister;
Expand Down Expand Up @@ -48,7 +47,7 @@ public final class ForeignKeys {
public static class Nullifier {
private final boolean isDelete;
private final boolean isEarlyInsert;
private final SessionImplementor session;
private final SharedSessionContractImplementor session;
private final Object self;
private final EntityPersister persister;

Expand All @@ -65,7 +64,7 @@ public Nullifier(
final Object self,
final boolean isDelete,
final boolean isEarlyInsert,
final SessionImplementor session,
final SharedSessionContractImplementor session,
final EntityPersister persister) {
this.isDelete = isDelete;
this.isEarlyInsert = isEarlyInsert;
Expand Down Expand Up @@ -270,7 +269,7 @@ private CompletionStage<Boolean> isNullifiable(final String entityName, Object o
*
* @return {@code true} if the given entity is not transient (meaning it is either detached/persistent)
*/
public static CompletionStage<Boolean> isNotTransient(String entityName, Object entity, Boolean assumed, SessionImplementor session) {
public static CompletionStage<Boolean> isNotTransient(String entityName, Object entity, Boolean assumed, SharedSessionContractImplementor session) {
if ( isHibernateProxy( entity ) ) {
return trueFuture();
}
Expand All @@ -297,7 +296,7 @@ public static CompletionStage<Boolean> isNotTransient(String entityName, Object
*
* @return {@code true} if the given entity is transient (unsaved)
*/
public static CompletionStage<Boolean> isTransient(String entityName, Object entity, Boolean assumed, SessionImplementor session) {
public static CompletionStage<Boolean> isTransient(String entityName, Object entity, Boolean assumed, SharedSessionContractImplementor session) {
if ( entity == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
// an unfetched association can only point to
// an entity that already exists in the db
Expand Down Expand Up @@ -350,7 +349,7 @@ public static CompletionStage<Boolean> isTransient(String entityName, Object ent
public static CompletionStage<Object> getEntityIdentifierIfNotUnsaved(
final String entityName,
final Object object,
final SessionImplementor session) throws TransientObjectException {
final SharedSessionContractImplementor session) throws TransientObjectException {
if ( object == null ) {
return nullFuture();
}
Expand Down Expand Up @@ -387,7 +386,7 @@ public static CompletionStage<NonNullableTransientDependencies> findNonNullableT

final EntityPersister persister = session.getEntityPersister( entityName, entity );
final Type[] types = persister.getPropertyTypes();
final Nullifier nullifier = new Nullifier( entity, false, isEarlyInsert, (SessionImplementor) session, persister );
final Nullifier nullifier = new Nullifier( entity, false, isEarlyInsert, session, persister );
final String[] propertyNames = persister.getPropertyNames();
final boolean[] nullability = persister.getPropertyNullability();
final NonNullableTransientDependencies nonNullableTransientEntities = new NonNullableTransientDependencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.hibernate.engine.spi.EntityHolder;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.persister.entity.EntityPersister;
Expand Down Expand Up @@ -64,7 +63,7 @@ public interface ReactiveEntityInsertAction extends ReactiveExecutable, Comparab
// @see org.hibernate.action.internal.AbstractEntityInsertAction#nullifyTransientReferencesIfNotAlready()
default CompletionStage<Void> reactiveNullifyTransientReferencesIfNotAlready() {
if ( !areTransientReferencesNullified() ) {
return new ForeignKeys.Nullifier( getInstance(), false, isEarlyInsert(), (SessionImplementor) getSession(), getPersister() )
return new ForeignKeys.Nullifier( getInstance(), false, isEarlyInsert(), getSession(), getPersister() )
.nullifyTransientReferences( getState() )
.thenAccept( v -> {
new Nullability( getSession() ).checkNullability( getState(), getPersister(), false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public interface ReactiveSession extends ReactiveQueryProducer, ReactiveSharedSe

ReactiveActionQueue getReactiveActionQueue();

@Override
SessionImplementor getSharedContract();

<E,T> CompletionStage<T> reactiveFetch(E entity, Attribute<E,T> field);
Expand Down
Loading