JSlim  


com.gtcgroup.jslim
Class JSlimDataSource

java.lang.Object
  extended bycom.gtcgroup.jslim.JSlimDataSource
All Implemented Interfaces:
javax.sql.DataSource, IJSlimCachable

final class JSlimDataSource
extends java.lang.Object
implements javax.sql.DataSource, IJSlimCachable

This class implements DataSource in order to override methods throwing a SQLException. If an exception is thrown, all cached objects are discarded preventing further use. The typical scenario supported is the unavailability of a previously available remote resource.

Copyright (c) 1999 - 2004 by Global Technology Consulting Group, Inc. at gtcGroup.com.
Use is authorized, provided the source is acknowledged by inclusion of this copyright notice.

Since:
v. 1.0
Author:
MDT (MarvinToll@gtcGroup.com)

Field Summary
private  javax.sql.DataSource dataSource
          A DataSource object is the preferred means of getting a connection.
private  int intUrlSelected
          Identifies which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.
 
Constructor Summary
JSlimDataSource()
          Constructor.
JSlimDataSource(javax.sql.DataSource dataSource, int intUrlSelected)
          Constructor.
 
Method Summary
 java.sql.Connection getConnection()
          Attempts to establish a connection with the data source that this DataSource object represents.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempts to establish a connection with the data source that this DataSource object represents.
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Retrieves the log writer for this DataSource object.
 int getUrlSelected()
          Identifies which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.
private static void rethrowSQLException(java.sql.SQLException e)
           
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Sets the log writer for this DataSource object to the given java.io.PrintWriter object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSource

private final javax.sql.DataSource dataSource
A DataSource object is the preferred means of getting a connection.


intUrlSelected

private final int intUrlSelected
Identifies which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.

Constructor Detail

JSlimDataSource

public JSlimDataSource()
Constructor.


JSlimDataSource

public JSlimDataSource(javax.sql.DataSource dataSource,
                       int intUrlSelected)
Constructor.

Parameters:
dataSource - A DataSource object is the preferred means of getting a connection.
intUrlSelected - Identifies which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.
Method Detail

getUrlSelected

public final int getUrlSelected()
Identifies which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.

Specified by:
getUrlSelected in interface IJSlimCachable
Returns:
Which of the descriptor document URLs were used to obtain the initial context for the instantiation of this object.

getLoginTimeout

public final int getLoginTimeout()
                          throws java.sql.SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.
See Also:
setLoginTimeout(int)

setLoginTimeout

public final void setLoginTimeout(int seconds)
                           throws java.sql.SQLException

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.
See Also:
getLoginTimeout()

getLogWriter

public final java.io.PrintWriter getLogWriter()
                                       throws java.sql.SQLException

Retrieves the log writer for this DataSource object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created, the log writer is initially null; in other words, the default is for logging to be disabled.

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
the log writer for this data source or null if logging is disabled
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
setLogWriter(java.io.PrintWriter)

setLogWriter

public final void setLogWriter(java.io.PrintWriter out)
                        throws java.sql.SQLException

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null; in other words, the default is for logging to be disabled.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out - the new log writer; to disable logging, set to null
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
getLogWriter()

getConnection

public final java.sql.Connection getConnection()
                                        throws java.sql.SQLException

Attempts to establish a connection with the data source that this DataSource object represents.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
a connection to the data source
Throws:
java.sql.SQLException - if a database access error occurs

getConnection

public final java.sql.Connection getConnection(java.lang.String username,
                                               java.lang.String password)
                                        throws java.sql.SQLException

Attempts to establish a connection with the data source that this DataSource object represents.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username - the database user on whose behalf the connection is being made
password - the user's password
Returns:
a connection to the data source
Throws:
java.sql.SQLException - if a database access error occurs

rethrowSQLException

private static void rethrowSQLException(java.sql.SQLException e)
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

JSlim  


Copyright (c) 1999 - 2004 by Global Technology Consulting Group, Inc. at gtcGroup.com.
Use is authorized, provided the source is acknowledged by inclusion of this copyright notice.