List of usage examples for org.springframework.jdbc.core BatchPreparedStatementSetter BatchPreparedStatementSetter
BatchPreparedStatementSetter
From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java
private void insertProperties(Page page) { if (page.getProperties() != null && !page.getProperties().isEmpty()) { Map<String, String> properties = page.getProperties(); final List<Map.Entry<String, String>> entryList = new ArrayList<Map.Entry<String, String>>( properties.entrySet());//from w w w. j a v a 2 s. c om final long pageId = page.getPageId(); final long pageVersionId = page.getVersionId(); getExtendedJdbcTemplate().batchUpdate( getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PAGE_PROPERTY").getSql(), new BatchPreparedStatementSetter() { public int getBatchSize() { return entryList.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Map.Entry<String, String> e = entryList.get(index); ps.setLong(1, pageId); ps.setLong(2, pageVersionId); ps.setString(3, e.getKey()); ps.setString(4, e.getValue()); } }); } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaIdentityDao.java
/** * Insert new identities in a single batch statement * //from w w w . j a va 2 s .c o m * @param newIdentityIndex * @param drops */ private void batchInsert(final Map<String, List<Integer>> newIdentityIndex, final List<Drop> drops, Sequence seq) { final List<String> hashes = new ArrayList<String>(); hashes.addAll(newIdentityIndex.keySet()); final long startKey = sequenceDao.getIds(seq, hashes.size()); String sql = "INSERT INTO identities (id, hash, channel, " + "identity_orig_id, identity_username, " + "identity_name, identity_avatar) " + "VALUES (?,?,?,?,?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { String hash = hashes.get(i); // Update drops with the newly generated id for (int index : newIdentityIndex.get(hash)) { drops.get(index).getIdentity().setId(startKey + i); } Drop drop = drops.get(newIdentityIndex.get(hash).get(0)); ps.setLong(1, drop.getIdentity().getId()); ps.setString(2, drop.getIdentity().getHash()); ps.setString(3, drop.getChannel()); ps.setString(4, drop.getIdentity().getOriginId()); ps.setString(5, drop.getIdentity().getUsername()); ps.setString(6, drop.getIdentity().getName()); ps.setString(7, drop.getIdentity().getAvatar()); } public int getBatchSize() { return hashes.size(); } }); }
From source file:com.sg.capstone.dao.BlogDaoDbImpl.java
private void insertBlogPostCategories(BlogPost blogPost) { final int blogPostId = blogPost.getBlogPostId(); final ArrayList<Integer> categoryIds = blogPost.getCategoryIds(); jdbcTemplate.batchUpdate(SQL_INSERT_BLOGPOST_CATEGORIES, new BatchPreparedStatementSetter() { @Override/*from ww w .j a v a2 s. co m*/ public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, blogPostId); ps.setInt(2, categoryIds.get(i)); } @Override public int getBatchSize() { return categoryIds.size(); } }); }
From source file:com.thesoftwareguild.flightmaster.daos.RequestDaoJdbcImpl.java
@Override @Transactional(propagation = Propagation.REQUIRED) public List<Flight> addFlights(int requestId, List<Flight> flights) { if (flights != null && flights.size() > 0) { Date timeOfQuery = flights.get(0).getQueryTime(); jdbcTemplate.update(SQL_ADD_REQUESTDATA_POINT, requestId, timeOfQuery); int requestDataId = jdbcTemplate.queryForObject(SQL_GET_LAST_ID, Integer.class); jdbcTemplate.batchUpdate(SQL_ADD_FLIGHT_DATA, new BatchPreparedStatementSetter() { @Override// w w w . ja va2 s . c om public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, requestDataId); ps.setDouble(2, flights.get(i).getPrice()); ps.setString(3, flights.get(i).getCarrier()); } @Override public int getBatchSize() { return flights.size(); } }); // Decrement queries_left to keep it consistant with in-memory representation jdbcTemplate.update(SQL_DECREMENT_QUERIESLEFT, requestId); // Get interval and set next execution time in database long interval = jdbcTemplate.queryForObject(SQL_GET_INTERVAL, Long.class, requestId); jdbcTemplate.update(SQL_UPDATE_NEXT_EXECUTION, (System.currentTimeMillis() + interval), requestId); } return flights; }
From source file:com.sinet.gage.dao.DomainsRepository.java
/** * /*from ww w . j a va2 s .c o m*/ * @param domains */ public void updateDomains(List<Domain> domains) { try { jdbcTemplate.batchUpdate(DOMAINS_FULL_UPDATE_SQL, new BatchPreparedStatementSetter() { public int getBatchSize() { if (domains == null) return 0; return domains.size(); } @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Domain domain = domains.get(i); ps.setObject(1, domain.getGuid()); ps.setString(2, domain.getDomainName()); ps.setString(3, domain.getLoginPrefix()); ps.setLong(4, domain.getFlag()); ps.setString(5, domain.getDomainType()); ps.setLong(6, domain.getParentDomainId()); ps.setString(7, domain.getParentDomainName()); ps.setLong(8, domain.getStateDomainId()); ps.setString(9, domain.getStateDomainName()); ps.setString(10, domain.getLicenseType()); ps.setString(11, domain.getLicensePoolType()); ps.setInt(12, domain.getNoOfLicense()); ps.setBoolean(13, domain.isPilot()); ps.setDate(14, domain.getPilotStartDate()); ps.setDate(15, domain.getPilotEndDate()); ps.setBoolean(16, domain.isFullSubscription()); ps.setObject(17, domain.getSubscriptionStartDate()); ps.setObject(18, domain.getSubscriptionEndDate()); ps.setLong(19, domain.getModifierUserId()); ps.setTimestamp(20, domain.getModifiedDate()); ps.setLong(21, domain.getDomainId()); } }); } catch (Exception e) { log.error("Error in updating Domains", e); } }
From source file:shell.framework.organization.agentcode.service.impl.TblSysAgentCodeService4JdbcImpl.java
public int assignUser(TblSysAgentCodeVO agentCodeVO) { String sql = "update TBL_SYS_USER set AGENTCODE_ID=? where ID=? "; final String agentCodeID = agentCodeVO.getSysAgentCode().getAgentCode(); String sysUserIds[] = agentCodeVO.getSysUser().getId().split("-"); final List<String> idList = new ArrayList<String>(); for (String id : sysUserIds) { idList.add(id);/* www .j av a2s.c om*/ } int[] deleteNumbers = jdbcBaseDao.batchUpdate(sql, idList, new BatchPreparedStatementSetter() { /* * (non-Javadoc) * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#setValues(java.sql.PreparedStatement, int) */ public void setValues(PreparedStatement ps, int index) throws SQLException { String sysUser_id = idList.get(index); ps.setString(1, agentCodeID); ps.setString(2, sysUser_id); } /* * (non-Javadoc) * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#getBatchSize() */ public int getBatchSize() { return idList.size(); } }); return deleteNumbers.length; }
From source file:org.brickhouse.impl.SqlTable.java
@Override public void batchInsert(List<HMap> rows) { jt.batchUpdate(insert, new BatchPreparedStatementSetter() { @Override//from w w w . j av a 2 s .co m public void setValues(PreparedStatement ps, int i) throws SQLException { HMap row = rows.get(i); HReference id = row.id(); if (id == null) throw new RuntimeException("id is required"); clean(row); ps.setString(1, id.getId()); ps.setString(2, row.disOrNull()); ps.setString(3, SqlTable.toString(row)); } @Override public int getBatchSize() { return rows.size(); } }); for (TableListener l : listeners) l.batchInsert(rows); }
From source file:shell.framework.organization.department.service.impl.TblSysDepartmentServiceI4JdbcImpl.java
public int deleteByID(TblSysDepartmentVO departmentVO) { String sql = "delete from TBL_SYS_DEPARTMENT where ID = ?"; final List<String> idList = new ArrayList<String>(); String ids[] = departmentVO.getId().split("-"); for (String id : ids) { if (!hasSysUser(id) && !hasSysPosition(id)) { idList.add(id);/*from w ww .ja v a 2 s. c om*/ } } int[] deleteNumbers = jdbcBaseDao.batchUpdate(sql, idList, new BatchPreparedStatementSetter() { /* (non-Javadoc) * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#getBatchSize() */ public int getBatchSize() { return idList.size(); } /* (non-Javadoc) * @see org.springframework.jdbc.core.BatchPreparedStatementSetter#setValues(java.sql.PreparedStatement, int) */ public void setValues(PreparedStatement ps, int index) throws SQLException { String id = idList.get(index); ps.setString(1, id); } }); return deleteNumbers.length; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaLinkDao.java
/** * Insert new links in a single batch statement * /*from w ww. j a v a 2 s. co m*/ * @param newLinkIndex * @param drops */ private void batchInsert(final Map<String, List<int[]>> newLinkIndex, final List<Drop> drops, Sequence seq) { final List<String> hashes = new ArrayList<String>(); hashes.addAll(newLinkIndex.keySet()); final long startKey = sequenceDao.getIds(seq, hashes.size()); String sql = "INSERT INTO links (id, hash, url) " + "VALUES (?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { String hash = hashes.get(i); // Update drops with the newly generated id for (int[] index : newLinkIndex.get(hash)) { drops.get(index[0]).getLinks().get(index[1]).setId(startKey + i); } int[] index = newLinkIndex.get(hash).get(0); Link link = drops.get(index[0]).getLinks().get(index[1]); ps.setLong(1, link.getId()); ps.setString(2, link.getHash()); ps.setString(3, link.getUrl()); } public int getBatchSize() { return hashes.size(); } }); // Update the droplet_links table insertDropletLinks(drops); }
From source file:gov.nih.nci.cabig.caaers.dao.index.AbstractIndexDao.java
/** * @param userName - the login name of the user * @param indexEntries - entries to insert into the database. *///ww w . ja va 2s. com @Transactional(readOnly = false) public void updateIndex(final String userName, List<IndexEntry> indexEntries) { String dataBase = ""; if (this.getProperties().getProperty(DB_NAME) != null) { dataBase = getProperties().getProperty(DB_NAME); } boolean oracleDB = dataBase.equals(ORACLE_DB); Map<String, List<IndexEntry>> diffMap = diff(userName, indexEntries); final List<IndexEntry> toInsert = diffMap.get("insert"); if (!CollectionUtils.isEmpty(toInsert)) { BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int index) throws SQLException { IndexEntry entry = toInsert.get(index); ps.setString(1, userName); ps.setInt(2, entry.getEntityId()); ps.setInt(3, entry.getPrivilege()); } public int getBatchSize() { return toInsert.size(); } }; if (log.isInfoEnabled()) { log.info("Inserting : " + toInsert.size() + " records"); log.info(toInsert.toString()); } getJdbcTemplate().batchUpdate(generateSQLInsertTemplate(oracleDB).toString(), setter); } final List<IndexEntry> toUpdate = diffMap.get("update"); if (!CollectionUtils.isEmpty(toUpdate)) { BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int index) throws SQLException { IndexEntry entry = toUpdate.get(index); ps.setInt(1, entry.getPrivilege()); ps.setString(2, userName); ps.setInt(3, entry.getEntityId()); } public int getBatchSize() { return toUpdate.size(); } }; if (log.isInfoEnabled()) { log.info("Updating : " + toUpdate.size() + " records"); log.info(toUpdate.toString()); } getJdbcTemplate().batchUpdate(generateSQLUpdateTemplate(oracleDB).toString(), setter); } List<String> deleteQueries = new ArrayList<String>(); List<IndexEntry> toDelete = diffMap.get("delete"); if (!CollectionUtils.isEmpty(toDelete)) { if (CollectionUtils.isEmpty(indexEntries)) { deleteQueries.add(generateSQL("delete-all", userName, null, oracleDB)); } else { for (IndexEntry entry : toDelete) { deleteQueries.add(generateSQL("delete", userName, entry, oracleDB)); } } getJdbcTemplate().batchUpdate(deleteQueries.toArray(new String[] {})); if (log.isInfoEnabled()) { log.info("Deleting : " + deleteQueries.size() + " records"); log.info(deleteQueries.toString()); } } }