Package adams.db
Class AbstractDatabaseConnection
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.db.AbstractDatabaseConnection
-
- All Implemented Interfaces:
CloneHandler<AbstractDatabaseConnection>,Destroyable,LoggingSupporter,OptionHandler,PasswordSupporter,SizeOfHandler,DatabaseConnectionParameterHandler,Serializable,Comparable<AbstractDatabaseConnection>
- Direct Known Subclasses:
AbstractReconnectableDatabaseConnection,DatabaseConnection
public abstract class AbstractDatabaseConnection extends LoggingObject implements OptionHandler, DatabaseConnectionParameterHandler, Comparable<AbstractDatabaseConnection>, CloneHandler<AbstractDatabaseConnection>, PasswordSupporter
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 protected booleanm_AutoCommitautocommit?protected HashSet<DatabaseConnectionChangeListener>m_ChangeListenersthe listeners in case of connect/disconnect.protected Connectionm_ConnectionThe database connection.protected booleanm_ConnectionOKwhether we could connect successfully.protected booleanm_ConnectOnStartUpwhether to connect on startup.protected AbstractEnvironmentm_Environmentthe environment to use.protected static HashMap<Class,AbstractEnvironment>m_Environmentskeeping track of environment instances.protected Hashtable<String,Integer>m_FailedConnectAttemptsfor keeping track of unsuccessful connection attempts.protected Stringm_LastConnectionErrorstores the last connection error.protected intm_MaxConnectAttemptsthe maximum number of allowed connection attempts for a driver/URL/user/pw combination.protected OptionManagerm_OptionManagerfor managing the available options.protected DatabaseManagerm_Ownerthe database manager this connection belongs to.protected BasePasswordm_Passworddatabase password.protected Propertiesm_Propertiesthe properties for database access.protected static Map<Class,Properties>m_PropertiesCacheprotected intm_ReconnectWaitthe number of seconds to wait before trying to reconnect.protected Stringm_URLthe URL to connect to the database.protected Stringm_Userdatabase username.static StringPREFIX_CONNECTIONthe prefix in the props file for connections.static StringSUFFIX_COUNTthe suffix in the props file for the number of connections.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDatabaseConnection()Constructor, uses the default settings.protectedAbstractDatabaseConnection(String url, String user, BasePassword password)Local Database Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(DatabaseConnectionChangeListener l)Adds a listener for connect/disconnect events to the internal list.booleanaddConnectionParameters(ConnectionParameters conn)Adds the given connection to the props file.StringautoCommitTipText()Returns the tip text for this property.voidcleanUpOptions()Cleans up the options.intcompareTo(AbstractDatabaseConnection o)Compares this object with the specified object for order.intcompareTo(ConnectionParameters o)Compares this object with the specified object for order.protected voidconfigureLogger()Initializes the logger.booleanconnect()Try to make a connection to the database, with the url,username and password.protected booleanconnectionsToProperties(List<ConnectionParameters> connections)Replaces the current connections with the provided ones and updates the .props file.StringconnectOnStartUpTipText()Returns the tip text for this property.protected abstract AbstractEnvironmentcreateEnvironment()Creates a new instance of the environment object that we require.voiddefineOptions()Adds options to the internal list of options.voiddestroy()Frees up memory in a "destructive" non-reversible way.booleandisconnect()Attempt disconnect from db.booleanequals(Object o)Checks wether this object is the same as the provided one.protected voidfinishInit()Finishes the initialization.List<ConnectionParameters>getAllConnectionParameters()Returns the stored connections.booleangetAutoCommit()Returns whether to use auto-commit.Set<DatabaseConnectionChangeListener>getChangeListeners()Returns the change listeners data structure.AbstractDatabaseConnectiongetClone()Returns a clone of the object.ConnectiongetConnection(boolean keepTrying)Return db connection.booleangetConnectOnStartUp()Returns whether to use connect on start-up.ConnectionParametersgetCurrentConnectionParameters()Returns the current connection parameters.booleangetDefaultAutoCommit()Returns whether to use auto-commit.ConnectionParametersgetDefaultConnectionParameters()Returns the default connection parameter object.booleangetDefaultConnectOnStartUp()Returns whether to automatically connect on startup, i.e., when obtaining the singleton for the first time.LoggingLevelgetDefaultLoggingLevel()Returns the logging level specified in the props file.intgetDefaultMaxConnectAttempts()Returns the maximum number of connection attempts.BasePasswordgetDefaultPassword()Returns the password specified in the props file.intgetDefaultReconnectWait()Returns the number of seconds to wait before trying to reconnect.StringgetDefaultURL()Returns the database URL specified in the props file.StringgetDefaultUser()Returns the user specified in the props file.protected abstract StringgetDefinitionKey()Returns the properties key to use for retrieving the properties.protected AbstractEnvironmentgetEnvironment()Returns the environment instance to use, creates it if necessary.protected intgetFailedConnectAttempt(String url, String user, BasePassword password)Returns the failed attempt count for the given connection.protected StringgetFailedConnectAttemptKey(String url, String user, BasePassword password)Generates a key for the failed connect attempt hashtable.StringgetLastConnectionError()Returns the last error that happened when connecting to the database.intgetMaxConnectAttempts()Returns the maximum number of connection attempts for a driver/URL/user/pw combination.OptionManagergetOptionManager()Returns the option manager.DatabaseManagergetOwner()Returns the current database manager that owns this connection.BasePasswordgetPassword()Returns the currently set database password.PropertiesgetProperties()Returns the properties, loads them on demand.intgetReconnectWait()Returns the number of seconds to wait before trying to reconnect.StringgetURL()Returns the currently set database URL.StringgetUser()Returns the currently set database user.inthashCode()Hashcode so can be used as hashtable key.protected voidincFailedConnectAttempt(String url, String user, BasePassword password)Increments the failed attempt for the given connection.protected voidinitialize()initializes member variables.booleanisConnected()Is database connected?booleanisConnectionOK()Returns if connection to database is OK.StringloggingLevelTipText()Returns the tip text for this property.booleanmakeDefaultConnection(ConnectionParameters conn)Sets the given connection as the default one.StringmaxConnectAttemptsTipText()Returns the tip text for this property.ConnectionParametersnewConnectionParameters()Returns a new instance of a ConnectionParameters object.protected OptionManagernewOptionManager()Returns a new instance of the option manager.voidnotifyChangeListeners(DatabaseConnectionChangeEvent e)Notifies all listeners with the given event.protected voidoutputChangeListeners()Outputs the change listeners if debugging is on.StringpasswordTipText()Returns the tip text for this property.protected PropertiesreadProperties()Reads the properties.StringreconnectWaitTipText()Returns the tip text for this property.voidremoveChangeListener(DatabaseConnectionChangeListener l)Removes a listener for connect/disconnect events from the internal list.booleanremoveConnectionParameters(ConnectionParameters conn)Removes the given connection from the props file.voidresetFailedConnectAttempt()Resets the failed attempts for the current connection.protected voidresetFailedConnectAttempt(String url, String user, BasePassword password)Resets the failed attempt for the given connection.booleanretryConnect()Redo connection to database.voidsetAutoCommit(boolean value)Sets whether to use auto-commit.voidsetConnectOnStartUp(boolean value)Sets whether to connect on start-up (only if not connected).voidsetDefaultAutoCommit(boolean value)Sets the default for auto-commit.voidsetDefaultConnectOnStartUp(boolean value)Sets the default for whether to connect on startup.voidsetDefaultLoggingLevel(LoggingLevel value)Sets the default logging level in the props file.voidsetDefaultPassword(BasePassword value)Sets the default password in the props file.voidsetDefaultURL(String value)Sets the default database URL in the props file.voidsetDefaultUser(String value)Sets the default user in the props file.voidsetLoggingLevel(LoggingLevel value)Sets the logging level.voidsetMaxConnectAttempts(int value)Sets the maximum number of connection attempts for a driver/URL/user/pw combination (only if not connected).voidsetOwner(DatabaseManager value)Sets the database manager that owns this connection.voidsetPassword(BasePassword value)Sets the database password to use (only if not connected).voidsetReconnectWait(int value)Sets the number of seconds to wait before trying to reconnect.voidsetURL(String value)Sets the database URL to use (only if not connected).voidsetUser(String value)Sets the database user to use (only if not connected).StringtoCommandLine()Returns the commandline string.ConnectionParameterstoConnectionParameters(AbstractDatabaseConnection conn)Turns the database connection into a parameters object.StringtoString()Returns a string representation of the connection object.StringtoStringShort()Returns a short string representation of the connection.protected booleantryConnection()Tries to reconnect.booleanupdateConnectionParameters()Updates the props file in the project's home directory.StringURLTipText()Returns the tip text for this property.StringuserTipText()Returns the tip text for this property.-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
PREFIX_CONNECTION
public static final String PREFIX_CONNECTION
the prefix in the props file for connections.- See Also:
- Constant Field Values
-
SUFFIX_COUNT
public static final String SUFFIX_COUNT
the suffix in the props file for the number of connections.- See Also:
- Constant Field Values
-
m_Environments
protected static HashMap<Class,AbstractEnvironment> m_Environments
keeping track of environment instances.
-
m_PropertiesCache
protected static Map<Class,Properties> m_PropertiesCache
-
m_OptionManager
protected OptionManager m_OptionManager
for managing the available options.
-
m_ChangeListeners
protected transient HashSet<DatabaseConnectionChangeListener> m_ChangeListeners
the listeners in case of connect/disconnect.
-
m_Properties
protected Properties m_Properties
the properties for database access.
-
m_FailedConnectAttempts
protected Hashtable<String,Integer> m_FailedConnectAttempts
for keeping track of unsuccessful connection attempts.
-
m_URL
protected String m_URL
the URL to connect to the database.
-
m_User
protected String m_User
database username.
-
m_Password
protected BasePassword m_Password
database password.
-
m_ConnectOnStartUp
protected boolean m_ConnectOnStartUp
whether to connect on startup.
-
m_MaxConnectAttempts
protected int m_MaxConnectAttempts
the maximum number of allowed connection attempts for a driver/URL/user/pw combination.
-
m_ReconnectWait
protected int m_ReconnectWait
the number of seconds to wait before trying to reconnect.
-
m_AutoCommit
protected boolean m_AutoCommit
autocommit?
-
m_Connection
protected transient Connection m_Connection
The database connection.
-
m_ConnectionOK
protected boolean m_ConnectionOK
whether we could connect successfully.
-
m_LastConnectionError
protected String m_LastConnectionError
stores the last connection error.
-
m_Owner
protected DatabaseManager m_Owner
the database manager this connection belongs to.
-
m_Environment
protected transient AbstractEnvironment m_Environment
the environment to use.
-
-
Constructor Detail
-
AbstractDatabaseConnection
protected AbstractDatabaseConnection()
Constructor, uses the default settings.
-
AbstractDatabaseConnection
protected AbstractDatabaseConnection(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
-
initialize
protected void initialize()
initializes member variables.
-
finishInit
protected void finishInit()
Finishes the initialization.
-
setOwner
public void setOwner(DatabaseManager value)
Sets the database manager that owns this connection.- Parameters:
value- the manager
-
getOwner
public DatabaseManager getOwner()
Returns the current database manager that owns this connection.- Returns:
- the manager
-
getChangeListeners
public Set<DatabaseConnectionChangeListener> getChangeListeners()
Returns the change listeners data structure. Initializes it if necessary.- Returns:
- the change listeners
-
newOptionManager
protected OptionManager newOptionManager()
Returns a new instance of the option manager.- Returns:
- the manager to use
-
defineOptions
public void defineOptions()
Adds options to the internal list of options. Derived classes must override this method to add additional options.- Specified by:
defineOptionsin interfaceOptionHandler
-
getOptionManager
public OptionManager getOptionManager()
Returns the option manager.- Specified by:
getOptionManagerin interfaceOptionHandler- Returns:
- the manager
-
cleanUpOptions
public void cleanUpOptions()
Cleans up the options.- Specified by:
cleanUpOptionsin interfaceOptionHandler
-
destroy
public void destroy()
Frees up memory in a "destructive" non-reversible way.
Cleans up the options.- Specified by:
destroyin interfaceDestroyable- See Also:
cleanUpOptions()
-
getDefinitionKey
protected abstract String getDefinitionKey()
Returns the properties key to use for retrieving the properties.- Returns:
- the key
-
createEnvironment
protected abstract AbstractEnvironment createEnvironment()
Creates a new instance of the environment object that we require.- Returns:
- the instance
-
getEnvironment
protected AbstractEnvironment getEnvironment()
Returns the environment instance to use, creates it if necessary.- Returns:
- the instance
-
readProperties
protected Properties readProperties()
Reads the properties.- Returns:
- the properties
- See Also:
getDefinitionKey()
-
getProperties
public Properties getProperties()
Returns the properties, loads them on demand.- Returns:
- the properties
-
getDefaultLoggingLevel
public LoggingLevel getDefaultLoggingLevel()
Returns the logging level specified in the props file.- Returns:
- the default logging level
-
setDefaultLoggingLevel
public void setDefaultLoggingLevel(LoggingLevel value)
Sets the default logging level in the props file.- Parameters:
value- the default logging level
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Parameters:
value- the level
-
loggingLevelTipText
public String loggingLevelTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
configureLogger
protected void configureLogger()
Initializes the logger.- Overrides:
configureLoggerin classLoggingObject
-
getDefaultURL
public String getDefaultURL()
Returns the database URL specified in the props file.- Returns:
- the default URL, if any
-
setDefaultURL
public void setDefaultURL(String value)
Sets the default database URL in the props file.- Parameters:
value- the default URL
-
getURL
public String getURL()
Returns the currently set database URL.- Specified by:
getURLin interfaceDatabaseConnectionParameterHandler- Returns:
- the current URL
-
setURL
public void setURL(String value)
Sets the database URL to use (only if not connected).- Specified by:
setURLin interfaceDatabaseConnectionParameterHandler- Parameters:
value- the URL to use
-
URLTipText
public String URLTipText()
Returns the tip text for this property.- Specified by:
URLTipTextin interfaceDatabaseConnectionParameterHandler- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getDefaultUser
public String getDefaultUser()
Returns the user specified in the props file.- Returns:
- the default user, if any
-
setDefaultUser
public void setDefaultUser(String value)
Sets the default user in the props file.- Parameters:
value- the default user
-
getUser
public String getUser()
Returns the currently set database user.- Specified by:
getUserin interfaceDatabaseConnectionParameterHandler- Returns:
- the current user
-
setUser
public void setUser(String value)
Sets the database user to use (only if not connected).- Specified by:
setUserin interfaceDatabaseConnectionParameterHandler- Parameters:
value- the user to use
-
userTipText
public String userTipText()
Returns the tip text for this property.- Specified by:
userTipTextin interfaceDatabaseConnectionParameterHandler- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getDefaultPassword
public BasePassword getDefaultPassword()
Returns the password specified in the props file.- Returns:
- the default password, if any
-
setDefaultPassword
public void setDefaultPassword(BasePassword value)
Sets the default password in the props file.- Parameters:
value- the default password
-
getPassword
public BasePassword getPassword()
Returns the currently set database password.- Specified by:
getPasswordin interfaceDatabaseConnectionParameterHandler- Specified by:
getPasswordin interfacePasswordSupporter- Returns:
- the current password
-
setPassword
public void setPassword(BasePassword value)
Sets the database password to use (only if not connected).- Specified by:
setPasswordin interfaceDatabaseConnectionParameterHandler- Specified by:
setPasswordin interfacePasswordSupporter- Parameters:
value- the password to use
-
passwordTipText
public String passwordTipText()
Returns the tip text for this property.- Specified by:
passwordTipTextin interfaceDatabaseConnectionParameterHandler- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getMaxConnectAttempts
public int getMaxConnectAttempts()
Returns the maximum number of connection attempts for a driver/URL/user/pw combination.- Returns:
- the max number
-
setMaxConnectAttempts
public void setMaxConnectAttempts(int value)
Sets the maximum number of connection attempts for a driver/URL/user/pw combination (only if not connected).- Parameters:
value- the max number
-
getDefaultMaxConnectAttempts
public int getDefaultMaxConnectAttempts()
Returns the maximum number of connection attempts.- Returns:
- the default maximum number of attempts
-
maxConnectAttemptsTipText
public String maxConnectAttemptsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getReconnectWait
public int getReconnectWait()
Returns the number of seconds to wait before trying to reconnect.- Returns:
- the number of seconds
-
setReconnectWait
public void setReconnectWait(int value)
Sets the number of seconds to wait before trying to reconnect.- Parameters:
value- the number of seconds
-
getDefaultReconnectWait
public int getDefaultReconnectWait()
Returns the number of seconds to wait before trying to reconnect.- Returns:
- the default number of seconds
-
reconnectWaitTipText
public String reconnectWaitTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getDefaultConnectOnStartUp
public boolean getDefaultConnectOnStartUp()
Returns whether to automatically connect on startup, i.e., when obtaining the singleton for the first time.- Returns:
- true if to connect automatically on startup
-
setDefaultConnectOnStartUp
public void setDefaultConnectOnStartUp(boolean value)
Sets the default for whether to connect on startup.- Parameters:
value- the default
-
getConnectOnStartUp
public boolean getConnectOnStartUp()
Returns whether to use connect on start-up.- Returns:
- true if connecting on startup
-
setConnectOnStartUp
public void setConnectOnStartUp(boolean value)
Sets whether to connect on start-up (only if not connected).- Parameters:
value- true if to connect on startup
-
connectOnStartUpTipText
public String connectOnStartUpTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getDefaultAutoCommit
public boolean getDefaultAutoCommit()
Returns whether to use auto-commit.- Returns:
- true if to use auto-commit
-
setDefaultAutoCommit
public void setDefaultAutoCommit(boolean value)
Sets the default for auto-commit.- Parameters:
value- the default
-
getAutoCommit
public boolean getAutoCommit()
Returns whether to use auto-commit.- Returns:
- true if to use auto-commit
-
setAutoCommit
public void setAutoCommit(boolean value)
Sets whether to use auto-commit.- Parameters:
value- true if to use auto-commit
-
autoCommitTipText
public String autoCommitTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getCurrentConnectionParameters
public ConnectionParameters getCurrentConnectionParameters()
Returns the current connection parameters.- Returns:
- the parameters
-
toConnectionParameters
public ConnectionParameters toConnectionParameters(AbstractDatabaseConnection conn)
Turns the database connection into a parameters object.- Parameters:
conn- the connection to convert- Returns:
- the parameters
-
getFailedConnectAttemptKey
protected String getFailedConnectAttemptKey(String url, String user, BasePassword password)
Generates a key for the failed connect attempt hashtable.- Parameters:
url- the JDBC URLuser- the database userpassword- the database password- Returns:
- the generated key for the hashtable
-
getFailedConnectAttempt
protected int getFailedConnectAttempt(String url, String user, BasePassword password)
Returns the failed attempt count for the given connection.- Parameters:
url- the JDBC URLuser- the database userpassword- the database password- Returns:
- the current count
-
incFailedConnectAttempt
protected void incFailedConnectAttempt(String url, String user, BasePassword password)
Increments the failed attempt for the given connection.- Parameters:
url- the JDBC URLuser- the database userpassword- the database password
-
resetFailedConnectAttempt
public void resetFailedConnectAttempt()
Resets the failed attempts for the current connection.
-
resetFailedConnectAttempt
protected void resetFailedConnectAttempt(String url, String user, BasePassword password)
Resets the failed attempt for the given connection.- Parameters:
url- the JDBC URLuser- the database userpassword- the database password
-
getLastConnectionError
public String getLastConnectionError()
Returns the last error that happened when connecting to the database.- Returns:
- the last error, "" if non occurred
-
getConnection
public Connection getConnection(boolean keepTrying)
Return db connection.- Parameters:
keepTrying- continue attempting to connect- Returns:
- new Connection
-
tryConnection
protected boolean tryConnection()
Tries to reconnect.- Returns:
- true if successful
-
isConnectionOK
public boolean isConnectionOK()
Returns if connection to database is OK.- Returns:
- true if connection OK
-
isConnected
public boolean isConnected()
Is database connected?- Returns:
- database connected?
-
retryConnect
public boolean retryConnect()
Redo connection to database.- Returns:
- success?
-
connect
public boolean connect() throws ExceptionTry to make a connection to the database, with the url,username and password.- Returns:
- connect OK
- Throws:
Exception- if connection cannot be instantiated
-
disconnect
public boolean disconnect()
Attempt disconnect from db.- Returns:
- success?
-
newConnectionParameters
public ConnectionParameters newConnectionParameters()
Returns a new instance of a ConnectionParameters object.- Returns:
- the new instance
-
getDefaultConnectionParameters
public ConnectionParameters getDefaultConnectionParameters()
Returns the default connection parameter object.- Returns:
- the default
-
getAllConnectionParameters
public List<ConnectionParameters> getAllConnectionParameters()
Returns the stored connections.- Returns:
- the connections
-
connectionsToProperties
protected boolean connectionsToProperties(List<ConnectionParameters> connections)
Replaces the current connections with the provided ones and updates the .props file.- Parameters:
connections- the connections to store- Returns:
- true if successfully updated
-
addConnectionParameters
public boolean addConnectionParameters(ConnectionParameters conn)
Adds the given connection to the props file.- Parameters:
conn- the connection to add- Returns:
- true if successfully added
-
removeConnectionParameters
public boolean removeConnectionParameters(ConnectionParameters conn)
Removes the given connection from the props file.- Parameters:
conn- the connection to remove- Returns:
- true if successfully removed
-
makeDefaultConnection
public boolean makeDefaultConnection(ConnectionParameters conn)
Sets the given connection as the default one.- Parameters:
conn- the connection to use as default- Returns:
- true if successfully set as default
-
updateConnectionParameters
public boolean updateConnectionParameters()
Updates the props file in the project's home directory.- Returns:
- true if sucessfully updated
-
outputChangeListeners
protected void outputChangeListeners()
Outputs the change listeners if debugging is on.
-
addChangeListener
public void addChangeListener(DatabaseConnectionChangeListener l)
Adds a listener for connect/disconnect events to the internal list.- Parameters:
l- the listener to add
-
removeChangeListener
public void removeChangeListener(DatabaseConnectionChangeListener l)
Removes a listener for connect/disconnect events from the internal list.- Parameters:
l- the listener to remove
-
notifyChangeListeners
public void notifyChangeListeners(DatabaseConnectionChangeEvent e)
Notifies all listeners with the given event.- Parameters:
e- the event to send to the listeners
-
compareTo
public int compareTo(AbstractDatabaseConnection o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Uses the database URL and user for comparison.- Specified by:
compareToin interfaceComparable<AbstractDatabaseConnection>- Parameters:
o- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException- if the specified object's type prevents it from being compared to this object.
-
compareTo
public int compareTo(ConnectionParameters o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Uses the database URL and user for comparison.- Parameters:
o- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object o)
Checks wether this object is the same as the provided one. Only uses the database URL for comparison.
-
hashCode
public int hashCode()
Hashcode so can be used as hashtable key. Returns the hashcode of the "url \t user" string.
-
getClone
public AbstractDatabaseConnection getClone()
Returns a clone of the object.- Specified by:
getClonein interfaceCloneHandler<AbstractDatabaseConnection>- Returns:
- the clone
-
toStringShort
public String toStringShort()
Returns a short string representation of the connection.- Returns:
- a short string representation
-
toString
public String toString()
Returns a string representation of the connection object.
-
toCommandLine
public String toCommandLine()
Returns the commandline string.- Specified by:
toCommandLinein interfaceOptionHandler- Returns:
- the commandline
-
-