|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jasig.portal.RDBMServices
public class RDBMServices
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.
Nested Class Summary | |
---|---|
static class |
RDBMServices.GenericDataSource
Inner class implementation of DataSource. |
static class |
RDBMServices.PreparedStatement
Deprecated. Instead of this class a wrapper around the DataSource, Connection and Prepared statement should be done in DatabaseMetaDataImpl |
Field Summary | |
---|---|
private static int |
activeConnections
|
private static IDatabaseMetadata |
dbMetaData
|
static java.lang.String |
DEFAULT_DATABASE
|
private static java.lang.String |
FLAG_FALSE
|
private static java.lang.String |
FLAG_TRUE
|
private static java.lang.String |
FLAG_TRUE_OTHER
|
private static boolean |
getDatasourceFromJndi
|
private static java.lang.String |
jdbcDriver
|
private static java.lang.String |
jdbcUrl
|
private static java.lang.String |
jdbcUser
|
private static int |
JNDI_RETRY_TIME
Specifies how long to wait before trying to look a JNDI data source that previously failed |
private static org.apache.commons.logging.Log |
LOG
|
private static java.util.Map |
namedDataSources
|
private static java.util.Map |
namedDbServerFailures
|
static java.lang.String |
PORTAL_DB
|
private static java.lang.Object |
SYNC_OBJECT
|
Constructor Summary | |
---|---|
RDBMServices()
|
Method Summary | |
---|---|
static void |
closePreparedStatement(java.sql.PreparedStatement pst)
Deprecated. Use closeStatement(Statement) . |
static void |
closeResultSet(java.sql.ResultSet rs)
Close a ResultSet |
static void |
closeStatement(java.sql.Statement st)
Close a Statement |
static void |
commit(java.sql.Connection connection)
Commit pending transactions. |
static java.lang.String |
dbFlag(boolean flag)
Return DB format of a boolean. |
static boolean |
dbFlag(java.lang.String flag)
Return boolean value of DB flag, "Y" or "N". |
static int |
getActiveConnectionCount()
Return the current number of active connections |
static java.sql.Connection |
getConnection()
Gets a database connection to the portal database. |
static java.sql.Connection |
getConnection(java.lang.String dbName)
Returns a connection produced by a DataSource found in the JNDI context. |
static javax.sql.DataSource |
getDataSource()
Gets the default DataSource. |
static javax.sql.DataSource |
getDataSource(java.lang.String name)
Gets a named DataSource from JNDI, with special handling for the PORTAL_DB datasource. |
static IDatabaseMetadata |
getDbMetaData()
Get metadata about the default DataSource. |
static java.lang.String |
getJdbcDriver()
Returns the name of the JDBC driver being used for the default uPortal database connections. |
static java.lang.String |
getJdbcUrl()
Gets the JDBC URL of the default uPortal database connections. |
static java.lang.String |
getJdbcUser()
Get the username under which we are connecting for the default uPortal database connections. |
private static javax.sql.DataSource |
getJndiDataSource(java.lang.String name)
Does the JNDI lookup and returns datasource |
static boolean |
isGetDatasourceFromJndi()
|
static void |
releaseConnection(java.sql.Connection con)
Releases database connection. |
static void |
rollback(java.sql.Connection connection)
rollback unwanted changes to the database |
static void |
setAutoCommit(java.sql.Connection connection,
boolean autocommit)
Set auto commit state for the connection. |
static void |
setGetDatasourceFromJndi(boolean getDatasourceFromJndi)
|
static java.lang.String |
sqlEscape(java.lang.String sql)
Make a string SQL safe |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String PORTAL_DB
public static final java.lang.String DEFAULT_DATABASE
private static boolean getDatasourceFromJndi
private static final org.apache.commons.logging.Log LOG
private static final java.lang.String FLAG_TRUE
private static final java.lang.String FLAG_TRUE_OTHER
private static final java.lang.String FLAG_FALSE
private static final int JNDI_RETRY_TIME
private static java.util.Map namedDataSources
private static java.util.Map namedDbServerFailures
private static java.lang.String jdbcUrl
private static java.lang.String jdbcUser
private static java.lang.String jdbcDriver
private static IDatabaseMetadata dbMetaData
private static final java.lang.Object SYNC_OBJECT
private static int activeConnections
Constructor Detail |
---|
public RDBMServices()
Method Detail |
---|
public static javax.sql.DataSource getDataSource()
java.lang.RuntimeException
- on failurepublic static javax.sql.DataSource getDataSource(java.lang.String name)
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.
name
- The name of the DataSource to get.
null
if one cannot be found.private static javax.sql.DataSource getJndiDataSource(java.lang.String name)
name
-
public static int getActiveConnectionCount()
public static java.sql.Connection getConnection()
DataAccessException
- if unable to return a connectionpublic static java.sql.Connection getConnection(java.lang.String dbName)
dbName
- the database name which will be retrieved from
the JNDI context relative to "jdbc/"
null
if no Connectionpublic static void releaseConnection(java.sql.Connection con)
con
- a database Connection objectpublic static void closeResultSet(java.sql.ResultSet rs)
rs
- a database ResultSet objectpublic static void closeStatement(java.sql.Statement st)
st
- a database Statement objectpublic static void closePreparedStatement(java.sql.PreparedStatement pst)
closeStatement(Statement)
.
closeStatement(Statement)
pst
- a database PreparedStatement objectpublic static final void commit(java.sql.Connection connection)
connection
- public static final void setAutoCommit(java.sql.Connection connection, boolean autocommit)
connection
- autocommit
- public static final void rollback(java.sql.Connection connection) throws java.sql.SQLException
connection
-
java.sql.SQLException
public static java.lang.String getJdbcDriver()
public static java.lang.String getJdbcUrl()
public static java.lang.String getJdbcUser()
public static final java.lang.String dbFlag(boolean flag)
flag
- true or false
public static final boolean dbFlag(java.lang.String flag)
flag
- either "Y" or "N"
public static final java.lang.String sqlEscape(java.lang.String sql)
sql
-
public static IDatabaseMetadata getDbMetaData()
public static boolean isGetDatasourceFromJndi()
public static void setGetDatasourceFromJndi(boolean getDatasourceFromJndi)
getDatasourceFromJndi
- The getDatasourceFromJndi to set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |