@Override public Connection getConnection() throws SQLException { return connectionProvider.getConnection(); }
@Override public Connection obtainConnection() throws SQLException { return connectionProvider.getConnection(); }
@Override public Connection obtainConnection() throws SQLException { return connectionProvider.getConnection(); }
public void prepare(boolean needsAutoCommit) throws SQLException { connection = provider.getConnection(); toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit(); if ( toggleAutoCommit ) { try { connection.commit(); } catch( Throwable ignore ) { // might happen with a managed connection } connection.setAutoCommit( true ); } }
@Override public Connection getConnection(String tenantIdentifier) throws SQLException { return selectConnectionProvider( tenantIdentifier ).getConnection(); }
@Override public Connection getAnyConnection() throws SQLException { return getAnyConnectionProvider().getConnection(); }
public void prepare(boolean needsAutoCommit) throws SQLException { serviceRegistry = createServiceRegistry( cfgProperties ); connection = serviceRegistry.getService( ConnectionProvider.class ).getConnection(); if ( needsAutoCommit && ! connection.getAutoCommit() ) { connection.commit(); connection.setAutoCommit( true ); } }
@Override public Connection obtainConnection() throws SQLException { try { listener.jdbcConnectionAcquisitionStart(); return connectionProvider.getConnection(); } finally { listener.jdbcConnectionAcquisitionEnd(); } }
this.jdbcConnection = connectionProvider.getConnection();
@Test public void testSettingIsolationAsNumericString() throws Exception { Properties properties = Environment.getProperties(); augmentConfigurationSettings( properties ); properties.put( AvailableSettings.ISOLATION, Integer.toString( Connection.TRANSACTION_SERIALIZABLE ) ); ConnectionProvider provider = getConnectionProviderUnderTest(); try { ( (Configurable) provider ).configure( properties ); if ( Startable.class.isInstance( provider ) ) { ( (Startable) provider ).start(); } Connection connection = provider.getConnection(); assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); provider.closeConnection( connection ); } finally { ( (Stoppable) provider ).stop(); } }
@Override public Connection obtainConnection() throws SQLException { return !settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ? serviceRegistry.getService( ConnectionProvider.class ).getConnection() : serviceRegistry.getService( MultiTenantConnectionProvider.class ).getAnyConnection(); }
@Test public void testSettingIsolationAsNumeric() throws Exception { Properties properties = Environment.getProperties(); augmentConfigurationSettings( properties ); properties.put( AvailableSettings.ISOLATION, Connection.TRANSACTION_SERIALIZABLE ); ConnectionProvider provider = getConnectionProviderUnderTest(); try { ( (Configurable) provider ).configure( properties ); if ( Startable.class.isInstance( provider ) ) { ( (Startable) provider ).start(); } Connection connection = provider.getConnection(); assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); provider.closeConnection( connection ); } finally { ( (Stoppable) provider ).stop(); } }
@Override @SuppressWarnings("unchecked") protected void addSettings(Map settings) { super.addSettings( settings ); settings.put( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE.toString() ); settings.put( Environment.CONNECTION_PROVIDER, UserSuppliedConnectionProviderImpl.class.getName() ); Connection connection; try { connection = cp.getConnection(); try { boolean supportsScroll = connection.getMetaData().supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE ); settings.put( Environment.USE_SCROLLABLE_RESULTSET, "" + supportsScroll ); } finally { connection.close(); } } catch (SQLException ignore) { } }
public void prepare(boolean allowAggressiveRelease) throws SQLException { dialect = ConnectionProviderBuilder.getCorrespondingDialect(); connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease ); sqlStatementLogger = new SqlStatementLogger( true, false ); Connection jdbcConnection = connectionProvider.getConnection(); try { jdbcEnvironment = new JdbcEnvironmentImpl( jdbcConnection.getMetaData(), dialect ); } finally { try { connectionProvider.closeConnection( jdbcConnection ); } catch (SQLException ignore) { } } this.jdbcConnectionAccess = new JdbcConnectionAccessImpl( connectionProvider ); }
@Test public void testSettingIsolationAsName() throws Exception { Properties properties = Environment.getProperties(); augmentConfigurationSettings( properties ); properties.put( AvailableSettings.ISOLATION, "TRANSACTION_SERIALIZABLE" ); ConnectionProvider provider = getConnectionProviderUnderTest(); try { ( (Configurable) provider ).configure( properties ); if ( Startable.class.isInstance( provider ) ) { ( (Startable) provider ).start(); } Connection connection = provider.getConnection(); assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); provider.closeConnection( connection ); } finally { ( (Stoppable) provider ).stop(); } }
@Test public void testSettingIsolationAsNameAlt() throws Exception { Properties properties = Environment.getProperties(); augmentConfigurationSettings( properties ); properties.put( AvailableSettings.ISOLATION, "SERIALIZABLE" ); ConnectionProvider provider = getConnectionProviderUnderTest(); try { ( (Configurable) provider ).configure( properties ); if ( Startable.class.isInstance( provider ) ) { ( (Startable) provider ).start(); } Connection connection = provider.getConnection(); assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); provider.closeConnection( connection ); } finally { ( (Stoppable) provider ).stop(); } } }
@Override protected Session getSessionUnderTest() throws Throwable { connectionUnderTest = cp.getConnection(); Session session = sessionFactory().withOptions().connection( connectionUnderTest ).openSession(); session.beginTransaction(); return session; }
@Test @RequiresDialect(value = H2Dialect.class, comment = "this is more like a unit test") public void testUserProvidedConnection() throws Exception { ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider(); Session s = sessionFactory().withOptions().connection( dcp.getConnection() ).openSession(); Transaction tx = s.beginTransaction(); s.createQuery( "from Fo" ).list(); tx.commit(); Connection c = s.disconnect(); assertTrue( c != null ); s.reconnect( c ); tx = s.beginTransaction(); s.createQuery( "from Fo" ).list(); tx.commit(); c.close(); }
@Override protected void prepareTest() throws Exception { super.prepareTest(); try { Connection conn = cp.getConnection(); try { final GenerationTargetToDatabase target = new GenerationTargetToDatabase( new DdlTransactionIsolatorTestingImpl( serviceRegistry(), conn ), true ); new SchemaCreatorImpl( serviceRegistry() ).doCreation( metadata(), false, target ); } finally { cp.closeConnection( conn ); } } catch( Throwable ignore ) { } }
@Override protected void cleanupTest() throws Exception { try { Connection conn = cp.getConnection(); try { final GenerationTargetToDatabase target = new GenerationTargetToDatabase( new DdlTransactionIsolatorTestingImpl( serviceRegistry(), conn ), true ); new SchemaDropperImpl( serviceRegistry() ).doDrop( metadata(), false, target ); } finally { cp.closeConnection( conn ); } } catch( Throwable ignore ) { } super.cleanupTest(); } }