
@Named @Dependent public class JdbcItemWriter extends JdbcItemReaderWriterBase implements javax.batch.api.chunk.ItemWriter
javax.batch.api.chunk.ItemWriter that inserts data items into the target database.JdbcItemReader,
JdbcItemReaderWriterBase| Modifier and Type | Field and Description |
|---|---|
protected String[] |
parameterNames
String keys used to retrieve values from incoming data and apply to SQL insert statement parameters.
|
protected String[] |
parameterTypes
Tells this class which
PreparedStatement setter method to call to set insert statement parameters. |
beanType, dataSource, dataSourceLookup, password, preparedStatement, properties, sql, url, usercustomDataTypeModules, customDeserializers, customSerializers, deserializationFeatures, jsonFactory, jsonFactoryFeatures, jsonFactoryLookup, mapperFeatures, objectMapper, serializationFeaturesNEW_LINE, resource, skipBeanValidation| Constructor and Description |
|---|
JdbcItemWriter() |
| Modifier and Type | Method and Description |
|---|---|
Serializable |
checkpointInfo() |
void |
close() |
void |
open(Serializable checkpoint) |
void |
writeItems(List<Object> items) |
close, getConnection, initinitJsonFactory, initJsonFactoryAndObjectMapper, registerModulegetInputStream, getOutputStream, getValidator, validate@Inject protected String[] parameterNames
JdbcItemReaderWriterBase.beanType
is java.util.List, which assumes that incoming data is already in the same order as SQL parameters.
If JdbcItemReaderWriterBase.beanType is java.util.Map, and any of its key is different than the target table column
names, parameterNames should be specified. For example, if an incoming data item is:
{"name" = "Jon", "address" = "1 Main st", "age" = 30}
And JdbcItemReaderWriterBase.sql is
INSERT INTO PERSON(NAME, ADDRESS, AGE) VALUES(?, ?, ?)
then parameterNames should be specified as follows in job xml:
"name, address, age"
If JdbcItemReaderWriterBase.beanType is custom bean type, custom mapping may be achieved with either parameterNames, or
in bean class with annotations, e.g., JAXB or Jackson annotations. If the bean class does not contain field
mapping, or the field mapping is intended for other part of the application (e.g., ItemReader),
parameterNames can be used to customize mapping.
@Inject protected String[] parameterTypes
PreparedStatement setter method to call to set insert statement parameters.
It should have the same length and order as SQL insert statement parameters. Optional property, and if not set,
this class calls PreparedStatement.setObject(int, Object) for all parameters. For example,
this property can be configured as follows in job xml:
"String, String, Int"
And this class will call PreparedStatement.setString(int, String),
PreparedStatement.setString(int, String), and PreparedStatement.setInt(int, int).
Note that the value of this property is case sensitive.
public void writeItems(List<Object> items) throws Exception
writeItems in interface javax.batch.api.chunk.ItemWriterExceptionpublic void open(Serializable checkpoint) throws Exception
open in interface javax.batch.api.chunk.ItemWriterExceptionpublic void close()
throws Exception
close in interface javax.batch.api.chunk.ItemWriterExceptionpublic Serializable checkpointInfo() throws Exception
checkpointInfo in interface javax.batch.api.chunk.ItemWriterExceptionCopyright © 2018 JBoss by Red Hat. All rights reserved.