HHH-18449 Remove deprecated Integrator#integrate form
This commit is contained in:
parent
fe3d8ac13b
commit
53bca2467d
|
@ -11,6 +11,7 @@ import java.util.Set;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.action.internal.CollectionAction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.cache.spi.access.CollectionDataAccess;
|
||||
import org.hibernate.cache.spi.access.SoftLock;
|
||||
|
@ -29,7 +30,6 @@ import org.hibernate.integrator.spi.Integrator;
|
|||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -53,13 +53,11 @@ public class CollectionCacheInvalidator
|
|||
public static boolean PROPAGATE_EXCEPTION = false;
|
||||
|
||||
@Override
|
||||
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry, sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +80,7 @@ public class CollectionCacheInvalidator
|
|||
evictCache( event.getEntity(), event.getPersister(), event.getSession(), event.getOldState() );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry, SessionFactoryImplementor sessionFactory) {
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
|
||||
if ( !sessionFactoryOptions.isAutoEvictCollectionCache() ) {
|
||||
// feature is disabled
|
||||
|
@ -92,7 +90,7 @@ public class CollectionCacheInvalidator
|
|||
// Nothing to do, if caching is disabled
|
||||
return;
|
||||
}
|
||||
EventListenerRegistry eventListenerRegistry = serviceRegistry.requireService( EventListenerRegistry.class );
|
||||
final EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry().requireService( EventListenerRegistry.class );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.integrator.spi;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -33,22 +32,6 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
|||
@JavaServiceLoadable
|
||||
public interface Integrator {
|
||||
|
||||
/**
|
||||
* Perform integration.
|
||||
*
|
||||
* @param metadata The "compiled" representation of the mapping information
|
||||
* @param sessionFactory The session factory being created
|
||||
* @param serviceRegistry The session factory's service registry
|
||||
* @deprecated - use
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
default void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
throw new UnsupportedOperationException( "Call to un-implemented deprecated legacy `Integrator#integrate` overload form" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform integration.
|
||||
*
|
||||
|
@ -56,13 +39,10 @@ public interface Integrator {
|
|||
* @param bootstrapContext The context for bootstrapping of the SessionFactory
|
||||
* @param sessionFactory The SessionFactory being created
|
||||
*/
|
||||
@Incubating
|
||||
default void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
// simply call the legacy one, keeping implementors bytecode compatible.
|
||||
integrate( metadata, sessionFactory, (SessionFactoryServiceRegistry) sessionFactory.getServiceRegistry() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.orm.test.cdi.general.hibernatesearch;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.resource.beans.container.spi.BeanContainer;
|
||||
|
@ -60,7 +61,10 @@ public class HibernateSearchSimulatedIntegrator implements Integrator, BeanConta
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
ManagedBeanRegistry registry = sessionFactory.getServiceRegistry().getService( ManagedBeanRegistry.class );
|
||||
|
||||
BeanContainer beanContainer = registry.getBeanContainer();
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.AbstractCollectionEvent;
|
||||
|
@ -144,18 +145,19 @@ public class AggregatedCollectionEventListener
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
protected void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
protected void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
if ( listener != null ) {
|
||||
log.warn( "integrate called second time on testing collection listener Integrator (could be result of rebuilding SF on test failure)" );
|
||||
}
|
||||
listener = new AggregatedCollectionEventListener();
|
||||
|
||||
final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
||||
final EventListenerRegistry listenerRegistry = sessionFactory.getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class );
|
||||
listenerRegistry.appendListeners( EventType.INIT_COLLECTION, listener );
|
||||
listenerRegistry.appendListeners( EventType.PRE_COLLECTION_RECREATE, listener );
|
||||
listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, listener );
|
||||
|
|
|
@ -9,107 +9,118 @@ package org.hibernate.orm.test.events;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.AutoFlushEvent;
|
||||
import org.hibernate.event.spi.AutoFlushEventListener;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class AutoFlushEventListenerTest extends BaseCoreFunctionalTestCase {
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
private TheListener listener = new TheListener();
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
AutoFlushEventListenerTest.Entity1.class,
|
||||
AutoFlushEventListenerTest.Entity2.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BootstrapServiceRegistry(
|
||||
integrators = AutoFlushEventListenerTest.CustomLoadIntegrator.class
|
||||
)
|
||||
public class AutoFlushEventListenerTest {
|
||||
|
||||
private static final TheListener LISTENER = new TheListener();
|
||||
|
||||
@Test
|
||||
public void testAutoFlushRequired() {
|
||||
listener.events.clear();
|
||||
public void testAutoFlushRequired(SessionFactoryScope scope) {
|
||||
LISTENER.events.clear();
|
||||
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
try {
|
||||
session.persist( new Entity1() );
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 0 );
|
||||
|
||||
s.persist( new Entity1() );
|
||||
assertEquals( 0, listener.events.size() );
|
||||
// An entity of this type was persisted; a flush is required
|
||||
session.createQuery( "select i from Entity1 i", Entity1.class )
|
||||
.setHibernateFlushMode( FlushMode.AUTO )
|
||||
.getResultList();
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
assertTrue( LISTENER.events.get( 0 ).isFlushRequired() );
|
||||
|
||||
// An entity of this type was persisted; a flush is required
|
||||
session.createQuery( "select i from Entity1 i" )
|
||||
.setHibernateFlushMode( FlushMode.AUTO )
|
||||
.getResultList();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
assertTrue( listener.events.get( 0 ).isFlushRequired() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
s.close();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoFlushNotRequired() {
|
||||
listener.events.clear();
|
||||
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
s.persist( new Entity2() );
|
||||
assertEquals( 0, listener.events.size() );
|
||||
|
||||
// No entity of this type was persisted; no flush is required
|
||||
session.createQuery( "select i from Entity1 i" )
|
||||
.setHibernateFlushMode( FlushMode.AUTO )
|
||||
.getResultList();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
assertFalse( listener.events.get( 0 ).isFlushRequired() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
s.close();
|
||||
assertEquals( 1, listener.events.size() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
builder.applyIntegrator(
|
||||
new Integrator() {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).appendListeners(
|
||||
EventType.AUTO_FLUSH,
|
||||
listener
|
||||
);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
catch (Exception e) {
|
||||
session.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
}
|
||||
);
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Entity1.class, Entity2.class };
|
||||
@Test
|
||||
public void testAutoFlushNotRequired(SessionFactoryScope scope) {
|
||||
LISTENER.events.clear();
|
||||
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
try {
|
||||
session.persist( new Entity2() );
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 0 );
|
||||
|
||||
// No entity of this type was persisted; no flush is required
|
||||
session.createQuery( "select i from Entity1 i", Entity1.class )
|
||||
.setHibernateFlushMode( FlushMode.AUTO )
|
||||
.getResultList();
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
assertFalse( LISTENER.events.get( 0 ).isFlushRequired() );
|
||||
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
session.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
}
|
||||
);
|
||||
|
||||
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
|
||||
}
|
||||
|
||||
public static class CustomLoadIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).appendListeners(
|
||||
EventType.AUTO_FLUSH,
|
||||
LISTENER
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "Entity1")
|
||||
|
@ -133,7 +144,7 @@ public class AutoFlushEventListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
private static class TheListener implements AutoFlushEventListener {
|
||||
private List<AutoFlushEvent> events = new ArrayList<>();
|
||||
final private List<AutoFlushEvent> events = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onAutoFlush(AutoFlushEvent event) throws HibernateException {
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.SessionFactory;
|
|||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
|
@ -57,13 +58,13 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).setListeners(
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).setListeners(
|
||||
EventType.DELETE,
|
||||
listener
|
||||
);
|
||||
|
|
|
@ -6,53 +6,67 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.events;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.ClearEvent;
|
||||
import org.hibernate.event.spi.ClearEventListener;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ClearEventListenerTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel
|
||||
@SessionFactory
|
||||
@BootstrapServiceRegistry(integrators = ClearEventListenerTest.CustomLoadIntegrator.class)
|
||||
public class ClearEventListenerTest {
|
||||
@Test
|
||||
public void testExplicitClear() {
|
||||
listener.callCount = 0;
|
||||
public void testExplicitClear(SessionFactoryScope scope) {
|
||||
LISTENER.callCount = 0;
|
||||
|
||||
Session s = openSession();
|
||||
s.clear();
|
||||
assertEquals( 1, listener.callCount );
|
||||
s.close();
|
||||
assertEquals( 1, listener.callCount );
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.clear();
|
||||
assertThat( LISTENER.callCount ).isEqualTo( 1 );
|
||||
}
|
||||
);
|
||||
assertThat( LISTENER.callCount ).isEqualTo( 1 );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoClear() {
|
||||
listener.callCount = 0;
|
||||
public void testAutoClear(SessionFactoryScope scope) {
|
||||
LISTENER.callCount = 0;
|
||||
|
||||
Session s = openSession();
|
||||
( (SessionImplementor) s ).setAutoClear( true );
|
||||
s.beginTransaction();
|
||||
assertEquals( 0, listener.callCount );
|
||||
s.getTransaction().commit();
|
||||
assertEquals( 1, listener.callCount );
|
||||
s.close();
|
||||
assertEquals( 1, listener.callCount );
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.setAutoClear( true );
|
||||
session.getTransaction().begin();
|
||||
try {
|
||||
assertThat( LISTENER.callCount ).isEqualTo( 0 );
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
session.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
assertThat( LISTENER.callCount ).isEqualTo( 1 );
|
||||
}
|
||||
);
|
||||
|
||||
assertThat( LISTENER.callCount ).isEqualTo( 1 );
|
||||
}
|
||||
|
||||
private TheListener listener = new TheListener();
|
||||
private static final TheListener LISTENER = new TheListener();
|
||||
|
||||
private static class TheListener implements ClearEventListener {
|
||||
private int callCount;
|
||||
|
@ -63,31 +77,20 @@ public class ClearEventListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
builder.applyIntegrator(
|
||||
new Integrator() {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
}
|
||||
public static class CustomLoadIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).setListeners(
|
||||
EventType.CLEAR,
|
||||
listener
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).setListeners(
|
||||
EventType.CLEAR,
|
||||
LISTENER
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
|
@ -22,7 +23,7 @@ import org.hibernate.event.spi.PostUpdateEvent;
|
|||
import org.hibernate.event.spi.PostUpdateEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -36,9 +37,9 @@ import org.junit.Test;
|
|||
* @author ShawnClowater
|
||||
*/
|
||||
public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
||||
private PostInsertEventListener postCommitInsertEventListener = new LegacyPostCommitInsertEventListener();
|
||||
private PostDeleteEventListener postCommitDeleteEventListener = new LegacyPostCommitDeleteEventListener();
|
||||
private PostUpdateEventListener postCommitUpdateEventListener = new LegacyPostCommitUpdateEventListener();
|
||||
private final PostInsertEventListener postCommitInsertEventListener = new LegacyPostCommitInsertEventListener();
|
||||
private final PostDeleteEventListener postCommitDeleteEventListener = new LegacyPostCommitDeleteEventListener();
|
||||
private final PostUpdateEventListener postCommitUpdateEventListener = new LegacyPostCommitUpdateEventListener();
|
||||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
|
@ -55,12 +56,13 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup(
|
||||
EventType.POST_COMMIT_DELETE
|
||||
).appendListener( postCommitDeleteEventListener );
|
||||
|
@ -71,11 +73,6 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
EventType.POST_COMMIT_INSERT
|
||||
).appendListener( postCommitInsertEventListener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -218,7 +215,7 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
Assert.assertEquals( 1, ( (LegacyPostCommitDeleteEventListener) postCommitDeleteEventListener ).fired );
|
||||
}
|
||||
|
||||
private class LegacyPostCommitDeleteEventListener implements PostDeleteEventListener {
|
||||
private static class LegacyPostCommitDeleteEventListener implements PostDeleteEventListener {
|
||||
int fired;
|
||||
|
||||
@Override
|
||||
|
@ -232,7 +229,7 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private class LegacyPostCommitUpdateEventListener implements PostUpdateEventListener {
|
||||
private static class LegacyPostCommitUpdateEventListener implements PostUpdateEventListener {
|
||||
int fired;
|
||||
|
||||
@Override
|
||||
|
@ -246,7 +243,7 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private class LegacyPostCommitInsertEventListener implements PostInsertEventListener {
|
||||
private static class LegacyPostCommitInsertEventListener implements PostInsertEventListener {
|
||||
int fired;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
|
@ -25,7 +26,7 @@ import org.hibernate.event.spi.PostUpdateEvent;
|
|||
import org.hibernate.event.spi.PostUpdateEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -39,9 +40,9 @@ import org.junit.Test;
|
|||
* @author ShawnClowater
|
||||
*/
|
||||
public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
||||
private PostInsertEventListener postCommitInsertEventListener = new TestPostCommitInsertEventListener();
|
||||
private PostDeleteEventListener postCommitDeleteEventListener = new TestPostCommitDeleteEventListener();
|
||||
private PostUpdateEventListener postCommitUpdateEventListener = new TestPostCommitUpdateEventListener();
|
||||
private final PostInsertEventListener postCommitInsertEventListener = new TestPostCommitInsertEventListener();
|
||||
private final PostDeleteEventListener postCommitDeleteEventListener = new TestPostCommitDeleteEventListener();
|
||||
private final PostUpdateEventListener postCommitUpdateEventListener = new TestPostCommitUpdateEventListener();
|
||||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
|
@ -61,12 +62,13 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup(
|
||||
EventType.POST_COMMIT_DELETE
|
||||
).appendListener( postCommitDeleteEventListener );
|
||||
|
@ -77,11 +79,6 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
EventType.POST_COMMIT_INSERT
|
||||
).appendListener( postCommitInsertEventListener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -227,7 +224,7 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
Assert.assertEquals( 1, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).failed );
|
||||
}
|
||||
|
||||
private class TestPostCommitDeleteEventListener implements PostCommitDeleteEventListener {
|
||||
private static class TestPostCommitDeleteEventListener implements PostCommitDeleteEventListener {
|
||||
int success;
|
||||
int failed;
|
||||
|
||||
|
@ -247,7 +244,7 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private class TestPostCommitUpdateEventListener implements PostCommitUpdateEventListener {
|
||||
private static class TestPostCommitUpdateEventListener implements PostCommitUpdateEventListener {
|
||||
int sucess;
|
||||
int failed;
|
||||
|
||||
|
@ -267,7 +264,7 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private class TestPostCommitInsertEventListener implements PostCommitInsertEventListener {
|
||||
private static class TestPostCommitInsertEventListener implements PostCommitInsertEventListener {
|
||||
int success;
|
||||
int failed;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.ActionQueue;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -47,9 +48,9 @@ public class TestAutoFlushBeforeQueryExecution extends BaseCoreFunctionalTestCas
|
|||
Publisher publisher = new Publisher();
|
||||
publisher.setName( "name" );
|
||||
s.persist( publisher );
|
||||
assertTrue( "autoflush entity create", s.createQuery( "from Publisher p" ).list().size() == 1 );
|
||||
assertTrue( "autoflush entity create", s.createQuery( "from Publisher p", Publisher.class ).list().size() == 1 );
|
||||
publisher.setName( "name" );
|
||||
assertTrue( "autoflush entity update", s.createQuery( "from Publisher p where p.name='name'" ).list().size() == 1 );
|
||||
assertTrue( "autoflush entity update", s.createQuery( "from Publisher p where p.name='name'", Publisher.class ).list().size() == 1 );
|
||||
txn.commit();
|
||||
s.close();
|
||||
|
||||
|
@ -214,21 +215,16 @@ public class TestAutoFlushBeforeQueryExecution extends BaseCoreFunctionalTestCas
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class )
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.PRE_UPDATE )
|
||||
.appendListener( InitializingPreUpdateEventListener.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,93 +7,107 @@
|
|||
package org.hibernate.orm.test.flush;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.event.spi.PreUpdateEvent;
|
||||
import org.hibernate.event.spi.PreUpdateEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-2763" )
|
||||
public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTestCase {
|
||||
@TestForIssue(jiraKey = "HHH-2763")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Author.class,
|
||||
Book.class,
|
||||
Publisher.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BootstrapServiceRegistry(integrators = TestCollectionInitializingDuringFlush.CustomLoadIntegrator.class)
|
||||
public class TestCollectionInitializingDuringFlush {
|
||||
|
||||
@Test
|
||||
public void testInitializationDuringFlush() {
|
||||
public void testInitializationDuringFlush(SessionFactoryScope scope) {
|
||||
assertFalse( InitializingPreUpdateEventListener.INSTANCE.executed );
|
||||
assertFalse( InitializingPreUpdateEventListener.INSTANCE.foundAny );
|
||||
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Publisher publisher = new Publisher( "acme" );
|
||||
final Publisher publisher = new Publisher( "acme" );
|
||||
Author author = new Author( "john" );
|
||||
author.setPublisher( publisher );
|
||||
publisher.getAuthors().add( author );
|
||||
author.getBooks().add( new Book( "Reflections on a Wimpy Kid", author ) );
|
||||
s.persist( author );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
publisher = (Publisher) s.get( Publisher.class, publisher.getId() );
|
||||
publisher.setName( "random nally" );
|
||||
s.flush();
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.remove( author );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
assertTrue( InitializingPreUpdateEventListener.INSTANCE.executed );
|
||||
assertTrue( InitializingPreUpdateEventListener.INSTANCE.foundAny );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Author.class, Book.class, Publisher.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
builder.applyIntegrator(
|
||||
new Integrator() {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.PRE_UPDATE )
|
||||
.appendListener( InitializingPreUpdateEventListener.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
author.setPublisher( publisher );
|
||||
publisher.getAuthors().add( author );
|
||||
author.getBooks().add( new Book( "Reflections on a Wimpy Kid", author ) );
|
||||
session.persist( author );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
try {
|
||||
Publisher p = session.get( Publisher.class, publisher.getId() );
|
||||
p.setName( "random nally" );
|
||||
session.flush();
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
session.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
session.clear();
|
||||
|
||||
scope.inSession(
|
||||
s -> {
|
||||
s.beginTransaction();
|
||||
try {
|
||||
s.remove( author );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
session.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
s.clear();
|
||||
|
||||
assertTrue( InitializingPreUpdateEventListener.INSTANCE.executed );
|
||||
assertTrue( InitializingPreUpdateEventListener.INSTANCE.foundAny );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static class CustomLoadIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.PRE_UPDATE )
|
||||
.appendListener( InitializingPreUpdateEventListener.INSTANCE );
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializingPreUpdateEventListener implements PreUpdateEventListener {
|
||||
|
@ -112,7 +126,7 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes
|
|||
// Iterate through all fields of the updated object
|
||||
for ( int i = 0; i < properties.length; i++ ) {
|
||||
if ( oldValues != null && oldValues[i] != null ) {
|
||||
if ( ! Hibernate.isInitialized( oldValues[i] ) ) {
|
||||
if ( !Hibernate.isInitialized( oldValues[i] ) ) {
|
||||
// force any proxies and/or collections to initialize to illustrate HHH-2763
|
||||
foundAny = true;
|
||||
Hibernate.initialize( oldValues );
|
||||
|
|
|
@ -10,10 +10,10 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.jpa.boot.spi.IntegratorProvider;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
|
@ -26,16 +26,10 @@ public class DtoIntegratorProvider implements IntegratorProvider {
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
metadata.getImports().put( "PersonDto", PersonDto.class.getName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.hibernate.boot.Metadata;
|
|||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
|
@ -23,7 +24,6 @@ import org.hibernate.event.internal.DefaultFlushEventListener;
|
|||
import org.hibernate.event.internal.DefaultPersistEventListener;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.AutoFlushEventListener;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.event.spi.FlushEntityEventListener;
|
||||
import org.hibernate.event.spi.FlushEventListener;
|
||||
|
@ -31,7 +31,6 @@ import org.hibernate.event.spi.PersistContext;
|
|||
import org.hibernate.event.spi.PersistEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import org.hibernate.testing.SkipLog;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
|
@ -55,7 +54,7 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
|
|||
|
||||
@Override
|
||||
protected void applySettings(StandardServiceRegistryBuilder builder) {
|
||||
builder.applySetting( Environment.JPAQL_STRICT_COMPLIANCE, "true" );
|
||||
builder.applySetting( Environment.JPA_QUERY_COMPLIANCE, "true" );
|
||||
builder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
}
|
||||
|
||||
|
@ -69,17 +68,17 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
|
|||
public void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
builder.applyIntegrator(
|
||||
new Integrator() {
|
||||
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry().getService(
|
||||
EventListenerRegistry.class );
|
||||
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
|
||||
eventListenerRegistry.setListeners(
|
||||
EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners()
|
||||
|
@ -88,11 +87,6 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
|
|||
eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() );
|
||||
eventListenerRegistry.setListeners( EventType.FLUSH_ENTITY, buildFlushEntityEventListeners() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -141,31 +135,11 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
|
|||
public static class JPAAutoFlushEventListener extends DefaultAutoFlushEventListener {
|
||||
// not sure why EM code has this ...
|
||||
public static final AutoFlushEventListener INSTANCE = new JPAAutoFlushEventListener();
|
||||
|
||||
@Override
|
||||
protected CascadingAction<PersistContext> getCascadingAction(EventSource session) {
|
||||
return CascadingActions.PERSIST_ON_FLUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PersistContext getContext(EventSource session) {
|
||||
return PersistContext.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class JPAFlushEventListener extends DefaultFlushEventListener {
|
||||
// not sure why EM code has this ...
|
||||
public static final FlushEventListener INSTANCE = new JPAFlushEventListener();
|
||||
|
||||
@Override
|
||||
protected CascadingAction<PersistContext> getCascadingAction(EventSource session) {
|
||||
return CascadingActions.PERSIST_ON_FLUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PersistContext getContext(EventSource session) {
|
||||
return PersistContext.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class JPAFlushEntityEventListener extends DefaultFlushEntityEventListener {
|
||||
|
@ -176,8 +150,7 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
|
|||
final int isolation;
|
||||
try (Session testSession = sessionFactory().openSession()) {
|
||||
isolation = testSession.doReturningWork(
|
||||
connection ->
|
||||
connection.getTransactionIsolation()
|
||||
Connection::getTransactionIsolation
|
||||
);
|
||||
}
|
||||
if ( isolation < Connection.TRANSACTION_READ_COMMITTED ) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import jakarta.persistence.criteria.CriteriaQuery;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.internal.DefaultLoadEventListener;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
|
@ -19,13 +20,11 @@ import org.hibernate.event.spi.EventType;
|
|||
import org.hibernate.event.spi.LoadEvent;
|
||||
import org.hibernate.event.spi.LoadEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -49,22 +48,17 @@ public class EagerKeyManyToOneTest {
|
|||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry );
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
integrate( sessionFactory );
|
||||
}
|
||||
|
||||
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
|
||||
serviceRegistry.getService( EventListenerRegistry.class ).prependListeners(
|
||||
private void integrate(SessionFactoryImplementor sessionFactory) {
|
||||
sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).prependListeners(
|
||||
EventType.LOAD,
|
||||
new CustomLoadListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(
|
||||
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.service;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class TestIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -7,20 +7,16 @@
|
|||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
public class SharedDriverManagerTypeCacheClearingIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(
|
||||
Metadata metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
SharedDriverManagerConnectionProviderImpl.getInstance().clearTypeCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,6 +246,7 @@ XML processing.
|
|||
* Removed `org.hibernate.Session#delete` in favor of `org.hibernate.Session#remove`
|
||||
* Removed `org.hibernate.annotations.CascadeType.DELETE` in favor of `org.hibernate.annotations.CascadeType#REMOVE`
|
||||
* Removed the attribute value from `@DynamicInsert` and `@DynamicUpdate`
|
||||
* Removed `org.hibernate.integrator.spi.Integrator#integrate(Metadata,SessionFactoryImplementor,SessionFactoryServiceRegistry)` in favor of `org.hibernate.integrator.spi.Integrator#integrate(Metadata,BootstrapContext,SessionFactoryImplementor)`
|
||||
|
||||
|
||||
[[todo]]
|
||||
|
|
Loading…
Reference in New Issue