com.sun.appserv.jdbc
Interface DataSource

All Superinterfaces:
javax.sql.CommonDataSource, javax.sql.DataSource, java.sql.Wrapper

public interface DataSource
extends javax.sql.DataSource

The javax.sql.DataSource implementation of SunONE application server will implement this interface. An application program would be able to use this interface to do the extended functionality exposed by SunONE application server.

A sample code for getting driver's connection implementation would like the following.

     InitialContext ic = new InitialContext();
     com.sun.appserv.DataSource ds = (com.sun.appserv.DataSOurce) ic.lookup("jdbc/PointBase"); 
     Connection con = ds.getConnection();
     Connection drivercon = ds.getConnection(con);

     // Do db operations.

     con.close();
   

Author:
Binod P.G

Method Summary
 java.sql.Connection getConnection(java.sql.Connection con)
          Retrieves the actual SQLConnection from the Connection wrapper implementation of SunONE application server.
 java.sql.Connection getNonTxConnection()
          Gets a connection that is not in the scope of any transaction.
 java.sql.Connection getNonTxConnection(java.lang.String userName, java.lang.String password)
          Gets a connection that is not in the scope of any transaction.
 void markConnectionAsBad(java.sql.Connection conn)
          API to mark a connection as bad.
 
Methods inherited from interface javax.sql.DataSource
getConnection, getConnection
 
Methods inherited from interface javax.sql.CommonDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Method Detail

getConnection

java.sql.Connection getConnection(java.sql.Connection con)
                                  throws java.sql.SQLException
Retrieves the actual SQLConnection from the Connection wrapper implementation of SunONE application server. If an actual connection is supplied as argument, then it will be just returned.

Parameters:
con - Connection obtained from Datasource.getConnection()
Returns:
java.sql.Connection implementation of the driver.
Throws:
java.sql.SQLException - If connection cannot be obtained.
java.sql.SQLException

getNonTxConnection

java.sql.Connection getNonTxConnection()
                                       throws java.sql.SQLException
Gets a connection that is not in the scope of any transaction. This can be used to save performance overhead incurred on enlisting/delisting each connection got, irrespective of whether its required or not. Note here that this meethod does not fit in the connector contract per se.

Returns:
java.sql.Connection
Throws:
java.sql.SQLException - If connection cannot be obtained
java.sql.SQLException

getNonTxConnection

java.sql.Connection getNonTxConnection(java.lang.String userName,
                                       java.lang.String password)
                                       throws java.sql.SQLException
Gets a connection that is not in the scope of any transaction. This can be used to save performance overhead incurred on enlisting/delisting each connection got, irrespective of whether its required or not. Note here that this meethod does not fit in the connector contract per se.

Parameters:
user - User name for authenticating the connection
password - Password for authenticating the connection
Returns:
java.sql.Connection
Throws:
java.sql.SQLException - If connection cannot be obtained
java.sql.SQLException

markConnectionAsBad

void markConnectionAsBad(java.sql.Connection conn)
API to mark a connection as bad. If the application can determine that the connection is bad, using this api, it can notify the resource-adapter which inturn will notify the connection-pool. Connection-pool will drop and create a new connection. eg:
        com.sun.appserv.jdbc.DataSource ds=
           (com.sun.appserv.jdbc.DataSource)context.lookup("dataSource");
                Connection con = ds.getConnection();
                Statement stmt = null;
                try{
                         stmt = con.createStatement();
                         stmt.executeUpdate("Update");
                }catch(BadConnectionException e){
                        dataSource.markConnectionAsBad(con) //marking it as bad for removal
                }finally{
                        stmt.close();
                        con.close(); //Connection will be destroyed while close or Tx completion
            }
 

Parameters:
conn - java.sql.Connection


Copyright © 2012 GlassFish Community. All Rights Reserved.