Class JDBCResourceConnector

All Implemented Interfaces:
AuditLoggingComponent, SecureConnectorExtension, VirtualConnectorExtension

public class JDBCResourceConnector extends ConnectorBase implements AuditLoggingComponent
JDBCResourceConnector provides basic implementation of DataSource interface in order to get a Connection to target database. This is done via a static inner class, since DataSource.getConnection() clashes with ConnectorBase.getConnection().

The DataSource can be used directly. There are also selected methods to issue common SQL statements to the database.
  • Constructor Details

    • JDBCResourceConnector

      public JDBCResourceConnector()
  • Method Details

    • setAuditLog

      public void setAuditLog(AuditLog auditLog)
      Receive an audit log object that can be used to record audit log messages. The caller has initialized it with the correct component description and log destinations.
      Specified by:
      setAuditLog in interface AuditLoggingComponent
      Parameters:
      auditLog - audit log object
    • getConnectorComponentDescription

      public ComponentDescription getConnectorComponentDescription()
      Return the component description that is used by this connector in the audit log.
      Specified by:
      getConnectorComponentDescription in interface AuditLoggingComponent
      Returns:
      id, name, description, wiki page URL.
    • start

      public void start() throws ConnectorCheckedException
      Indicates that the connector is completely configured and can begin processing.
      Overrides:
      start in class ConnectorBase
      Throws:
      ConnectorCheckedException - there is a problem within the connector.
    • getDatabaseName

      public String getDatabaseName()
      Return the name of the database.
      Returns:
      string name
    • getDataSource

      public DataSource getDataSource()
      Return the DataSource implementation for this database. This supports creating the connection to the database.
      Returns:
      DataSource
    • addDatabaseDefinitions

      public void addDatabaseDefinitions(List<String> ddlStatements) throws PropertyServerException
      Issue the supplied DDL statements.
      Parameters:
      ddlStatements - statements to execute
      Throws:
      PropertyServerException - problem communicating with the database
    • issueSQLCommand

      public void issueSQLCommand(String sqlCommand) throws PropertyServerException
      Issue a SQL command that expects no results.
      Parameters:
      sqlCommand - command to issue
      Throws:
      PropertyServerException - something went wrong
    • getLatestRow

      public Map<String,JDBCDataValue> getLatestRow(String tableName, String identifierColumnName, String identifierColumnValue, String timestampColumnName, Map<String,Integer> columnNameTypeMap) throws PropertyServerException
      Retrieve the row with the requested identifier and with the latest timestamp.
      Parameters:
      tableName - name of the table to query
      identifierColumnName - name of the column with the identifier in it
      identifierColumnValue - value of the identifier to match on
      timestampColumnName - name of the column with the timestamp
      columnNameTypeMap - map of resulting column names and values to include in the results
      Returns:
      Map of column names to data values that represent the requested row
      Throws:
      PropertyServerException - there was a problem calling the database
    • getMatchingRow

      public Map<String,JDBCDataValue> getMatchingRow(String tableName, String whereClause, Map<String,Integer> columnNameTypeMap) throws PropertyServerException
      Retrieve the row that matches the where clause.
      Parameters:
      tableName - name of the table to query
      whereClause - condition describing how to match the desired columns
      columnNameTypeMap - map of resulting column names and values to include in the results
      Returns:
      row consisting of column names to data values that represent the requested row
      Throws:
      PropertyServerException - there was a problem calling the database
    • getMatchingRows

      public List<Map<String,JDBCDataValue>> getMatchingRows(String tableName, String whereClause, Map<String,Integer> columnNameTypeMap) throws PropertyServerException
      Retrieve the row with the requested identifier and with the latest timestamp.
      Parameters:
      tableName - name of the table to query
      whereClause - condition describing how to match the desired columns
      columnNameTypeMap - map of resulting column names and values to include in the results
      Returns:
      list of rows consisting of column names to data values that represent the requested row
      Throws:
      PropertyServerException - there was a problem calling the database
    • getMatchingRows

      public List<Map<String,JDBCDataValue>> getMatchingRows(String sqlCommand, Map<String,Integer> columnNameTypeMap) throws PropertyServerException
      Retrieve the row with the requested identifier and with the latest timestamp.
      Parameters:
      sqlCommand - condition describing how to match the desired columns
      columnNameTypeMap - map of resulting column names and values to include in the results
      Returns:
      list of rows consisting of column names to data values that represent the requested row
      Throws:
      PropertyServerException - there was a problem calling the database
    • getRows

      public List<Map<String,JDBCDataValue>> getRows(String tableName, Map<String,Integer> columnNameTypeMap) throws PropertyServerException
      Retrieve the row with the requested identifier and with the latest timestamp.
      Parameters:
      tableName - name of the table to query
      columnNameTypeMap - map of resulting column names and values to include in the results
      Returns:
      list of rows consisting of column names to data values that represent the requested row
      Throws:
      PropertyServerException - there was a problem calling the database
    • insertRowIntoTable

      public void insertRowIntoTable(String tableName, Map<String,JDBCDataValue> columnNameValueMap) throws PropertyServerException
      Prepare an INSERT SQL statement with all the columns for the new row filled out.
      Parameters:
      tableName - name of the table where the row is to be added
      columnNameValueMap - column names, values and types
      Throws:
      PropertyServerException - problem executing the command
    • insertRowsIntoTable

      public void insertRowsIntoTable(String tableName, List<Map<String,JDBCDataValue>> rows) throws PropertyServerException
      Prepare an INSERT SQL statement with all the columns for each of the new rows filled out.
      Parameters:
      tableName - name of the table where the row is to be added
      rows - list of column names, values and types
      Throws:
      PropertyServerException - problem executing the command
    • disconnect

      public void disconnect() throws ConnectorCheckedException
      Free up any resources held since the connector is no longer needed.
      Overrides:
      disconnect in class ConnectorBase
      Throws:
      ConnectorCheckedException - there is a problem within the connector.