Class JdbcPersistorImpl

  • All Implemented Interfaces:
    Persistor

    public class JdbcPersistorImpl
    extends java.lang.Object
    implements Persistor

    A basic JDBC Implementation of a Persistor. This implementation expects the user to provide the following configuration in Transformers persistence.conf configuration file

     persistence.conf
         
              persistence-classid com/caplin/transformer/persistence/JdbcPersistorImpl
              add-database-params
                  init-string    <jdbc url>
                  driver-name    <jdbc driver - must be explicitly added to transformers jvm-global-classpath>
                  username       <db user>
                  password       <db password>
                  extra-params   <timeout in seconds for Connection.isValid()> <timeout in seconds for queryTimeout(), -1 to use driver defaults>
              end-database-params
         
     
     java.conf
         
              jvm-global-classpath <path_to_jdbc_driver>
          end-database-params
         
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.lang.String> onCall​(java.lang.String procedureName, java.lang.String[] args)
      Call a stored procedure in the database.
      int onDelete​(java.lang.String table, java.util.Map<java.lang.String,​java.lang.String> selector)
      Delete one or more rows from a table
      java.util.List<java.util.Map<java.lang.String,​java.lang.String>> onQuery​(java.lang.String table, java.lang.String query, QueryParams params)
      Query the database for results.
      void onShutdown()
      Called when transformer shuts down to close open connections and release acquired resources
      int onUpsert​(java.lang.String table, java.util.Map<java.lang.String,​java.lang.String> keys, java.util.Map<java.lang.String,​java.lang.String> data)
      Implement this method to handle update or insert callbacks.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JdbcPersistorImpl

        public JdbcPersistorImpl​(PersistorConfiguration configuration,
                                 java.util.logging.Logger logger)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • onUpsert

        public int onUpsert​(java.lang.String table,
                            java.util.Map<java.lang.String,​java.lang.String> keys,
                            java.util.Map<java.lang.String,​java.lang.String> data)
        Description copied from interface: Persistor

        Implement this method to handle update or insert callbacks. This method is expected to update an existing row or insert a new one if the update did not affect any rows

        This method should attempt to update an existing row first by setting all the values given in data and using the entries of this map where the key matches key anded together in the where clause like: "key1=value1 and key2=value2". If the update did not affect any rows, then an insert should be executed with the data given

        Specified by:
        onUpsert in interface Persistor
        Parameters:
        table - The table to be modified
        keys - Map containing column/value pairs to be used in the where clause for updates. If no row matches the criteria, a combination of keys and data is used as data for the rows, where entries in data take precedence over entries in keys
        data - Map containing column/value pairs to be set in the row identified by keys
        Returns:
        -1 on error or >=0 affected rows on success
      • onQuery

        public java.util.List<java.util.Map<java.lang.String,​java.lang.String>> onQuery​(java.lang.String table,
                                                                                              java.lang.String query,
                                                                                              QueryParams params)
        Description copied from interface: Persistor

        Query the database for results.

        Queries the database with query being a valid sql selection and args being a list of arguments that get bound to ? in the query string

        Specified by:
        onQuery in interface Persistor
        Parameters:
        table - The table name to execute the query on.
        query - a valid sql where clause or an empty string for all rows.
        params - QueryParams to be used for the query
        Returns:
        null on error, an empty array if there were no results or an array holding all the rows returned by the query.
      • onDelete

        public int onDelete​(java.lang.String table,
                            java.util.Map<java.lang.String,​java.lang.String> selector)
        Description copied from interface: Persistor

        Delete one or more rows from a table

        Delete rows where the all the columns specified in selector match their specified values

        Specified by:
        onDelete in interface Persistor
        Parameters:
        table - The table name to delete from.
        selector - Map of column names (keys) and values to be anded together in the where clause.
        Returns:
        true if the operation affected more than 0 rows, false otherwise.
      • onCall

        public java.util.Map<java.lang.String,​java.lang.String> onCall​(java.lang.String procedureName,
                                                                             java.lang.String[] args)
        Description copied from interface: Persistor

        Call a stored procedure in the database.

        Calls a stored procedure in the database with procedureName being a valid procedure name within the database and args being a list of arguments to pass to the stored procedure.

        Specified by:
        onCall in interface Persistor
        Parameters:
        procedureName - The name of the procedure to call.
        args - An ordered list of input arguments to be provided as input parameters to the procedure call.
        Returns:
        list of output parameters, null on error.
      • onShutdown

        public void onShutdown()
        Description copied from interface: Persistor

        Called when transformer shuts down to close open connections and release acquired resources

        Specified by:
        onShutdown in interface Persistor