Class BatchInsertJsonArray
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.jdbc.JdbcService
-
- com.adaptris.core.services.jdbc.JdbcMapInsert
-
- com.adaptris.core.json.jdbc.InsertJsonObject
-
- com.adaptris.core.json.jdbc.InsertJsonObjects
-
- com.adaptris.core.json.jdbc.BatchInsertJsonArray
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,ConnectedService
,MessageEventGenerator
,Service
,StateManagedComponent
@ComponentProfile(summary="Insert a JSON array into a database", tag="service,json,jdbc", since="3.6.5") public class BatchInsertJsonArray extends InsertJsonObjects
Convenience service for inserting a JSON array into a database.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" } ]
INSERT INTO table (firstname,lastname,dob) VALUES (?,?,?)
3 times; batching as required usingPreparedStatement.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"}'
- Since:
- 3.6.5
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.adaptris.core.services.jdbc.JdbcMapInsert
JdbcMapInsert.BasicType, JdbcMapInsert.InsertWrapper, JdbcMapInsert.StatementParam, JdbcMapInsert.StatementWrapper
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BATCH_WINDOW
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description BatchInsertJsonArray()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static int
accumulate(int[] rc)
void
doService(AdaptrisMessage msg)
java.lang.Integer
getBatchWindow()
void
setBatchWindow(java.lang.Integer i)
Set the batch window for operations.-
Methods inherited from class com.adaptris.core.json.jdbc.InsertJsonObjects
getJsonStyle, jsonStyle, setJsonStyle, withJsonStyle
-
Methods inherited from class com.adaptris.core.json.jdbc.InsertJsonObject
getNullConverter, setNullConverter
-
Methods inherited from class com.adaptris.core.services.jdbc.JdbcMapInsert
addUpdatedMetadata, buildStatementParam, closeJdbcService, columnBookend, getColumnBookendCharacter, getFieldMappings, getRowsAffectedMetadataKey, getTable, handleInsert, initJdbcService, prepareService, setColumnBookendCharacter, setFieldMappings, setRowsAffectedMetadataKey, setTable, startService, stopService, table, withColumnBookend, withMappings, withRowsAffectedMetadataKey, withTable
-
Methods inherited from class com.adaptris.core.jdbc.JdbcService
applyTimeout, closeService, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, setConnection, setStatementTimeout, start, stop
-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
-
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
-
-
-
Field Detail
-
DEFAULT_BATCH_WINDOW
public static final int DEFAULT_BATCH_WINDOW
- See Also:
- Constant Field Values
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
- Specified by:
doService
in interfaceService
- Overrides:
doService
in classInsertJsonObject
- Throws:
ServiceException
-
accumulate
protected static int accumulate(int[] rc) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getBatchWindow
public java.lang.Integer getBatchWindow()
- Returns:
- the batchWindow
-
setBatchWindow
public void setBatchWindow(java.lang.Integer i)
Set the batch window for operations.- Parameters:
i
- the batchWindow to set; default is 1024 if not specified.
-
-