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 @@ -7,7 +7,9 @@
import org.hibernate.HibernateException;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventManager;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.HibernateMonitoringEvent;
import org.hibernate.event.spi.PostCollectionRecreateEvent;
import org.hibernate.event.spi.PostCollectionRecreateEventListener;
import org.hibernate.event.spi.PreCollectionRecreateEvent;
Expand Down Expand Up @@ -42,14 +44,26 @@ public void execute() throws HibernateException {
final PersistentCollection<?> collection = getCollection();
preRecreate();
final SharedSessionContractImplementor session = getSession();
getPersister().recreate( collection, getKey(), session);
final CollectionPersister persister = getPersister();
final Object key = getKey();
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginCollectionRecreateEvent();
boolean success = false;
try {
persister.recreate( collection, key, session );
success = true;
}
finally {
eventManager.completeCollectionRecreateEvent( event, key, persister.getRole(), success, session );
}

session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
evict();
postRecreate();

final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.recreateCollection( getPersister().getRole() );
statistics.recreateCollection( persister.getRole() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.hibernate.HibernateException;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventManager;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.HibernateMonitoringEvent;
import org.hibernate.event.spi.PostCollectionRemoveEvent;
import org.hibernate.event.spi.PostCollectionRemoveEventListener;
import org.hibernate.event.spi.PreCollectionRemoveEvent;
Expand Down Expand Up @@ -108,8 +110,20 @@ public void execute() throws HibernateException {
// is replaced by null or a different collection
// (if the collection is uninitialized, Hibernate has no way of
// knowing if the collection is actually empty without querying the db)
getPersister().remove( getKey(), session );
final CollectionPersister persister = getPersister();
final Object key = getKey();
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginCollectionRemoveEvent();
boolean success = false;
try {
persister.remove( key, session );
success = true;
}
finally {
eventManager.completeCollectionRemoveEvent( event, key, persister.getRole(), success, session );
}
}

final PersistentCollection<?> collection = getCollection();
if ( collection != null ) {
session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
Expand All @@ -130,12 +144,7 @@ private void preRemove() {
}

private PreCollectionRemoveEvent newPreCollectionRemoveEvent() {
return new PreCollectionRemoveEvent(
getPersister(),
getCollection(),
eventSource(),
affectedOwner
);
return new PreCollectionRemoveEvent( getPersister(), getCollection(), eventSource(), affectedOwner );
}

private void postRemove() {
Expand All @@ -145,12 +154,7 @@ private void postRemove() {
}

private PostCollectionRemoveEvent newPostCollectionRemoveEvent() {
return new PostCollectionRemoveEvent(
getPersister(),
getCollection(),
eventSource(),
affectedOwner
);
return new PostCollectionRemoveEvent( getPersister(), getCollection(), eventSource(), affectedOwner );
}

public Object getAffectedOwner() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.hibernate.HibernateException;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventManager;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.HibernateMonitoringEvent;
import org.hibernate.event.spi.PostCollectionUpdateEvent;
import org.hibernate.event.spi.PostCollectionUpdateEventListener;
import org.hibernate.event.spi.PreCollectionUpdateEvent;
Expand Down Expand Up @@ -45,7 +47,7 @@ public CollectionUpdateAction(

@Override
public void execute() throws HibernateException {
final Object id = getKey();
final Object key = getKey();
final SharedSessionContractImplementor session = getSession();
final CollectionPersister persister = getPersister();
final PersistentCollection<?> collection = getCollection();
Expand All @@ -54,34 +56,45 @@ public void execute() throws HibernateException {
preUpdate();

if ( !collection.wasInitialized() ) {
// If there were queued operations, they would have been processed
// and cleared by now.
// The collection should still be dirty.
// If there were queued operations, they would have
// been processed and cleared by now.
if ( !collection.isDirty() ) {
// The collection should still be dirty.
throw new AssertionFailure( "collection is not dirty" );
}
//do nothing - we only need to notify the cache...
// Do nothing - we only need to notify the cache
}
else if ( !affectedByFilters && collection.empty() ) {
if ( !emptySnapshot ) {
persister.remove( id, session );
}
}
else if ( collection.needsRecreate( persister ) ) {
if ( affectedByFilters ) {
throw new HibernateException( "cannot recreate collection while filter is enabled: "
+ collectionInfoString( persister, collection, id, session )
);
else {
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginCollectionUpdateEvent();
boolean success = false;
try {
if ( !affectedByFilters && collection.empty() ) {
if ( !emptySnapshot ) {
persister.remove( key, session );
}
//TODO: else we really shouldn't have sent an update event to JFR
}
else if ( collection.needsRecreate( persister ) ) {
if ( affectedByFilters ) {
throw new HibernateException( "cannot recreate collection while filter is enabled: "
+ collectionInfoString( persister, collection, key, session ) );
}
if ( !emptySnapshot ) {
persister.remove( key, session );
}
persister.recreate( collection, key, session );
}
else {
persister.deleteRows( collection, key, session );
persister.updateRows( collection, key, session );
persister.insertRows( collection, key, session );
}
success = true;
}
if ( !emptySnapshot ) {
persister.remove( id, session );
finally {
eventManager.completeCollectionUpdateEvent( event, key, persister.getRole(), success, session );
}
persister.recreate( collection, id, session );
}
else {
persister.deleteRows( collection, id, session );
persister.updateRows( collection, id, session );
persister.insertRows( collection, id, session );
}

session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
Expand All @@ -101,11 +114,7 @@ private void preUpdate() {
}

private PreCollectionUpdateEvent newPreCollectionUpdateEvent() {
return new PreCollectionUpdateEvent(
getPersister(),
getCollection(),
eventSource()
);
return new PreCollectionUpdateEvent( getPersister(), getCollection(), eventSource() );
}

private void postUpdate() {
Expand All @@ -115,11 +124,7 @@ private void postUpdate() {
}

private PostCollectionUpdateEvent newPostCollectionUpdateEvent() {
return new PostCollectionUpdateEvent(
getPersister(),
getCollection(),
eventSource()
);
return new PostCollectionUpdateEvent( getPersister(), getCollection(), eventSource() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.spi.EventManager;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.HibernateMonitoringEvent;
import org.hibernate.event.spi.PostCommitDeleteEventListener;
import org.hibernate.event.spi.PostDeleteEvent;
import org.hibernate.event.spi.PostDeleteEventListener;
Expand Down Expand Up @@ -126,7 +128,16 @@ public void execute() throws HibernateException {
final Object ck = lockCacheItem();

if ( !isCascadeDeleteEnabled && !veto ) {
persister.getDeleteCoordinator().delete( instance, id, version, session );
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginEntityDeleteEvent();
boolean success = false;
try {
persister.getDeleteCoordinator().delete( instance, id, version, session );
success = true;
}
finally {
eventManager.completeEntityDeleteEvent( event, id, persister.getEntityName(), success, session );
}
}

if ( isInstanceLoaded() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.spi.EventManager;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.HibernateMonitoringEvent;
import org.hibernate.event.spi.PostCommitInsertEventListener;
import org.hibernate.event.spi.PostInsertEvent;
import org.hibernate.event.spi.PostInsertEventListener;
Expand Down Expand Up @@ -80,12 +82,18 @@ public void execute() throws HibernateException {
// else inserted the same pk first, the insert would fail

if ( !isVeto() ) {
final GeneratedValues generatedValues = persister.getInsertCoordinator().insert(
instance,
getState(),
session
);
generatedId = castNonNull( generatedValues ).getGeneratedValue( persister.getIdentifierMapping() );
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginEntityInsertEvent();
boolean success = false;
final GeneratedValues generatedValues;
try {
generatedValues = persister.getInsertCoordinator().insert( instance, getState(), session );
generatedId = castNonNull( generatedValues ).getGeneratedValue( persister.getIdentifierMapping() );
success = true;
}
finally {
eventManager.completeEntityInsertEvent( event, generatedId, persister.getEntityName(), success, session );
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( persister.getRowIdMapping() != null ) {
rowId = generatedValues.getGeneratedValue( persister.getRowIdMapping() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ public void execute() throws HibernateException {
if ( !veto ) {
final EntityPersister persister = getPersister();
final Object instance = getInstance();
final GeneratedValues generatedValues = persister.getInsertCoordinator().insert(
instance,
id,
getState(),
session
);
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginEntityInsertEvent();
boolean success = false;
final GeneratedValues generatedValues;
try {
generatedValues = persister.getInsertCoordinator().insert( instance, id, getState(), session );
success = true;
}
finally {
eventManager.completeEntityInsertEvent( event, id, persister.getEntityName(), success, session );
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( instance );
if ( entry == null ) {
Expand Down Expand Up @@ -181,7 +186,7 @@ protected void putCacheIfNecessary() {
}

protected boolean cacheInsert(EntityPersister persister, Object ck) {
SharedSessionContractImplementor session = getSession();
final SharedSessionContractImplementor session = getSession();
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent cachePutEvent = eventManager.beginCachePutEvent();
final EntityDataAccess cacheAccessStrategy = persister.getCacheAccessStrategy();
Expand Down Expand Up @@ -227,8 +232,8 @@ protected void postCommitInsert(boolean success) {
}

private void postCommitOnFailure(PostInsertEventListener listener, PostInsertEvent event) {
if ( listener instanceof PostCommitInsertEventListener ) {
((PostCommitInsertEventListener) listener).onPostInsertCommitFailed( event );
if ( listener instanceof PostCommitInsertEventListener postCommitInsertEventListener ) {
postCommitInsertEventListener.onPostInsertCommitFailed( event );
}
else {
//default to the legacy implementation that always fires the event
Expand Down Expand Up @@ -257,7 +262,7 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
final EntityPersister persister = getPersister();
if ( success && isCachePutEnabled( persister, getSession() ) ) {
final EntityDataAccess cache = persister.getCacheAccessStrategy();
SessionFactoryImplementor factory = session.getFactory();
final SessionFactoryImplementor factory = session.getFactory();
final Object ck = cache.generateCacheKey( getId(), persister, factory, session.getTenantIdentifier() );
final boolean put = cacheAfterInsert( cache, ck );

Expand All @@ -273,7 +278,7 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
}

protected boolean cacheAfterInsert(EntityDataAccess cache, Object ck) {
SharedSessionContractImplementor session = getSession();
final SharedSessionContractImplementor session = getSession();
final SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent cachePutEvent = eventManager.beginCachePutEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,27 @@ public void execute() throws HibernateException {
final Object instance = getInstance();
final Object previousVersion = getPreviousVersion();
final Object ck = lockCacheItem( previousVersion );
final GeneratedValues generatedValues = persister.getUpdateCoordinator().update(
instance,
id,
rowId,
state,
previousVersion,
previousState,
dirtyFields,
hasDirtyCollection,
session
);
final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent event = eventManager.beginEntityUpdateEvent();
boolean success = false;
final GeneratedValues generatedValues;
try {
generatedValues = persister.getUpdateCoordinator().update(
instance,
id,
rowId,
state,
previousVersion,
previousState,
dirtyFields,
hasDirtyCollection,
session
);
success = true;
}
finally {
eventManager.completeEntityUpdateEvent( event, id, persister.getEntityName(), success, session );
}
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible non thread safe access to session" );
Expand Down
Loading
Loading