diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java index 9840f45447..98d10147a9 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java @@ -31,14 +31,14 @@ import javax.management.ObjectName; import org.hibernate.c3p0.internal.C3P0ConnectionProvider; import org.hibernate.cfg.Environment; -import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -50,8 +50,12 @@ public class C3P0ConnectionProviderTest extends BaseCoreFunctionalTestCase { @Test public void testC3P0isDefaultWhenThereIsC3P0Properties() { JdbcServices jdbcServices = serviceRegistry().getService( JdbcServices.class ); - ConnectionProvider provider = jdbcServices.getConnectionProvider(); - assertTrue( provider instanceof C3P0ConnectionProvider ); + ConnectionProviderJdbcConnectionAccess connectionAccess = + assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider() instanceof C3P0ConnectionProvider ); } diff --git a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java index c44aac4b09..436b0e272b 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java @@ -52,20 +52,19 @@ import org.hibernate.stat.Statistics; * @author Steve Ebersole */ public interface SessionFactory extends Referenceable, Serializable, java.io.Closeable { - /** * Get the special options used to build the factory. * * @return The special options used to build the factory. */ - public SessionFactoryOptions getSessionFactoryOptions(); + SessionFactoryOptions getSessionFactoryOptions(); /** * Obtain a {@link Session} builder. * * @return The session builder */ - public SessionBuilder withOptions(); + SessionBuilder withOptions(); /** * Open a {@link Session}. @@ -78,7 +77,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Indicates a problem opening the session; pretty rare here. */ - public Session openSession() throws HibernateException; + Session openSession() throws HibernateException; /** * Obtains the current session. The definition of what exactly "current" @@ -93,21 +92,21 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Indicates an issue locating a suitable current session. */ - public Session getCurrentSession() throws HibernateException; + Session getCurrentSession() throws HibernateException; /** * Obtain a {@link StatelessSession} builder. * * @return The stateless session builder */ - public StatelessSessionBuilder withStatelessOptions(); + StatelessSessionBuilder withStatelessOptions(); /** * Open a new stateless session. * * @return The created stateless session. */ - public StatelessSession openStatelessSession(); + StatelessSession openStatelessSession(); /** * Open a new stateless session, utilizing the specified JDBC @@ -117,7 +116,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @return The created stateless session. */ - public StatelessSession openStatelessSession(Connection connection); + StatelessSession openStatelessSession(Connection connection); /** * Retrieve the {@link ClassMetadata} associated with the given entity class. @@ -129,7 +128,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Generally null is returned instead of throwing. */ - public ClassMetadata getClassMetadata(Class entityClass); + ClassMetadata getClassMetadata(Class entityClass); /** * Retrieve the {@link ClassMetadata} associated with the given entity class. @@ -142,7 +141,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * @throws HibernateException Generally null is returned instead of throwing. * @since 3.0 */ - public ClassMetadata getClassMetadata(String entityName); + ClassMetadata getClassMetadata(String entityName); /** * Get the {@link CollectionMetadata} associated with the named collection role. @@ -154,7 +153,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Generally null is returned instead of throwing. */ - public CollectionMetadata getCollectionMetadata(String roleName); + CollectionMetadata getCollectionMetadata(String roleName); /** * Retrieve the {@link ClassMetadata} for all mapped entities. @@ -166,7 +165,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @since 3.0 changed key from {@link Class} to {@link String}. */ - public Map getAllClassMetadata(); + Map getAllClassMetadata(); /** * Get the {@link CollectionMetadata} for all mapped collections. @@ -175,14 +174,14 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Generally empty map is returned instead of throwing. */ - public Map getAllCollectionMetadata(); + Map getAllCollectionMetadata(); /** * Retrieve the statistics fopr this factory. * * @return The statistics. */ - public Statistics getStatistics(); + Statistics getStatistics(); /** * Destroy this SessionFactory and release all resources (caches, @@ -196,159 +195,28 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * * @throws HibernateException Indicates an issue closing the factory. */ - public void close() throws HibernateException; + void close() throws HibernateException; /** * Is this factory already closed? * * @return True if this factory is already closed; false otherwise. */ - public boolean isClosed(); + boolean isClosed(); /** * Obtain direct access to the underlying cache regions. * * @return The direct cache access API. */ - public Cache getCache(); - - /** - * Evict all entries from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param persistentClass The entity class for which to evict data. - * - * @throws HibernateException Generally will mean that either that - * 'persisttentClass' did not name a mapped entity or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictEntityRegion(Class)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evict(Class persistentClass) throws HibernateException; - - /** - * Evict an entry from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param persistentClass The entity class for which to evict data. - * @param id The entity id - * - * @throws HibernateException Generally will mean that either that - * 'persisttentClass' did not name a mapped entity or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#containsEntity(Class, Serializable)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evict(Class persistentClass, Serializable id) throws HibernateException; - - /** - * Evict all entries from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param entityName The entity name for which to evict data. - * - * @throws HibernateException Generally will mean that either that - * 'persisttentClass' did not name a mapped entity or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictEntityRegion(String)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictEntity(String entityName) throws HibernateException; - - /** - * Evict an entry from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param entityName The entity name for which to evict data. - * @param id The entity id - * - * @throws HibernateException Generally will mean that either that - * 'persisttentClass' did not name a mapped entity or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictEntity(String,Serializable)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictEntity(String entityName, Serializable id) throws HibernateException; - - /** - * Evict all entries from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param roleName The name of the collection role whose regions should be evicted - * - * @throws HibernateException Generally will mean that either that - * 'roleName' did not name a mapped collection or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictCollectionRegion(String)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictCollection(String roleName) throws HibernateException; - - /** - * Evict an entry from the second-level cache. This method occurs outside - * of any transaction; it performs an immediate "hard" remove, so does not respect - * any transaction isolation semantics of the usage strategy. Use with care. - * - * @param roleName The name of the collection role - * @param id The id of the collection owner - * - * @throws HibernateException Generally will mean that either that - * 'roleName' did not name a mapped collection or a problem - * communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictCollection(String,Serializable)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictCollection(String roleName, Serializable id) throws HibernateException; - - /** - * Evict any query result sets cached in the named query cache region. - * - * @param cacheRegion The named query cache region from which to evict. - * - * @throws HibernateException Since a not-found 'cacheRegion' simply no-ops, - * this should indicate a problem communicating with underlying cache impl. - * - * @deprecated Use {@link Cache#evictQueryRegion(String)} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictQueries(String cacheRegion) throws HibernateException; - - /** - * Evict any query result sets cached in the default query cache region. - * - * @throws HibernateException Indicate a problem communicating with - * underlying cache impl. - * - * @deprecated Use {@link Cache#evictQueryRegions} accessed through - * {@link #getCache()} instead. - */ - @Deprecated - public void evictQueries() throws HibernateException; + Cache getCache(); /** * Obtain a set of the names of all filters defined on this SessionFactory. * * @return The set of filter names. */ - public Set getDefinedFilterNames(); + Set getDefinedFilterNames(); /** * Obtain the definition of a filter by name. @@ -357,7 +225,7 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * @return The filter definition. * @throws HibernateException If no filter defined with the given name. */ - public FilterDefinition getFilterDefinition(String filterName) throws HibernateException; + FilterDefinition getFilterDefinition(String filterName) throws HibernateException; /** * Determine if this session factory contains a fetch profile definition @@ -366,12 +234,12 @@ public interface SessionFactory extends Referenceable, Serializable, java.io.Clo * @param name The name to check * @return True if there is such a fetch profile; false otherwise. */ - public boolean containsFetchProfileDefinition(String name); + boolean containsFetchProfileDefinition(String name); /** * Retrieve this factory's {@link TypeHelper}. * * @return The factory's {@link TypeHelper} */ - public TypeHelper getTypeHelper(); + TypeHelper getTypeHelper(); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index a0a1481175..4e57f506c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -181,13 +181,17 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator + * {@link SqlExceptionHelper#getSqlExceptionConverter()} instead as obtained from {@link #getServiceRegistry()} */ + @Deprecated public SQLExceptionConverter getSQLExceptionConverter(); - // TODO: deprecate??? /** * Retrieves the SqlExceptionHelper in effect for this SessionFactory. * * @return The SqlExceptionHelper for this SessionFactory. + * + * @deprecated since 5.0; use {@link JdbcServices#getSqlExceptionHelper()} instead as + * obtained from {@link #getServiceRegistry()} */ + @Deprecated public SqlExceptionHelper getSQLExceptionHelper(); /** - * @deprecated Use {@link #getSessionFactoryOptions()} instead + * @deprecated since 5.0; use {@link #getSessionFactoryOptions()} instead */ @Deprecated public Settings getSettings(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 623ffb6f2e..904464946b 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -182,8 +182,7 @@ import org.hibernate.type.TypeResolver; * @see org.hibernate.persister.collection.CollectionPersister * @author Gavin King */ -public final class SessionFactoryImpl - implements SessionFactoryImplementor { +public final class SessionFactoryImpl implements SessionFactoryImplementor { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, @@ -1022,10 +1021,6 @@ public final class SessionFactoryImpl return getEntityPersister( className ).getPropertyType( propertyName ); } - public ConnectionProvider getConnectionProvider() { - return jdbcServices.getConnectionProvider(); - } - /** * Closes the session factory, releasing all held resources. * diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java index d39ed298a3..b81d84cf6b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -279,7 +279,7 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase { s.close(); sessionFactory().getStatistics().clear(); sessionFactory().getStatistics().setStatisticsEnabled( true ); - sessionFactory().evict( ZipCode.class ); + sessionFactory().getCache().evictEntityRegion( ZipCode.class ); s = openSession(); tx = s.beginTransaction(); s.get( ZipCode.class, zc.code ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java index af41af1f66..fd177fede6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java @@ -407,9 +407,9 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase { s.persist( chaos ); s.flush(); s.clear(); - s.getSessionFactory().evict( Chaos.class ); + s.getSessionFactory().getCache().evictEntityRegion( Chaos.class ); - Chaos resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() ); + Chaos resultChaos = s.load( Chaos.class, chaos.getId() ); assertEquals( upperName, resultChaos.getName() ); assertEquals( "nickname", resultChaos.getNickname() ); @@ -439,16 +439,16 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase { chaos.getParticles().add( p ); s.flush(); s.clear(); - s.getSessionFactory().evict( Chaos.class ); + s.getSessionFactory().getCache().evictEntityRegion( Chaos.class ); - Chaos resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() ); + Chaos resultChaos = s.load( Chaos.class, chaos.getId() ); assertEquals( 2, resultChaos.getParticles().size() ); resultChaos.getParticles().remove( resultChaos.getParticles().iterator().next() ); resultChaos.getParticles().remove( resultChaos.getParticles().iterator().next() ); s.flush(); s.clear(); - resultChaos = (Chaos) s.load( Chaos.class, chaos.getId() ); + resultChaos = s.load( Chaos.class, chaos.getId() ); assertEquals( 0, resultChaos.getParticles().size() ); tx.rollback(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java b/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java index 771db25d91..fc8a900af4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/test/common/BasicTestingJdbcServiceImpl.java @@ -96,10 +96,6 @@ public class BasicTestingJdbcServiceImpl implements JdbcServices { return jdbcEnvironment; } - public ConnectionProvider getConnectionProvider() { - return connectionProvider; - } - @Override public JdbcConnectionAccess getBootstrapJdbcConnectionAccess() { return jdbcConnectionAccess; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/AggressiveReleaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/AggressiveReleaseTest.java index 0bd51a182f..06d422f160 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/AggressiveReleaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/AggressiveReleaseTest.java @@ -59,7 +59,7 @@ public class AggressiveReleaseTest extends BaseCoreFunctionalTestCase { Connection connection = null; Statement stmnt = null; try { - connection = services.getConnectionProvider().getConnection(); + connection = services.getBootstrapJdbcConnectionAccess().obtainConnection(); stmnt = connection.createStatement(); stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" ); @@ -74,7 +74,7 @@ public class AggressiveReleaseTest extends BaseCoreFunctionalTestCase { } if ( connection != null ) { try { - connection.close(); + services.getBootstrapJdbcConnectionAccess().releaseConnection( connection ); } catch ( SQLException ignore ) { } @@ -87,7 +87,7 @@ public class AggressiveReleaseTest extends BaseCoreFunctionalTestCase { Connection connection = null; Statement stmnt = null; try { - connection = services.getConnectionProvider().getConnection(); + connection = services.getBootstrapJdbcConnectionAccess().obtainConnection(); stmnt = connection.createStatement(); stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); } @@ -101,7 +101,7 @@ public class AggressiveReleaseTest extends BaseCoreFunctionalTestCase { } if ( connection != null ) { try { - connection.close(); + services.getBootstrapJdbcConnectionAccess().releaseConnection( connection ); } catch ( SQLException ignore ) { } diff --git a/hibernate-core/src/test/java/org/hibernate/test/joinfetch/JoinFetchTest.java b/hibernate-core/src/test/java/org/hibernate/test/joinfetch/JoinFetchTest.java index e5f67fc73c..be56227876 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/joinfetch/JoinFetchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/joinfetch/JoinFetchTest.java @@ -91,11 +91,11 @@ public class JoinFetchTest extends BaseCoreFunctionalTestCase { t.commit(); s.close(); - sessionFactory().evict(Item.class); + sessionFactory().getCache().evictEntityRegion(Item.class); s = openSession(); t = s.beginTransaction(); - i = (Item) s.get( Item.class, i.getId() ); + i = s.get( Item.class, i.getId() ); assertTrue( Hibernate.isInitialized( i.getBids() ) ); assertEquals( i.getBids().size(), 2 ); assertTrue( Hibernate.isInitialized( i.getComments() ) ); @@ -103,11 +103,11 @@ public class JoinFetchTest extends BaseCoreFunctionalTestCase { t.commit(); s.close(); - sessionFactory().evict(Bid.class); + sessionFactory().getCache().evictEntityRegion(Bid.class); s = openSession(); t = s.beginTransaction(); - b = (Bid) s.get( Bid.class, b.getId() ); + b = s.get( Bid.class, b.getId() ); assertTrue( Hibernate.isInitialized( b.getItem() ) ); assertTrue( Hibernate.isInitialized( b.getItem().getComments() ) ); assertEquals( b.getItem().getComments().size(), 3 ); @@ -115,7 +115,7 @@ public class JoinFetchTest extends BaseCoreFunctionalTestCase { t.commit(); s.close(); - sessionFactory().evictCollection(Item.class.getName() + ".bids"); + sessionFactory().getCache().evictCollectionRegion(Item.class.getName() + ".bids"); s = openSession(); t = s.beginTransaction(); @@ -254,11 +254,11 @@ public class JoinFetchTest extends BaseCoreFunctionalTestCase { s = openSession(); t = s.beginTransaction(); - hb = (Group) s.get(Group.class, "hibernate"); + hb = s.get(Group.class, "hibernate"); assertTrue( Hibernate.isInitialized( hb.getUsers() ) ); gavin = (User) hb.getUsers().get("gavin"); assertFalse( Hibernate.isInitialized( gavin.getGroups() ) ); - max = (User) s.get(User.class, "max"); + max = s.get(User.class, "max"); assertFalse( Hibernate.isInitialized( max.getGroups() ) ); t.commit(); s.close(); @@ -272,7 +272,7 @@ public class JoinFetchTest extends BaseCoreFunctionalTestCase { assertTrue( Hibernate.isInitialized( hb.getUsers() ) ); gavin = (User) hb.getUsers().get("gavin"); assertTrue( Hibernate.isInitialized( gavin.getGroups() ) ); - max = (User) s.get(User.class, "max"); + max = s.get(User.class, "max"); assertTrue( Hibernate.isInitialized( max.getGroups() ) ); t.commit(); s.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java index 78809c99c1..83bb3e1c1a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java @@ -307,7 +307,7 @@ public class FooBarTest extends LegacyTestCase { s.getTransaction().commit(); s.close(); - sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet"); + sessionFactory().getCache().evictCollectionRegion("org.hibernate.test.legacy.Baz.fooSet"); s = openSession(); s.beginTransaction(); @@ -356,7 +356,7 @@ public class FooBarTest extends LegacyTestCase { s.getTransaction().commit(); s.close(); - sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet"); + sessionFactory().getCache().evictCollectionRegion("org.hibernate.test.legacy.Baz.fooSet"); s = openSession(); s.beginTransaction(); @@ -1560,7 +1560,7 @@ public class FooBarTest extends LegacyTestCase { s.getTransaction().commit(); s.close(); - sessionFactory().evict(Foo.class); + sessionFactory().getCache().evictEntityRegion(Foo.class); s = openSession(); s.beginTransaction(); @@ -3255,7 +3255,7 @@ public class FooBarTest extends LegacyTestCase { txn.commit(); s.close(); - sessionFactory().evict(Glarch.class); + sessionFactory().getCache().evictEntityRegion(Glarch.class); s = openSession(); txn = s.beginTransaction(); @@ -3274,7 +3274,7 @@ public class FooBarTest extends LegacyTestCase { txn.commit(); s.close(); - sessionFactory().evict(Glarch.class); + sessionFactory().getCache().evictEntityRegion(Glarch.class); s = openSession(); txn = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java index 6d28390b85..a080474150 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java @@ -44,6 +44,8 @@ import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.MckoiDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.SAPDBDialect; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; +import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.jdbc.AbstractWork; import org.hibernate.testing.SkipLog; @@ -883,15 +885,16 @@ public class MasterDetailTest extends LegacyTestCase { } protected boolean isSerializableIsolationEnforced() throws Exception { + JdbcConnectionAccess connectionAccess = sessionFactory().getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); Connection conn = null; try { - conn = sessionFactory().getConnectionProvider().getConnection(); + conn = connectionAccess.obtainConnection(); return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE; } finally { if ( conn != null ) { try { - sessionFactory().getConnectionProvider().closeConnection( conn ); + connectionAccess.releaseConnection( conn ); } catch ( Throwable ignore ) { // ignore... diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java index f54d6a6fbf..7b97f983a0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java @@ -127,7 +127,7 @@ public class MultiTableTest extends LegacyTestCase { s.getTransaction().commit(); s.close(); - sessionFactory().evict(SubMulti.class); + sessionFactory().getCache().evictEntityRegion(SubMulti.class); final Session s2 = openSession(); s2.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/OneToOneCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/OneToOneCacheTest.java index 740b23d19d..a915ca1acb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/OneToOneCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/OneToOneCacheTest.java @@ -64,7 +64,7 @@ public class OneToOneCacheTest extends LegacyTestCase { assertNotNull( mainObject.getObj2() ); // after evicting, it works. - sessionFactory().evict( MainObject.class ); + sessionFactory().getCache().evictEntityRegion( MainObject.class ); mainObject = readMainObject(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java index 3d7859e4cc..8cdcea18f7 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java @@ -132,7 +132,7 @@ public class QueryCacheTest extends BaseNonConfigCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "JBPAPP-4224" ) public void testHitCacheInSameSession() { - sessionFactory().evictQueries(); + sessionFactory().getCache().evictQueryRegions(); sessionFactory().getStatistics().clear(); Session s = openSession(); List list = new ArrayList(); @@ -178,7 +178,7 @@ public class QueryCacheTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testQueryCacheInvalidation() throws Exception { - sessionFactory().evictQueries(); + sessionFactory().getCache().evictQueryRegions(); sessionFactory().getStatistics().clear(); final String queryString = "from Item i where i.name='widget'"; @@ -278,7 +278,7 @@ public class QueryCacheTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testQueryCacheFetch() throws Exception { - sessionFactory().evictQueries(); + sessionFactory().getCache().evictQueryRegions(); sessionFactory().getStatistics().clear(); // persist our 2 items. This saves them to the db, but also into the second level entity cache region @@ -314,7 +314,7 @@ public class QueryCacheTest extends BaseNonConfigCoreFunctionalTestCase { // evict the Items from the second level entity cache region - sessionFactory().evict(Item.class); + sessionFactory().getCache().evictEntityRegion( Item.class ); // now, perform the cacheable query again. this time we should not execute the query (query cache hit). // However, the Items will not be found in second level entity cache region this time (we evicted them above) @@ -341,7 +341,7 @@ public class QueryCacheTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testProjectionCache() throws Exception { - sessionFactory().evictQueries(); + sessionFactory().getCache().evictQueryRegions(); sessionFactory().getStatistics().clear(); final String queryString = "select i.description as desc from Item i where i.name='widget'"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java index 5a3dc82bc2..976514da3f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java @@ -23,6 +23,7 @@ */ package org.hibernate.test.service; +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -35,6 +36,9 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; +import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator; +import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.env.ConnectionProviderBuilder; @@ -48,13 +52,16 @@ import org.junit.Test; public class ServiceBootstrappingTest extends BaseUnitTestCase { @Test public void testBasicBuild() { - StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() + final StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() ) .build(); - JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - + final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); assertFalse( jdbcServices.getSqlStatementLogger().isLogToStdout() ); serviceRegistry.destroy(); @@ -72,7 +79,11 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); assertTrue( jdbcServices.getSqlStatementLogger().isLogToStdout() ); serviceRegistry.destroy(); @@ -86,7 +97,11 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); props.setProperty( Environment.DIALECT, H2Dialect.class.getName() ); @@ -98,7 +113,11 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { jdbcServices = serviceRegistry.getService( JdbcServices.class ); assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( UserSuppliedConnectionProviderImpl.class ) ); + connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( UserSuppliedConnectionProviderImpl.class ) ); serviceRegistry.destroy(); } diff --git a/hibernate-ehcache/src/test/java/org/hibernate/test/cache/HibernateCacheTest.java b/hibernate-ehcache/src/test/java/org/hibernate/test/cache/HibernateCacheTest.java index 1021484fec..3e6b5a1355 100644 --- a/hibernate-ehcache/src/test/java/org/hibernate/test/cache/HibernateCacheTest.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/test/cache/HibernateCacheTest.java @@ -108,7 +108,7 @@ public class HibernateCacheTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testEmptySecondLevelCacheEntry() throws Exception { - sessionFactory().evictEntity( Item.class.getName() ); + sessionFactory().getCache().evictEntityRegion( Item.class.getName() ); Statistics stats = sessionFactory().getStatistics(); stats.clear(); SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( REGION_PREFIX + Item.class.getName() ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/DateTimeParameterTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/DateTimeParameterTest.java index 37fea5d05b..b97b40dab4 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/DateTimeParameterTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/DateTimeParameterTest.java @@ -48,6 +48,8 @@ import java.util.List; import java.util.Map; import org.hibernate.dialect.DerbyTenSevenDialect; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; +import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernateEntityManagerFactory; @@ -155,9 +157,10 @@ public class DateTimeParameterTest extends BaseUnitTestCase { private void createProcedures(HibernateEntityManagerFactory emf) { final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); + final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; try { - conn = sf.getConnectionProvider().getConnection(); + conn = connectionAccess.obtainConnection(); conn.setAutoCommit( false ); try { @@ -217,7 +220,7 @@ public class DateTimeParameterTest extends BaseUnitTestCase { } try { - sf.getConnectionProvider().closeConnection( conn ); + connectionAccess.releaseConnection( conn ); } catch (SQLException ignore) { } @@ -281,11 +284,11 @@ public class DateTimeParameterTest extends BaseUnitTestCase { } private void dropProcedures(HibernateEntityManagerFactory emf) { - final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); + final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; try { - conn = sf.getConnectionProvider().getConnection(); + conn = connectionAccess.obtainConnection(); conn.setAutoCommit( false ); try { @@ -306,7 +309,7 @@ public class DateTimeParameterTest extends BaseUnitTestCase { } try { - sf.getConnectionProvider().closeConnection( conn ); + connectionAccess.releaseConnection( conn ); } catch (SQLException ignore) { } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/JpaTckUsageTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/JpaTckUsageTest.java index e734c79887..02bb5e0859 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/JpaTckUsageTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/procedure/JpaTckUsageTest.java @@ -37,6 +37,8 @@ import java.util.List; import java.util.Map; import org.hibernate.dialect.DerbyTenSevenDialect; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; +import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernateEntityManagerFactory; @@ -316,9 +318,10 @@ public class JpaTckUsageTest extends BaseUnitTestCase { private void createProcedures(HibernateEntityManagerFactory emf) { final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); + final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; try { - conn = sf.getConnectionProvider().getConnection(); + conn = connectionAccess.obtainConnection(); conn.setAutoCommit( false ); try { @@ -348,7 +351,7 @@ public class JpaTckUsageTest extends BaseUnitTestCase { } try { - sf.getConnectionProvider().closeConnection( conn ); + connectionAccess.releaseConnection( conn ); } catch (SQLException ignore) { } @@ -429,11 +432,11 @@ public class JpaTckUsageTest extends BaseUnitTestCase { } private void dropProcedures(HibernateEntityManagerFactory emf) { - final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); + final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; try { - conn = sf.getConnectionProvider().getConnection(); + conn = connectionAccess.obtainConnection(); conn.setAutoCommit( false ); try { @@ -454,7 +457,7 @@ public class JpaTckUsageTest extends BaseUnitTestCase { } try { - sf.getConnectionProvider().closeConnection( conn ); + connectionAccess.releaseConnection( conn ); } catch (SQLException ignore) { } diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java index 22a2e56d1b..bfd73ddb47 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java @@ -23,22 +23,24 @@ */ package org.hibernate.test.hikaricp; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.hikaricp.internal.HikariCPConnectionProvider; + import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Brett Meyer */ @@ -47,10 +49,13 @@ public class HikariCPConnectionProviderTest extends BaseCoreFunctionalTestCase { @Test public void testHikariCPConnectionProvider() throws Exception { JdbcServices jdbcServices = serviceRegistry().getService( JdbcServices.class ); - ConnectionProvider provider = jdbcServices.getConnectionProvider(); - assertTrue( provider instanceof HikariCPConnectionProvider ); + ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTyping( HikariCPConnectionProvider.class, connectionAccess.getConnectionProvider() ); - HikariCPConnectionProvider hikariCP = (HikariCPConnectionProvider) provider; + HikariCPConnectionProvider hikariCP = (HikariCPConnectionProvider) connectionAccess.getConnectionProvider(); // For simplicity's sake, using the following in hibernate.properties: // hibernate.hikari.minimumPoolSize 2 // hibernate.hikari.maximumPoolSize 2