Package com.sun.gjc.spi.base
Class AbstractDataSource
- java.lang.Object
-
- com.sun.gjc.spi.base.AbstractDataSource
-
- All Implemented Interfaces:
DataSource
,jakarta.resource.Referenceable
,Serializable
,Wrapper
,Referenceable
,CommonDataSource
,DataSource
- Direct Known Subclasses:
DataSource40
public abstract class AbstractDataSource extends Object implements DataSource, Serializable, DataSource, jakarta.resource.Referenceable
Holds thejava.sql.Connection
object, which is to be passed to the application program.- Version:
- 1.0, 02/07/31
- Author:
- Binod P.G
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static Logger
_logger
protected MethodExecutor
executor
protected ManagedConnectionFactoryImpl
mcf
-
Constructor Summary
Constructors Constructor Description AbstractDataSource(ManagedConnectionFactoryImpl mcf, jakarta.resource.spi.ConnectionManager cm)
ConstructsDataSource
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Connection
getConnection()
Retrieves theConnection
object.Connection
getConnection(String user, String pwd)
Retrieves theConnection
object.Connection
getConnection(Connection con)
Retrieves the actual SQLConnection from the Connection wrapper implementation of SunONE application server.String
getDescription()
Retrieves the description.int
getLoginTimeout()
Get the login timeoutPrintWriter
getLogWriter()
Get the logwriter object.Connection
getNonTxConnection()
Gets a connection that is not in the scope of any transaction.Connection
getNonTxConnection(String user, String password)
Gets a connection that is not in the scope of any transaction.Reference
getReference()
Get the reference.void
markConnectionAsBad(Connection conn)
API to mark a connection as bad.void
setDescription(String description)
Set the description.void
setLoginTimeout(int loginTimeout)
Set the login timeoutvoid
setLogWriter(PrintWriter logWriter)
Set the logwriter on this object.void
setReference(Reference reference)
Get the reference.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLogger
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
-
-
-
Field Detail
-
mcf
protected ManagedConnectionFactoryImpl mcf
-
executor
protected MethodExecutor executor
-
_logger
protected static final Logger _logger
-
-
Constructor Detail
-
AbstractDataSource
public AbstractDataSource(ManagedConnectionFactoryImpl mcf, jakarta.resource.spi.ConnectionManager cm)
ConstructsDataSource
object. This is created by theManagedConnectionFactory
object.- Parameters:
mcf
-ManagedConnectionFactory
object creating this object.cm
-ConnectionManager
object either associated with Application server or Resource Adapter.
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
Retrieves theConnection
object.- Specified by:
getConnection
in interfaceDataSource
- Returns:
Connection
object.- Throws:
SQLException
- In case of an error.
-
getConnection
public Connection getConnection(String user, String pwd) throws SQLException
Retrieves theConnection
object.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
user
- User name for the Connection.pwd
- Password for the Connection.- Returns:
Connection
object.- Throws:
SQLException
- In case of an error.
-
getConnection
public Connection getConnection(Connection con) throws 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.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
con
- Connection obtained fromDatasource.getConnection()
- Returns:
java.sql.Connection
implementation of the driver.- Throws:
SQLException
- if connection cannot be obtained.
-
getNonTxConnection
public Connection getNonTxConnection() throws 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.- Specified by:
getNonTxConnection
in interfaceDataSource
- Returns:
java.sql.Connection
- Throws:
SQLException
- if connection cannot be obtained
-
getNonTxConnection
public Connection getNonTxConnection(String user, String password) throws 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.- Specified by:
getNonTxConnection
in interfaceDataSource
- Parameters:
user
- User name for authenticating the connectionpassword
- Password for authenticating the connection- Returns:
java.sql.Connection
- Throws:
SQLException
- if connection cannot be obtained
-
getLoginTimeout
public int getLoginTimeout() throws SQLException
Get the login timeout- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Returns:
- login timeout.
- Throws:
SQLException
- If a database error occurs.
-
setLoginTimeout
public void setLoginTimeout(int loginTimeout) throws SQLException
Set the login timeout- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Parameters:
loginTimeout
- Login timeout.- Throws:
SQLException
- If a database error occurs.
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
Get the logwriter object.- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Returns:
PrintWriter
object.- Throws:
SQLException
- If a database error occurs.
-
setLogWriter
public void setLogWriter(PrintWriter logWriter) throws SQLException
Set the logwriter on this object.- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Parameters:
logWriter
- object.- Throws:
SQLException
- If a database error occurs.
-
getDescription
public String getDescription()
Retrieves the description.- Returns:
- Description about the DataSource.
-
setDescription
public void setDescription(String description)
Set the description.- Parameters:
description
- Description about the DataSource.
-
getReference
public Reference getReference()
Get the reference.- Specified by:
getReference
in interfaceReferenceable
- Returns:
Reference
object.
-
setReference
public void setReference(Reference reference)
Get the reference.- Specified by:
setReference
in interfacejakarta.resource.Referenceable
- Parameters:
reference
-Reference
object.
-
markConnectionAsBad
public void markConnectionAsBad(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 }
- Specified by:
markConnectionAsBad
in interfaceDataSource
- Parameters:
conn
-java.sql.Connection
-
-