@Override public Connection getConnection() throws SQLException { openConnection++; return super.getConnection(); }
@Override public Connection getConnection() throws SQLException { Transaction currentTransaction = findCurrentTransaction(); try { if ( currentTransaction == null ) { // this block handles non enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Connection connection = delegate.getConnection(); nonEnlistedConnections.add( connection ); return connection; } // this portion handles enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Connection connection = (Connection) TestingJtaPlatformImpl.synchronizationRegistry().getResource( CONNECTION_KEY ); if ( connection == null ) { connection = delegate.getConnection(); TestingJtaPlatformImpl.synchronizationRegistry().putResource( CONNECTION_KEY, connection ); XAResourceWrapper xaResourceWrapper = new XAResourceWrapper( this, connection ); currentTransaction.enlistResource( xaResourceWrapper ); } return connection; } catch (SQLException e) { throw e; } catch (Exception e) { throw new SQLException(e); } }
@Override public void releaseResources() { super.releaseResources(); try(Connection connection = connectionProvider.getConnection(); Statement statement = connection.createStatement()) { statement.execute( "DROP TABLE IF EXISTS roles CASCADE" ); } catch (SQLException e) { fail(e.getMessage()); } if ( connectionProvider != null ) { connectionProvider.stop(); } }
@Override public void buildEntityManagerFactory() { connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( Environment.getProperties() ); try(Connection connection = connectionProvider.getConnection(); Statement statement = connection.createStatement()) { statement.execute( "DROP TABLE IF EXISTS roles CASCADE" ); statement.execute( "CREATE TABLE roles ( id BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY )" ); } catch (SQLException e) { fail(e.getMessage()); } super.buildEntityManagerFactory(); }
@Before public void setUp() throws Exception { connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( properties() ); connection = connectionProvider.getConnection(); ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.HBM2DDL_CONNECTION, connection ) .build(); tool = (HibernateSchemaManagementTool) ssr.getService( SchemaManagementTool.class ); configurationValues = ssr.getService( ConfigurationService.class ).getSettings(); executionOptions = new ExecutionOptions() { @Override public boolean shouldManageNamespaces() { return true; } @Override public Map getConfigurationValues() { return configurationValues; } @Override public ExceptionHandler getExceptionHandler() { return ExceptionHandlerLoggedImpl.INSTANCE; } }; }