|
OpenNMS API 1.2.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opennms.netmgt.config.DatabaseConnectionFactory
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
Nested Class Summary | |
(package private) static class |
DatabaseConnectionFactory.CachedConnection
This class is used to represent a cached database connection within this factory. |
Field Summary | |
private org.exolab.castor.jdo.conf.Database |
m_database
The database class loaded from the config file |
private java.util.LinkedList |
m_dbcCache
The linked list of cached connections that are reused if the garbage collector has not finalized them yet. |
private java.lang.String |
m_driverPass
The cached database password. |
private java.lang.String |
m_driverUrl
The cached database URL |
private java.lang.String |
m_driverUser
The cached database user |
private static boolean |
m_loaded
This member is set to true if the configuration file has been loaded. |
private static DbConnectionFactory |
m_singleton
The singleton instance of this factory |
private static int |
MAX_AGE
The maximum age before a connection is closed |
Constructor Summary | |
private |
DatabaseConnectionFactory(java.lang.String configFile)
Private constructor |
Method Summary | |
java.sql.Connection |
getConnection()
Return a new database connection to the database configured in the opennms-database.xml. |
org.exolab.castor.jdo.conf.Database |
getDatabase()
Return the database that was configured in the config file |
org.exolab.castor.jdo.conf.DataSource |
getDataSource()
Return the datasource configured for the database |
org.exolab.castor.jdo.conf.Driver |
getDriver()
Return the driver configured for the database |
java.lang.String |
getEngine()
Return the engine configured for the database |
static DbConnectionFactory |
getInstance()
Return the singleton instance of this factory. |
org.exolab.castor.jdo.conf.Jndi |
getJndi()
Return the JNDI configuration for the database |
org.exolab.castor.jdo.conf.Mapping[] |
getMapping()
Return the mapping configured for the database. |
static void |
init()
Load the config from the default config file and create the singleton instance of this factory. |
private static void |
reload()
Reload the config from the default config file |
static void |
setInstance(DbConnectionFactory singleton)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int MAX_AGE
private static DbConnectionFactory m_singleton
private static boolean m_loaded
private org.exolab.castor.jdo.conf.Database m_database
private java.lang.String m_driverUrl
private java.lang.String m_driverUser
private java.lang.String m_driverPass
private java.util.LinkedList m_dbcCache
Constructor Detail |
private DatabaseConnectionFactory(java.lang.String configFile) throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException, java.lang.ClassNotFoundException
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.lang.ClassNotFoundException
Method Detail |
public static void init() throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException, java.lang.ClassNotFoundException
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.lang.ClassNotFoundException
private static void reload() throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException, java.lang.ClassNotFoundException
java.io.IOException
- Thrown if the specified config file cannot be read/loaded
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.lang.ClassNotFoundException
public static DbConnectionFactory 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 void setInstance(DbConnectionFactory singleton)
public org.exolab.castor.jdo.conf.Database getDatabase()
public org.exolab.castor.jdo.conf.DataSource getDataSource()
public org.exolab.castor.jdo.conf.Driver getDriver()
public java.lang.String getEngine()
public org.exolab.castor.jdo.conf.Jndi getJndi()
public org.exolab.castor.jdo.conf.Mapping[] getMapping()
public java.sql.Connection getConnection() throws java.sql.SQLException
close
method.
getConnection
in interface DbConnectionFactory
java.sql.SQLException
- Thrown if there is an error opening the connection to the
database.
|
OpenNMS API 1.2.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |