use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.
the class FileDiffDao method update.
public int[] update(final FileDiff[] fileDiffs) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "UPDATE " + TABLE_NAME + " SET " + "rid = ?, " + "diff_type = ?, " + "src = ?, " + "parameters = ?, " + "state = ?, " + "create_time = ? " + "WHERE did = ?";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setLong(1, fileDiffs[i].getRuleId());
ps.setInt(2, fileDiffs[i].getDiffType().getValue());
ps.setString(3, fileDiffs[i].getSrc());
ps.setString(4, fileDiffs[i].getParametersJsonString());
ps.setInt(5, fileDiffs[i].getState().getValue());
ps.setLong(6, fileDiffs[i].getCreateTime());
ps.setLong(7, fileDiffs[i].getDiffId());
}
@Override
public int getBatchSize() {
return fileDiffs.length;
}
});
}
use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.
the class CmdletDao method batchDelete.
public int[] batchDelete(final List<Long> cids) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
final String sql = "DELETE FROM " + TABLE_NAME + " WHERE cid = ?";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setLong(1, cids.get(i));
}
public int getBatchSize() {
return cids.size();
}
});
}
use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.
the class SmallFileDao method batchInsertUpdate.
public int[] batchInsertUpdate(final CompactFileState[] fileStates) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "REPLACE INTO small_file (path, container_file_path, offset, length)" + " VALUES (?,?,?,?)";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, fileStates[i].getPath());
ps.setString(2, fileStates[i].getFileContainerInfo().getContainerFilePath());
ps.setLong(3, fileStates[i].getFileContainerInfo().getOffset());
ps.setLong(4, fileStates[i].getFileContainerInfo().getLength());
}
@Override
public int getBatchSize() {
return fileStates.length;
}
});
}
use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project SSM by Intel-bigdata.
the class StorageHistoryDao method insertStorageHistTable.
public void insertStorageHistTable(final StorageCapacity[] storages, final long interval) throws SQLException {
if (storages.length == 0) {
return;
}
final Long curr = System.currentTimeMillis();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "INSERT INTO storage_hist (type, time_stamp, capacity, free) VALUES (?,?,?,?);";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, storages[i].getType() + "-" + interval);
if (storages[i].getTimeStamp() == null) {
ps.setLong(2, curr);
} else {
ps.setLong(2, storages[i].getTimeStamp());
}
ps.setLong(3, storages[i].getCapacity());
ps.setLong(4, storages[i].getFree());
}
public int getBatchSize() {
return storages.length;
}
});
}
use of org.springframework.jdbc.core.BatchPreparedStatementSetter in project spring-framework by spring-projects.
the class NamedParameterJdbcTemplate method batchUpdate.
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
if (batchArgs.length == 0) {
return new int[0];
}
ParsedSql parsedSql = getParsedSql(sql);
PreparedStatementCreatorFactory pscf = getPreparedStatementCreatorFactory(parsedSql, batchArgs[0]);
return getJdbcOperations().batchUpdate(pscf.getSql(), new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
pscf.newPreparedStatementSetter(values).setValues(ps);
}
@Override
public int getBatchSize() {
return batchArgs.length;
}
});
}
Aggregations