FileDocCategorySizeDatePackage
LogicalConnection.javaAPI DocExample10082Mon Mar 31 23:10:16 BST 2003org.dasein.persist

LogicalConnection

public class LogicalConnection extends Object implements Connection
Represents a logical connection to the database for use by an application. When closed, this logical connection returns the physical connection back to the connection pool.
Last modified $Date$
version
$Revision$
author
George Reese

Fields Summary
private PhysicalConnection
physical
The physical connection behind this logical one.
private ArrayList
statements
The statements that this connection has generated.
Constructors Summary
public LogicalConnection(PhysicalConnection conn)
Constructs a new logical connection tied to the specified physical connection.


                    
       
        super();
        physical = conn;
    
Methods Summary
public voidclearWarnings()
Delegates to the physical connection.

throws
java.sql.SQLException a database error occurred

        validate();
        physical.clearWarnings();
    
public voidclose()
Notifies the physical connection that this logical connection is no longer open so that the physical connection may return to the connection pool. After this method is called, any further attempts by an application to use this logical connection will result in an exception.

throws
java.sql.SQLException a database error occurred

        Iterator it = statements.iterator();
        
        validate();
        while( it.hasNext() ) {
            PreparedStatement stmt = (PreparedStatement)it.next();

            try { stmt.close(); }
            catch( SQLException e ) { }
        }
        statements.clear();
        physical.connectionClosed();
        physical = null;
    
public voidcommit()
Delegates to the physical connection.

throws
java.sql.SQLException a database error occurred

        validate();
        physical.commit();
    
public java.sql.StatementcreateStatement()
Delegates to the physical connection.

return
a new statement instance
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.createStatement();
    
public java.sql.StatementcreateStatement(int rst, int rsc)
Delegates to the physical connection.

param
rst the result set type
param
rsc the result set concurrrency
return
a new statement instance
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.createStatement(rst, rsc);
    
public booleangetAutoCommit()
Delegates to the physical connection.

return
the current auto-commit status
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getAutoCommit();
    
public java.lang.StringgetCatalog()
Delegates to the physical connection.

return
the currently selected catalog
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getCatalog();
    
public java.sql.DatabaseMetaDatagetMetaData()
Delegates to the physical connection.

return
the meta data for the current database
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getMetaData();
    
public intgetTransactionIsolation()
Delegates to the physical connection.

return
the current transaction isolation level
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getTransactionIsolation();
    
public java.util.MapgetTypeMap()
Delegates to the physical connection.

return
the current type mapping
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getTypeMap();
    
public java.sql.SQLWarninggetWarnings()
Delegates to the physical connection.

return
any warnings
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.getWarnings();
    
public booleanisClosed()
This method checks to see if it has a valid physical connection.

return
true if the physical connection is no longer available
throws
java.sql.SQLException never thrown

        return (physical == null);
    
public booleanisReadOnly()
Delegates to the physical connection.

return
whether this connection is read only
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.isReadOnly();
    
public java.lang.StringnativeSQL(java.lang.String sql)
Delegates to the physical connection.

return
the SQL native to the underlying database for the specified ANSI SQL
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.nativeSQL(sql);
    
public java.sql.CallableStatementprepareCall(java.lang.String sql)
Delegates to the physical connection.

param
the name of the stored procedure
return
a callable statement for the specified stored procedure
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.prepareCall(sql);
    
public java.sql.CallableStatementprepareCall(java.lang.String sql, int rst, int rsc)
Delegates to the physical connection.

param
the name of the stored procedure
param
rst the result set type
param
the result set concurrency
return
a callable statement for the specified stored procedure
throws
java.sql.SQLException a database error occurred

        validate();
        return physical.prepareCall(sql, rst, rsc);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql)
Delegates to the physical connection.

param
the prepared SQL
return
a prepared statement for the specified SQL
throws
java.sql.SQLException a database error occurred

        PreparedStatement stmt;
        
        validate();
        stmt = physical.prepareStatement(sql);
        statements.add(stmt);
        return stmt;
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int rst, int rsc)
Delegates to the physical connection.

param
the prepared SQL
param
rst the result set type
param
rsc the result set concurrency
return
a prepared statement for the specified SQL
throws
java.sql.SQLException a database error occurred

        PreparedStatement stmt;
        
        validate();
        stmt = physical.prepareStatement(sql, rst, rsc);
        statements.add(stmt);
        return stmt;
    
public voidrollback()
Delegates to the physical connection.

throws
java.sql.SQLException a database error occurred

        validate();
        physical.rollback();
    
public voidsetAutoCommit(boolean ac)
Delegates to the physical connection.

param
ac the auto-commit status to assign
throws
java.sql.SQLException a database error occurred

        validate();
        physical.setAutoCommit(ac);
    
public voidsetCatalog(java.lang.String cat)
Delegates to the physical connection.

param
cat the catalog status to select
throws
java.sql.SQLException a database error occurred

        validate();
        physical.setCatalog(cat);
    
public voidsetReadOnly(boolean ro)
Delegates to the physical connection.

param
ro the read-only status
throws
java.sql.SQLException a database error occurred

        validate();
        physical.setReadOnly(ro);
    
public voidsetTransactionIsolation(int lvl)
Delegates to the physical connection.

param
lvl the transaction isolation level to assign
throws
java.sql.SQLException a database error occurred

        validate();
        physical.setTransactionIsolation(lvl);
    
public voidsetTypeMap(java.util.Map map)
Delegates to the physical connection.

param
map the map to use for type mapping
throws
java.sql.SQLException a database error occurred

        validate();
        physical.setTypeMap(map);
    
public java.lang.StringtoString()

        if( physical != null ) {
            return super.toString() + "(Physical: " + physical.toString() +")";
        }
        else {
            return super.toString();
        }
    
private voidvalidate()

        if( isClosed() ) {
            throw new SQLException("Illegal attempt to reuse connection.");
        }