List of usage examples for org.springframework.jdbc.core BatchPreparedStatementSetter BatchPreparedStatementSetter
BatchPreparedStatementSetter
From source file:wiki.link.LinkResource.java
public static void insertAll(List<Link> links, DbConnector dbc) { BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() { @Override/* w w w. ja va 2 s . com*/ public void setValues(PreparedStatement preparedStatement, int i) throws SQLException { preparedStatement.setLong(1, links.get(i).from); preparedStatement.setLong(2, links.get(i).to); } @Override public int getBatchSize() { return links.size(); } }; try { dbc.jdbcTemplate.batchUpdate("INSERT INTO links(fromPage, toPage) values(?, ?)", bpss); } catch (BadSqlGrammarException e) { e.printStackTrace(); BatchUpdateException bue = (BatchUpdateException) e.getCause(); System.out.println(bue.getNextException()); System.exit(1); } }
From source file:com.github.ffremont.writers.PersonDaoWriter.java
@Override public void write(List<? extends Person> list) throws Exception { jdbcTemplate.batchUpdate(INSERTS, new BatchPreparedStatementSetter() { @Override//from w ww . j a v a2s . c o m public void setValues(PreparedStatement ps, int i) throws SQLException { Person person = list.get(i); ps.setInt(1, person.getId()); ps.setString(2, person.getNom()); ps.setString(3, person.getPrenom()); ps.setString(4, person.getCivilite()); } @Override public int getBatchSize() { return list.size(); } }); }
From source file:org.apache.lucene.store.jdbc.handler.ActualDeleteFileEntryHandler.java
public List deleteFiles(final List names) throws IOException { jdbcTemplate.batchUpdate(table.sqlDeleteByName(), new BatchPreparedStatementSetter() { @Override// ww w.j a v a2 s .c o m public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setFetchSize(1); ps.setString(1, (String) names.get(i)); } @Override public int getBatchSize() { return names.size(); } }); return null; }
From source file:org.apache.lucene.store.jdbc.handler.MarkDeleteFileEntryHandler.java
public List deleteFiles(final List names) throws IOException { jdbcTemplate.batchUpdate(table.sqlMarkDeleteByName(), new BatchPreparedStatementSetter() { @Override//from w w w . j a v a2 s. c om public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setFetchSize(1); ps.setBoolean(1, true); ps.setString(2, (String) names.get(i)); ps.addBatch(); } @Override public int getBatchSize() { return names.size(); } }); return null; }
From source file:com.pivotal.gfxd.demo.loader.Loader.java
public void insertBatch(final List<String[]> lines, final long timestamp) { String sql = "insert into raw_sensor (id, timestamp, value, property, plug_id, household_id, house_id, weekday, time_slice) values (?,?,?,?,?,?,?,?,?)"; final Calendar cal = Calendar.getInstance(); getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { @Override//from www. j a va2s . c o m public void setValues(PreparedStatement ps, int i) throws SQLException { final String[] split = lines.get(i); int plugId = Integer.parseInt(split[4]); int householdId = Integer.parseInt(split[5]); int houseId = Integer.parseInt(split[6]); ps.setLong(1, Long.parseLong(split[0])); ps.setLong(2, timestamp); float value = Float.parseFloat(split[2]); ps.setFloat(3, value + value * disturbance); ps.setInt(4, Integer.parseInt(split[3])); ps.setInt(5, computePlugId(plugId, householdId, houseId)); ps.setInt(6, householdId); ps.setInt(7, houseId); cal.setTimeInMillis(timestamp * 1000L); int weekDay = cal.get(Calendar.DAY_OF_WEEK); int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) / MINUTES_PER_INTERVAL; ps.setInt(8, weekDay); // weekday ps.setInt(9, timeSlice); // time_slice } @Override public int getBatchSize() { return lines.size(); } }); cal.setTimeInMillis(timestamp * 1000L); int weekDay = cal.get(Calendar.DAY_OF_WEEK); int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) / MINUTES_PER_INTERVAL; LOG.debug("rows=" + lines.size() + " weekday=" + weekDay + " slice=" + timeSlice + " stamp=" + timestamp + " now=" + (int) (System.currentTimeMillis() / 1000)); rowsInserted += lines.size(); }
From source file:com.ccoe.build.tracking.jdbc.SessionJDBCTemplate.java
public int[] batchUpdateDuration(final List<DurationObject> durations) { int[] updateCounts = jdbcTemplateObject.batchUpdate( "update RBT_SESSION set duration_download = ?, duration_build = ? where id = ?", new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, (durations.get(i)).getDownloadDuration()); ps.setInt(2, (durations.get(i)).getBuildDuration()); ps.setInt(3, (durations.get(i)).getSessionId()); }/* w ww .ja v a 2s. com*/ public int getBatchSize() { return durations.size(); } }); return updateCounts; }
From source file:cn.vlabs.duckling.vwb.service.emailnotifier.dao.EmailSubscriberProviderImpl.java
@Override public void createEmailSubscriber(final int siteId, List<EmailSubscriber> subscribers) { final String sql = "insert into vwb_email_notify (subscriber,receiver,rec_time,siteId,resourceId) values(?,?,?,?,?)"; final List<EmailSubscriber> tsubscribers = subscribers; getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return tsubscribers.size(); }// w w w. j av a 2 s . c om public void setValues(PreparedStatement ps, int count) throws SQLException { EmailSubscriber email = (EmailSubscriber) tsubscribers.get(count); int i = 0; ps.setString(++i, email.getNotify_creator()); ps.setString(++i, email.getReceiver()); ps.setInt(++i, email.getRec_time()); ps.setInt(++i, siteId); ps.setString(++i, email.getresourceId()); } }); }
From source file:com.mvdb.etl.dao.impl.JdbcOrderDAO.java
@Override public void insertBatch(final List<Order> orders) { String sql = "INSERT INTO ORDERS " + "(ORDER_ID, NOTE, SALE_CODE, CREATE_TIME, UPDATE_TIME) VALUES (?, ?, ?, ?, ?)"; getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { @Override// w w w . j a v a 2s . co m public void setValues(PreparedStatement ps, int i) throws SQLException { Order order = orders.get(i); ps.setLong(1, order.getOrderId()); ps.setString(2, order.getNote()); ps.setInt(3, order.getSaleCode()); ps.setTimestamp(4, new java.sql.Timestamp(order.getCreateTime().getTime())); ps.setTimestamp(5, new java.sql.Timestamp(order.getUpdateTime().getTime())); } @Override public int getBatchSize() { return orders.size(); } }); }
From source file:gov.nih.nci.cabig.caaers.dao.MedDRADao.java
/** * This method populates the meddra_llt table. It uses the meddra_llt.asc file for loading the data into this table. * Different sqls are used for postgres and oracle db. * //from w w w . j a v a2 s. c om * @param llts * @param startIndex * @return */ public int[] insertLowLevelTerms(final List llts, final int startIndex, final int version_id, final Map<String, Integer> codeToIdMap) { String sql = "insert into meddra_llt (meddra_code,meddra_term,meddra_pt_id,version_id) " + "values (?,?,?,?)"; String dataBase = ""; if (properties.getProperty(DB_NAME) != null) { dataBase = properties.getProperty(DB_NAME); } if (dataBase.equals(ORACLE_DB)) sql = "insert into meddra_llt (id,meddra_code,meddra_term,meddra_pt_id,version_id) " + "values (SEQ_MEDDRA_LLT_ID.NEXTVAL,?,?,?,?)"; BatchPreparedStatementSetter setter = null; setter = new BatchPreparedStatementSetter() { public int getBatchSize() { return llts.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { String[] llt = (String[]) llts.get(index); ps.setString(1, llt[0]); ps.setString(2, llt[1]); if (codeToIdMap.containsKey(llt[2])) ps.setInt(3, (codeToIdMap.get(llt[2]).intValue())); else ps.setInt(3, 0); ps.setInt(4, version_id); } }; return jdbcTemplate.batchUpdate(sql, setter); }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int[] batchInsert(final List<Plugin> plugins, final int sessionID, final int projectID) { final String SQL = "insert into RBT_RAW_DATA (plugin_id, session_id, " + "project_id, duration, event_time, plugin_key) values (?, ?, ?, ?, ?, ?)"; int[] updateCounts = jdbcTemplateObject.batchUpdate(SQL, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, plugins.get(i).getId()); ps.setInt(2, sessionID);/*from w w w. j a va 2s. co m*/ ps.setInt(3, projectID); ps.setLong(4, plugins.get(i).getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugins.get(i).getStartTime().getTime())); ps.setString(6, plugins.get(i).getGroupId() + ":" + plugins.get(i).getArtifactId()); } public int getBatchSize() { return plugins.size(); } }); return updateCounts; }