本文整理汇总了Java中org.hibernate.connection.ConnectionProvider.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionProvider.getConnection方法的具体用法?Java ConnectionProvider.getConnection怎么用?Java ConnectionProvider.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.connection.ConnectionProvider
的用法示例。
在下文中一共展示了ConnectionProvider.getConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownDBIfNeeded
import org.hibernate.connection.ConnectionProvider; //导入方法依赖的package包/类
@Override
public void shutdownDBIfNeeded() {
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getSessionFactory();
ConnectionProvider connectionProvider = sessionFactory.getConnectionProvider();
try {
Connection connection = connectionProvider.getConnection();
try {
String dbName = connection.getMetaData().getDatabaseProductName();
if (dbName.startsWith("HSQL")) {
new JDBCWrapper(connection).execute("SHUTDOWN");
LOG.info("Shutdown on HSQL Database was successful");
}
} finally {
connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
LOG.warn("Error shutting down database connection", e);
}
}
示例2: getConnection
import org.hibernate.connection.ConnectionProvider; //导入方法依赖的package包/类
protected Connection getConnection() throws SQLException {
if (sessionFactory instanceof SessionFactoryImplementor) {
ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider();
return cp.getConnection();
}
return super.getConnection();
}
示例3: testJdbcOnly
import org.hibernate.connection.ConnectionProvider; //导入方法依赖的package包/类
public void testJdbcOnly() throws Exception {
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
for ( int n=2; n<4000; n*=2 ) {
Session s = openSession();
Simple[] simples = new Simple[n];
s.delete("from Simple");
s.flush();
Serializable[] ids = new Serializable[n];
for ( int i=0; i<n; i++ ) {
simples[i] = new Simple();
simples[i].init();
simples[i].setCount(i);
ids[i] = new Long(i);
s.save(simples[i], ids[i]);
}
s.flush();
s.connection().commit();
s.close();
//Now do timings
Connection c = cp.getConnection();
long time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j1" );
long jdbc = System.currentTimeMillis() - time;
cp.closeConnection(c);
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
System.out.println( "Objects: " + n + " Direct JDBC: " + jdbc );
}
cp.close();
System.gc();
}
示例4: testSimultaneous
import org.hibernate.connection.ConnectionProvider; //导入方法依赖的package包/类
public void testSimultaneous() throws Exception {
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
for ( int n=2; n<4000; n*=2 ) {
Simple[] simples = new Simple[n];
Serializable[] ids = new Serializable[n];
for ( int i=0; i<n; i++ ) {
simples[i] = new Simple();
simples[i].init();
simples[i].setCount(i);
ids[i] = new Long(i);
}
//allow cache to settle
Session s = openSession();
hibernate(s, simples, ids, n, "h0");
s.close();
Connection c = cp.getConnection();
directJDBC( c, simples, ids, n, "j0" );
cp.closeConnection(c);
s = openSession();
hibernate(s, simples, ids, n, "h0");
s.close();
c = cp.getConnection();
directJDBC( c, simples, ids, n, "j0" );
cp.closeConnection(c);
//Now do timings
s = openSession();
long time = System.currentTimeMillis();
hibernate(s, simples, ids, n, "h1");
long hiber = System.currentTimeMillis() - time;
s.close();
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j1" );
long jdbc = System.currentTimeMillis() - time;
cp.closeConnection(c);
s = openSession();
time = System.currentTimeMillis();
hibernate(s, simples, ids, n, "h2");
hiber += System.currentTimeMillis() - time;
s.close();
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
s = openSession();
time = System.currentTimeMillis();
hibernate(s, simples, ids, n, "h2");
hiber += System.currentTimeMillis() - time;
s.close();
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
}
cp.close();
System.gc();
}
示例5: testJdbcOnly
import org.hibernate.connection.ConnectionProvider; //导入方法依赖的package包/类
public void testJdbcOnly() throws Exception {
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
for ( int n=2; n<4000; n*=2 ) {
Simple[] simples = new Simple[n];
Serializable[] ids = new Serializable[n];
for ( int i=0; i<n; i++ ) {
simples[i] = new Simple();
simples[i].init();
simples[i].setCount(i);
ids[i] = new Long(i);
}
//Now do timings
Connection c = cp.getConnection();
long time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j1" );
long jdbc = System.currentTimeMillis() - time;
cp.closeConnection(c);
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
c = cp.getConnection();
time = System.currentTimeMillis();
directJDBC( c, simples, ids, n, "j2" );
jdbc += System.currentTimeMillis() - time;
cp.closeConnection(c);
System.out.println( "Objects: " + n + " Direct JDBC: " + jdbc );
}
cp.close();
System.gc();
}