HHH-9790 - Remove deprecated methods from Session and SessionFactory

This commit is contained in:
Steve Ebersole 2015-05-13 09:03:44 -05:00
parent 48cafb2664
commit 13736ab5da
22 changed files with 140 additions and 262 deletions

View File

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

View File

@ -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<String,ClassMetadata> getAllClassMetadata();
Map<String,ClassMetadata> 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 <tt>SessionFactory</tt> 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();
}

View File

@ -181,13 +181,17 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
}
}
private static class ConnectionProviderJdbcConnectionAccess implements JdbcConnectionAccess {
public static class ConnectionProviderJdbcConnectionAccess implements JdbcConnectionAccess {
private final ConnectionProvider connectionProvider;
public ConnectionProviderJdbcConnectionAccess(ConnectionProvider connectionProvider) {
this.connectionProvider = connectionProvider;
}
public ConnectionProvider getConnectionProvider() {
return connectionProvider;
}
@Override
public Connection obtainConnection() throws SQLException {
return connectionProvider.getConnection();
@ -204,13 +208,17 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
}
}
private static class MultiTenantConnectionProviderJdbcConnectionAccess implements JdbcConnectionAccess {
public static class MultiTenantConnectionProviderJdbcConnectionAccess implements JdbcConnectionAccess {
private final MultiTenantConnectionProvider connectionProvider;
public MultiTenantConnectionProviderJdbcConnectionAccess(MultiTenantConnectionProvider connectionProvider) {
this.connectionProvider = connectionProvider;
}
public MultiTenantConnectionProvider getConnectionProvider() {
return connectionProvider;
}
@Override
public Connection obtainConnection() throws SQLException {
return connectionProvider.getAnyConnection();

View File

@ -30,7 +30,6 @@ import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.LobCreator;
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.spi.ExtractedDatabaseMetaData;
@ -55,7 +54,6 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
private MultiTenancyStrategy multiTenancyStrategy;
private ConnectionProvider connectionProvider;
private SqlStatementLogger sqlStatementLogger;
@Override
@ -69,9 +67,6 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
assert jdbcEnvironment != null : "JdbcEnvironment was not found!";
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues );
this.connectionProvider = MultiTenancyStrategy.NONE == multiTenancyStrategy ?
serviceRegistry.getService( ConnectionProvider.class ) :
null;
final boolean showSQL = ConfigurationHelper.getBoolean( Environment.SHOW_SQL, configValues, false );
final boolean formatSQL = ConfigurationHelper.getBoolean( Environment.FORMAT_SQL, configValues, false );
@ -84,11 +79,6 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
return jdbcEnvironment;
}
@Override
public ConnectionProvider getConnectionProvider() {
return connectionProvider;
}
@Override
public JdbcConnectionAccess getBootstrapJdbcConnectionAccess() {
return JdbcEnvironmentInitiator.buildBootstrapJdbcConnectionAccess( multiTenancyStrategy, serviceRegistry );

View File

@ -26,7 +26,6 @@ package org.hibernate.engine.jdbc.spi;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@ -45,17 +44,6 @@ public interface JdbcServices extends Service {
*/
public JdbcEnvironment getJdbcEnvironment();
/**
* Obtain service for providing JDBC connections.
*
* @return The connection provider.
*
* @deprecated See deprecation notice on {@link org.hibernate.engine.spi.SessionFactoryImplementor#getConnectionProvider()}
* for details
*/
@Deprecated
public ConnectionProvider getConnectionProvider();
public JdbcConnectionAccess getBootstrapJdbcConnectionAccess();
/**

View File

@ -152,16 +152,6 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
*/
public String[] getReturnAliases(String queryString) throws HibernateException;
/**
* Get the connection provider
*
* @deprecated Access to connections via {@link org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess} should
* be preferred over access via {@link ConnectionProvider}, whenever possible.
* {@link org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess} is tied to the Hibernate Session to
* properly account for contextual information. See {@link SessionImplementor#getJdbcConnectionAccess()}
*/
@Deprecated
public ConnectionProvider getConnectionProvider();
/**
* Get the names of all persistent classes that implement/extend the given interface/class
*/
@ -236,19 +226,25 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
*
* @return The SQLExceptionConverter for this SessionFactory.
*
* @deprecated since 5.0; use {@link JdbcServices#getSqlExceptionHelper()} ->
* {@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();

View File

@ -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.
*

View File

@ -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 );

View File

@ -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();

View File

@ -96,10 +96,6 @@ public class BasicTestingJdbcServiceImpl implements JdbcServices {
return jdbcEnvironment;
}
public ConnectionProvider getConnectionProvider() {
return connectionProvider;
}
@Override
public JdbcConnectionAccess getBootstrapJdbcConnectionAccess() {
return jdbcConnectionAccess;

View File

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

View File

@ -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();

View File

@ -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();

View File

@ -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...

View File

@ -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();

View File

@ -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();

View File

@ -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'";

View File

@ -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();
}

View File

@ -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() );

View File

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

View File

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

View File

@ -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