Class FailoverConfig

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class FailoverConfig
    extends java.lang.Object
    implements java.lang.Cloneable
    Class that is used to configure a failover database connection.
    See Also:
    FailoverConnection
    • 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.url key then the natural ordering of the keys is used to specify the order in which urls are added to the FailoverConfig object.

        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 - the Map from 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.IllegalArgumentException
        Set 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:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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:
        clone in class java.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)