Question

i have seen the code for batch update like the below one using ArrayList :

@Override
public void saveBatch(final List<Employee> employeeList) {
    final int batchSize = 500;

    for (int j = 0; j < employeeList.size(); j += batchSize) {

        final List<Employee> batchList = employeeList.subList(j, j + batchSize > employeeList.size() ? employeeList.size() : j + batchSize);

        getJdbcTemplate().batchUpdate(QUERY_SAVE,
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i)
                        throws SQLException {
                    Employee employee = batchList.get(i);
                    ps.setString(1, employee.getFirstname());
                    ps.setString(2, employee.getLastname());
                    ps.setString(3, employee.getEmployeeIdOnSourceSystem());
                }

                @Override
                public int getBatchSize() {
                    return batchList.size();
                }
            });

    }
}

but if I use Hashmap like the below : HashMap<String, VerifyPaymentRO> verifyPaymentInfoMap

VerifyPaymentRO is java bean

how do I use it for updating the record ?

Was it helpful?

Solution

Just create List<?> out from the map values and you can use the same code you have posted:

List<VerifyPaymentRO> verifyPaymentList = new ArrayList<>(verifyPaymentInfoMap.values());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top