Package javax.sql

Examples of javax.sql.PooledConnection


     * @throws SQLException
     */
    public static void testDerby1144() throws SQLException
    {
      Connection conn = null;
      PooledConnection pc1 = null;
    Properties p = new Properties();
   
    p.put("databaseName","sample");
    p.put("connectionAttributes","create=true");
    p.put("user","APP");
    p.put("password","pw");
   
        // Test holdability  
        ConnectionPoolDataSource ds = TestUtil.getConnectionPoolDataSource(p);
        pc1 = ds.getPooledConnection();
        testPooledConnHoldability("PooledConnection", pc1);
        pc1.close();
       
        // Test autocommit
        pc1 = ds.getPooledConnection();
        testPooledConnAutoCommit("PooledConnection", pc1);
        pc1.close();
       
        // Test pooled connection isolation
    ds = TestUtil.getConnectionPoolDataSource(p);
    pc1 = ds.getPooledConnection();
    testPooledConnIso("PooledConnection" , pc1);  
        pc1.close();
      
        // Test xa connection isolation
    XADataSource xds = TestUtil.getXADataSource(p);
      XAConnection xpc1 = xds.getXAConnection();       
        testPooledConnIso("XAConnection", xpc1);                
View Full Code Here


            useuser = user!=null;
        }
       
        public TestResult call() {
            TestResult test = new TestResult();
            PooledConnection pcon = null;
            for (int i=0; (!done) && (i<iterations); i++) {
                test.iterations = i+1;
                try {
                   
                   
                    pcon = useuser ? (PooledConnection)AlternateUsernameTest.this.datasource.getConnection(username, password) :
                                     (PooledConnection)AlternateUsernameTest.this.datasource.getConnection();
                   
                    Connection con = (Connection)pcon.getConnection();
                   
                    assertTrue("Username mismatch: Requested User:"+username+" Actual user:"+con.getUsername(), con.getUsername().equals(username));
                    assertTrue("Password mismatch: Requested Password:"+password+" Actual password:"+con.getPassword(), con.getPassword().equals(password));
                }catch (SQLException x) {
                    test.failures++;
                    test.lastMessage = x.getMessage();
                    done = true;
                    x.printStackTrace();
                }catch (Exception x) {
                    test.failures++;
                    test.lastMessage = x.getMessage();
                    x.printStackTrace();
                } finally {
                    if (pcon!=null) {
                        try {pcon.close(); }catch (Exception ignore) {}
                        pcon = null;
                    }
                }
            }
            done = true;
View Full Code Here

     * Creates and returns new PooledConnection object, adding itself as a listener for
     * connection events.
     */
    protected PooledConnection newPooledConnection(String userName, String password)
            throws SQLException {
        PooledConnection connection = (userName != null) ? poolDataSource
                .getPooledConnection(userName, password) : poolDataSource
                .getPooledConnection();
        connection.addConnectionEventListener(this);
        return connection;
    }
View Full Code Here

    public void shutdown() throws SQLException {
        synchronized (this) {
            // clean connections from the pool
            ListIterator<PooledConnection> unusedIterator = unusedPool.listIterator();
            while (unusedIterator.hasNext()) {
                PooledConnection con = unusedIterator.next();
                // close connection
                con.close();
                // remove connection from the list
                unusedIterator.remove();
            }

            // clean used connections
            ListIterator<PooledConnection> usedIterator = usedPool.listIterator();
            while (usedIterator.hasNext()) {
                PooledConnection con = usedIterator.next();
                // stop listening for connection events
                con.removeConnectionEventListener(this);
                // close connection
                con.close();
                // remove connection from the list
                usedIterator.remove();
            }
        }
View Full Code Here

            String password) throws SQLException {

        int i = 0;
        int startPoolSize = getPoolSize();
        for (; i < addConnections && startPoolSize + i < maxConnections; i++) {
            PooledConnection newConnection = newPooledConnection(userName, password);
            unusedPool.add(newConnection);
        }

        return i;
    }
View Full Code Here

    }

    protected synchronized void shrinkPool(int closeConnections) {
        int idleSize = unusedPool.size();
        for (int i = 0; i < closeConnections && i < idleSize; i++) {
            PooledConnection con = unusedPool.remove(i);

            try {
                con.close();
            }
            catch (SQLException ex) {
                // ignore
            }
        }
View Full Code Here

    /** Returns connection from the pool. */
    public synchronized Connection getConnection(String userName, String password)
            throws SQLException {

        PooledConnection pooledConnection = uncheckPooledConnection(userName, password);

        try {
            return uncheckConnection(pooledConnection);
        }
        catch (SQLException ex) {

            try {
                pooledConnection.close();
            }
            catch (SQLException ignored) {
            }

            // do one reconnect attempt...
            pooledConnection = uncheckPooledConnection(userName, password);
            try {
                return uncheckConnection(pooledConnection);
            }
            catch (SQLException reconnectEx) {
                try {
                    pooledConnection.close();
                }
                catch (SQLException ignored) {
                }

                throw reconnectEx;
View Full Code Here

    /**
     * Returns closed connection to the pool.
     */
    public synchronized void connectionClosed(ConnectionEvent event) {
        // return connection to the pool
        PooledConnection closedConn = (PooledConnection) event.getSource();

        // remove this connection from the list of connections
        // managed by this pool...
        int usedInd = usedPool.indexOf(closedConn);
        if (usedInd >= 0) {
View Full Code Here

     */
    public synchronized void connectionErrorOccurred(ConnectionEvent event) {
        // later on we should analyze the error to see if this
        // is fatal... right now just kill this PooledConnection

        PooledConnection errorSrc = (PooledConnection) event.getSource();

        // remove this connection from the list of connections
        // managed by this pool...

        int usedInd = usedPool.indexOf(errorSrc);
View Full Code Here

         *
         * @param event an event object describing the source of
         * the event
         */
        public void connectionClosed(ConnectionEvent event) {
            PooledConnection pconn = (PooledConnection) event.getSource();
            ConnectionInfo cinfo = connMap.get(pconn);
            if (cinfo == null) {
                throw new IllegalStateException(
                "No mapping for PooledConnection 0x"+pconn.hashCode()+
                "["+pconn.getClass().getName()+"]");
            }
            if (dbmgr.getDEBUG() || DEBUG) {
                logger.log(logger.INFO, toString()+".connectionClosed event on "+cinfo);
            }
            if (!cinfo.inValidating()) {
View Full Code Here

TOP

Related Classes of javax.sql.PooledConnection

Copyright © 2018 www.massapicom. 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.