Package adams.db
Class DatabaseConnection
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.db.AbstractDatabaseConnection
-
- adams.db.DatabaseConnection
-
- All Implemented Interfaces:
CloneHandler<AbstractDatabaseConnection>
,Destroyable
,LoggingSupporter
,OptionHandler
,PasswordSupporter
,SizeOfHandler
,DatabaseConnectionParameterHandler
,Serializable
,Comparable<AbstractDatabaseConnection>
public class DatabaseConnection extends AbstractDatabaseConnection
DatabaseConnection manages the interface to the database back-end. Currently set up for MYSQL.- Author:
- dale (dale at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
FILENAME
the props file.-
Fields inherited from class adams.db.AbstractDatabaseConnection
m_AutoCommit, m_ChangeListeners, m_Connection, m_ConnectionOK, m_ConnectOnStartUp, m_Environment, m_Environments, m_FailedConnectAttempts, m_LastConnectionError, m_MaxConnectAttempts, m_OptionManager, m_Owner, m_Password, m_Properties, m_PropertiesCache, m_ReconnectWait, m_URL, m_User, PREFIX_CONNECTION, SUFFIX_COUNT
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description DatabaseConnection()
Local Database Constructor.DatabaseConnection(String url, String user, BasePassword password)
Local Database Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AbstractEnvironment
createEnvironment()
Creates a new instance of the environment object that we require.protected static DatabaseManager<DatabaseConnection>
getDatabaseManager()
Returns the database manager, instantiates it if necessary.protected String
getDefinitionKey()
Returns the properties key to use for retrieving the properties.static DatabaseConnection
getSingleton()
Returns the global database connection object.static DatabaseConnection
getSingleton(String url, String user, BasePassword password)
Returns the global database connection object.String
toCommandLine()
Returns the commandline string.-
Methods inherited from class adams.db.AbstractDatabaseConnection
addChangeListener, addConnectionParameters, autoCommitTipText, cleanUpOptions, compareTo, compareTo, configureLogger, connect, connectionsToProperties, connectOnStartUpTipText, defineOptions, destroy, disconnect, equals, finishInit, getAllConnectionParameters, getAutoCommit, getChangeListeners, getClone, getConnection, getConnectOnStartUp, getCurrentConnectionParameters, getDefaultAutoCommit, getDefaultConnectionParameters, getDefaultConnectOnStartUp, getDefaultLoggingLevel, getDefaultMaxConnectAttempts, getDefaultPassword, getDefaultReconnectWait, getDefaultURL, getDefaultUser, getEnvironment, getFailedConnectAttempt, getFailedConnectAttemptKey, getLastConnectionError, getMaxConnectAttempts, getOptionManager, getOwner, getPassword, getProperties, getReconnectWait, getURL, getUser, hashCode, incFailedConnectAttempt, initialize, isConnected, isConnectionOK, loggingLevelTipText, makeDefaultConnection, maxConnectAttemptsTipText, newConnectionParameters, newOptionManager, notifyChangeListeners, outputChangeListeners, passwordTipText, readProperties, reconnectWaitTipText, removeChangeListener, removeConnectionParameters, resetFailedConnectAttempt, resetFailedConnectAttempt, retryConnect, setAutoCommit, setConnectOnStartUp, setDefaultAutoCommit, setDefaultConnectOnStartUp, setDefaultLoggingLevel, setDefaultPassword, setDefaultURL, setDefaultUser, setLoggingLevel, setMaxConnectAttempts, setOwner, setPassword, setReconnectWait, setURL, setUser, toConnectionParameters, toString, toStringShort, tryConnection, updateConnectionParameters, URLTipText, userTipText
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the props file.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DatabaseConnection
public DatabaseConnection()
Local Database Constructor.
-
DatabaseConnection
public DatabaseConnection(String url, String user, BasePassword password)
Local Database Constructor. Initialise the JDBC driver, and attempt connection to the database specified in the URL, with the given username and password.- Parameters:
url
- the JDBC URLuser
- the user to connect withpassword
- the password for the user
-
-
Method Detail
-
createEnvironment
protected AbstractEnvironment createEnvironment()
Creates a new instance of the environment object that we require.- Specified by:
createEnvironment
in classAbstractDatabaseConnection
- Returns:
- the instance
-
getDefinitionKey
protected String getDefinitionKey()
Returns the properties key to use for retrieving the properties.- Specified by:
getDefinitionKey
in classAbstractDatabaseConnection
- Returns:
- the key
-
getDatabaseManager
protected static DatabaseManager<DatabaseConnection> getDatabaseManager()
Returns the database manager, instantiates it if necessary.- Returns:
- the manager
-
getSingleton
public static DatabaseConnection getSingleton(String url, String user, BasePassword password)
Returns the global database connection object. If not instantiated yet, it will automatically try to connect to the database server.- Parameters:
url
- the database URLuser
- the database userpassword
- the database password- Returns:
- the singleton
-
getSingleton
public static DatabaseConnection getSingleton()
Returns the global database connection object. If not instantiated yet, it can automatically try to connect to the database server, depending on the default in the props file (SUFFIX_CONNECTONSTARTUP).- Returns:
- the singleton
- See Also:
AbstractDatabaseConnection.getConnectOnStartUp()
-
toCommandLine
public String toCommandLine()
Returns the commandline string.- Specified by:
toCommandLine
in interfaceOptionHandler
- Overrides:
toCommandLine
in classAbstractDatabaseConnection
- Returns:
- the commandline
-
-