Class QueryConsumer

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

@Wiring public class QueryConsumer extends Object implements Consumer
Persists JSON data to a database using SQL.
 Use this when you need to:
 - Insert web service data directly to a database
 - Auto-generate sequence IDs during insertion
 - Connect via JNDI with minimal configuration
 
Author:
jbanes
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.invirgance.convirgance.json.JSONArray
    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.
    Returns the JDNI name.
    com.invirgance.convirgance.dbms.AtomicOperation
    getOperation(Iterable<com.invirgance.convirgance.json.JSONObject> iterable, com.invirgance.convirgance.dbms.DBMS dbms, com.invirgance.convirgance.json.JSONArray keys)
    Creates an AtomicOperation for database insertion, optionally generating sequence values.
    The field name.
    Returns query used to get the next sequence id.
    Returns the SQL that will be executed.
    void
    setJndiName(String jndiName)
    Updates the JDNI connection name to use.
    void
    setSequenceId(String sequenceId)
    Sets the field name to store sequence ids.
    void
    setSequenceSql(String sequenceSql)
    Sets the query used to get the next sequence id.
    void
    Sets the query to execute.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.
    • 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 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 com.invirgance.convirgance.json.JSONArray 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