Class QueryConsumer
java.lang.Object
com.invirgance.convirgance.web.consumer.QueryConsumer
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIterable
<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.Child records to include as part of the insertion.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<com.invirgance.convirgance.json.JSONObject> keys) Creates anAtomicOperation
for database insertion, optionally generating sequence values.The field name.Returns query used to get the next sequence id.getSql()
Returns the SQL that will be executed.void
setChildren
(Map<String, QueryConsumer> children) Child records to include as part of the insertion.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.
-
Constructor Details
-
QueryConsumer
public QueryConsumer()
-
-
Method Details
-
getJndiName
Returns the JDNI name.- Returns:
- The name.
-
setJndiName
Updates the JDNI connection name to use.- Parameters:
jndiName
- The new connection.
-
getSql
Returns the SQL that will be executed.- Returns:
- The raw unbound SQL.
-
setSql
Sets the query to execute. Named bindings are supported.- Parameters:
sql
- The query.
-
getSequenceSql
Returns query used to get the next sequence id.- Returns:
- The query.
-
setSequenceSql
Sets the query used to get the next sequence id.- Parameters:
sequenceSql
- The query.
-
getSequenceId
The field name.- Returns:
- The name.
-
setSequenceId
Sets the field name to store sequence ids.- Parameters:
sequenceId
- Field name.
-
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
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 anAtomicOperation
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 transformeddbms
- 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 interfaceConsumer
- Parameters:
iterable
- Collection of JSONObject records to be inserted into the databaseparameters
- 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
-