Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Firebird Open Source J2ee connector - jdbc driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
 package org.firebirdsql.pool;
 
 
 
Firebird pooled connection implementing javax.sql.XAConnection interface.

Author(s):
Roman Rokytskyy
 
     implements XAConnection 
 {
    
Internal connection event listener. This class is responsible for closing connections when corresponding event comes to the server.
 
     private static class FBManagedConnectionEvetListener implements ConnectionEventListener {
         public void connectionClosed(ConnectionEvent event) {
             
             PrintWriter externalLog = ((FBManagedConnection)event.getSource()).getLogWriter();
             try {
                 ((FBManagedConnection)event.getSource()).destroy();
             }
             catch (ResourceException e) {
                 if (externalLog != nullexternalLog.println("Exception closing unmanaged connection: " + e);
             }
 
         }
         public void connectionErrorOccurred(ConnectionEvent event) {
             PrintWriter externalLog = ((FBManagedConnection)event.getSource()).getLogWriter();
             try {
                 ((FBManagedConnection)event.getSource()).destroy();
             }
             catch (ResourceException e) {
                 if (externalLog != nullexternalLog.println("Exception closing unmanaged connection: " + e);
             }
 
         }
         public void localTransactionCommitted(ConnectionEvent event) {
 
         }
         public void localTransactionRolledback(ConnectionEvent event) {
 
         }
         public void localTransactionStarted(ConnectionEvent event) {
 
         }
     }
 
     
         new FBManagedConnectionEvetListener();

    
Create instance of this class for the specified managed connection.

Parameters:
managedConnection instance of org.firebirdsql.jca.FBManagedConnection
cri connection request information.
statementPooling true if statement pooling is enabled.
maxStatements Maximum number of statements to pools
keepStatements Keep statements after closing logical connection obtained from this pooled connection
Throws:
java.sql.SQLException if some SQL error happened.
javax.resource.ResourceException if resource management error happened.
 
    public FBPooledConnection(FBManagedConnection managedConnection
        FBConnectionRequestInfo criboolean statementPooling
        int maxStatementsboolean keepStatementsPooledConnectionQueue owningQueue)
        throws SQLExceptionResourceException 
    {
        super((Connection)managedConnection.getConnection(nullcri), 
            statementPoolingmaxStatementskeepStatementsowningQueue);
        
        this. = managedConnection;
        
    }

    
Create instance of this class for the specified managed connection and ping statement.

Parameters:
managedConnection instance of org.firebirdsql.jca.FBManagedConnection
cri connection request information.
pingStatement ping statement.
pingInterval interval after which connection will be pinged.
statementPooling true if statement pooling is enabled.
Throws:
java.sql.SQLException if SQL error happened.
javax.resource.ResourceException if resource management error happened.
    protected FBPooledConnection(FBManagedConnection managedConnection
        FBConnectionRequestInfo criString pingStatementint pingInterval
        boolean statementPooling,int maxStatements
        boolean keepStatementsPooledConnectionQueue owningQueue)
        throws SQLExceptionResourceException 
    {
        super((Connection)managedConnection.getConnection(nullcri), 
            pingStatementpingIntervalstatementPooling/*transactionIsolation,*/ 
            maxStatementskeepStatementsowningQueue);
        
        this. = managedConnection;
        
    }
    
    /* (non-Javadoc)
     * @see org.firebirdsql.pool.PingablePooledConnection#configureConnectionDefaults(java.sql.Connection)
     */
    protected void configureConnectionDefaults(Connection connectionthrows SQLException {
        if (!.isManagedEnvironment()) 
            connection.setAutoCommit(true);
        connection.setReadOnly(false);
    }
    
Get XA resource for this connection.

Returns:
instance of javax.transaction.xa.XAResource.
Throws:
java.sql.SQLException if SQL error happened.
    public XAResource getXAResource() throws SQLException {
        return .getXAResource();
    }
    
    
Close this statement. This method also destroys managed connection and closes physical connection to the database.

Throws:
java.sql.SQLException if SQL error happened.
    public void close() throws SQLException {
        super.close();
        
        try {
            .destroy();
        } catch(ResourceException ex) {
            throw new FBSQLException(ex);
        }
    }
    
    
Notify this class that statement was closed. This method closes open result set if there is one. Note, it works only for statements implementing org.firebirdsql.jdbc.FirebirdStatement interface.

Parameters:
key Key to SQL statement that was closed.
proxy corresponding proxy.
Throws:
java.sql.SQLException if something went wrong.
    public void statementClosed(XPreparedStatementModel keyObject proxy)
            throws SQLException {
        
        if (proxy instanceof FirebirdStatement) {
            FirebirdStatement fbStmt = (FirebirdStatement)proxy;
            
            ResultSet rs = fbStmt.getCurrentResultSet();
            
            if (rs != null)
                rs.close();
            
        }
        
        super.statementClosed(keyproxy);
    }
    @Override
    protected boolean isRollbackAllowed() {
    }
    void setManagedEnvironment(boolean managedEnvironmentthrows SQLException {
        try {
            .setManagedEnvironment(managedEnvironment);
        } catch(ResourceException ex) {
            throw new FBSQLException(ex);
        }
    }
New to GrepCode? Check out our FAQ X