Class JDBCConnector

  • All Implemented Interfaces:
    ConnectionSettings

    public class JDBCConnector
    extends Object
    implements ConnectionSettings
    Basic JDBC connector class. Stores information required to create new JDBC connections and provides various common utility methods.
    • Constructor Detail

      • JDBCConnector

        public JDBCConnector()
    • Method Detail

      • setDriverName

        public void setDriverName​(String driverName)
        Sets the class name of the JDBC driver to use, for example: "sun.jdbc.odbc.JdbcOdbcDriver".
        Parameters:
        driverName - the class name of the JDBC driver to use
      • getDriverName

        public String getDriverName()
        Retrieves the class name of the JDBC driver to use.
        Specified by:
        getDriverName in interface ConnectionSettings
        Returns:
        the class name of the JDBC driver to use
      • setUser

        public void setUser​(String user)
        Sets the user name for connecting to the database.
        Parameters:
        user - the user name for connecting to the database
      • getUser

        public String getUser()
        Retrieves the user name for connecting to the database.
        Specified by:
        getUser in interface ConnectionSettings
        Returns:
        the user name for connecting to the database
      • setPassword

        public void setPassword​(String password)
        Sets the password for connecting to the database.
        Parameters:
        password - the password for connecting to the database
      • setEncryyptedPassword

        public void setEncryyptedPassword​(Password password)
      • getPassword

        public String getPassword()
        Retrieves the password for connecting to the database.
        Specified by:
        getPassword in interface ConnectionSettings
        Returns:
        the password for connecting to the database
      • getEncryptedPassword

        public Password getEncryptedPassword()
      • setUrl

        public void setUrl​(String url)
        Sets the URL for connecting to the database, for example: jdbc:odbc:SampleTest.
        Parameters:
        url - the URL for connecting to the database
      • getUrl

        public String getUrl()
        Retrieves the URL for connecting to the database.
        Specified by:
        getUrl in interface ConnectionSettings
        Returns:
        the URL for connecting to the database
      • getTableName

        public String getTableName()
        Retrieves the name of the database table to access.
        Returns:
        the name of the database table to access
      • setTableName

        public void setTableName​(String tableName)
        Sets the name of the database table to access. The table name is required by WriteToJDBC, but optional for ReadFromJDBC, since ReadFromJDBC#setSelectStatement(String) may be used instead.
        Parameters:
        tableName - the name of the database table to access
      • getHostNames

        public List<String> getHostNames()
        Get the list of configured database host names.
        Returns:
        database host names
      • setHostNames

        public void setHostNames​(List<String> hostNames)
        Set the list of database host names that can be used to execute queries. This is an optional parameter this is only valid for databases that support multiple database hosts for executing queries.
        Parameters:
        hostNames - list of database host names
      • setHostNames

        public void setHostNames​(String... hostNames)
        Set the list of database host names that can be used to execute queries. This is an optional parameter this is only valid for databases that support multiple database hosts for executing queries.
        Parameters:
        hostNames - list of database host names
      • setConnectionFactory

        public void setConnectionFactory​(ConnectionFactory connectionFactory)
        Sets the connection factory to be used for creating connections. Defaults to DefaultConnectionFactory.
        Parameters:
        connectionFactory - the connection factory to be used for creating connections.
      • getConnectionFactory

        public ConnectionFactory getConnectionFactory()
        Returns the connection factory to be used for creating connections. Defaults to DefaultConnectionFactory.
        Returns:
        the connection factory to be used for creating connections.
      • getDelimiter

        public String getDelimiter()
        Get the delimiter character.
        Returns:
        delimiter character
      • setDelimiter

        public void setDelimiter​(String delimiter)
        Set the delimiter character used to delimiter table names in SQL queries.
        Parameters:
        delimiter - delimiter character used to surround table names
      • getConnection

        public Connection getConnection()
        Creates a JDBC connection as necessary and returns it. This is the connection object that is used by all utility methods. If a new connection is required create one using the factory provided by the getConnectionFactory() method.
        Returns:
        JDBC connection
      • cleanupConnection

        public void cleanupConnection()
        Close all resources opened during getConnection()
        See Also:
        getConnection()
      • getMetadata

        public DatabaseMetaData getMetadata()
        Gets the database metadata associated with this connection.
        Returns:
        a DatabaseMetaData object associated with this connection
      • getTableMetadata

        public ResultSetMetaData getTableMetadata()
        Gets the metadata associated with this connection's table.
        Returns:
        a ResultSetMetaData object associated with this connection's table
      • getTableMetadata

        public ResultSetMetaData getTableMetadata​(String statement)
        Gets the metadata associated with the provided statement
        Returns:
        a ResultSetMetaData object associated with the statement
      • tableExists

        public boolean tableExists()
        Determine if the table associated with the connection exists
        Returns:
        true if the table exists
      • executeAndLogStatement

        public void executeAndLogStatement​(String statement)
        Executes the given statement closing the result set when finished.
        Parameters:
        statement - the statement to execute
      • executeAndLogSql

        public ResultSet executeAndLogSql​(String statement,
                                          boolean haltOnError,
                                          int fetchSize)
        Executes a given SQL statement, returning the result. Caller is responsible for freeing the result set.
        Parameters:
        statement - the statement to execute
        haltOnError - if true an error will be thrown if a SQLException is encountered
        fetchSize - the fetch size to use with the PreparedStatement
        Returns:
        the result set
      • closeStatement

        public void closeStatement​(String statement,
                                   PreparedStatement s)
        Closes a prepared statement object.
        Parameters:
        statement - the original SQL statement
        s - the prepared statement to close
      • closeResultSetAndStatement

        public void closeResultSetAndStatement​(String statement,
                                               ResultSet rs)
        Closes a result set object.
        Parameters:
        statement - the original SQL statement
        rs - the result set to close