@ComponentProfile(summary="Insert a JSON array into a database", tag="service,json,jdbc", since="3.6.5") public class BatchInsertJsonArray extends InsertJsonObject
This creates insert statements based on the contents of each JSON object inside the array. The actual insert statement will only be generated once based on the first JSON object in the array and executed the appropriate number of times.
[
{ "firstname":"alice", "lastname":"smith", "dob":"2017-01-01" },
{ "firstname":"bob", "lastname":"smith", "dob":"2017-01-02" },
{ "firstname":"carol", "lastname":"smith", "dob":"2017-01-03" }
]
will effectively execute the following statement INSERT INTO table (firstname,lastname,dob) VALUES (?,?,?)
3 times;
batching as required using PreparedStatement.addBatch()
/ Statement.executeBatch()
.
Note that no parsing/assertion of the column names will be done, so if they are invalid SQL columns then it's going to be
fail. Additionally, nested JSON objects will be rendered as strings before being passed into the appropriate statement; so
{ "firstname":"alice", "lastname":"smith", "address": { "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}}
would
still be 3 parameters, the address parameter will be '{ "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}'
In the adapter configuration file this class is aliased as json-array-jdbc-batch-insert which is the preferred alternative to the fully qualified classname when building your configuration.
JdbcMapInsert.BasicType, JdbcMapInsert.InsertWrapper, JdbcMapInsert.StatementParam, JdbcMapInsert.StatementWrapper
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_WINDOW |
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
BatchInsertJsonArray() |
Modifier and Type | Method and Description |
---|---|
void |
doService(AdaptrisMessage msg) |
java.lang.Integer |
getBatchWindow() |
void |
setBatchWindow(java.lang.Integer i)
Set the batch window for operations.
|
getNullConverter, setNullConverter
buildStatementParam, closeJdbcService, columnBookend, getColumnBookendCharacter, getFieldMappings, getTable, handleInsert, initJdbcService, prepareService, setColumnBookendCharacter, setFieldMappings, setTable, startService, stopService, table, withColumnBookend, withMappings, withTable
applyTimeout, closeService, commit, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, rollback, setConnection, setStatementTimeout, start, stop
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsConfirmation, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isConfirmation, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, rethrowServiceException, retrieveComponentState, setContinueOnFail, setIsConfirmation, setIsTrackingEndpoint, setLookupName, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isConfirmation, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
getLookupName
public static final int DEFAULT_BATCH_WINDOW
public void doService(AdaptrisMessage msg) throws ServiceException
doService
in interface Service
doService
in class InsertJsonObject
ServiceException
public java.lang.Integer getBatchWindow()
public void setBatchWindow(java.lang.Integer i)
i
- the batchWindow to set; default is 1024 if not specified.