Package com.adaptris.jdbc.connection
Class FailoverConfig
- java.lang.Object
-
- com.adaptris.jdbc.connection.FailoverConfig
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class FailoverConfig extends java.lang.Object implements java.lang.CloneableClass that is used to configure a failover database connection.- See Also:
FailoverConnection
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJDBC_ALWAYS_VERIFYresource key for connection verify settingstatic java.lang.StringJDBC_AUTO_COMMITresource key for driver autocommit settingstatic java.lang.StringJDBC_DEBUGresource key specifying extra debug.static java.lang.StringJDBC_DRIVERresource key for driver classnamestatic java.lang.StringJDBC_PASSWORDresource key for specifying the passwordstatic java.lang.StringJDBC_TEST_STATEMENTResource key for testing a connection.static java.lang.StringJDBC_URL_ROOTresource key for driver urlstatic java.lang.StringJDBC_USERNAMEresource key for specifying the username
-
Constructor Summary
Constructors Constructor Description FailoverConfig()FailoverConfig(java.util.Properties map)Constructor using a pre-existing map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionUrl(java.lang.String string)Add a Connection URL to the configured list.java.lang.Objectclone()booleanequals(java.lang.Object o)booleangetAlwaysValidateConnection()booleangetAutoCommit()Get autoCommit flag for this configurationjava.util.PropertiesgetConnectionProperties()java.util.List<java.lang.String>getConnectionUrls()Get the configured list of URLs.java.lang.StringgetDatabaseDriver()Get the configured database Driver for this configbooleangetDebugMode()Return whether the database connection should have further verbose logging.java.lang.StringgetPassword()java.lang.StringgetTestStatement()Get the statement that will test the connection.java.lang.StringgetUsername()inthashCode()voidsetAlwaysValidateConnection(boolean b)voidsetAutoCommit(boolean b)Set the autocommit flag for this configurationvoidsetConnectionProperties(java.util.Properties p)voidsetConnectionUrls(java.util.List<java.lang.String> list)Set a Connection URL to the configured list.voidsetDatabaseDriver(java.lang.String string)Set the database driver.voidsetDebugMode(boolean b)Specify verbose logging.voidsetPassword(java.lang.String password)voidsetTestStatement(java.lang.String string)Set the statement that will test the connection.voidsetUsername(java.lang.String username)java.lang.StringtoString()
-
-
-
Field Detail
-
JDBC_DRIVER
public static final java.lang.String JDBC_DRIVER
resource key for driver classname- See Also:
- Constant Field Values
-
JDBC_TEST_STATEMENT
public static final java.lang.String JDBC_TEST_STATEMENT
Resource key for testing a connection.- See Also:
- Constant Field Values
-
JDBC_URL_ROOT
public static final java.lang.String JDBC_URL_ROOT
resource key for driver url- See Also:
- Constant Field Values
-
JDBC_AUTO_COMMIT
public static final java.lang.String JDBC_AUTO_COMMIT
resource key for driver autocommit setting- See Also:
- Constant Field Values
-
JDBC_ALWAYS_VERIFY
public static final java.lang.String JDBC_ALWAYS_VERIFY
resource key for connection verify setting- See Also:
- Constant Field Values
-
JDBC_DEBUG
public static final java.lang.String JDBC_DEBUG
resource key specifying extra debug.- See Also:
- Constant Field Values
-
JDBC_USERNAME
public static final java.lang.String JDBC_USERNAME
resource key for specifying the username- See Also:
- Constant Field Values
-
JDBC_PASSWORD
public static final java.lang.String JDBC_PASSWORD
resource key for specifying the password- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FailoverConfig
public FailoverConfig()
- See Also:
Object()
-
FailoverConfig
public FailoverConfig(java.util.Properties map)
Constructor using a pre-existing map.This allows us to easily configure the repository from a set of properties.
The properties object is expected to contain the following keys with associated values
- jdbc.driver.classname - this represents the jdbc driver classname
- jdbc.driver.url.n - where n is some unique identifier. Each of these entries will specify a database connection string in
the general form
jdbc:mysql://localhost:3306/portal. There must be at least one of these entries. Each entry is used to as a parameter to FailoverConfig.addConnectionUrl(String s) - jdbc.driver.autocommit - either true or false, the default is true
- jdbc.username - the username for the connection - this is optional, if all connection urls have a username/password inline.
- jdbc.password - password for the connection - this is optional, if all connection urls have a username/password inline.
If there is more than one
jdbc.driver.urlkey then the natural ordering of the keys is used to specify the order in which urls are added to theFailoverConfigobject.An Example property file would be:-
jdbc.driver.classname=com.mysql.jdbc.Driver jdbc.driver.url.1=jdbc:mysql://master:3306/portal?user=user jdbc.driver.url.2=jdbc:mysql://slave1:3306/portal?user=user jdbc.driver.url.3=jdbc:mysql://slave2:3306/portal?user=user- Parameters:
map- theMapfrom which we will initialise from.- See Also:
JDBC_DRIVER,JDBC_URL_ROOT,addConnectionUrl(String)
-
-
Method Detail
-
setConnectionUrls
public void setConnectionUrls(java.util.List<java.lang.String> list)
Set a Connection URL to the configured list.- Parameters:
list- a list of connection urls- Throws:
java.lang.IllegalArgumentException- if the string is null.
-
addConnectionUrl
public void addConnectionUrl(java.lang.String string)
Add a Connection URL to the configured list.- Parameters:
string- a connection url- Throws:
java.lang.IllegalArgumentException- if the string is null.
-
getConnectionUrls
public java.util.List<java.lang.String> getConnectionUrls()
Get the configured list of URLs.- Returns:
- The configured collection of urls
-
getDatabaseDriver
public java.lang.String getDatabaseDriver()
Get the configured database Driver for this config- Returns:
- the database driver
-
setDatabaseDriver
public void setDatabaseDriver(java.lang.String string)
Set the database driver.- Parameters:
string- the database driver- Throws:
java.lang.IllegalArgumentException- if the driver is null.
-
getTestStatement
public java.lang.String getTestStatement()
Get the statement that will test the connection.- Returns:
- the statement
-
setTestStatement
public void setTestStatement(java.lang.String string) throws java.lang.IllegalArgumentExceptionSet the statement that will test the connection.- Parameters:
string- the statement- Throws:
java.lang.IllegalArgumentException- if the statement is null.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getAutoCommit
public boolean getAutoCommit()
Get autoCommit flag for this configuration- Returns:
- the autoCommit flag
-
setAutoCommit
public void setAutoCommit(boolean b)
Set the autocommit flag for this configuration- Parameters:
b- the new flag
-
getDebugMode
public boolean getDebugMode()
Return whether the database connection should have further verbose logging.- Returns:
- true or false.
-
setDebugMode
public void setDebugMode(boolean b)
Specify verbose logging.- Parameters:
b- true or false.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException- See Also:
Object.clone()
-
getAlwaysValidateConnection
public boolean getAlwaysValidateConnection()
-
setAlwaysValidateConnection
public void setAlwaysValidateConnection(boolean b)
-
getUsername
public java.lang.String getUsername()
-
setUsername
public void setUsername(java.lang.String username)
-
getPassword
public java.lang.String getPassword()
-
setPassword
public void setPassword(java.lang.String password)
-
getConnectionProperties
public java.util.Properties getConnectionProperties()
-
setConnectionProperties
public void setConnectionProperties(java.util.Properties p)
-
-