@Test public void test_create() { when(assetConfigurationService.getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, "ap.kurnool")).thenReturn("500"); currentValueRepository.create(getAssetCurrentValues()); }
public void create(final List<AssetCurrentValue> assetCurrentValues) { final String sql = currentValueQueryBuilder.getInsertQuery(); final String tenantId = assetCurrentValues.get(0).getTenantId(); final int batchSize = Integer.parseInt(assetConfigurationService .getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, tenantId)); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < assetCurrentValues.size(); j += batchSize) { final List<AssetCurrentValue> batchList = assetCurrentValues.subList(j, j + batchSize > assetCurrentValues.size() ? assetCurrentValues.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int rowNum) throws SQLException { final AssetCurrentValue assetCurrentValue = assetCurrentValues.get(rowNum); final AuditDetails auditDetails = assetCurrentValue.getAuditDetails(); ps.setLong(1, assetCurrentValue.getId()); ps.setLong(2, assetCurrentValue.getAssetId()); ps.setString(3, assetCurrentValue.getTenantId()); ps.setString(4, assetCurrentValue.getAssetTranType().toString()); ps.setBigDecimal(5, assetCurrentValue.getCurrentAmount()); ps.setString(6, auditDetails.getCreatedBy()); ps.setLong(7, auditDetails.getCreatedDate()); ps.setString(8, auditDetails.getLastModifiedBy()); ps.setLong(9, auditDetails.getLastModifiedDate()); } @Override public int getBatchSize() { return batchList.size(); } }); } }
CurrentValueRepository { public void create(final List<AssetCurrentValue> assetCurrentValues) { final String sql = currentValueQueryBuilder.getInsertQuery(); final String tenantId = assetCurrentValues.get(0).getTenantId(); final int batchSize = Integer.parseInt(assetConfigurationService .getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, tenantId)); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < assetCurrentValues.size(); j += batchSize) { final List<AssetCurrentValue> batchList = assetCurrentValues.subList(j, j + batchSize > assetCurrentValues.size() ? assetCurrentValues.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int rowNum) throws SQLException { final AssetCurrentValue assetCurrentValue = assetCurrentValues.get(rowNum); final AuditDetails auditDetails = assetCurrentValue.getAuditDetails(); ps.setLong(1, assetCurrentValue.getId()); ps.setLong(2, assetCurrentValue.getAssetId()); ps.setString(3, assetCurrentValue.getTenantId()); ps.setString(4, assetCurrentValue.getAssetTranType().toString()); ps.setBigDecimal(5, assetCurrentValue.getCurrentAmount()); ps.setString(6, auditDetails.getCreatedBy()); ps.setLong(7, auditDetails.getCreatedDate()); ps.setString(8, auditDetails.getLastModifiedBy()); ps.setLong(9, auditDetails.getLastModifiedDate()); } @Override public int getBatchSize() { return batchList.size(); } }); } } }
CurrentValueRepository { public void create(final List<AssetCurrentValue> assetCurrentValues) { final String sql = currentValueQueryBuilder.getInsertQuery(); final String tenantId = assetCurrentValues.get(0).getTenantId(); final int batchSize = Integer.parseInt(assetConfigurationService .getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, tenantId)); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < assetCurrentValues.size(); j += batchSize) { final List<AssetCurrentValue> batchList = assetCurrentValues.subList(j, j + batchSize > assetCurrentValues.size() ? assetCurrentValues.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int rowNum) throws SQLException { final AssetCurrentValue assetCurrentValue = assetCurrentValues.get(rowNum); final AuditDetails auditDetails = assetCurrentValue.getAuditDetails(); ps.setLong(1, assetCurrentValue.getId()); ps.setLong(2, assetCurrentValue.getAssetId()); ps.setString(3, assetCurrentValue.getTenantId()); ps.setString(4, assetCurrentValue.getAssetTranType().toString()); ps.setBigDecimal(5, assetCurrentValue.getCurrentAmount()); ps.setString(6, auditDetails.getCreatedBy()); ps.setLong(7, auditDetails.getCreatedDate()); ps.setString(8, auditDetails.getLastModifiedBy()); ps.setLong(9, auditDetails.getLastModifiedDate()); } @Override public int getBatchSize() { return batchList.size(); } }); } }  }
CurrentValueRepository { public void create(final List<AssetCurrentValue> assetCurrentValues) { final String sql = currentValueQueryBuilder.getInsertQuery(); final String tenantId = assetCurrentValues.get(0).getTenantId(); final int batchSize = Integer.parseInt(assetConfigurationService .getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, tenantId)); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < assetCurrentValues.size(); j += batchSize) { final List<AssetCurrentValue> batchList = assetCurrentValues.subList(j, j + batchSize > assetCurrentValues.size() ? assetCurrentValues.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int rowNum) throws SQLException { final AssetCurrentValue assetCurrentValue = assetCurrentValues.get(rowNum); final AuditDetails auditDetails = assetCurrentValue.getAuditDetails(); ps.setLong(1, assetCurrentValue.getId()); ps.setLong(2, assetCurrentValue.getAssetId()); ps.setString(3, assetCurrentValue.getTenantId()); ps.setString(4, assetCurrentValue.getAssetTranType().toString()); ps.setBigDecimal(5, assetCurrentValue.getCurrentAmount()); ps.setString(6, auditDetails.getCreatedBy()); ps.setLong(7, auditDetails.getCreatedDate()); ps.setString(8, auditDetails.getLastModifiedBy()); ps.setLong(9, auditDetails.getLastModifiedDate()); } @Override public int getBatchSize() { return batchList.size(); } }); } }  List<AssetCurrentValue> getCurrentValues(final Set<Long> assetIds, final String tenantId); void create(final List<AssetCurrentValue> assetCurrentValues); void update(final List<AssetCurrentValue> assetCurrentValues); }
CurrentValueRepository { public void create(final List<AssetCurrentValue> assetCurrentValues) { final String sql = currentValueQueryBuilder.getInsertQuery(); final String tenantId = assetCurrentValues.get(0).getTenantId(); final int batchSize = Integer.parseInt(assetConfigurationService .getAssetConfigValueByKeyAndTenantId(AssetConfigurationKeys.ASSETBATCHSIZE, tenantId)); log.debug("Batch Size :: " + batchSize); for (int j = 0; j < assetCurrentValues.size(); j += batchSize) { final List<AssetCurrentValue> batchList = assetCurrentValues.subList(j, j + batchSize > assetCurrentValues.size() ? assetCurrentValues.size() : j + batchSize); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int rowNum) throws SQLException { final AssetCurrentValue assetCurrentValue = assetCurrentValues.get(rowNum); final AuditDetails auditDetails = assetCurrentValue.getAuditDetails(); ps.setLong(1, assetCurrentValue.getId()); ps.setLong(2, assetCurrentValue.getAssetId()); ps.setString(3, assetCurrentValue.getTenantId()); ps.setString(4, assetCurrentValue.getAssetTranType().toString()); ps.setBigDecimal(5, assetCurrentValue.getCurrentAmount()); ps.setString(6, auditDetails.getCreatedBy()); ps.setLong(7, auditDetails.getCreatedDate()); ps.setString(8, auditDetails.getLastModifiedBy()); ps.setLong(9, auditDetails.getLastModifiedDate()); } @Override public int getBatchSize() { return batchList.size(); } }); } }  List<AssetCurrentValue> getCurrentValues(final Set<Long> assetIds, final String tenantId); void create(final List<AssetCurrentValue> assetCurrentValues); void update(final List<AssetCurrentValue> assetCurrentValues);  }