Class QueryConsumer

java.lang.Object
com.invirgance.convirgance.web.consumer.QueryConsumer
All Implemented Interfaces:
Consumer

@Wiring public class QueryConsumer extends Object implements Consumer
Inserts stream of data into a SQL database. Supports the use of sequences to allow for inserts of children in the same flow. Each object is bound to a batch SQL operation with named parameters.
Author:
jbanes
  • Constructor Details

    • QueryConsumer

      public QueryConsumer()
  • Method Details

    • getJndiName

      public String getJndiName()
      Returns the JDNI name.
      Returns:
      The name.
    • setJndiName

      public void setJndiName(String jndiName)
      Updates the JDNI connection name to use.
      Parameters:
      jndiName - The new connection.
    • getSql

      public String getSql()
      Returns the SQL that will be executed.
      Returns:
      The raw unbound SQL.
    • setSql

      public void setSql(String sql)
      Sets the query to execute. Named bindings are supported.
      Parameters:
      sql - The query.
    • getSequenceSql

      public String getSequenceSql()
      Returns query used to get the next sequence id.
      Returns:
      The query.
    • setSequenceSql

      public void setSequenceSql(String sequenceSql)
      Sets the query used to get the next sequence id.
      Parameters:
      sequenceSql - The query.
    • getSequenceId

      public String getSequenceId()
      The field name.
      Returns:
      The name.
    • setSequenceId

      public void setSequenceId(String sequenceId)
      Sets the field name to store sequence ids.
      Parameters:
      sequenceId - Field name.
    • getChildren

      public Map<String,QueryConsumer> getChildren()
      Child records to include as part of the insertion. The key must refer to a JSONArray in the incoming data. The specified QueryConsumer will handle the records found in the JSONArray.
      Returns:
      The mapping of keys to consumers of child records
    • setChildren

      public void setChildren(Map<String,QueryConsumer> children)
      Child records to include as part of the insertion. The key must refer to a JSONArray in the incoming data. The specified QueryConsumer will handle the records found in the JSONArray.
      Parameters:
      children - The mapping of keys to consumers of child records
    • getOperation

      public com.invirgance.convirgance.dbms.AtomicOperation getOperation(Iterable<com.invirgance.convirgance.json.JSONObject> iterable, com.invirgance.convirgance.dbms.DBMS dbms, com.invirgance.convirgance.json.JSONArray<com.invirgance.convirgance.json.JSONObject> keys)
      Creates an AtomicOperation for database insertion, optionally generating sequence values.

      If sequence generation is configured, this method will fetch sequence values before building the batch operation.

      Parameters:
      iterable - Data that will be transformed
      dbms - The DBMS to get the sequence ids.
      keys - Output collection where generated sequence values will be stored
      Returns:
      An BatchOperation with the transformed data to add to the database.
      Throws:
      com.invirgance.convirgance.ConvirganceException - if sequenceSql is set but sequenceId is not
    • consume

      public Iterable<com.invirgance.convirgance.json.JSONObject> consume(Iterable<com.invirgance.convirgance.json.JSONObject> iterable, com.invirgance.convirgance.json.JSONObject parameters)
      Consumes a collection of JSONObject records, inserting them into the connected database.
      Specified by:
      consume in interface Consumer
      Parameters:
      iterable - Collection of JSONObject records to be inserted into the database
      parameters - Additional parameters that might influence the operation (unused in this implementation)
      Returns:
      A JSONArray containing any generated sequence values, or an empty array if no sequences were used
      Throws:
      com.invirgance.convirgance.ConvirganceException - if database errors occur or if sequenceSql is set without sequenceId