Class QueryConsumer
java.lang.Object
com.invirgance.convirgance.web.consumer.QueryConsumer
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptioncom.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 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
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.
-
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 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 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 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
-