@Override public void save(String graphName, String version, List<IDefaultSegmentXInfo> xInfoList) throws GraphNotExistsException { if (xInfoList != null) { preProcessList(graphName, version, xInfoList); getJdbcTemplate().batchUpdate("INSERT INTO " + schema + TABLENAME + " (segment_id, direction_tow, graphversion_id, tags) VALUES (?,?,?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, xInfoList.get(i).getSegmentId()); if (xInfoList.get(i).isDirectionTow() != null) { ps.setBoolean(2, xInfoList.get(i).isDirectionTow()); } else { ps.setNull(2, Types.BOOLEAN); } ps.setLong(3, xInfoList.get(i).getGraphVersionId()); ps.setObject(4, xInfoList.get(i).getValues()); } @Override public int getBatchSize() { return xInfoList.size(); } }); } }
@Override public void update(String graphName, String version, List<IDefaultSegmentXInfo> xInfoList) throws GraphNotExistsException { if (xInfoList != null) { preProcessList(graphName, version, xInfoList); getJdbcTemplate().batchUpdate("UPDATE " + schema + TABLENAME + " SET tags=? WHERE segment_id=? AND direction_tow=? AND graphversion_id=?", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setObject(1, xInfoList.get(i).getValues()); ps.setLong(2, xInfoList.get(i).getSegmentId()); ps.setBoolean(3, xInfoList.get(i).isDirectionTow()); ps.setLong(4, xInfoList.get(i).getGraphVersionId()); } @Override public int getBatchSize() { return xInfoList.size(); } }); } }
public void swapIdUsingDataFromFile(String idsFile) throws IOException { System.out.println("\nReading ids\n"); final List<Ids> ids = parseFileForId(idsFile); String sql = "UPDATE kaltura_item SET kalturaId = ? where kalturaId = ?"; System.out.println("Begining database update\n"); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return ids.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Ids id = ids.get(index); ps.setString(1, id.getNewId()); ps.setString(2, id.getOldId()); } }); System.out.println("Update complete\n"); }
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) { if (batchArgs.length <= 0) { return new int[] {0}; } String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]); return jdbcOperations.batchUpdate( sqlToUse, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]); setStatementParameters(values, ps, columnTypes); } @Override public int getBatchSize() { return batchArgs.length; } }); }
/** * Method to execute the batch insert. */ private int[] executeBatchInternal(final List<Object>[] batchValues) { if (logger.isDebugEnabled()) { logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.length); } return getJdbcTemplate().batchUpdate(getInsertString(), new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { List<Object> values = batchValues[i]; setParameterValues(ps, values, getInsertTypes()); } @Override public int getBatchSize() { return batchValues.length; } }); }
/** * Creates a new row in acl_entry for every ACE defined in the passed MutableAcl object. * * @param acl containing the ACEs to insert */ protected void createEntries(final MutableAcl acl) { if (acl.getEntries().isEmpty()) { return; } jdbcTemplate.batchUpdate(insertEntry, new BatchPreparedStatementSetter() { public int getBatchSize() { return acl.getEntries().size(); } public void setValues(PreparedStatement stmt, int i) throws SQLException { AccessControlEntry entry_ = acl.getEntries().get(i); Assert.isTrue(entry_ instanceof AccessControlEntryImpl, "Unknown ACE class"); AccessControlEntryImpl entry = (AccessControlEntryImpl) entry_; stmt.setLong(1, ((Long) acl.getId()).longValue()); stmt.setInt(2, i); stmt.setLong(3, createOrRetrieveSidPrimaryKey(entry.getSid(), true).longValue()); stmt.setInt(4, entry.getPermission().getMask()); stmt.setBoolean(5, entry.isGranting()); stmt.setBoolean(6, entry.isAuditSuccess()); stmt.setBoolean(7, entry.isAuditFailure()); } }); }
public void updateZonePalstaList(final long zoneId, final int[] boundaryIds) { final String insertSql = "INSERT INTO zone_palsta (zone_id, palsta_id, geom, palsta_tunnus)" + " SELECT ?, pa.id, pa.geom, pa.tunnus FROM palstaalue pa WHERE pa.id = ?"; jdbcOperations.batchUpdate(insertSql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { final Integer palstaId = boundaryIds[i]; ps.setLong(1, zoneId); ps.setInt(2, palstaId); } @Override public int getBatchSize() { return boundaryIds.length; } }); }
public void removeZonePalsta(final long zoneId, final int[] toRemoveArray) { final String deleteSql = "DELETE FROM zone_palsta WHERE zone_id = ? AND palsta_id = ?"; jdbcOperations.batchUpdate(deleteSql, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { ps.setLong(1, zoneId); ps.setInt(2, toRemoveArray[i]); } @Override public int getBatchSize() { return toRemoveArray.length; } }); }
/** * Delegate method to execute the batch insert. */ private int[] executeBatchInternal(final List<List<Object>> batchValues) { if (logger.isDebugEnabled()) { logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.size()); } return getJdbcTemplate().batchUpdate(getInsertString(), new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { setParameterValues(ps, batchValues.get(i), getInsertTypes()); } @Override public int getBatchSize() { return batchValues.size(); } }); }
@Override public void batchSave(final List<CangoTable> cangoTables) { if (cangoTables != null && cangoTables.size() > 0) { String insertSql = "insert into cango_table instances_name, table_name, create_time values(?, ?, ?)"; final Date current = getCurrentTime(); jdbcTemplate.batchUpdate(insertSql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { CangoTable cangoTable = cangoTables.get(i); ps.setString(1, cangoTable.getInstancesName()); ps.setString(2, cangoTable.getTableName()); ps.setDate(3, current); } @Override public int getBatchSize() { return cangoTables.size(); } }); } }
public void save(List<DbSellingOrder> orders) { for (int i = 0; i < orders.size(); i += INSERT_BATCH_SIZE) { final List<DbSellingOrder> batchList = orders.subList(i, i + INSERT_BATCH_SIZE > orders.size() ? orders.size() : i + INSERT_BATCH_SIZE); jdbcTpl.batchUpdate(SQL_insert, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int j) throws SQLException { DbSellingOrder o = batchList.get(j); ps.setString(1, o.getProductId()); ps.setLong(2, o.getCustomerId()); ps.setDate(3, new Date(o.getOrderDate().getTime())); ps.setInt(4, o.getQuantity()); ps.setLong(5, o.getRevenue()); ps.setFloat(6, o.getDiscount()); } @Override public int getBatchSize() { return batchList.size(); } }); } }
public void save(List<DbUser> users) { for (int i = 0; i < users.size(); i += INSERT_BATCH_SIZE) { final List<DbUser> batchList = users.subList(i, i + INSERT_BATCH_SIZE > users.size() ? users.size() : i + INSERT_BATCH_SIZE); jdbcTpl.batchUpdate(SQL_insert, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int j) throws SQLException { DbUser u = batchList.get(j); ps.setString(1, u.getName()); ps.setString(2, u.getEmail()); ps.setInt(3, u.getAge()); ps.setInt(4, u.getGender()); ps.setString(5, u.getLocation()); ps.setTimestamp(6, new Timestamp(u.getCreationDate().getTime())); ps.setTimestamp(7, new Timestamp(u.getModification().getTime())); } @Override public int getBatchSize() { return batchList.size(); } }); } }
/** * Exemple d'utilisation d'un BatchPreparedStatementSetter * * Cette m�thode permet de mettre � jour en masse une liste de users */ public int[] updateUsers(final User... usersToUpdate) { BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { User user = usersToUpdate[i]; ps.setString(1, user.getName()); ps.setString(2, user.getMail()); ps.setInt(3, user.getId()); } /** * Le batchsize est �gal au nombre d'�l�ment � traiter. * S'il est sup�rieur -> ArrayIndexOutOfBoundException * S'il est inf�rieur au nombre d'�l�ments � traiter, seuls les n premiers seront trait�s * * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#getBatchSize() */ @Override public int getBatchSize() { return usersToUpdate.length; } }; return jdbcTemplate.batchUpdate("update users set name = ?, email = ? where id = ?", bpss); }
/** * Exemple d'utilisation d'un BatchPreparedStatementSetter avec taille variable * * Cette m�thode permet de mettre � jour en masse une liste de users * Seuls les <batchSize> premiers �l�ments seront trait�s * Si <batchSize> est sup�rieur au nombre d'�l�ments � traiter, on aura une erreur */ public int[] updateUsersWithBatchSize(final int batchSize, final User... usersToUpdate) { BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { User user = usersToUpdate[i]; ps.setString(1, user.getName()); ps.setString(2, user.getMail()); ps.setInt(3, user.getId()); } @Override public int getBatchSize() { return batchSize; } }; return jdbcTemplate.batchUpdate("update users set name = ?, email = ? where id = ?", bpss); }
@Override public <T> int[] batchDelete(Class<T> clazz, List<Serializable> ids) { //XXX: thinking 共享第一实体的sql TableMapper<T> tableMapper = DbMappingBuilder.ME.getTableMapper(clazz); String sql = tableMapper.getDeleteSqlWithId().toString(); final List<Serializable> tempids = ids; final int batchSize = ids.size(); int[] rows = jdbcTemplate.batchUpdate(sql,new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setObject(1, tempids.get(i)); } @Override public int getBatchSize() { return batchSize; } }); return rows; }
@Override public <T> int[] batchDelete(Class<T> clazz, Serializable[] ids) { TableMapper<T> tableMapper = DbMappingBuilder.ME.getTableMapper(clazz); String sql = tableMapper.getDeleteSqlWithId().toString(); final Serializable[] tempids = ids; final int batchSize = ids.length; int[] rows = jdbcTemplate.batchUpdate(sql,new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setObject(1, tempids[i]); } @Override public int getBatchSize() { return batchSize; } }); return rows; }
@Override public void insertBatch(final List<Product> products) { getJdbcTemplate().batchUpdate(SQL_INSERT, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Product product = products.get(i); ps.setByte(1, product.getFtiny()); ps.setShort(2, product.getFsmall()); ps.setLong(3, product.getFbig()); ps.setDouble(4, product.getFdouble()); ps.setTimestamp(5, product.getFdate()); ps.setInt(6, product.getFyear()); ps.setString(7, product.getFchar()); ps.setString(8, product.getFvchar()); ps.setBigDecimal(9, product.getFdec()); } @Override public int getBatchSize() { return products.size(); } }); }
@Override public void insertBatch(final List<Order> orders) { getJdbcTemplate().batchUpdate(SQL_INSERT, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Order order = orders.get(i); ps.setByte(1, order.getFtiny()); ps.setShort(2, order.getFsmall()); ps.setLong(3, order.getFbig()); ps.setDouble(4, order.getFdouble()); ps.setTimestamp(5, order.getFdate()); ps.setInt(6, order.getFyear()); ps.setString(7, order.getFchar()); ps.setString(8, order.getFvchar()); ps.setBigDecimal(9, order.getFdec()); } @Override public int getBatchSize() { return orders.size(); } }); }
@Override public void insertBatch(final List<User> users) { getJdbcTemplate().batchUpdate(SQL_INSERT, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { User user = users.get(i); ps.setByte(1, user.getFtiny()); ps.setShort(2, user.getFsmall()); ps.setLong(3, user.getFbig()); ps.setDouble(4, user.getFdouble()); ps.setTimestamp(5, user.getFdate()); ps.setInt(6, user.getFyear()); ps.setString(7, user.getFchar()); ps.setString(8, user.getFvchar()); ps.setBigDecimal(9, user.getFdec()); } @Override public int getBatchSize() { return users.size(); } }); }
public void removeSearch(final String loginname, final int... searchIds) { JdbcTemplate jdbcTemplate = JdbcFactory.getTemplate(DbInstance.operation); String updateSql = "delete from queryhistory where loginname = ? and queryid = ?"; jdbcTemplate.batchUpdate(updateSql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setString(1, loginname); ps.setInt(2, searchIds[i]); } public int getBatchSize() { return searchIds.length; } }); }
@Override public void saveProjectUserPrivilege(final String projectId, final List<String> users, final String teamName) { jdbcTemplate.batchUpdate(INSERT_INTO_AUTHORISE_PROJECT, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { String empId = users.get(i); ps.setString(1, projectId); ps.setString(2, empId); ps.setString(3, teamName); } @Override public int getBatchSize() { return users.size(); } }); }
@Override public void deleteProjectUserPrivilege(final String projectId, final List<String> users, final String teamName) { jdbcTemplate.batchUpdate(DELETE_AUTHORIZE_PROJECT, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { String empId = users.get(i); ps.setString(1, teamName); ps.setString(2, empId); ps.setString(3, projectId); } @Override public int getBatchSize() { return users.size(); } }); }
public void saveSubProjectDescriptionDetails( final List < ProjDescDetail > projDescDetails) { jdbcTemplate.batchUpdate(INSERTSUBPROJECTDESCRIPTION, new BatchPreparedStatementSetter() {@Override public void setValues(PreparedStatement ps, int i) throws SQLException { ProjDescDetail projDescDetail = projDescDetails.get(i); ps.setInt(1, projDescDetail.getProjId()); ps.setInt(2, projDescDetail.getSubProjId()); ps.setString(3, projDescDetail.getSerialNumber()); ps.setString(4, projDescDetail.getWorkType()); ps.setString(5, projDescDetail.getQuantity()); ps.setString(6, projDescDetail.getMetric()); ps.setString(7, projDescDetail.getDescription()); ps.setString(8, projDescDetail.getAliasDescription()); ps.setString(9, projDescDetail.getLastUpdatedBy()); ps.setDate(10, new java.sql.Date(Calendar.getInstance().getTimeInMillis())); } @Override public int getBatchSize() { return projDescDetails.size(); } }); }
public void updateProjectDescriptions(final List<ProjDescDetail> projDescDetails,String descriptionType) { LOGGER.info("batch updating projectDescriptions with new priceperQuantity and totalCost"); String UPDATE_PRICE_COST_DESCRIPTIONS = "update "+DescriptionType.getDescriptionTableName(descriptionType)+" set PricePerQuantity = ? , TotalCost = ? where ProjDescId = ?"; try{ jdbcTemplate.batchUpdate(UPDATE_PRICE_COST_DESCRIPTIONS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ProjDescDetail projDescDetail = projDescDetails.get(i); ps.setString(1, projDescDetail.getPricePerQuantity()); ps.setString(2, projDescDetail.getTotalCost()); ps.setInt(3, projDescDetail.getProjDescId()); } @Override public int getBatchSize() { return projDescDetails.size(); } }); }catch (Exception e){ LOGGER.error("Error got occurred"+e); } }
@Override public void saveDispatchedDetails(final DispatchDetail dispatchDetail, final String dispatched) { jdbcTemplate.batchUpdate(CREATE_TRANSACTION_DETAILS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { DispatchDetail.DispatchItems dispatchItem = dispatchDetail .getDispatchItems().get(i); ps.setInt(1, dispatchDetail.getProjId()); ps.setString(2, dispatchItem.getItemName()); ps.setDate(3, dispatchDetail.getSqlDispatchedDate()); ps.setString(4, dispatchDetail.getFieldUser()); ps.setString(5, dispatched); ps.setString(6, dispatchItem.getRequestedQuantity()); } @Override public int getBatchSize() { return dispatchDetail.getDispatchItems().size(); } }); }
@Override public void saveReturnedDetails(final DispatchDetail dispatchDetail, final String returned) { jdbcTemplate.batchUpdate(CREATE_TRANSACTION_DETAILS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { DispatchDetail.DispatchItems returnItem = dispatchDetail .getDispatchItems().get(i); ps.setInt(1, dispatchDetail.getProjId()); ps.setString(2, returnItem.getItemName()); ps.setDate(3, dispatchDetail.getSqlReturnedDate()); ps.setString(4, dispatchDetail.getFieldUser()); ps.setString(5, returned); ps.setString(6, returnItem.getReturnedQuantity()); } @Override public int getBatchSize() { return dispatchDetail.getDispatchItems().size(); } }); }
@Override public void saveSupplierQuoteDetails(final QuoteDetails quoteDetails, final String status) { jdbcTemplate.batchUpdate(CREATE_QUOTE_DETAILS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { SupplierQuoteDetails supplierQuoteDetails = quoteDetails.getSupplierQuoteDetails().get(i); ps.setString(1, quoteDetails.getProjName()); ps.setString(2, quoteDetails.getItemName()); ps.setString(3, quoteDetails.getItemQty()); ps.setString(4, quoteDetails.getItemType()); ps.setString(5, supplierQuoteDetails.getSupplierAliasName()); ps.setString(6, supplierQuoteDetails.getEmailAddress()); ps.setString(7, supplierQuoteDetails.getPhoneNumber()); ps.setString(8, supplierQuoteDetails.getQuotedPrice()); ps.setString(9, supplierQuoteDetails.getTotalPrice()); ps.setString(10, status); ps.setString(11, supplierQuoteDetails.getBrandName()); } @Override public int getBatchSize() { return quoteDetails.getSupplierQuoteDetails().size(); } }); }
void insertIndentDescItem(final Integer indentDescId, final List<IndentDesc.ItemDetail> itemDetailList) { String indentDescItemSql = "INSERT INTO IndentDescItem (IndentDescId, ItemName, ItemType, ItemQty, ItemUnit)" + "VALUES (?, ?, ?, ?, ?)"; jdbcTemplate.batchUpdate(indentDescItemSql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ItemDetail itemDetail = itemDetailList.get(i); ps.setString(1, indentDescId.toString()); ps.setString(2, itemDetail.getItemName()); ps.setString(3, itemDetail.getItemType()); ps.setString(4, itemDetail.getItemQty()); ps.setString(5, itemDetail.getItemUnit()); } @Override public int getBatchSize() { return itemDetailList.size(); } }); }
void updateIndentDescItem(final Integer indentDescId, final List<IndentDesc.ItemDetail> itemDetailList) { jdbcTemplate.update("DELETE FROM IndentDescItem WHERE IndentDescId = ?", indentDescId); String indentDescItemSql = "INSERT INTO IndentDescItem (IndentDescId, ItemName, ItemType, ItemQty, ItemUnit)" + "VALUES (?, ?, ?, ?, ?)"; jdbcTemplate.batchUpdate(indentDescItemSql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ItemDetail itemDetail = itemDetailList.get(i); ps.setString(1, indentDescId.toString()); ps.setString(2, itemDetail.getItemName()); ps.setString(3, itemDetail.getItemType()); ps.setString(4, itemDetail.getItemQty()); ps.setString(5, itemDetail.getItemUnit()); } @Override public int getBatchSize() { return itemDetailList.size(); } }); }
@Override public boolean configureItemPrice(final ProjectConfiguration projectItemConfiguration) { deactivateExistingPrices(projectItemConfiguration); jdbcTemplate.batchUpdate(INSERTPRICEFORITEMS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ProjectConfiguration.ItemDetail itemDetail = projectItemConfiguration.getItemDetail().get(i); ps.setInt(1, projectItemConfiguration.getProjId()); ps.setInt(2, projectItemConfiguration.getSubProjId()); ps.setString(3, itemDetail.getItemName()); ps.setString(4, itemDetail.getItemUnit()); ps.setString(5, itemDetail.getItemPrice()); ps.setString(6, itemDetail.getItemType()); ps.setDate(7, new java.sql.Date(Calendar.getInstance().getTimeInMillis())); } @Override public int getBatchSize() { return projectItemConfiguration.getItemDetail().size(); } }); return true; }
@Override @Transactional public void saveItemRateDescriptions(final List<ItemRateDescription> itemRateDescriptions) { jdbcTemplate.batchUpdate(PmsMasterQuery.INSERT_ITEM_RATE_DESCRIPTION, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ItemRateDescription itemRateDescription = itemRateDescriptions.get(i); ps.setString(1, itemRateDescription.getItemName()); ps.setString(2, itemRateDescription.getItemUnit()); ps.setString(3, itemRateDescription.getWorkType()); ps.setString(4, itemRateDescription.getItemRate()); ps.setDate(5, new java.sql.Date(Calendar.getInstance().getTimeInMillis())); ps.setString(6, itemRateDescription.getScheduleItemNumber()); ps.setString(7, itemRateDescription.getItemDescription()); } @Override public int getBatchSize() { return itemRateDescriptions.size(); } }); }
public void updatePriceAndCostOfProjectDescItems(final List<ItemDetailDto> itemDetailDtos, String descriptionType) { LOGGER.info("Batch updating projectDescriptionItems into database."); String UPDATE_PRICE_COST_DESC_ITEMS = "update " + DescriptionType.getDescriptionItemTableName(descriptionType) + " set ItemPrice = ? ,ItemCost = ? where DescItemId = ?"; jdbcTemplate.batchUpdate(UPDATE_PRICE_COST_DESC_ITEMS, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ItemDetailDto itemDetailDto = itemDetailDtos.get(i); ps.setString(1, itemDetailDto.getItemPrice().toString()); ps.setString(2, itemDetailDto.getItemCost().toString()); ps.setInt(3, itemDetailDto.getProjectDescItemId()); } @Override public int getBatchSize() { return itemDetailDtos.size(); } }); }
@Test public void saveNewWithAttributes() { JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); session.setAttribute("testName", "testValue"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("INSERT"), isA(PreparedStatementSetter.class)); verify(this.jdbcOperations, times(1)).batchUpdate( and(startsWith("INSERT"), contains("ATTRIBUTE_BYTES")), isA(BatchPreparedStatementSetter.class)); }
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) { if (batchArgs.length <= 0) { return new int[] {0}; } String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]); return jdbcOperations.batchUpdate( sqlToUse, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]); setStatementParameters(values, ps, columnTypes); } public int getBatchSize() { return batchArgs.length; } }); }
/** * Method to execute the batch insert. */ private int[] executeBatchInternal(final List<Object>[] batchValues) { if (logger.isDebugEnabled()) { logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.length); } return getJdbcTemplate().batchUpdate(getInsertString(), new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { List<Object> values = batchValues[i]; setParameterValues(ps, values, getInsertTypes()); } public int getBatchSize() { return batchValues.length; } }); }
/** * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#updateAssetPayments(java.util.List, java.lang.Integer) */ @Override public void updateAssetPayments(final List<AssetPaymentInfo> assetPayments, final Integer fiscalMonth) { if ( LOG.isInfoEnabled() ) { LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Batch updating [" + assetPayments.size() + "] payments"); } getJdbcTemplate().batchUpdate("UPDATE CM_AST_PAYMENT_T SET AST_ACUM_DEPR1_AMT=? , AST_PRD" + fiscalMonth + (fiscalMonth < 10 ? "_" : "") + "DEPR1_AMT = ? WHERE CPTLAST_NBR = ? AND AST_PMT_SEQ_NBR = ? ", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return assetPayments.size(); } @Override public void setValues(PreparedStatement pstmt, int index) throws SQLException { pstmt.setBigDecimal(1, assetPayments.get(index).getAccumulatedPrimaryDepreciationAmount().bigDecimalValue()); pstmt.setBigDecimal(2, assetPayments.get(index).getTransactionAmount().bigDecimalValue()); pstmt.setLong(3, assetPayments.get(index).getCapitalAssetNumber()); pstmt.setInt(4, assetPayments.get(index).getPaymentSequenceNumber()); } }); }
@Override public void insertExecutionStates(final List<ExecutionMessage> stateMessages) { String insertExecStateSQL = INSERT_EXEC_STATE; insertExecutionJDBCTemplate.batchUpdate(insertExecStateSQL, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ExecutionMessage msg = stateMessages.get(i); ps.setLong(1, msg.getExecStateId()); ps.setString(2, msg.getMsgId()); ps.setBytes(3, msg.getPayload().getData()); } @Override public int getBatchSize() { return stateMessages.size(); } }); }
/** * 保存消息-设备列表 * * @param messageDevices * @return */ public int[] saveOrUpdateMessageDeviceList(final List<MessageDevice> messageDevices) { if (messageDevices == null || messageDevices.size() <= 0) { return null; } BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { public int getBatchSize() { return messageDevices.size(); } public void setValues(PreparedStatement ps, int i) { MessageDevice messageDevice = messageDevices.get(i); if (messageDevice != null) { try { ps.setLong(1, messageDevice.getMsgId()); ps.setString(2, messageDevice.getDeviceId()); } catch (Exception e) { e.printStackTrace(); } } } }; return getJdbcTemplate().batchUpdate(MESSAGEDEVICE_SQL, setter); }