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.Connectionobject, 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_loggerprotected MethodExecutorexecutorprotected ManagedConnectionFactoryImplmcf
-
Constructor Summary
Constructors Constructor Description AbstractDataSource(ManagedConnectionFactoryImpl mcf, jakarta.resource.spi.ConnectionManager cm)ConstructsDataSourceobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectiongetConnection()Retrieves theConnectionobject.ConnectiongetConnection(String user, String pwd)Retrieves theConnectionobject.ConnectiongetConnection(Connection con)Retrieves the actual SQLConnection from the Connection wrapper implementation of SunONE application server.StringgetDescription()Retrieves the description.intgetLoginTimeout()Get the login timeoutPrintWritergetLogWriter()Get the logwriter object.ConnectiongetNonTxConnection()Gets a connection that is not in the scope of any transaction.ConnectiongetNonTxConnection(String user, String password)Gets a connection that is not in the scope of any transaction.ReferencegetReference()Get the reference.voidmarkConnectionAsBad(Connection conn)API to mark a connection as bad.voidsetDescription(String description)Set the description.voidsetLoginTimeout(int loginTimeout)Set the login timeoutvoidsetLogWriter(PrintWriter logWriter)Set the logwriter on this object.voidsetReference(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)
ConstructsDataSourceobject. This is created by theManagedConnectionFactoryobject.- Parameters:
mcf-ManagedConnectionFactoryobject creating this object.cm-ConnectionManagerobject either associated with Application server or Resource Adapter.
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
Retrieves theConnectionobject.- Specified by:
getConnectionin interfaceDataSource- Returns:
Connectionobject.- Throws:
SQLException- In case of an error.
-
getConnection
public Connection getConnection(String user, String pwd) throws SQLException
Retrieves theConnectionobject.- Specified by:
getConnectionin interfaceDataSource- Parameters:
user- User name for the Connection.pwd- Password for the Connection.- Returns:
Connectionobject.- 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:
getConnectionin interfaceDataSource- Parameters:
con- Connection obtained fromDatasource.getConnection()- Returns:
java.sql.Connectionimplementation 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:
getNonTxConnectionin 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:
getNonTxConnectionin 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 SQLExceptionGet the login timeout- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Returns:
- login timeout.
- Throws:
SQLException- If a database error occurs.
-
setLoginTimeout
public void setLoginTimeout(int loginTimeout) throws SQLExceptionSet the login timeout- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Parameters:
loginTimeout- Login timeout.- Throws:
SQLException- If a database error occurs.
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
Get the logwriter object.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Returns:
PrintWriterobject.- Throws:
SQLException- If a database error occurs.
-
setLogWriter
public void setLogWriter(PrintWriter logWriter) throws SQLException
Set the logwriter on this object.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin 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:
getReferencein interfaceReferenceable- Returns:
Referenceobject.
-
setReference
public void setReference(Reference reference)
Get the reference.- Specified by:
setReferencein interfacejakarta.resource.Referenceable- Parameters:
reference-Referenceobject.
-
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:
markConnectionAsBadin interfaceDataSource- Parameters:
conn-java.sql.Connection
-
-