本文整理匯總了Java中org.springframework.jdbc.core.BatchPreparedStatementSetter類的典型用法代碼示例。如果您正苦於以下問題:Java BatchPreparedStatementSetter類的具體用法?Java BatchPreparedStatementSetter怎麽用?Java BatchPreparedStatementSetter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BatchPreparedStatementSetter類屬於org.springframework.jdbc.core包,在下文中一共展示了BatchPreparedStatementSetter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
@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();
}
});
}
}
示例2: update
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
@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();
}
});
}
}
示例3: swapIdUsingDataFromFile
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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");
}
示例4: executeBatchUpdateWithNamedParameters
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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;
}
});
}
示例5: executeBatchInternal
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
/**
* 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;
}
});
}
示例6: createEntries
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
/**
* 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());
}
});
}
示例7: updateZonePalstaList
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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;
}
});
}
示例8: removeZonePalsta
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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;
}
});
}
示例9: executeBatchInternal
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
/**
* 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();
}
});
}
示例10: batchSave
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
@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();
}
});
}
}
示例11: save
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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();
}
});
}
}
示例12: save
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
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();
}
});
}
}
示例13: updateUsers
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
/**
* 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);
}
示例14: batchDelete
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
@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;
}
示例15: insertBatch
import org.springframework.jdbc.core.BatchPreparedStatementSetter; //導入依賴的package包/類
@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();
}
});
}