Examples of JdbcConnectionPool


Examples of org.glassfish.jdbc.config.JdbcConnectionPool

        return status;
    }

    private JdbcConnectionPool createResource(Resources param, Properties properties) throws PropertyVetoException,
            TransactionFailure {
        JdbcConnectionPool newResource = createConfigBean(param, properties);
        param.getResources().add(newResource);
        return newResource;
    }
View Full Code Here

Examples of org.glassfish.jdbc.config.JdbcConnectionPool

        return newResource;
    }

    private JdbcConnectionPool createConfigBean(Resources param, Properties properties) throws PropertyVetoException,
            TransactionFailure {
        JdbcConnectionPool newResource = param.createChild(JdbcConnectionPool.class);
        newResource.setWrapJdbcObjects(wrapJDBCObjects);
        if (validationtable != null)
            newResource.setValidationTableName(validationtable);
        newResource.setValidateAtmostOncePeriodInSeconds(validateAtmostOncePeriod);
        if (isolationlevel != null) {
            newResource.setTransactionIsolationLevel(isolationlevel);
        }
        newResource.setSteadyPoolSize(steadypoolsize);
        if(statementTimeout != null){
            newResource.setStatementTimeoutInSeconds(statementTimeout);
        }
        if (restype != null) {
            newResource.setResType(restype);
        }
        newResource.setPoolResizeQuantity(poolresize);
        newResource.setNonTransactionalConnections(nontransactionalconnections);
        newResource.setMaxWaitTimeInMillis(maxwait);
        newResource.setMaxPoolSize(maxpoolsize);
        if(maxConnectionUsageCount != null){
            newResource.setMaxConnectionUsageCount(maxConnectionUsageCount);
        }
        if(matchConnections != null){
            newResource.setMatchConnections(matchConnections);
        }
        if(lazyConnectionEnlistment != null){
            newResource.setLazyConnectionEnlistment(lazyConnectionEnlistment);
        }
        if(lazyConnectionAssociation != null){
            newResource.setLazyConnectionAssociation(lazyConnectionAssociation);
        }
        newResource.setIsIsolationLevelGuaranteed(isisolationguaranteed);
        newResource.setIsConnectionValidationRequired(isconnectvalidatereq);
        newResource.setIdleTimeoutInSeconds(idletimeout);
        newResource.setFailAllConnections(failconnection);
        if (datasourceclassname != null) {
            newResource.setDatasourceClassname(datasourceclassname);
        }
        newResource.setConnectionValidationMethod(validationmethod);
        if(connectionLeakTimeout != null){
            newResource.setConnectionLeakTimeoutInSeconds(connectionLeakTimeout);
        }
        if(connectionLeakReclaim != null){
            newResource.setConnectionLeakReclaim(connectionLeakReclaim);
        }
        if(connectionCreationRetryInterval != null){
            newResource.setConnectionCreationRetryIntervalInSeconds(connectionCreationRetryInterval);
        }
        if(connectionCreationRetryAttempts != null){
            newResource.setConnectionCreationRetryAttempts(connectionCreationRetryAttempts);
        }
        if(associateWithThread != null){
            newResource.setAssociateWithThread(associateWithThread);
        }
        if(allownoncomponentcallers != null){
            newResource.setAllowNonComponentCallers(allownoncomponentcallers);
        }
        if(statementcachesize != null){
            newResource.setStatementCacheSize(statementcachesize);
        }
        if (validationclassname != null) {
            newResource.setValidationClassname(validationclassname);
        }
        if(initsql != null){
            newResource.setInitSql(initsql);
        }
        if (sqltracelisteners != null) {
            newResource.setSqlTraceListeners(sqltracelisteners);
        }
        if(pooling != null){
            newResource.setPooling(pooling);
        }
        if(ping != null){
            newResource.setPing(ping);
        }
        if (driverclassname != null) {
            newResource.setDriverClassname(driverclassname);
        }
        if (description != null) {
            newResource.setDescription(description);
        }
        newResource.setName(jdbcconnectionpoolid);
        if (properties != null) {
            for (Map.Entry e : properties.entrySet()) {
                Property prop = newResource.createChild(Property.class);
                prop.setName((String) e.getKey());
                prop.setValue((String) e.getValue());
                newResource.getProperty().add(prop);
            }
        }
        return newResource;
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        deleteDb("connectionPool2");
    }

    private void testShutdown() throws SQLException {
        String url = getURL("connectionPool2", true), user = getUser(), password = getPassword();
        JdbcConnectionPool cp = JdbcConnectionPool.create(url, user, password);
        StringWriter w = new StringWriter();
        cp.setLogWriter(new PrintWriter(w));
        Connection conn1 = cp.getConnection();
        Connection conn2 = cp.getConnection();
        conn1.close();
        conn2.createStatement().execute("shutdown immediately");
        cp.dispose();
        assertTrue(w.toString().length() > 0);
        cp.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        assertTrue(w.toString().length() > 0);
        cp.dispose();
    }

    private void testWrongUrl() {
        JdbcConnectionPool cp = JdbcConnectionPool.create("jdbc:wrong:url", "", "");
        try {
            cp.getConnection();
        } catch (SQLException e) {
            assertEquals(8001, e.getErrorCode());
        }
        cp.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        cp.dispose();
    }

    private void testTimeout() throws Exception {
        String url = getURL("connectionPool", true), user = getUser(), password = getPassword();
        final JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
        man.setLoginTimeout(1);
        createClassProxy(man.getClass());
        assertThrows(IllegalArgumentException.class, man).
                setMaxConnections(-1);
        man.setMaxConnections(2);
        // connection 1 (of 2)
        Connection conn = man.getConnection();
        Task t = new Task() {
            public void call() {
                while (!stop) {
                    // this calls notifyAll
                    man.setMaxConnections(1);
                    man.setMaxConnections(2);
                }
            }
        };
        t.execute();
        long time = System.currentTimeMillis();
        try {
            // connection 2 (of 1 or 2) may fail
            man.getConnection();
            // connection 3 (of 1 or 2) must fail
            man.getConnection();
            fail();
        } catch (SQLException e) {
            assertTrue(e.toString().toLowerCase().indexOf("timeout") >= 0);
            time = System.currentTimeMillis() - time;
            assertTrue("timeout after " + time + " ms", time > 1000);
        } finally {
            conn.close();
            t.get();
        }

        man.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        man.dispose();
    }

    private void testUncommittedTransaction() throws SQLException {
        String url = getURL("connectionPool", true), user = getUser(), password = getPassword();
        JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);

        assertEquals(30, man.getLoginTimeout());
        man.setLoginTimeout(1);
        assertEquals(1, man.getLoginTimeout());
        man.setLoginTimeout(0);
        assertEquals(30, man.getLoginTimeout());
        assertEquals(10, man.getMaxConnections());

        PrintWriter old = man.getLogWriter();
        PrintWriter pw = new PrintWriter(new StringWriter());
        man.setLogWriter(pw);
        assertTrue(pw == man.getLogWriter());
        man.setLogWriter(old);

        Connection conn1 = man.getConnection();
        assertTrue(conn1.getAutoCommit());
        conn1.setAutoCommit(false);
        conn1.close();
        assertTrue(conn1.isClosed());

        Connection conn2 = man.getConnection();
        assertTrue(conn2.getAutoCommit());
        conn2.close();

        man.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        man.dispose();
    }

    private void testPerformance() throws SQLException {
        String url = getURL("connectionPool", true), user = getUser(), password = getPassword();
        JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
        Connection conn = man.getConnection();
        int len = 1000;
        long time = System.currentTimeMillis();
        for (int i = 0; i < len; i++) {
            man.getConnection().close();
        }
        man.dispose();
        trace((int) (System.currentTimeMillis() - time));
        time = System.currentTimeMillis();
        for (int i = 0; i < len; i++) {
            DriverManager.getConnection(url, user, password).close();
        }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        trace((int) (System.currentTimeMillis() - time));
        conn.close();
    }

    private void testKeepOpen() throws Exception {
        JdbcConnectionPool man = getConnectionPool(1);
        Connection conn = man.getConnection();
        Statement stat = conn.createStatement();
        stat.execute("create local temporary table test(id int)");
        conn.close();
        conn = man.getConnection();
        stat = conn.createStatement();
        stat.execute("select * from test");
        conn.close();
        man.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

        man.dispose();
    }

    private void testThreads() throws Exception {
        final int len = getSize(4, 20);
        final JdbcConnectionPool man = getConnectionPool(len - 2);
        final boolean[] stop = { false };

        /**
         * This class gets and returns connections from the pool.
         */
        class TestRunner implements Runnable {
            public void run() {
                try {
                    while (!stop[0]) {
                        Connection conn = man.getConnection();
                        if (man.getActiveConnections() >= len + 1) {
                            throw new Exception("a: " + man.getActiveConnections()  + " is not smaller than b: " + len + 1);
                        }
                        Statement stat = conn.createStatement();
                        stat.execute("SELECT 1 FROM DUAL");
                        conn.close();
                        Thread.sleep(100);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        Thread[] threads = new Thread[len];
        for (int i = 0; i < len; i++) {
            threads[i] = new Thread(new TestRunner());
            threads[i].start();
        }
        Thread.sleep(1000);
        stop[0] = true;
        for (int i = 0; i < len; i++) {
            threads[i].join();
        }
        assertEquals(0, man.getActiveConnections());
        man.dispose();
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcConnectionPool

    private JdbcConnectionPool getConnectionPool(int poolSize) {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(getURL("connectionPool", true));
        ds.setUser(getUser());
        ds.setPassword(getPassword());
        JdbcConnectionPool pool = JdbcConnectionPool.create(ds);
        pool.setMaxConnections(poolSize);
        return pool;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.