|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opennms.netmgt.config.DataSourceFactory
public final class DataSourceFactory
This is the singleton class used to load the OpenNMS database configuration from the opennms-database.xml. This provides convenience methods to create database connections to the database configured in this default xml
Note: Users of this class should make sure the init() is called before calling any other method to ensure the config is loaded before accessing other convenience methods
| Constructor Summary | |
|---|---|
DataSourceFactory()
|
|
| Method Summary | ||
|---|---|---|
static void |
close()
|
|
java.sql.Connection |
getConnection()
Return a new database connection to the database configured in the opennms-database.xml. |
|
java.sql.Connection |
getConnection(java.lang.String dsName)
|
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
|
|
org.exolab.castor.jdo.conf.Database |
getDatabase()
Return the database that was configured in the config file |
|
static javax.sql.DataSource |
getDataSource()
Return the datasource configured for the database |
|
static javax.sql.DataSource |
getDataSource(java.lang.String dsName)
|
|
static javax.sql.DataSource |
getInstance()
Return the singleton instance of this factory. |
|
static javax.sql.DataSource |
getInstance(java.lang.String name)
|
|
int |
getLoginTimeout()
|
|
int |
getLoginTimeout(java.lang.String dsName)
|
|
java.io.PrintWriter |
getLogWriter()
|
|
java.io.PrintWriter |
getLogWriter(java.lang.String dsName)
|
|
static void |
init()
Load the config from the default config file and create the singleton instance of this factory. |
|
static void |
init(java.lang.String dsName)
|
|
void |
initialize()
|
|
boolean |
isWrapperFor(java.lang.Class<?> iface)
|
|
static void |
setInstance(javax.sql.DataSource singleton)
|
|
static void |
setInstance(java.lang.String dsName,
javax.sql.DataSource singleton)
|
|
void |
setLoginTimeout(int seconds)
|
|
void |
setLoginTimeout(java.lang.String dsName,
int seconds)
|
|
void |
setLogWriter(java.io.PrintWriter out)
|
|
void |
setLogWriter(java.lang.String dsName,
java.io.PrintWriter out)
|
|
|
unwrap(java.lang.Class<T> iface)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DataSourceFactory()
| Method Detail |
|---|
public static void init()
throws java.io.IOException,
org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
java.lang.ClassNotFoundException,
java.beans.PropertyVetoException,
java.sql.SQLException
java.io.IOException - Thrown if the specified config file cannot be read
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
java.sql.SQLException
java.beans.PropertyVetoException
java.lang.ClassNotFoundException
public static void init(java.lang.String dsName)
throws java.io.IOException,
org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
java.lang.ClassNotFoundException,
java.beans.PropertyVetoException,
java.sql.SQLException
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
java.lang.ClassNotFoundException
java.beans.PropertyVetoException
java.sql.SQLExceptionpublic static javax.sql.DataSource getInstance()
Return the singleton instance of this factory. This is the instance of
the factory that was last created when the
init or
reload method was invoked. The instance will not change
unless a reload method is invoked.
java.lang.IllegalStateException - Thrown if the factory has not yet been initialized.public static javax.sql.DataSource getInstance(java.lang.String name)
public java.sql.Connection getConnection()
throws java.sql.SQLException
close method.
getConnection in interface javax.sql.DataSourcejava.sql.SQLException - Thrown if there is an error opening the connection to the
database.
public java.sql.Connection getConnection(java.lang.String dsName)
throws java.sql.SQLException
java.sql.SQLExceptionpublic static void setInstance(javax.sql.DataSource singleton)
public static void setInstance(java.lang.String dsName,
javax.sql.DataSource singleton)
public org.exolab.castor.jdo.conf.Database getDatabase()
public static javax.sql.DataSource getDataSource()
public static javax.sql.DataSource getDataSource(java.lang.String dsName)
public java.sql.Connection getConnection(java.lang.String username,
java.lang.String password)
throws java.sql.SQLException
getConnection in interface javax.sql.DataSourcejava.sql.SQLException
public java.io.PrintWriter getLogWriter()
throws java.sql.SQLException
getLogWriter in interface javax.sql.DataSourcejava.sql.SQLException
public java.io.PrintWriter getLogWriter(java.lang.String dsName)
throws java.sql.SQLException
java.sql.SQLException
public void setLogWriter(java.io.PrintWriter out)
throws java.sql.SQLException
setLogWriter in interface javax.sql.DataSourcejava.sql.SQLException
public void setLogWriter(java.lang.String dsName,
java.io.PrintWriter out)
throws java.sql.SQLException
java.sql.SQLException
public void setLoginTimeout(int seconds)
throws java.sql.SQLException
setLoginTimeout in interface javax.sql.DataSourcejava.sql.SQLException
public void setLoginTimeout(java.lang.String dsName,
int seconds)
throws java.sql.SQLException
java.sql.SQLException
public int getLoginTimeout()
throws java.sql.SQLException
getLoginTimeout in interface javax.sql.DataSourcejava.sql.SQLException
public int getLoginTimeout(java.lang.String dsName)
throws java.sql.SQLException
java.sql.SQLException
public void initialize()
throws org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
java.io.IOException,
java.lang.ClassNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
java.io.IOException
java.lang.ClassNotFoundException
public static void close()
throws java.sql.SQLException
java.sql.SQLException
public <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
java.sql.SQLException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||