Java 类org.hibernate.connection.ConnectionProviderFactory 实例源码

项目:document-management-system    文件:SchemaUpdate.java   
public SchemaUpdate(Configuration cfg, Properties connectionProperties) throws HibernateException {
    this.configuration = cfg;
    dialect = Dialect.getDialect(connectionProperties);
    Properties props = new Properties();
    props.putAll(dialect.getDefaultProperties());
    props.putAll(connectionProperties);
    connectionProvider = ConnectionProviderFactory.newConnectionProvider(props);
    exceptions = new ArrayList<Exception>();
}
项目:cacheonix-core    文件:ManagedProviderConnectionHelper.java   
public void prepare(boolean needsAutoCommit) throws SQLException {
    connectionProvider = ConnectionProviderFactory.newConnectionProvider( cfgProperties );
    connection = connectionProvider.getConnection();
    if ( needsAutoCommit && !connection.getAutoCommit() ) {
        connection.commit();
        connection.setAutoCommit( true );
    }
}
项目:jasperreports    文件:HibernateConnectionProvider.java   
@Override
public void configure(Properties props) throws HibernateException {

    String driverClass = props.getProperty(Environment.DRIVER);

    poolSize = PropertiesHelper.getInt(Environment.POOL_SIZE, props, 20); //default pool size 20
    log.info("Using Hibernate built-in connection pool (not for production use!)");
    log.info("Hibernate connection pool size: " + poolSize);

    autocommit = PropertiesHelper.getBoolean(Environment.AUTOCOMMIT, props);
    log.info("autocommit mode: " + autocommit);

    isolation = PropertiesHelper.getInteger(Environment.ISOLATION, props);
    if (isolation!=null)
    log.info( "JDBC isolation level: " + Environment.isolationLevelToString( isolation.intValue() ) );

    if (driverClass==null) {
        log.warn("no JDBC Driver class was specified by property " + Environment.DRIVER);
    }
    else {
        try {
            // trying via forName() first to be as close to DriverManager's semantics
            // NOTE for JSS: we use the context class loader because it will be able to locate the database drivers
            // already loaded in our plug-ins or projects
            driver = (Driver) Class.forName(driverClass, true, Thread.currentThread().getContextClassLoader()).newInstance();
        }
        catch (Exception e) {
            try {
                driver = (Driver) ReflectHelper.classForName(driverClass).newInstance();
            }
            catch (Exception e1) {
                log.error(e1.getMessage());
                throw new HibernateException(e1);
            }
        }
    }

    url = props.getProperty( Environment.URL );
    if ( url == null ) {
        String msg = "JDBC URL was not specified by property " + Environment.URL;
        log.error( msg );
        throw new HibernateException( msg );
    }

    connectionProps = ConnectionProviderFactory.getConnectionProperties( props );

    log.info( "using driver: " + driverClass + " at URL: " + url );
    // if debug level is enabled, then log the password, otherwise mask it
    if ( log.isDebugEnabled() ) {
        log.info( "connection properties: " + connectionProps );
    }
    else if ( log.isInfoEnabled() ) {
        log.info( "connection properties: " + PropertiesHelper.maskOut(connectionProps, "password") );
    }

}
项目:cacheonix-core    文件:SettingsFactory.java   
protected ConnectionProvider createConnectionProvider(Properties properties) {
    return ConnectionProviderFactory.newConnectionProvider(properties);
}
项目:cacheonix-core    文件:DummyConnectionProvider.java   
public void configure(Properties props) throws HibernateException {
    cp = ConnectionProviderFactory.newConnectionProvider();
}
项目:cacheonix-core    文件:DummyTransactionManager.java   
public DummyTransactionManager(Properties props) {
    connections = ConnectionProviderFactory.newConnectionProvider();
}
项目:cacheonix-core    文件:NewerPerformanceTest.java   
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();
    }
项目:cacheonix-core    文件:PerformanceTest.java   
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();
    }
项目:cacheonix-core    文件:PerformanceTest.java   
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();
    }