public static DataSource getDataSource(SessionFactory sessionFactory) { if (sessionFactory instanceof SessionFactoryImplementor) { ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider(); if (cp instanceof DataSourceConnectionProvider) { return ((DataSourceConnectionProvider) cp) .getDataSource(); } } return null; }
public ConnectionProvider getConnectionProvider() { return getCurrentSessionFactoryImplementor().getConnectionProvider(); }
/** * Determine the DataSource of the given SessionFactory. * @param sessionFactory the SessionFactory to check * @return the DataSource, or {@code null} if none found * @see org.hibernate.engine.SessionFactoryImplementor#getConnectionProvider * @see LocalDataSourceConnectionProvider */ public static DataSource getDataSource(SessionFactory sessionFactory) { if (sessionFactory instanceof SessionFactoryImplementor) { ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider(); if (cp instanceof LocalDataSourceConnectionProvider) { return ((LocalDataSourceConnectionProvider) cp).getDataSource(); } } return null; }
protected Connection getConnection() throws SQLException { if (sessionFactory instanceof SessionFactoryImplementor) { ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider(); return cp.getConnection(); } return super.getConnection(); }
protected Connection getConnection() throws SQLException { if (sessionFactory instanceof SessionFactoryImplementor) { ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider(); return cp.getConnection(); } return super.getConnection(); }
public Connection openConnection() throws HibernateException { log.debug("opening JDBC connection"); try { return factory.getConnectionProvider().getConnection(); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot open connection" ); } }
public Connection openConnection() throws HibernateException { log.debug("opening JDBC connection"); try { return factory.getConnectionProvider().getConnection(); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot open connection" ); } }
/** * Physically closes the JDBC Connection. */ private void closeConnection() { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection [" + batcher.openResourceStatsAsString() + "]" ); } try { if ( !connection.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings( connection ); } factory.getConnectionProvider().closeConnection( connection ); connection = null; } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }
/** * Pysically opens a JDBC Connection. * * @throws HibernateException */ private void openConnection() throws HibernateException { if ( connection != null ) { return; } log.debug("opening JDBC connection"); try { connection = factory.getConnectionProvider().getConnection(); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot open connection" ); } callback.connectionOpened(); // register synch; stats.connect() }
public void closeConnection(Connection conn) throws HibernateException { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection" + preparedStatementCountsToString() + resultSetCountsToString() ); } try { if ( !conn.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings(conn); } factory.getConnectionProvider().closeConnection(conn); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }
public void execute() throws BuildException { Configuration configuration = AntHelper.getConfiguration(config, properties); SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory(); ConnectionProvider connectionProvider = sessionFactory.getConnectionProvider(); try { Connection connection = connectionProvider.getConnection(); Statement statement = connection.createStatement(); log("shutting down database"); statement.executeUpdate("SHUTDOWN"); connectionProvider.closeConnection(connection); } catch (SQLException e) { throw new BuildException("could not shut down database", e); } finally { connectionProvider.close(); } }
/** * Pysically opens a JDBC Connection. * * @throws HibernateException */ private void openConnection() throws HibernateException { log.debug("opening JDBC connection"); try { connection = factory.getConnectionProvider().getConnection(); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot open connection" ); } shouldObtainConnection = false; callback.connectionOpened(); // register synch; stats.connect() }
/** * Physically closes the JDBC Connection. */ private void closeConnection() { if ( log.isDebugEnabled() ) { log.debug( "releasing JDBC connection [" + batcher.openResourceStatsAsString() + "]" ); } try { if ( !connection.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings( connection ); } factory.getConnectionProvider().closeConnection( connection ); connection = null; } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot release connection" ); } }
public void closeConnection(Connection conn) throws HibernateException { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection" + preparedStatementCountsToString() + resultSetCountsToString() ); } try { if ( !conn.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings(conn); } factory.getConnectionProvider().closeConnection(conn); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }