FileDocCategorySizeDatePackage
PoolConnEntry.javaAPI DocApache James 2.3.113827Fri Jan 12 12:56:34 GMT 2007org.apache.james.util.mordred

PoolConnEntry

public class PoolConnEntry extends Object implements Connection
An entry in a connection pool.

Fields Summary
private static final boolean
DEEP_DEBUG
public static final int
AVAILABLE
public static final int
ACTIVE
private JdbcDataSource
container
private Connection
connection
private int
status
private long
lockTime
private long
createDate
private long
lastActivity
private int
id
private Throwable
trace
Constructors Summary
public PoolConnEntry(JdbcDataSource container, Connection conn, int id)
Insert the method's description here. Creation date: (8/24/99 11:43:45 AM)

param
conn java.sql.Connection


                      
           
        this.container = container;
        this.connection = conn;
        status = AVAILABLE;
        createDate = System.currentTimeMillis();
        lastActivity = System.currentTimeMillis();
        this.id = id;
    
Methods Summary
public voidclearWarnings()
Simple method to log any warnings on an entry (connection), and then clear them.

throws
java.sql.SQLException

        try {
            SQLWarning currSQLWarning = connection.getWarnings();
            while (currSQLWarning != null) {
                StringBuffer logBuffer =
                    new StringBuffer(256)
                            .append("Warnings on connection ")
                            .append(id)
                            .append(currSQLWarning);
                container.debug(logBuffer.toString());
                currSQLWarning = currSQLWarning.getNextWarning();
            }
            connection.clearWarnings();
        } catch (SQLException sqle) {
            container.debug("Error while clearing exceptions on " + id);
            // It will probably get killed by itself before too long if this failed
        }
    
public voidclose()

        clearWarnings();
        container.releaseConnection(this);
    
public final voidcommit()

        connection.commit();
    
public final java.sql.StatementcreateStatement()

        return connection.createStatement();
    
public final java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)

        return connection.createStatement(resultSetType, resultSetConcurrency);
    
public final java.sql.StatementcreateStatement(int resulSetType, int resultSetConcurrency, int resultSetHoldability)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
protected voidfinalize()
Need to clean up the connection

        container.debug("Closing connection " + id);
        try {
            connection.close();
        } catch (SQLException ex) {
            StringBuffer warnBuffer =
                new StringBuffer(64)
                    .append("Cannot close connection ")
                    .append(id)
                    .append(" on finalize");
            container.warn(warnBuffer.toString());
        }
        // Dump the stack trace of whoever created this connection
        if (getTrace() != null) {
            StringWriter sout = new StringWriter();
            trace.printStackTrace(new PrintWriter(sout, true));
            container.info(sout.toString());
        }
    
public final booleangetAutoCommit()

        return connection.getAutoCommit();
    
public final java.lang.StringgetCatalog()

        return connection.getCatalog();
    
public longgetCreateDate()
Insert the method's description here. Creation date: (8/24/99 11:43:19 AM)

return
a long representing the time this entry was created

        return createDate;
    
public final intgetHoldability()

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public intgetId()
Insert the method's description here. Creation date: (8/24/99 12:09:01 PM)

return
int

        return id;
    
public longgetLastActivity()
Insert the method's description here. Creation date: (8/24/99 11:43:19 AM)

return
long

        return lastActivity;
    
public longgetLockTime()
Insert the method's description here. Creation date: (8/24/99 11:43:19 AM)

return
long

        return lockTime;
    
public final java.sql.DatabaseMetaDatagetMetaData()

        return connection.getMetaData();
    
public intgetStatus()
Insert the method's description here. Creation date: (8/24/99 11:43:19 AM)

return
int

        return status;
    
public java.lang.StringgetString()

        StringBuffer poolConnStringBuffer =
            new StringBuffer(64)
                    .append(getId())
                    .append(": ")
                    .append(connection.toString());
        return poolConnStringBuffer.toString();
    
public java.lang.ThrowablegetTrace()
Insert the method's description here. Creation date: (8/24/99 2:33:38 PM)

return
java.lang.Throwable

        return trace;
    
public final intgetTransactionIsolation()

        return connection.getTransactionIsolation();
    
public final java.util.MapgetTypeMap()

        return connection.getTypeMap();
    
public final java.sql.SQLWarninggetWarnings()

        return connection.getWarnings();
    
public booleanisClosed()
Returns whether this entry is closed.

return
whether the underlying conntection is closed

        return connection.isClosed();
    
public final booleanisReadOnly()

        return connection.isReadOnly();
    
public synchronized booleanlock()
Locks an entry for anybody else using it

        if (DEEP_DEBUG) {
            System.out.println("Trying to lock");
        }

        if (status != PoolConnEntry.AVAILABLE) {
            return false;
        }

        if (DEEP_DEBUG) {
            System.out.println("Available");
        }

        if (false) {
            //There really is no sense in doing this...
            //  maybe make it a conf option at some point, but really slows
            //  down the pooling.
            if (connection.isClosed()) {
                throw new SQLException("Connection has been closed.");
            }

            if (DEEP_DEBUG) {
                System.out.println("not closed");
            }
        }


        status = PoolConnEntry.ACTIVE;
        lockTime = System.currentTimeMillis();
        lastActivity = lockTime;
        trace = new Throwable();
        clearWarnings();
        if (DEEP_DEBUG) {
            System.out.println("Returning");
        }
        return true;
    
public final java.lang.StringnativeSQL(java.lang.String sql)

        return connection.nativeSQL( sql );
    
public final java.sql.CallableStatementprepareCall(java.lang.String sql)

        return connection.prepareCall(sql);
    
public final java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)

        return connection.prepareCall( sql, resultSetType, resultSetConcurrency );
    
public final java.sql.CallableStatementprepareCall(java.lang.String sql, int resulSetType, int resultSetConcurrency, int resultSetHoldability)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql)

        return connection.prepareStatement(sql);
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)

        return connection.prepareStatement( sql, resultSetType, resultSetConcurrency);
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resulSetType, int resultSetConcurrency, int resultSetHoldability)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final voidreleaseSavepoint(java.sql.Savepoint savepoint)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final voidrollback()

        connection.rollback();
    
public final voidrollback(java.sql.Savepoint savepoint)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final voidsetAutoCommit(boolean autoCommit)

        connection.setAutoCommit( autoCommit );
    
public final voidsetCatalog(java.lang.String catalog)

        connection.setCatalog( catalog );
    
public final voidsetHoldability(int holdability)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final voidsetReadOnly(boolean readOnly)

        connection.setReadOnly( readOnly );
    
public final java.sql.SavepointsetSavepoint()

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final java.sql.SavepointsetSavepoint(java.lang.String savepoint)

        throw new SQLException("This is not a Jdbc 3.0 Compliant Connection");
    
public final voidsetTransactionIsolation(int level)

        connection.setTransactionIsolation(level);
    
public final voidsetTypeMap(java.util.Map map)

        connection.setTypeMap( map );
    
public synchronized voidunlock()
Resets flags on an entry for reuse in the pool

        lastActivity = System.currentTimeMillis();
        trace = null;
        status = AVAILABLE;