@Test public void testUpdate() { int[] value = new int[] { 1, 2 }; when(jdbcTemplate.batchUpdate(any(String.class), any(List.class))).thenReturn(value); when(serviceConfigurationService.getServiceConfigValueByKeyAndTenantId(Matchers.any(), Matchers.anyString())) .thenReturn("500"); marriageDocumentTypeRepository.update(getMarriageDocumentTypes()); }
public void update(List<MarriageDocumentType> marriageDocumentTypes) { log.debug("MarriageDocumentTypes: " + marriageDocumentTypes); final String sql = MarriageDocumentTypeQueryBuilder.BATCH_UPDATE_QUERY; final String tenantId = marriageDocumentTypes.get(0).getTenantId(); final int batchSize = Integer.parseInt(serviceConfigurationService .getServiceConfigValueByKeyAndTenantId(ServiceConfigurationKeys.MARRIAGEBATCHSIZE, tenantId) .toString()); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < marriageDocumentTypes.size(); j += batchSize) { final List<MarriageDocumentType> batchList = marriageDocumentTypes.subList(j, j + batchSize > marriageDocumentTypes.size() ? marriageDocumentTypes.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int index) throws SQLException { final MarriageDocumentType marriageDocumentType = marriageDocumentTypes.get(index); ps.setString(1, marriageDocumentType.getName()); ps.setBoolean(2, marriageDocumentType.getIsActive()); ps.setBoolean(3, marriageDocumentType.getIsIndividual()); ps.setBoolean(4, marriageDocumentType.getIsRequired()); ps.setString(5, marriageDocumentType.getProof().toString()); ps.setString(6, marriageDocumentType.getApplicationType().toString()); ps.setLong(7, marriageDocumentType.getId()); ps.setString(8, marriageDocumentType.getCode()); ps.setString(9, marriageDocumentType.getTenantId()); } @Override public int getBatchSize() { return marriageDocumentTypes.size(); } }); } }
MarriageDocumentTypeRepository { public void update(List<MarriageDocumentType> marriageDocumentTypes) { log.debug("MarriageDocumentTypes: " + marriageDocumentTypes); final String sql = MarriageDocumentTypeQueryBuilder.BATCH_UPDATE_QUERY; final String tenantId = marriageDocumentTypes.get(0).getTenantId(); final int batchSize = Integer.parseInt(serviceConfigurationService .getServiceConfigValueByKeyAndTenantId(ServiceConfigurationKeys.MARRIAGEBATCHSIZE, tenantId) .toString()); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < marriageDocumentTypes.size(); j += batchSize) { final List<MarriageDocumentType> batchList = marriageDocumentTypes.subList(j, j + batchSize > marriageDocumentTypes.size() ? marriageDocumentTypes.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int index) throws SQLException { final MarriageDocumentType marriageDocumentType = marriageDocumentTypes.get(index); ps.setString(1, marriageDocumentType.getName()); ps.setBoolean(2, marriageDocumentType.getIsActive()); ps.setBoolean(3, marriageDocumentType.getIsIndividual()); ps.setBoolean(4, marriageDocumentType.getIsRequired()); ps.setString(5, marriageDocumentType.getProof().toString()); ps.setString(6, marriageDocumentType.getApplicationType().toString()); ps.setLong(7, marriageDocumentType.getId()); ps.setString(8, marriageDocumentType.getCode()); ps.setString(9, marriageDocumentType.getTenantId()); } @Override public int getBatchSize() { return marriageDocumentTypes.size(); } }); } } }
MarriageDocumentTypeRepository { public void update(List<MarriageDocumentType> marriageDocumentTypes) { log.debug("MarriageDocumentTypes: " + marriageDocumentTypes); final String sql = MarriageDocumentTypeQueryBuilder.BATCH_UPDATE_QUERY; final String tenantId = marriageDocumentTypes.get(0).getTenantId(); final int batchSize = Integer.parseInt(serviceConfigurationService .getServiceConfigValueByKeyAndTenantId(ServiceConfigurationKeys.MARRIAGEBATCHSIZE, tenantId) .toString()); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < marriageDocumentTypes.size(); j += batchSize) { final List<MarriageDocumentType> batchList = marriageDocumentTypes.subList(j, j + batchSize > marriageDocumentTypes.size() ? marriageDocumentTypes.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int index) throws SQLException { final MarriageDocumentType marriageDocumentType = marriageDocumentTypes.get(index); ps.setString(1, marriageDocumentType.getName()); ps.setBoolean(2, marriageDocumentType.getIsActive()); ps.setBoolean(3, marriageDocumentType.getIsIndividual()); ps.setBoolean(4, marriageDocumentType.getIsRequired()); ps.setString(5, marriageDocumentType.getProof().toString()); ps.setString(6, marriageDocumentType.getApplicationType().toString()); ps.setLong(7, marriageDocumentType.getId()); ps.setString(8, marriageDocumentType.getCode()); ps.setString(9, marriageDocumentType.getTenantId()); } @Override public int getBatchSize() { return marriageDocumentTypes.size(); } }); } }  }
MarriageDocumentTypeRepository { public void update(List<MarriageDocumentType> marriageDocumentTypes) { log.debug("MarriageDocumentTypes: " + marriageDocumentTypes); final String sql = MarriageDocumentTypeQueryBuilder.BATCH_UPDATE_QUERY; final String tenantId = marriageDocumentTypes.get(0).getTenantId(); final int batchSize = Integer.parseInt(serviceConfigurationService .getServiceConfigValueByKeyAndTenantId(ServiceConfigurationKeys.MARRIAGEBATCHSIZE, tenantId) .toString()); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < marriageDocumentTypes.size(); j += batchSize) { final List<MarriageDocumentType> batchList = marriageDocumentTypes.subList(j, j + batchSize > marriageDocumentTypes.size() ? marriageDocumentTypes.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int index) throws SQLException { final MarriageDocumentType marriageDocumentType = marriageDocumentTypes.get(index); ps.setString(1, marriageDocumentType.getName()); ps.setBoolean(2, marriageDocumentType.getIsActive()); ps.setBoolean(3, marriageDocumentType.getIsIndividual()); ps.setBoolean(4, marriageDocumentType.getIsRequired()); ps.setString(5, marriageDocumentType.getProof().toString()); ps.setString(6, marriageDocumentType.getApplicationType().toString()); ps.setLong(7, marriageDocumentType.getId()); ps.setString(8, marriageDocumentType.getCode()); ps.setString(9, marriageDocumentType.getTenantId()); } @Override public int getBatchSize() { return marriageDocumentTypes.size(); } }); } }  List<MarriageDocumentType> search(MarriageDocumentTypeSearchCriteria marriageDocumentTypeSearchCriteria); void create(List<MarriageDocumentType> marriageDocumentTypes); void update(List<MarriageDocumentType> marriageDocumentTypes); List<Long> getIds(List<MarriageDocumentType> marriageDocumentTypeList); }
MarriageDocumentTypeRepository { public void update(List<MarriageDocumentType> marriageDocumentTypes) { log.debug("MarriageDocumentTypes: " + marriageDocumentTypes); final String sql = MarriageDocumentTypeQueryBuilder.BATCH_UPDATE_QUERY; final String tenantId = marriageDocumentTypes.get(0).getTenantId(); final int batchSize = Integer.parseInt(serviceConfigurationService .getServiceConfigValueByKeyAndTenantId(ServiceConfigurationKeys.MARRIAGEBATCHSIZE, tenantId) .toString()); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < marriageDocumentTypes.size(); j += batchSize) { final List<MarriageDocumentType> batchList = marriageDocumentTypes.subList(j, j + batchSize > marriageDocumentTypes.size() ? marriageDocumentTypes.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int index) throws SQLException { final MarriageDocumentType marriageDocumentType = marriageDocumentTypes.get(index); ps.setString(1, marriageDocumentType.getName()); ps.setBoolean(2, marriageDocumentType.getIsActive()); ps.setBoolean(3, marriageDocumentType.getIsIndividual()); ps.setBoolean(4, marriageDocumentType.getIsRequired()); ps.setString(5, marriageDocumentType.getProof().toString()); ps.setString(6, marriageDocumentType.getApplicationType().toString()); ps.setLong(7, marriageDocumentType.getId()); ps.setString(8, marriageDocumentType.getCode()); ps.setString(9, marriageDocumentType.getTenantId()); } @Override public int getBatchSize() { return marriageDocumentTypes.size(); } }); } }  List<MarriageDocumentType> search(MarriageDocumentTypeSearchCriteria marriageDocumentTypeSearchCriteria); void create(List<MarriageDocumentType> marriageDocumentTypes); void update(List<MarriageDocumentType> marriageDocumentTypes); List<Long> getIds(List<MarriageDocumentType> marriageDocumentTypeList);  }