Skip to content

Instantly share code, notes, and snippets.

@langmi
Created September 30, 2011 09:14
Show Gist options
  • Save langmi/1253195 to your computer and use it in GitHub Desktop.
Save langmi/1253195 to your computer and use it in GitHub Desktop.
simple example CustomSqlParameterSourceProvider which constructs a MapSqlParameterSource with given item
/**
* CustomSqlParameterSourceProvider, constructs {@link MapSqlParameterSource} with
* given item.
*
* @author Michael R. Lange <[email protected]>
*/
public class CustomSqlParameterSourceProvider implements ItemSqlParameterSourceProvider<YourItemObject> {
@Override
public SqlParameterSource createSqlParameterSource(final YourItemObject item) {
return new MapSqlParameterSource(new HashMap<String, Object>() {
{
put("id", item.getId());
put("foo", item.getFoo);
}
});
}
}
<bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
INSERT INTO YOUR_ITEM_TABLE
(
id,
attribute
)
VALUES
(
:id,
:foo
)
]]>
</value>
</property>
<property name="itemSqlParameterSourceProvider">
<bean class="....CustomSqlParameterSourceProvider.java" />
</property>
</bean>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment