HHH-7387 - Integrate Draft 6 of the JPA 2.1 spec : CDI (small test change)
This commit is contained in:
parent
c9ff6f2fe2
commit
4282e23caa
|
@ -37,6 +37,7 @@ import org.hibernate.event.service.spi.EventListenerGroup;
|
||||||
import org.hibernate.event.spi.EventType;
|
import org.hibernate.event.spi.EventType;
|
||||||
import org.hibernate.event.spi.PostDeleteEvent;
|
import org.hibernate.event.spi.PostDeleteEvent;
|
||||||
import org.hibernate.event.spi.PostDeleteEventListener;
|
import org.hibernate.event.spi.PostDeleteEventListener;
|
||||||
|
import org.hibernate.event.spi.PostInsertEventListener;
|
||||||
import org.hibernate.event.spi.PreDeleteEvent;
|
import org.hibernate.event.spi.PreDeleteEvent;
|
||||||
import org.hibernate.event.spi.PreDeleteEventListener;
|
import org.hibernate.event.spi.PreDeleteEventListener;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
@ -189,6 +190,13 @@ public final class EntityDeleteAction extends EntityAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasPostCommitEventListeners() {
|
protected boolean hasPostCommitEventListeners() {
|
||||||
return ! listenerGroup( EventType.POST_COMMIT_DELETE ).isEmpty();
|
final EventListenerGroup<PostDeleteEventListener> group = listenerGroup( EventType.POST_COMMIT_DELETE );
|
||||||
|
for ( PostDeleteEventListener listener : group.listeners() ) {
|
||||||
|
if ( listener.requiresPostCommitHanding( getPersister() ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,14 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasPostCommitEventListeners() {
|
protected boolean hasPostCommitEventListeners() {
|
||||||
return ! listenerGroup( EventType.POST_COMMIT_INSERT ).isEmpty();
|
final EventListenerGroup<PostInsertEventListener> group = listenerGroup( EventType.POST_COMMIT_INSERT );
|
||||||
|
for ( PostInsertEventListener listener : group.listeners() ) {
|
||||||
|
if ( listener.requiresPostCommitHanding( getPersister() ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -204,7 +204,14 @@ public final class EntityInsertAction extends AbstractEntityInsertAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasPostCommitEventListeners() {
|
protected boolean hasPostCommitEventListeners() {
|
||||||
return ! listenerGroup( EventType.POST_COMMIT_INSERT ).isEmpty();
|
final EventListenerGroup<PostInsertEventListener> group = listenerGroup( EventType.POST_COMMIT_INSERT );
|
||||||
|
for ( PostInsertEventListener listener : group.listeners() ) {
|
||||||
|
if ( listener.requiresPostCommitHanding( getPersister() ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCachePutEnabled(EntityPersister persister, SessionImplementor session) {
|
private boolean isCachePutEnabled(EntityPersister persister, SessionImplementor session) {
|
||||||
|
|
|
@ -277,7 +277,14 @@ public final class EntityUpdateAction extends EntityAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasPostCommitEventListeners() {
|
protected boolean hasPostCommitEventListeners() {
|
||||||
return ! listenerGroup( EventType.POST_COMMIT_UPDATE ).isEmpty();
|
final EventListenerGroup<PostUpdateEventListener> group = listenerGroup( EventType.POST_COMMIT_UPDATE );
|
||||||
|
for ( PostUpdateEventListener listener : group.listeners() ) {
|
||||||
|
if ( listener.requiresPostCommitHanding( getPersister() ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,8 @@ package org.hibernate.event.spi;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after deleting an item from the datastore
|
* Called after deleting an item from the datastore
|
||||||
*
|
*
|
||||||
|
@ -32,4 +34,6 @@ import java.io.Serializable;
|
||||||
*/
|
*/
|
||||||
public interface PostDeleteEventListener extends Serializable {
|
public interface PostDeleteEventListener extends Serializable {
|
||||||
public void onPostDelete(PostDeleteEvent event);
|
public void onPostDelete(PostDeleteEvent event);
|
||||||
|
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,25 @@ package org.hibernate.event.spi;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after insterting an item in the datastore
|
* Called after insterting an item in the datastore
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface PostInsertEventListener extends Serializable {
|
public interface PostInsertEventListener extends Serializable {
|
||||||
public void onPostInsert(PostInsertEvent event);
|
public void onPostInsert(PostInsertEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this listener require that after transaction hooks be registered? Typically this is {@code true}
|
||||||
|
* for post-insert event listeners, but may not be, for example, in JPA cases where there are no callbacks defined
|
||||||
|
* for the particular entity.
|
||||||
|
*
|
||||||
|
* @param persister The persister for the entity in question.
|
||||||
|
*
|
||||||
|
* @return {@code true} if after transaction callbacks should be added.
|
||||||
|
*/
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ package org.hibernate.event.spi;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after updating the datastore
|
* Called after updating the datastore
|
||||||
*
|
*
|
||||||
|
@ -32,4 +34,6 @@ import java.io.Serializable;
|
||||||
*/
|
*/
|
||||||
public interface PostUpdateEventListener extends Serializable {
|
public interface PostUpdateEventListener extends Serializable {
|
||||||
public void onPostUpdate(PostUpdateEvent event);
|
public void onPostUpdate(PostUpdateEvent event);
|
||||||
|
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.hibernate.IrrelevantEntity;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
|
@ -241,12 +243,20 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
EventListenerRegistry eventListenerRegistry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
EventListenerRegistry eventListenerRegistry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
||||||
//register a post commit listener
|
//register a post commit listener
|
||||||
eventListenerRegistry.appendListeners( EventType.POST_COMMIT_INSERT, new PostInsertEventListener(){
|
eventListenerRegistry.appendListeners(
|
||||||
|
EventType.POST_COMMIT_INSERT,
|
||||||
|
new PostInsertEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPostInsert(PostInsertEvent event) {
|
public void onPostInsert(PostInsertEvent event) {
|
||||||
((IrrelevantEntity) event.getEntity()).setName( postCommitMessage );
|
((IrrelevantEntity) event.getEntity()).setName( postCommitMessage );
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ import org.hibernate.jpa.boot.spi.IntegratorProvider;
|
||||||
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
||||||
import org.hibernate.jpa.internal.EntityManagerFactoryImpl;
|
import org.hibernate.jpa.internal.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
|
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
|
||||||
import org.hibernate.jpa.internal.event.JpaIntegrator;
|
import org.hibernate.jpa.event.spi.JpaIntegrator;
|
||||||
import org.hibernate.jpa.internal.util.LogHelper;
|
import org.hibernate.jpa.internal.util.LogHelper;
|
||||||
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
|
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
|
||||||
import org.hibernate.jpa.packaging.internal.NativeScanner;
|
import org.hibernate.jpa.packaging.internal.NativeScanner;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marker interface for handling listener duplication checking (to avoid multiple registrations).
|
* Marker interface for handling listener duplication checking (to avoid multiple registrations).
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
|
|
@ -21,15 +21,15 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.event.internal.DefaultDeleteEventListener;
|
import org.hibernate.event.internal.DefaultDeleteEventListener;
|
||||||
import org.hibernate.event.spi.DeleteEvent;
|
import org.hibernate.event.spi.DeleteEvent;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -21,15 +21,15 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
|
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.event.internal.DefaultMergeEventListener;
|
import org.hibernate.event.internal.DefaultMergeEventListener;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -34,8 +34,8 @@ import org.hibernate.engine.spi.CascadingAction;
|
||||||
import org.hibernate.engine.spi.CascadingActions;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.event.internal.DefaultPersistEventListener;
|
import org.hibernate.event.internal.DefaultPersistEventListener;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
import org.hibernate.type.CollectionType;
|
import org.hibernate.type.CollectionType;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
import org.hibernate.engine.spi.CascadingActions;
|
import org.hibernate.engine.spi.CascadingActions;
|
|
@ -21,18 +21,19 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.event.spi.PostDeleteEvent;
|
import org.hibernate.event.spi.PostDeleteEvent;
|
||||||
import org.hibernate.event.spi.PostDeleteEventListener;
|
import org.hibernate.event.spi.PostDeleteEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
||||||
*/
|
*/
|
||||||
public class JpaPostDeleteEventListener implements PostDeleteEventListener, CallbackRegistryConsumer {
|
public class JpaPostDeleteEventListener implements PostDeleteEventListener, CallbackRegistryConsumer {
|
||||||
CallbackRegistry callbackRegistry;
|
private CallbackRegistry callbackRegistry;
|
||||||
|
|
||||||
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
||||||
this.callbackRegistry = callbackRegistry;
|
this.callbackRegistry = callbackRegistry;
|
||||||
|
@ -51,4 +52,8 @@ public class JpaPostDeleteEventListener implements PostDeleteEventListener, Call
|
||||||
callbackRegistry.postRemove( entity );
|
callbackRegistry.postRemove( entity );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return callbackRegistry.hasPostRemoveCallbacks( persister.getMappedClass() );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,18 +21,20 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.event.spi.PostInsertEvent;
|
import org.hibernate.event.spi.PostInsertEvent;
|
||||||
import org.hibernate.event.spi.PostInsertEventListener;
|
import org.hibernate.event.spi.PostInsertEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
||||||
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class JpaPostInsertEventListener implements PostInsertEventListener, CallbackRegistryConsumer {
|
public class JpaPostInsertEventListener implements PostInsertEventListener, CallbackRegistryConsumer {
|
||||||
CallbackRegistry callbackRegistry;
|
private CallbackRegistry callbackRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
||||||
|
@ -52,4 +54,9 @@ public class JpaPostInsertEventListener implements PostInsertEventListener, Call
|
||||||
Object entity = event.getEntity();
|
Object entity = event.getEntity();
|
||||||
callbackRegistry.postCreate( entity );
|
callbackRegistry.postCreate( entity );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return callbackRegistry.hasPostCreateCallbacks( persister.getMappedClass() );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,12 +21,12 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.event.spi.PostLoadEvent;
|
import org.hibernate.event.spi.PostLoadEvent;
|
||||||
import org.hibernate.event.spi.PostLoadEventListener;
|
import org.hibernate.event.spi.PostLoadEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
|
@ -34,8 +34,9 @@ import org.hibernate.event.spi.PostCollectionUpdateEvent;
|
||||||
import org.hibernate.event.spi.PostCollectionUpdateEventListener;
|
import org.hibernate.event.spi.PostCollectionUpdateEventListener;
|
||||||
import org.hibernate.event.spi.PostUpdateEvent;
|
import org.hibernate.event.spi.PostUpdateEvent;
|
||||||
import org.hibernate.event.spi.PostUpdateEventListener;
|
import org.hibernate.event.spi.PostUpdateEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the post update listeners.
|
* Implementation of the post update listeners.
|
||||||
|
@ -49,7 +50,7 @@ public class JpaPostUpdateEventListener
|
||||||
PostCollectionRecreateEventListener,
|
PostCollectionRecreateEventListener,
|
||||||
PostCollectionRemoveEventListener,
|
PostCollectionRemoveEventListener,
|
||||||
PostCollectionUpdateEventListener {
|
PostCollectionUpdateEventListener {
|
||||||
CallbackRegistry callbackRegistry;
|
private CallbackRegistry callbackRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
|
||||||
|
@ -80,6 +81,11 @@ public class JpaPostUpdateEventListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return callbackRegistry.hasPostUpdateCallbacks( persister.getMappedClass() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
|
public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
|
||||||
Object entity = event.getCollection().getOwner();
|
Object entity = event.getCollection().getOwner();
|
|
@ -21,14 +21,14 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.event.internal.DefaultSaveEventListener;
|
import org.hibernate.event.internal.DefaultSaveEventListener;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
|
@ -21,14 +21,14 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.event.internal.DefaultSaveOrUpdateEventListener;
|
import org.hibernate.event.internal.DefaultSaveOrUpdateEventListener;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.core;
|
package org.hibernate.jpa.event.internal.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate EntityManager specific implementations of Hibernate event listeners. Generally the listeners
|
* Hibernate EntityManager specific implementations of Hibernate event listeners. Generally the listeners
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import javax.enterprise.context.spi.CreationalContext;
|
import javax.enterprise.context.spi.CreationalContext;
|
||||||
import javax.enterprise.inject.spi.AnnotatedType;
|
import javax.enterprise.inject.spi.AnnotatedType;
|
||||||
|
@ -30,6 +30,8 @@ import javax.enterprise.inject.spi.InjectionTarget;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CID-based implementation of the ListenerFactory contract. Listener instances are kept in a map keyed by Class
|
* CID-based implementation of the ListenerFactory contract. Listener instances are kept in a map keyed by Class
|
||||||
* to achieve singleton-ness.
|
* to achieve singleton-ness.
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import javax.persistence.PostLoad;
|
import javax.persistence.PostLoad;
|
||||||
import javax.persistence.PostPersist;
|
import javax.persistence.PostPersist;
|
||||||
|
@ -52,7 +52,7 @@ public interface CallbackProcessor {
|
||||||
* @param entityObject
|
* @param entityObject
|
||||||
* @param registry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
public void processCallbacksForEntity(Object entityObject, CallbackRegistry registry);
|
public void processCallbacksForEntity(Object entityObject, CallbackRegistryImpl registry);
|
||||||
|
|
||||||
public void release();
|
public void release();
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -30,6 +30,9 @@ import java.util.List;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.Callback;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
import org.hibernate.metamodel.source.binder.JpaCallbackClass;
|
import org.hibernate.metamodel.source.binder.JpaCallbackClass;
|
||||||
|
@ -58,7 +61,7 @@ public class CallbackProcessorImpl implements CallbackProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processCallbacksForEntity(Object entityObject, CallbackRegistry callbackRegistry) {
|
public void processCallbacksForEntity(Object entityObject, CallbackRegistryImpl callbackRegistry) {
|
||||||
final EntityBinding entityBinding = (EntityBinding) entityObject;
|
final EntityBinding entityBinding = (EntityBinding) entityObject;
|
||||||
final String entityClassName = entityBinding.getEntity().getClassName();
|
final String entityClassName = entityBinding.getEntity().getClassName();
|
||||||
if ( entityClassName == null ) {
|
if ( entityClassName == null ) {
|
|
@ -21,9 +21,10 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import org.hibernate.jpa.internal.event.core.HibernateEntityManagerEventListener;
|
import org.hibernate.jpa.event.internal.core.HibernateEntityManagerEventListener;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for injecting the registry of Callbacks into event listeners.
|
* Contract for injecting the registry of Callbacks into event listeners.
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.PostLoad;
|
import javax.persistence.PostLoad;
|
||||||
|
@ -31,9 +31,11 @@ import javax.persistence.PostUpdate;
|
||||||
import javax.persistence.PrePersist;
|
import javax.persistence.PrePersist;
|
||||||
import javax.persistence.PreRemove;
|
import javax.persistence.PreRemove;
|
||||||
import javax.persistence.PreUpdate;
|
import javax.persistence.PreUpdate;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.Callback;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of all lifecycle callbacks and listeners for a given persistence unit
|
* Keep track of all lifecycle callbacks and listeners for a given persistence unit
|
||||||
*
|
*
|
||||||
|
@ -41,7 +43,7 @@ import java.util.HashMap;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "serial"})
|
@SuppressWarnings({"unchecked", "serial"})
|
||||||
public class CallbackRegistry implements Serializable {
|
public class CallbackRegistryImpl implements CallbackRegistry {
|
||||||
private HashMap<Class, Callback[]> preCreates = new HashMap<Class, Callback[]>();
|
private HashMap<Class, Callback[]> preCreates = new HashMap<Class, Callback[]>();
|
||||||
private HashMap<Class, Callback[]> postCreates = new HashMap<Class, Callback[]>();
|
private HashMap<Class, Callback[]> postCreates = new HashMap<Class, Callback[]>();
|
||||||
private HashMap<Class, Callback[]> preRemoves = new HashMap<Class, Callback[]>();
|
private HashMap<Class, Callback[]> preRemoves = new HashMap<Class, Callback[]>();
|
||||||
|
@ -50,30 +52,56 @@ public class CallbackRegistry implements Serializable {
|
||||||
private HashMap<Class, Callback[]> postUpdates = new HashMap<Class, Callback[]>();
|
private HashMap<Class, Callback[]> postUpdates = new HashMap<Class, Callback[]>();
|
||||||
private HashMap<Class, Callback[]> postLoads = new HashMap<Class, Callback[]>();
|
private HashMap<Class, Callback[]> postLoads = new HashMap<Class, Callback[]>();
|
||||||
|
|
||||||
public boolean preCreate(Object bean) {
|
@Override
|
||||||
return callback( preCreates.get( bean.getClass() ), bean );
|
public void preCreate(Object bean) {
|
||||||
|
callback( preCreates.get( bean.getClass() ), bean );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean postCreate(Object bean) {
|
@Override
|
||||||
return callback( postCreates.get( bean.getClass() ), bean );
|
public boolean hasPostCreateCallbacks(Class entityClass) {
|
||||||
|
return notEmpty( preCreates.get( entityClass ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean preRemove(Object bean) {
|
private boolean notEmpty(Callback[] callbacks) {
|
||||||
return callback( preRemoves.get( bean.getClass() ), bean );
|
return callbacks != null && callbacks.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean postRemove(Object bean) {
|
@Override
|
||||||
return callback( postRemoves.get( bean.getClass() ), bean );
|
public void postCreate(Object bean) {
|
||||||
|
callback( postCreates.get( bean.getClass() ), bean );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean preUpdate(Object bean) {
|
public boolean preUpdate(Object bean) {
|
||||||
return callback( preUpdates.get( bean.getClass() ), bean );
|
return callback( preUpdates.get( bean.getClass() ), bean );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean postUpdate(Object bean) {
|
@Override
|
||||||
return callback( postUpdates.get( bean.getClass() ), bean );
|
public boolean hasPostUpdateCallbacks(Class entityClass) {
|
||||||
|
return notEmpty( postUpdates.get( entityClass ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postUpdate(Object bean) {
|
||||||
|
callback( postUpdates.get( bean.getClass() ), bean );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preRemove(Object bean) {
|
||||||
|
callback( preRemoves.get( bean.getClass() ), bean );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPostRemoveCallbacks(Class entityClass) {
|
||||||
|
return notEmpty( postRemoves.get( entityClass ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRemove(Object bean) {
|
||||||
|
callback( postRemoves.get( bean.getClass() ), bean );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean postLoad(Object bean) {
|
public boolean postLoad(Object bean) {
|
||||||
return callback( postLoads.get( bean.getClass() ), bean );
|
return callback( postLoads.get( bean.getClass() ), bean );
|
||||||
}
|
}
|
||||||
|
@ -90,7 +118,14 @@ public class CallbackRegistry implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void addEntityCallbacks(Class entityClass, Class annotationClass, Callback[] callbacks) {
|
|
||||||
|
/**
|
||||||
|
* Great care should be taken calling this. Not a fan of it being public, but that is needed because of
|
||||||
|
* @param entityClass
|
||||||
|
* @param annotationClass
|
||||||
|
* @param callbacks
|
||||||
|
*/
|
||||||
|
public void addEntityCallbacks(Class entityClass, Class annotationClass, Callback[] callbacks) {
|
||||||
final HashMap<Class, Callback[]> map = determineAppropriateCallbackMap( annotationClass );
|
final HashMap<Class, Callback[]> map = determineAppropriateCallbackMap( annotationClass );
|
||||||
if ( map.containsKey( entityClass ) ) {
|
if ( map.containsKey( entityClass ) ) {
|
||||||
throw new PersistenceException( "Error build callback listeners; entity [" + entityClass.getName() + " was already processed" );
|
throw new PersistenceException( "Error build callback listeners; entity [" + entityClass.getName() + " was already processed" );
|
|
@ -21,11 +21,13 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a JPA callback on the entity itself
|
* Represents a JPA callback on the entity itself
|
||||||
*
|
*
|
||||||
|
@ -40,9 +42,10 @@ public class EntityCallback implements Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performCallback(Object entity) {
|
public boolean performCallback(Object entity) {
|
||||||
try {
|
try {
|
||||||
callbackMethod.invoke( entity );
|
callbackMethod.invoke( entity );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
//keep runtime exceptions as is
|
//keep runtime exceptions as is
|
||||||
|
@ -58,5 +61,8 @@ public class EntityCallback implements Callback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityListeners;
|
import javax.persistence.EntityListeners;
|
||||||
|
@ -29,13 +29,6 @@ import javax.persistence.ExcludeDefaultListeners;
|
||||||
import javax.persistence.ExcludeSuperclassListeners;
|
import javax.persistence.ExcludeSuperclassListeners;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.PostLoad;
|
|
||||||
import javax.persistence.PostPersist;
|
|
||||||
import javax.persistence.PostRemove;
|
|
||||||
import javax.persistence.PostUpdate;
|
|
||||||
import javax.persistence.PrePersist;
|
|
||||||
import javax.persistence.PreRemove;
|
|
||||||
import javax.persistence.PreUpdate;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
@ -50,6 +43,8 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||||
import org.hibernate.annotations.common.reflection.XClass;
|
import org.hibernate.annotations.common.reflection.XClass;
|
||||||
import org.hibernate.annotations.common.reflection.XMethod;
|
import org.hibernate.annotations.common.reflection.XMethod;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.Callback;
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
||||||
|
@ -67,7 +62,7 @@ public class LegacyCallbackProcessor implements CallbackProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processCallbacksForEntity(Object entityObject, CallbackRegistry callbackRegistry) {
|
public void processCallbacksForEntity(Object entityObject, CallbackRegistryImpl callbackRegistry) {
|
||||||
final String entityClassName = (String) entityObject;
|
final String entityClassName = (String) entityObject;
|
||||||
try {
|
try {
|
||||||
final XClass entityXClass = reflectionManager.classForName( entityClassName, this.getClass() );
|
final XClass entityXClass = reflectionManager.classForName( entityClassName, this.getClass() );
|
|
@ -21,11 +21,13 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a JPA callback using a dedicated listener
|
* Represents a JPA callback using a dedicated listener
|
||||||
*
|
*
|
||||||
|
@ -42,9 +44,10 @@ public class ListenerCallback implements Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performCallback(Object entity) {
|
public boolean performCallback(Object entity) {
|
||||||
try {
|
try {
|
||||||
callbackMethod.invoke( listenerInstance, entity );
|
callbackMethod.invoke( listenerInstance, entity );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
//keep runtime exceptions as is
|
//keep runtime exceptions as is
|
||||||
|
@ -59,4 +62,9 @@ public class ListenerCallback implements Callback {
|
||||||
throw new RuntimeException( e );
|
throw new RuntimeException( e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,12 +21,14 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard implementation of the ListenerFactory contract using simple instantiation. Listener instances
|
* Standard implementation of the ListenerFactory contract using simple instantiation. Listener instances
|
||||||
* are kept in a map keyed by Class to achieve singleton-ness.
|
* are kept in a map keyed by Class to achieve singleton-ness.
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.internal.jpa;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classes for integrating with JPA event callbacks
|
* Classes for integrating with JPA event callbacks
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event;
|
package org.hibernate.jpa.event.spi;
|
||||||
|
|
||||||
import javax.enterprise.inject.spi.BeanManager;
|
import javax.enterprise.inject.spi.BeanManager;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -40,28 +40,28 @@ import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
import org.hibernate.event.spi.EventType;
|
import org.hibernate.event.spi.EventType;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.internal.event.core.HibernateEntityManagerEventListener;
|
import org.hibernate.jpa.event.internal.core.HibernateEntityManagerEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaAutoFlushEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaAutoFlushEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaDeleteEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaDeleteEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaFlushEntityEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaFlushEntityEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaFlushEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaFlushEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaMergeEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaMergeEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPersistEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPersistEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPersistOnFlushEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPersistOnFlushEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPostDeleteEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPostDeleteEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPostInsertEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPostInsertEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPostLoadEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPostLoadEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaPostUpdateEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaPostUpdateEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaSaveEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaSaveEventListener;
|
||||||
import org.hibernate.jpa.internal.event.core.JpaSaveOrUpdateEventListener;
|
import org.hibernate.jpa.event.internal.core.JpaSaveOrUpdateEventListener;
|
||||||
import org.hibernate.jpa.internal.event.jpa.BeanManagerListenerFactory;
|
import org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackProcessor;
|
import org.hibernate.jpa.event.internal.jpa.CallbackProcessor;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackProcessorImpl;
|
import org.hibernate.jpa.event.internal.jpa.CallbackProcessorImpl;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistryConsumer;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryConsumer;
|
||||||
import org.hibernate.jpa.internal.event.jpa.CallbackRegistry;
|
import org.hibernate.jpa.event.internal.jpa.CallbackRegistryImpl;
|
||||||
import org.hibernate.jpa.internal.event.jpa.LegacyCallbackProcessor;
|
import org.hibernate.jpa.event.internal.jpa.LegacyCallbackProcessor;
|
||||||
import org.hibernate.jpa.internal.event.jpa.ListenerFactory;
|
import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
|
||||||
import org.hibernate.jpa.internal.event.jpa.StandardListenerFactory;
|
import org.hibernate.jpa.event.internal.jpa.StandardListenerFactory;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
|
@ -82,7 +82,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||||
public class JpaIntegrator implements Integrator {
|
public class JpaIntegrator implements Integrator {
|
||||||
private ListenerFactory jpaListenerFactory;
|
private ListenerFactory jpaListenerFactory;
|
||||||
private CallbackProcessor callbackProcessor;
|
private CallbackProcessor callbackProcessor;
|
||||||
private CallbackRegistry callbackRegistry;
|
private CallbackRegistryImpl callbackRegistry;
|
||||||
|
|
||||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -186,7 +186,7 @@ public class JpaIntegrator implements Integrator {
|
||||||
|
|
||||||
// handle JPA "entity listener classes"...
|
// handle JPA "entity listener classes"...
|
||||||
|
|
||||||
this.callbackRegistry = new CallbackRegistry();
|
this.callbackRegistry = new CallbackRegistryImpl();
|
||||||
final BeanManager beanManager = (BeanManager) configuration.getProperties().get( AvailableSettings.CDI_BEAN_MANAGER );
|
final BeanManager beanManager = (BeanManager) configuration.getProperties().get( AvailableSettings.CDI_BEAN_MANAGER );
|
||||||
this.jpaListenerFactory = beanManager == null
|
this.jpaListenerFactory = beanManager == null
|
||||||
? new StandardListenerFactory()
|
? new StandardListenerFactory()
|
||||||
|
@ -287,7 +287,7 @@ public class JpaIntegrator implements Integrator {
|
||||||
|
|
||||||
// handle JPA "entity listener classes"...
|
// handle JPA "entity listener classes"...
|
||||||
|
|
||||||
this.callbackRegistry = new CallbackRegistry();
|
this.callbackRegistry = new CallbackRegistryImpl();
|
||||||
final BeanManager beanManager = (BeanManager) sessionFactory.getProperties().get( AvailableSettings.CDI_BEAN_MANAGER );
|
final BeanManager beanManager = (BeanManager) sessionFactory.getProperties().get( AvailableSettings.CDI_BEAN_MANAGER );
|
||||||
this.jpaListenerFactory = beanManager == null
|
this.jpaListenerFactory = beanManager == null
|
||||||
? new StandardListenerFactory()
|
? new StandardListenerFactory()
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.spi.jpa;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ -36,6 +36,15 @@ public interface Callback extends Serializable {
|
||||||
* Contract for performing the callback
|
* Contract for performing the callback
|
||||||
*
|
*
|
||||||
* @param entity Reference to the entity for which the callback is triggered.
|
* @param entity Reference to the entity for which the callback is triggered.
|
||||||
|
*
|
||||||
|
* @return Did a callback actually happen?
|
||||||
*/
|
*/
|
||||||
public abstract void performCallback(Object entity);
|
public boolean performCallback(Object entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this callback active (will it do anything)?
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isActive();
|
||||||
}
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpa.event.spi.jpa;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public interface CallbackRegistry extends Serializable {
|
||||||
|
public void preCreate(Object entity);
|
||||||
|
public boolean hasPostCreateCallbacks(Class entityClass);
|
||||||
|
public void postCreate(Object entity);
|
||||||
|
|
||||||
|
public boolean preUpdate(Object entity);
|
||||||
|
public boolean hasPostUpdateCallbacks(Class entityClass);
|
||||||
|
public void postUpdate(Object entity);
|
||||||
|
|
||||||
|
public void preRemove(Object entity);
|
||||||
|
public boolean hasPostRemoveCallbacks(Class entityClass);
|
||||||
|
public void postRemove(Object entity);
|
||||||
|
|
||||||
|
public boolean postLoad(Object entity);
|
||||||
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.internal.event.jpa;
|
package org.hibernate.jpa.event.spi.jpa;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for building instances user-specified event listeners.
|
* Factory for building instances user-specified event listeners.
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpa.event.spi.jpa;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SPI classes for integrating with JPA event callbacks
|
||||||
|
*/
|
|
@ -29,6 +29,7 @@ import org.hibernate.envers.synchronization.work.AuditWorkUnit;
|
||||||
import org.hibernate.envers.synchronization.work.DelWorkUnit;
|
import org.hibernate.envers.synchronization.work.DelWorkUnit;
|
||||||
import org.hibernate.event.spi.PostDeleteEvent;
|
import org.hibernate.event.spi.PostDeleteEvent;
|
||||||
import org.hibernate.event.spi.PostDeleteEventListener;
|
import org.hibernate.event.spi.PostDeleteEventListener;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -71,4 +72,9 @@ public class EnversPostDeleteEventListenerImpl extends BaseEnversEventListener i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.envers.synchronization.work.AddWorkUnit;
|
||||||
import org.hibernate.envers.synchronization.work.AuditWorkUnit;
|
import org.hibernate.envers.synchronization.work.AuditWorkUnit;
|
||||||
import org.hibernate.event.spi.PostInsertEvent;
|
import org.hibernate.event.spi.PostInsertEvent;
|
||||||
import org.hibernate.event.spi.PostInsertEventListener;
|
import org.hibernate.event.spi.PostInsertEventListener;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -70,4 +71,9 @@ public class EnversPostInsertEventListenerImpl extends BaseEnversEventListener i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,4 +88,9 @@ public class EnversPostUpdateEventListenerImpl extends BaseEnversEventListener i
|
||||||
}
|
}
|
||||||
return newDbState;
|
return newDbState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPostCommitHanding(EntityPersister persister) {
|
||||||
|
return getAuditConfiguration().getEntCfg().isVersioned( persister.getEntityName() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue