HHH-18449 Remove deprecated Integrator#integrate form

This commit is contained in:
Andrea Boriero 2024-07-31 11:40:36 +02:00 committed by Steve Ebersole
parent fe3d8ac13b
commit 53bca2467d
17 changed files with 306 additions and 376 deletions

View File

@ -11,6 +11,7 @@ import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.action.internal.CollectionAction; import org.hibernate.action.internal.CollectionAction;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.cache.spi.access.CollectionDataAccess; import org.hibernate.cache.spi.access.CollectionDataAccess;
import org.hibernate.cache.spi.access.SoftLock; 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.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -53,13 +53,11 @@ public class CollectionCacheInvalidator
public static boolean PROPAGATE_EXCEPTION = false; public static boolean PROPAGATE_EXCEPTION = false;
@Override @Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, public void integrate(
SessionFactoryServiceRegistry serviceRegistry) { Metadata metadata,
integrate( serviceRegistry, sessionFactory ); BootstrapContext bootstrapContext,
} SessionFactoryImplementor sessionFactory) {
integrate( sessionFactory );
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
} }
@Override @Override
@ -82,7 +80,7 @@ public class CollectionCacheInvalidator
evictCache( event.getEntity(), event.getPersister(), event.getSession(), event.getOldState() ); 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(); final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
if ( !sessionFactoryOptions.isAutoEvictCollectionCache() ) { if ( !sessionFactoryOptions.isAutoEvictCollectionCache() ) {
// feature is disabled // feature is disabled
@ -92,7 +90,7 @@ public class CollectionCacheInvalidator
// Nothing to do, if caching is disabled // Nothing to do, if caching is disabled
return; 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_INSERT, this );
eventListenerRegistry.appendListeners( EventType.POST_DELETE, this ); eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this ); eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.integrator.spi; package org.hibernate.integrator.spi;
import org.hibernate.Incubating;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -33,22 +32,6 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
@JavaServiceLoadable @JavaServiceLoadable
public interface Integrator { 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. * Perform integration.
* *
@ -56,13 +39,10 @@ public interface Integrator {
* @param bootstrapContext The context for bootstrapping of the SessionFactory * @param bootstrapContext The context for bootstrapping of the SessionFactory
* @param sessionFactory The SessionFactory being created * @param sessionFactory The SessionFactory being created
*/ */
@Incubating
default void integrate( default void integrate(
Metadata metadata, Metadata metadata,
BootstrapContext bootstrapContext, BootstrapContext bootstrapContext,
SessionFactoryImplementor sessionFactory) { SessionFactoryImplementor sessionFactory) {
// simply call the legacy one, keeping implementors bytecode compatible.
integrate( metadata, sessionFactory, (SessionFactoryServiceRegistry) sessionFactory.getServiceRegistry() );
} }
/** /**

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.cdi.general.hibernatesearch; package org.hibernate.orm.test.cdi.general.hibernatesearch;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.resource.beans.container.spi.BeanContainer; import org.hibernate.resource.beans.container.spi.BeanContainer;
@ -60,7 +61,10 @@ public class HibernateSearchSimulatedIntegrator implements Integrator, BeanConta
@Override @Override
@SuppressWarnings("unchecked") @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 ); ManagedBeanRegistry registry = sessionFactory.getServiceRegistry().getService( ManagedBeanRegistry.class );
BeanContainer beanContainer = registry.getBeanContainer(); BeanContainer beanContainer = registry.getBeanContainer();

View File

@ -12,6 +12,7 @@ import java.util.List;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.AbstractCollectionEvent; import org.hibernate.event.spi.AbstractCollectionEvent;
@ -144,18 +145,19 @@ public class AggregatedCollectionEventListener
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
protected void integrate(SessionFactoryServiceRegistry serviceRegistry) { protected void integrate(SessionFactoryImplementor sessionFactory) {
if ( listener != null ) { if ( listener != null ) {
log.warn( "integrate called second time on testing collection listener Integrator (could be result of rebuilding SF on test failure)" ); log.warn( "integrate called second time on testing collection listener Integrator (could be result of rebuilding SF on test failure)" );
} }
listener = new AggregatedCollectionEventListener(); 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.INIT_COLLECTION, listener );
listenerRegistry.appendListeners( EventType.PRE_COLLECTION_RECREATE, listener ); listenerRegistry.appendListeners( EventType.PRE_COLLECTION_RECREATE, listener );
listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, listener ); listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, listener );

View File

@ -9,107 +9,118 @@ package org.hibernate.orm.test.events;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.boot.Metadata; 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.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.AutoFlushEvent; import org.hibernate.event.spi.AutoFlushEvent;
import org.hibernate.event.spi.AutoFlushEventListener; import org.hibernate.event.spi.AutoFlushEventListener;
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.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.junit.Test; 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 jakarta.persistence.Entity;
import static org.junit.Assert.assertFalse; import jakarta.persistence.GeneratedValue;
import static org.junit.Assert.assertTrue; 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 @Test
public void testAutoFlushRequired() { public void testAutoFlushRequired(SessionFactoryScope scope) {
listener.events.clear(); LISTENER.events.clear();
Session s = openSession(); scope.inSession(
s.beginTransaction(); session -> {
session.beginTransaction();
try {
session.persist( new Entity1() );
assertThat( LISTENER.events.size() ).isEqualTo( 0 );
s.persist( new Entity1() ); // An entity of this type was persisted; a flush is required
assertEquals( 0, listener.events.size() ); 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.getTransaction().commit();
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
);
} }
catch (Exception e) {
@Override session.getTransaction().rollback();
public void disintegrate(SessionFactoryImplementor sessionFactory, throw e;
SessionFactoryServiceRegistry serviceRegistry) {
} }
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
} }
); );
assertThat( LISTENER.events.size() ).isEqualTo( 1 );
} }
@Override @Test
protected Class<?>[] getAnnotatedClasses() { public void testAutoFlushNotRequired(SessionFactoryScope scope) {
return new Class[] { Entity1.class, Entity2.class }; 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") @Entity(name = "Entity1")
@ -133,7 +144,7 @@ public class AutoFlushEventListenerTest extends BaseCoreFunctionalTestCase {
} }
private static class TheListener implements AutoFlushEventListener { private static class TheListener implements AutoFlushEventListener {
private List<AutoFlushEvent> events = new ArrayList<>(); final private List<AutoFlushEvent> events = new ArrayList<>();
@Override @Override
public void onAutoFlush(AutoFlushEvent event) throws HibernateException { public void onAutoFlush(AutoFlushEvent event) throws HibernateException {

View File

@ -11,6 +11,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver; import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
@ -57,13 +58,13 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
serviceRegistry.getService( EventListenerRegistry.class ).setListeners( sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).setListeners(
EventType.DELETE, EventType.DELETE,
listener listener
); );

View File

@ -6,53 +6,67 @@
*/ */
package org.hibernate.orm.test.events; package org.hibernate.orm.test.events;
import org.hibernate.Session;
import org.hibernate.boot.Metadata; 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.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.ClearEvent; import org.hibernate.event.spi.ClearEvent;
import org.hibernate.event.spi.ClearEventListener; import org.hibernate.event.spi.ClearEventListener;
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.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.junit.Test; 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 * @author Steve Ebersole
*/ */
public class ClearEventListenerTest extends BaseCoreFunctionalTestCase { @DomainModel
@SessionFactory
@BootstrapServiceRegistry(integrators = ClearEventListenerTest.CustomLoadIntegrator.class)
public class ClearEventListenerTest {
@Test @Test
public void testExplicitClear() { public void testExplicitClear(SessionFactoryScope scope) {
listener.callCount = 0; LISTENER.callCount = 0;
Session s = openSession(); scope.inSession(
s.clear(); session -> {
assertEquals( 1, listener.callCount ); session.clear();
s.close(); assertThat( LISTENER.callCount ).isEqualTo( 1 );
assertEquals( 1, listener.callCount ); }
);
assertThat( LISTENER.callCount ).isEqualTo( 1 );
} }
@Test @Test
public void testAutoClear() { public void testAutoClear(SessionFactoryScope scope) {
listener.callCount = 0; LISTENER.callCount = 0;
Session s = openSession(); scope.inSession(
( (SessionImplementor) s ).setAutoClear( true ); session -> {
s.beginTransaction(); session.setAutoClear( true );
assertEquals( 0, listener.callCount ); session.getTransaction().begin();
s.getTransaction().commit(); try {
assertEquals( 1, listener.callCount ); assertThat( LISTENER.callCount ).isEqualTo( 0 );
s.close(); session.getTransaction().commit();
assertEquals( 1, listener.callCount ); }
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 static class TheListener implements ClearEventListener {
private int callCount; private int callCount;
@ -63,31 +77,20 @@ public class ClearEventListenerTest extends BaseCoreFunctionalTestCase {
} }
} }
@Override public static class CustomLoadIntegrator implements Integrator {
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { @Override
super.prepareBootstrapRegistryBuilder( builder ); public void integrate(
builder.applyIntegrator( Metadata metadata,
new Integrator() { BootstrapContext bootstrapContext,
@Override SessionFactoryImplementor sessionFactory) {
public void integrate( integrate( sessionFactory );
Metadata metadata, }
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
integrate( serviceRegistry );
}
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
serviceRegistry.getService( EventListenerRegistry.class ).setListeners( sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).setListeners(
EventType.CLEAR, EventType.CLEAR,
listener LISTENER
); );
} }
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
);
} }
} }

View File

@ -11,6 +11,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType; 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.event.spi.PostUpdateEventListener;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.persister.entity.EntityPersister; 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.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -36,9 +37,9 @@ import org.junit.Test;
* @author ShawnClowater * @author ShawnClowater
*/ */
public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase { public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
private PostInsertEventListener postCommitInsertEventListener = new LegacyPostCommitInsertEventListener(); private final PostInsertEventListener postCommitInsertEventListener = new LegacyPostCommitInsertEventListener();
private PostDeleteEventListener postCommitDeleteEventListener = new LegacyPostCommitDeleteEventListener(); private final PostDeleteEventListener postCommitDeleteEventListener = new LegacyPostCommitDeleteEventListener();
private PostUpdateEventListener postCommitUpdateEventListener = new LegacyPostCommitUpdateEventListener(); private final PostUpdateEventListener postCommitUpdateEventListener = new LegacyPostCommitUpdateEventListener();
@Override @Override
protected void prepareTest() throws Exception { protected void prepareTest() throws Exception {
@ -55,12 +56,13 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup( serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup(
EventType.POST_COMMIT_DELETE EventType.POST_COMMIT_DELETE
).appendListener( postCommitDeleteEventListener ); ).appendListener( postCommitDeleteEventListener );
@ -71,11 +73,6 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
EventType.POST_COMMIT_INSERT EventType.POST_COMMIT_INSERT
).appendListener( postCommitInsertEventListener ); ).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 ); Assert.assertEquals( 1, ( (LegacyPostCommitDeleteEventListener) postCommitDeleteEventListener ).fired );
} }
private class LegacyPostCommitDeleteEventListener implements PostDeleteEventListener { private static class LegacyPostCommitDeleteEventListener implements PostDeleteEventListener {
int fired; int fired;
@Override @Override
@ -232,7 +229,7 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
} }
} }
private class LegacyPostCommitUpdateEventListener implements PostUpdateEventListener { private static class LegacyPostCommitUpdateEventListener implements PostUpdateEventListener {
int fired; int fired;
@Override @Override
@ -246,7 +243,7 @@ public class LegacyPostCommitListenerTest extends BaseCoreFunctionalTestCase {
} }
} }
private class LegacyPostCommitInsertEventListener implements PostInsertEventListener { private static class LegacyPostCommitInsertEventListener implements PostInsertEventListener {
int fired; int fired;
@Override @Override

View File

@ -11,6 +11,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType; 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.event.spi.PostUpdateEventListener;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.persister.entity.EntityPersister; 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.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -39,9 +40,9 @@ import org.junit.Test;
* @author ShawnClowater * @author ShawnClowater
*/ */
public class PostCommitListenerTest extends BaseCoreFunctionalTestCase { public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
private PostInsertEventListener postCommitInsertEventListener = new TestPostCommitInsertEventListener(); private final PostInsertEventListener postCommitInsertEventListener = new TestPostCommitInsertEventListener();
private PostDeleteEventListener postCommitDeleteEventListener = new TestPostCommitDeleteEventListener(); private final PostDeleteEventListener postCommitDeleteEventListener = new TestPostCommitDeleteEventListener();
private PostUpdateEventListener postCommitUpdateEventListener = new TestPostCommitUpdateEventListener(); private final PostUpdateEventListener postCommitUpdateEventListener = new TestPostCommitUpdateEventListener();
@Override @Override
protected void prepareTest() throws Exception { protected void prepareTest() throws Exception {
@ -61,12 +62,13 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup( serviceRegistry.getService( EventListenerRegistry.class ).getEventListenerGroup(
EventType.POST_COMMIT_DELETE EventType.POST_COMMIT_DELETE
).appendListener( postCommitDeleteEventListener ); ).appendListener( postCommitDeleteEventListener );
@ -77,11 +79,6 @@ public class PostCommitListenerTest extends BaseCoreFunctionalTestCase {
EventType.POST_COMMIT_INSERT EventType.POST_COMMIT_INSERT
).appendListener( postCommitInsertEventListener ); ).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 ); Assert.assertEquals( 1, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).failed );
} }
private class TestPostCommitDeleteEventListener implements PostCommitDeleteEventListener { private static class TestPostCommitDeleteEventListener implements PostCommitDeleteEventListener {
int success; int success;
int failed; 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 sucess;
int failed; 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 success;
int failed; int failed;

View File

@ -15,6 +15,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.ActionQueue; import org.hibernate.engine.spi.ActionQueue;
import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -47,9 +48,9 @@ public class TestAutoFlushBeforeQueryExecution extends BaseCoreFunctionalTestCas
Publisher publisher = new Publisher(); Publisher publisher = new Publisher();
publisher.setName( "name" ); publisher.setName( "name" );
s.persist( publisher ); 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" ); 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(); txn.commit();
s.close(); s.close();
@ -214,21 +215,16 @@ public class TestAutoFlushBeforeQueryExecution extends BaseCoreFunctionalTestCas
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
serviceRegistry.getService( EventListenerRegistry.class ) sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class )
.getEventListenerGroup( EventType.PRE_UPDATE ) .getEventListenerGroup( EventType.PRE_UPDATE )
.appendListener( InitializingPreUpdateEventListener.INSTANCE ); .appendListener( InitializingPreUpdateEventListener.INSTANCE );
} }
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
} }
); );
} }

View File

@ -7,93 +7,107 @@
package org.hibernate.orm.test.flush; package org.hibernate.orm.test.flush;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.boot.Metadata; 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.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType; import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PreUpdateEvent; import org.hibernate.event.spi.PreUpdateEvent;
import org.hibernate.event.spi.PreUpdateEventListener; import org.hibernate.event.spi.PreUpdateEventListener;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.junit.Test; 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.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@TestForIssue( jiraKey = "HHH-2763" ) @TestForIssue(jiraKey = "HHH-2763")
public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
Author.class,
Book.class,
Publisher.class
}
)
@SessionFactory
@BootstrapServiceRegistry(integrators = TestCollectionInitializingDuringFlush.CustomLoadIntegrator.class)
public class TestCollectionInitializingDuringFlush {
@Test @Test
public void testInitializationDuringFlush() { public void testInitializationDuringFlush(SessionFactoryScope scope) {
assertFalse( InitializingPreUpdateEventListener.INSTANCE.executed ); assertFalse( InitializingPreUpdateEventListener.INSTANCE.executed );
assertFalse( InitializingPreUpdateEventListener.INSTANCE.foundAny ); assertFalse( InitializingPreUpdateEventListener.INSTANCE.foundAny );
Session s = openSession(); final Publisher publisher = new Publisher( "acme" );
s.beginTransaction();
Publisher publisher = new Publisher( "acme" );
Author author = new Author( "john" ); Author author = new Author( "john" );
author.setPublisher( publisher ); scope.inTransaction(
publisher.getAuthors().add( author ); session -> {
author.getBooks().add( new Book( "Reflections on a Wimpy Kid", author ) ); author.setPublisher( publisher );
s.persist( author ); publisher.getAuthors().add( author );
s.getTransaction().commit(); author.getBooks().add( new Book( "Reflections on a Wimpy Kid", author ) );
s.clear(); session.persist( author );
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.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 { public static class InitializingPreUpdateEventListener implements PreUpdateEventListener {
@ -112,7 +126,7 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes
// Iterate through all fields of the updated object // Iterate through all fields of the updated object
for ( int i = 0; i < properties.length; i++ ) { for ( int i = 0; i < properties.length; i++ ) {
if ( oldValues != null && oldValues[i] != null ) { 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 // force any proxies and/or collections to initialize to illustrate HHH-2763
foundAny = true; foundAny = true;
Hibernate.initialize( oldValues ); Hibernate.initialize( oldValues );

View File

@ -10,10 +10,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.jpa.boot.spi.IntegratorProvider; import org.hibernate.jpa.boot.spi.IntegratorProvider;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
@ -26,16 +26,10 @@ public class DtoIntegratorProvider implements IntegratorProvider {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
metadata.getImports().put( "PersonDto", PersonDto.class.getName() ); metadata.getImports().put( "PersonDto", PersonDto.class.getName() );
} }
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
}
} }
); );
} }

View File

@ -13,6 +13,7 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CascadingActions; 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.internal.DefaultPersistEventListener;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.AutoFlushEventListener; import org.hibernate.event.spi.AutoFlushEventListener;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.EventType; import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.FlushEntityEventListener; import org.hibernate.event.spi.FlushEntityEventListener;
import org.hibernate.event.spi.FlushEventListener; 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.event.spi.PersistEventListener;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.SkipLog; import org.hibernate.testing.SkipLog;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
@ -55,7 +54,7 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
@Override @Override
protected void applySettings(StandardServiceRegistryBuilder builder) { 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" ); builder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "false" );
} }
@ -69,17 +68,17 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
public void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { public void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
builder.applyIntegrator( builder.applyIntegrator(
new Integrator() { new Integrator() {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry().getService(
EventListenerRegistry.class );
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() ); eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
eventListenerRegistry.setListeners( eventListenerRegistry.setListeners(
EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners()
@ -88,11 +87,6 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() );
eventListenerRegistry.setListeners( EventType.FLUSH_ENTITY, buildFlushEntityEventListeners() ); 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 { public static class JPAAutoFlushEventListener extends DefaultAutoFlushEventListener {
// not sure why EM code has this ... // not sure why EM code has this ...
public static final AutoFlushEventListener INSTANCE = new JPAAutoFlushEventListener(); 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 { public static class JPAFlushEventListener extends DefaultFlushEventListener {
// not sure why EM code has this ... // not sure why EM code has this ...
public static final FlushEventListener INSTANCE = new JPAFlushEventListener(); 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 { public static class JPAFlushEntityEventListener extends DefaultFlushEntityEventListener {
@ -176,8 +150,7 @@ public abstract class AbstractJPATest extends BaseSessionFactoryFunctionalTest {
final int isolation; final int isolation;
try (Session testSession = sessionFactory().openSession()) { try (Session testSession = sessionFactory().openSession()) {
isolation = testSession.doReturningWork( isolation = testSession.doReturningWork(
connection -> Connection::getTransactionIsolation
connection.getTransactionIsolation()
); );
} }
if ( isolation < Connection.TRANSACTION_READ_COMMITTED ) { if ( isolation < Connection.TRANSACTION_READ_COMMITTED ) {

View File

@ -12,6 +12,7 @@ import jakarta.persistence.criteria.CriteriaQuery;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.internal.DefaultLoadEventListener; import org.hibernate.event.internal.DefaultLoadEventListener;
import org.hibernate.event.service.spi.EventListenerRegistry; 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.LoadEvent;
import org.hibernate.event.spi.LoadEventListener; import org.hibernate.event.spi.LoadEventListener;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.DomainModel; 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.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -49,22 +48,17 @@ public class EagerKeyManyToOneTest {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
integrate( serviceRegistry ); integrate( sessionFactory );
} }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { private void integrate(SessionFactoryImplementor sessionFactory) {
serviceRegistry.getService( EventListenerRegistry.class ).prependListeners( sessionFactory.getServiceRegistry().getService( EventListenerRegistry.class ).prependListeners(
EventType.LOAD, EventType.LOAD,
new CustomLoadListener() new CustomLoadListener()
); );
} }
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
} }
@AfterEach @AfterEach

View File

@ -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) {
}
}

View File

@ -7,20 +7,16 @@
package org.hibernate.testing.jdbc; package org.hibernate.testing.jdbc;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
public class SharedDriverManagerTypeCacheClearingIntegrator implements Integrator { public class SharedDriverManagerTypeCacheClearingIntegrator implements Integrator {
@Override @Override
public void integrate( public void integrate(
Metadata metadata, Metadata metadata,
SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryImplementor sessionFactory) {
SharedDriverManagerConnectionProviderImpl.getInstance().clearTypeCache(); SharedDriverManagerConnectionProviderImpl.getInstance().clearTypeCache();
} }
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
} }

View File

@ -246,6 +246,7 @@ XML processing.
* Removed `org.hibernate.Session#delete` in favor of `org.hibernate.Session#remove` * 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 `org.hibernate.annotations.CascadeType.DELETE` in favor of `org.hibernate.annotations.CascadeType#REMOVE`
* Removed the attribute value from `@DynamicInsert` and `@DynamicUpdate` * 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]] [[todo]]