Skip to content
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 @@ -16,23 +16,23 @@
*
* @author Steve Ebersole
*/
public abstract class AbstractTransactionCompletionProcessQueue<T extends CompletionCallback> {
protected SharedSessionContractImplementor session;
abstract class AbstractTransactionCompletionProcessQueue<T extends CompletionCallback> {
SharedSessionContractImplementor session;
// Concurrency handling required when transaction completion process is dynamically registered
// inside event listener (HHH-7478).
protected ConcurrentLinkedQueue<@NonNull T> processes = new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<@NonNull T> processes = new ConcurrentLinkedQueue<>();

protected AbstractTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
AbstractTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
this.session = session;
}

public void register(@Nullable T process) {
void register(@Nullable T process) {
if ( process != null ) {
processes.add( process );
}
}

public boolean hasActions() {
boolean hasActions() {
return !processes.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
/**
* Encapsulates behavior needed for after transaction processing
*/
public class AfterTransactionCompletionProcessQueue
class AfterTransactionCompletionProcessQueue
extends AbstractTransactionCompletionProcessQueue<AfterCompletionCallback> {

private final Set<String> querySpacesToInvalidate = new HashSet<>();

public AfterTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
AfterTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
super( session );
}

public void addSpaceToInvalidate(String space) {
void addSpaceToInvalidate(String space) {
querySpacesToInvalidate.add( space );
}

@Override
public boolean hasActions() {
boolean hasActions() {
return super.hasActions() || !querySpacesToInvalidate.isEmpty();
}

public void afterTransactionCompletion(boolean success) {
void afterTransactionCompletion(boolean success) {
AfterCompletionCallback process;
while ( (process = processes.poll()) != null ) {
try {
Expand All @@ -61,7 +61,7 @@ public void afterTransactionCompletion(boolean success) {
querySpacesToInvalidate.clear();
}

public void executePendingBulkOperationCleanUpActions() {
void executePendingBulkOperationCleanUpActions() {
AfterCompletionCallback process;
boolean hasPendingBulkOperationCleanUpActions = false;
while ( ( process = processes.poll() ) != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
/**
* Encapsulates behavior needed for before transaction processing
*/
public class BeforeTransactionCompletionProcessQueue
class BeforeTransactionCompletionProcessQueue
extends AbstractTransactionCompletionProcessQueue<BeforeCompletionCallback> {

public BeforeTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
BeforeTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {
super( session );
}

public void beforeTransactionCompletion() {
void beforeTransactionCompletion() {
BeforeCompletionCallback process;
while ( (process = processes.poll()) != null ) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*
* @author Steve Ebersole
*/
public class EntityEntryContext {
class EntityEntryContext {

private final transient PersistenceContext persistenceContext;

Expand All @@ -63,7 +63,7 @@ public class EntityEntryContext {
/**
* Constructs a EntityEntryContext
*/
public EntityEntryContext(PersistenceContext persistenceContext) {
EntityEntryContext(PersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext;
}

Expand All @@ -73,7 +73,7 @@ public EntityEntryContext(PersistenceContext persistenceContext) {
* @param entity The entity
* @param entityEntry The entry
*/
public void addEntityEntry(Object entity, EntityEntry entityEntry) {
void addEntityEntry(Object entity, EntityEntry entityEntry) {
// IMPORTANT!!!!!
// add is called more than once of some entities. In such cases the first
// call is simply setting up a "marker" to avoid infinite looping from reentrancy
Expand Down Expand Up @@ -233,7 +233,7 @@ private void checkNotAssociatedWithOtherPersistenceContextIfMutable(ManagedEntit
*
* @return {@code true} if it is associated with this context
*/
public boolean hasEntityEntry(Object entity) {
boolean hasEntityEntry(Object entity) {
return getEntityEntry( entity ) != null;
}

Expand All @@ -244,7 +244,7 @@ public boolean hasEntityEntry(Object entity) {
*
* @return The associated {@link EntityEntry}
*/
public EntityEntry getEntityEntry(Object entity) {
EntityEntry getEntityEntry(Object entity) {
// locate a ManagedEntity for the entity, but only if it is associated with the same PersistenceContext.
final var managedEntity = getAssociatedManagedEntity( entity );
// and get/return the EntityEntry from the ManagedEntry
Expand All @@ -260,7 +260,7 @@ public EntityEntry getEntityEntry(Object entity) {
*
* @return The removed {@link EntityEntry}
*/
public EntityEntry removeEntityEntry(Object entity) {
EntityEntry removeEntityEntry(Object entity) {
// locate a ManagedEntity for the entity, but only if it is associated with the same PersistenceContext.
// no need to check if the entity is a ManagedEntity that is associated with a different PersistenceContext
final var managedEntity = getAssociatedManagedEntity( entity );
Expand Down Expand Up @@ -335,7 +335,7 @@ else if ( !isManagedEntity( entity ) ) {
*
* @return The safe array
*/
public Map.Entry<Object, EntityEntry>[] reentrantSafeEntityEntries() {
Map.Entry<Object, EntityEntry>[] reentrantSafeEntityEntries() {
if ( dirty ) {
reentrantSafeEntries = new EntityEntryCrossRefImpl[count];
int i = 0;
Expand Down Expand Up @@ -758,7 +758,7 @@ private static boolean canClearEntityEntryReference(EntityEntry entityEntry) {
/**
* Used in building the {@link #reentrantSafeEntityEntries()} entries
*/
public interface EntityEntryCrossRef extends Map.Entry<Object,EntityEntry> {
private interface EntityEntryCrossRef extends Map.Entry<Object,EntityEntry> {
/**
* The entity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
*
* @author Emmanuel Bernard
*/
public class EntityEntryExtraStateHolder implements EntityEntryExtraState {
class EntityEntryExtraStateHolder implements EntityEntryExtraState {
private EntityEntryExtraState next;
private Object[] deletedState;

public Object[] getDeletedState() {
Object[] getDeletedState() {
return deletedState;
}

public void setDeletedState(Object[] deletedState) {
void setDeletedState(Object[] deletedState) {
this.deletedState = deletedState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ public void serialize(ObjectOutputStream oos) throws IOException {
/**
* Custom deserialization routine used during deserialization
* of a {@link PersistenceContext} for increased performance.
* <p>
* This method is called reflectively by {@link EntityEntryContext}.
*
* @param ois The stream from which to read the entry
* @param persistenceContext The context being deserialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.hibernate.engine.internal.CacheHelper.fromSharedCache;
import static org.hibernate.engine.internal.NaturalIdLogging.NATURAL_ID_LOGGER;

public class NaturalIdResolutionsImpl implements NaturalIdResolutions, Serializable {
class NaturalIdResolutionsImpl implements NaturalIdResolutions, Serializable {

private final StatefulPersistenceContext persistenceContext;
private final ConcurrentHashMap<EntityMappingType, EntityResolutions> resolutionsByEntity = new ConcurrentHashMap<>();
Expand All @@ -50,7 +50,7 @@ public class NaturalIdResolutionsImpl implements NaturalIdResolutions, Serializa
*
* @return The session
*/
protected SharedSessionContractImplementor session() {
private SharedSessionContractImplementor session() {
return persistenceContext.getSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
package org.hibernate.engine.internal;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import org.hibernate.SessionEventListener;
import org.hibernate.engine.spi.SessionEventListenerManager;

import static java.lang.System.arraycopy;
import static java.util.Arrays.copyOf;
import static java.util.Objects.requireNonNull;

/**
* @author Steve Ebersole
*/
Expand All @@ -21,28 +23,28 @@ public class SessionEventListenerManagerImpl implements SessionEventListenerMana

public SessionEventListenerManagerImpl(SessionEventListener... initialListener) {
//no need for defensive copies until the array is mutated:
this.listeners = initialListener;
listeners = initialListener;
}

public SessionEventListenerManagerImpl(List<SessionEventListener> initialListener) {
//no need for defensive copies until the array is mutated:
this.listeners = initialListener.toArray( new SessionEventListener[0] );
listeners = initialListener.toArray( new SessionEventListener[0] );
}

@Override
public void addListener(final SessionEventListener... additionalListeners) {
Objects.requireNonNull( additionalListeners );
final var existing = this.listeners;
requireNonNull( additionalListeners );
final var existing = listeners;
if ( existing == null ) {
//Make a defensive copy as this array can be tracked back to API (user code)
this.listeners = Arrays.copyOf( additionalListeners, additionalListeners.length );
listeners = copyOf( additionalListeners, additionalListeners.length );
}
else {
// Resize our existing array and add the new listeners
final var newList = new SessionEventListener[ existing.length + additionalListeners.length ];
System.arraycopy( existing, 0, newList, 0, existing.length );
System.arraycopy( additionalListeners, 0, newList, existing.length, additionalListeners.length );
this.listeners = newList;
arraycopy( existing, 0, newList, 0, existing.length );
arraycopy( additionalListeners, 0, newList, existing.length, additionalListeners.length );
listeners = newList;
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl;
import org.hibernate.cache.spi.entry.StandardCacheEntryImpl;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand Down Expand Up @@ -228,7 +227,7 @@ private static void makeEntityCircularReferenceSafe(
entityHolder.setEntityEntry( entityEntry );
}
else {
TwoPhaseLoad.addUninitializedCachedEntity(
addUninitializedCachedEntity(
entityKey,
entity,
referenceCacheEntry.getSubclassPersister(),
Expand Down Expand Up @@ -415,6 +414,46 @@ private static Object getFromSharedCache(
return cachedEntry;
}

/**
*
* @param key The entity key
* @param object The entity instance
* @param persister The entity persister
* @param lockMode The lock mode
* @param version The version
* @param session The Session
*/
static void addUninitializedCachedEntity(
final EntityKey key,
final Object object,
final EntityPersister persister,
final LockMode lockMode,
final Object version,
final SharedSessionContractImplementor session) {
final var persistenceContext = session.getPersistenceContextInternal();
final var entityHolder = persistenceContext.addEntityHolder( key, object );
final var entityEntry = persistenceContext.addEntry(
object,
Status.LOADING,
null,
null,
key.getIdentifier(),
version,
lockMode,
true,
persister,
false
);
entityHolder.setEntityEntry( entityEntry );
final Object proxy = entityHolder.getProxy();
if ( proxy != null ) {
// there is already a proxy for this impl
final var lazyInitializer = extractLazyInitializer( proxy );
assert lazyInitializer != null;
lazyInitializer.setImplementation( object );
}
}

public record PersistenceContextEntry(Object entity, EntityStatus status) {
public enum EntityStatus {
MANAGED,
Expand Down
Loading