|
|||||||||
| 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()
|
|
Connection |
getConnection()
Return a new database connection to the database configured in the opennms-database.xml. |
|
Connection |
getConnection(String dsName)
|
|
Connection |
getConnection(String username,
String password)
|
|
static DataSource |
getDataSource()
Return the datasource configured for the database |
|
static DataSource |
getDataSource(String dsName)
|
|
static DataSource |
getInstance()
Return the singleton instance of this factory. |
|
static DataSource |
getInstance(String name)
|
|
int |
getLoginTimeout()
|
|
int |
getLoginTimeout(String dsName)
|
|
PrintWriter |
getLogWriter()
|
|
PrintWriter |
getLogWriter(String dsName)
|
|
static void |
init()
Load the config from the default config file and create the singleton instance of this factory. |
|
static void |
init(String dsName)
|
|
void |
initialize()
|
|
boolean |
isWrapperFor(Class<?> iface)
|
|
static void |
setInstance(DataSource singleton)
|
|
static void |
setInstance(String dsName,
DataSource singleton)
|
|
void |
setLoginTimeout(int seconds)
|
|
void |
setLoginTimeout(String dsName,
int seconds)
|
|
void |
setLogWriter(PrintWriter out)
|
|
void |
setLogWriter(String dsName,
PrintWriter out)
|
|
|
unwrap(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 IOException,
org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
ClassNotFoundException,
PropertyVetoException,
SQLException
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.
SQLException
PropertyVetoException
ClassNotFoundException
public static void init(String dsName)
throws IOException,
org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
ClassNotFoundException,
PropertyVetoException,
SQLException
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
ClassNotFoundException
PropertyVetoException
SQLExceptionpublic static 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.
IllegalStateException - Thrown if the factory has not yet been initialized.public static DataSource getInstance(String name)
public Connection getConnection()
throws SQLException
close method.
getConnection in interface DataSourceSQLException - Thrown if there is an error opening the connection to the
database.
public Connection getConnection(String dsName)
throws SQLException
SQLExceptionpublic static void setInstance(DataSource singleton)
public static void setInstance(String dsName,
DataSource singleton)
public static DataSource getDataSource()
public static DataSource getDataSource(String dsName)
public Connection getConnection(String username,
String password)
throws SQLException
getConnection in interface DataSourceSQLException
public PrintWriter getLogWriter()
throws SQLException
getLogWriter in interface CommonDataSourceSQLException
public PrintWriter getLogWriter(String dsName)
throws SQLException
SQLException
public void setLogWriter(PrintWriter out)
throws SQLException
setLogWriter in interface CommonDataSourceSQLException
public void setLogWriter(String dsName,
PrintWriter out)
throws SQLException
SQLException
public void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLException
public void setLoginTimeout(String dsName,
int seconds)
throws SQLException
SQLException
public int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLException
public int getLoginTimeout(String dsName)
throws SQLException
SQLException
public void initialize()
throws org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException,
IOException,
ClassNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException
ClassNotFoundException
public static void close()
throws SQLException
SQLException
public <T> T unwrap(Class<T> iface)
throws SQLException
unwrap in interface WrapperSQLException
public boolean isWrapperFor(Class<?> iface)
throws SQLException
isWrapperFor in interface WrapperSQLException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||