Provides relational database access and helper methods.
A static routine determines if the database/driver supports
prepared statements and/or outer joins.
This class provides database access as a service. Via the class, uPortal
code can obtain a connection to the core uPortal database as well as to other
databases available via JNDI. (Doing that JNDI lookup directly allows your
code to avoid dependence upon this class.) This class provides
traditional getConnection() methods as well as static covers for getting a
reference to the backing DataSource.
This class also provides helper methods for manipulating connections.
Mostof the methods are wrappers around methods on the underlying Connection
that handle (log and swallow) the SQLExceptions that the underlying methods
declare to be thrown (these helpers also catch
and log RuntimeExceptions encountered). They provide an alternative to trying
and catching those methods using the JDBC APIs directly.
author: Ken Weiner, kweiner@unicon.net author: George Lindholm, george.lindholm@ubc.ca author: Eric Dalquist edalquist@unicon.net author: Susan Bramhall susan.bramhall@yale.edu version: $Revision: 36804 $ $Date: 2007-02-12 16:23:45 -0700 (Mon, 12 Feb 2007) $
Inner Class :public static class GenericDataSource implements DataSource
Inner Class :final public static class PreparedStatement
commit(Connection connection) Commit pending transactions.
Unlike the underlying commit(), this method does not throw SQLException or
any other exception.
releaseConnection(Connection con) Releases database connection.
Unlike the underlying connection.close(), this method does not throw
SQLException or any other exception.
setAutoCommit(Connection connection, boolean autocommit) Set auto commit state for the connection.
Unlike the underlying connection.setAutoCommit(), this method does not
throw SQLException or any other Exception.
Commit pending transactions.
Unlike the underlying commit(), this method does not throw SQLException or
any other exception. It will fail silently from the perspective of calling code,
logging any errors using Commons Logging.
Parameters: connection -
dbFlag
final public static String dbFlag(boolean flag)(Code)
Return DB format of a boolean. "Y" for true and "N" for false.
Parameters: flag - true or false either "Y" or "N"
dbFlag
final public static boolean dbFlag(String flag)(Code)
Return boolean value of DB flag, "Y" or "N".
Parameters: flag - either "Y" or "N" boolean true or false
getActiveConnectionCount
public static int getActiveConnectionCount()(Code)
Return the current number of active connections
int
Gets a database connection to the portal database.
If datasource not available a runtime exception is thrown
a database Connection object throws: DataAccessException - if unable to return a connection
Returns a connection produced by a DataSource found in the
JNDI context. The DataSource should be configured and
loaded into JNDI by the J2EE container or may be the portal
default database.
Parameters: dbName - the database name which will be retrieved fromthe JNDI context relative to "jdbc/" a database Connection object or null if no Connection
Gets the default DataSource. If no server is found
a runtime exception will be thrown. This method will never return null.
the core uPortal DataSource throws: RuntimeException - on failure
Gets a named DataSource from JNDI, with special handling for the PORTAL_DB
datasource. Successful lookups
are cached and not done again. Lookup failure is remembered and blocks retry
for a
number of milliseconds specified by
RDBMServices.JNDI_RETRY_TIME to reduce
JNDI overhead and log spam.
There are two ways in which we handle the core uPortal DataSource
specially.
We determine and remember metadata in an DbMetaData object for the core
uPortal DataSource. We do not compute this DbMetaData for any other
DataSource.
We fall back on using rdbm.properties to construct our core uPortal
DataSource in the case where we cannot find it from JNDI. If the portal
property org.jasig.portal.RDBMServices.getDatasourceFromJNDI is true,
we first
first try to get the connection by looking in the
JNDI context for the name defined by the portal property
org.jasig.portal.RDBMServices.PortalDatasourceJndiName .
If we were not configured to check JNDI or we didn't find it in JNDI having
checked, we then fall back on rdbm.properties.
Parameters: name - The name of the DataSource to get. A named DataSource or null if one cannot be found.
Releases database connection.
Unlike the underlying connection.close(), this method does not throw
SQLException or any other exception. It will fail silently from the
perspective of calling code, logging errors using Commons Logging.
Parameters: con - a database Connection object
rollback unwanted changes to the database
Parameters: connection -
setAutoCommit
final public static void setAutoCommit(Connection connection, boolean autocommit)(Code)
Set auto commit state for the connection.
Unlike the underlying connection.setAutoCommit(), this method does not
throw SQLException or any other Exception. It fails silently from the
perspective of calling code, logging any errors encountered using
Commons Logging.
Parameters: connection - Parameters: autocommit -
setGetDatasourceFromJndi
public static void setGetDatasourceFromJndi(boolean getDatasourceFromJndi)(Code)
Parameters: getDatasourceFromJndi - The getDatasourceFromJndi to set.