| |
Batch update example
The batchInsert method in following ..
package amalegenitest.t08batchupdate.generated;
bean SalesFactBean
{
int id;
String name;
double quantity;
}
package amalegenitest.t08batchupdate.generated;
service BatchService extends DualBaseService
{
void batchInsert(List<SalesFactBean> list) [int dbIdentifier]
<<
insert into t_listof_data(id,name,quant)
values( ?,?,? )
>>
..
..
.. will be translated into:
public void batchInsert(List<SalesFactBean> list, int dbIdentifier)
throws SQLException
{
Connection connection = getConnection(dbIdentifier);
PreparedStatement stmt= connection.prepareCall(
"insert into t_listof_data(id,name,quant) "+
"values( ?,?,? ) ");
for ( SalesFactBean _bean : list )
{
populatePreparedStatementWithSalesFactBean(stmt, _bean);
stmt.addBatch();
}
stmt.executeBatch();
stmt.close();
returnConnection(connection);
}
..
private void populatePreparedStatementWithSalesFactBean(PreparedStatement pstmt, SalesFactBean bean)
throws SQLException
{
pstmt.setInt( 1,bean.getId());
pstmt.setString( 2,bean.getName());
pstmt.setDouble( 3,bean.getQuantity());
}
(Generated SalesFactBean code ommited). |