Java 类org.springframework.jdbc.core.ParameterizedPreparedStatementSetter 实例源码

项目:sql-utils    文件:LogJdbcTemplate.java   
@Override
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException {
    LogOperate logOperate = parseOperate(sql);
    Assert.notNull(logOperate,"不匹配的操作类型,日志记录失败!");
    switch (logOperate){
        case DELETE:
            batchDeleteRecordLog(logOperate,sql,batchArgs,pss);
            break;
        case UPDATE:
            batchUpdateRecordLog(logOperate,sql,batchArgs,pss);
            break;
        case INSERT:
            batchInsertRecordLog(logOperate,sql,batchArgs,pss);
            break;
        default:
            break;
    }
    return super.batchUpdate(sql, batchArgs, batchSize, pss);
}
项目:java-samples    文件:Batch.java   
/**
 * Exemple d'utilisation du ParameterizedPreparedStatementSetter
 * Son int�r�t et de pouvoir utiliser des objets typ�s directement
 *
 * Par contre, il renvoie un int[][] pour refleter les actions sur chaque batchSize
 */
public int[][] updateUserAgain(final int batchSize, final User... usersToUpdate) {
    ParameterizedPreparedStatementSetter<User> ppss = new ParameterizedPreparedStatementSetter<User>() {

        @Override
        public void setValues(final PreparedStatement ps, final User user) throws SQLException {
            ps.setString(1, user.getName());
            ps.setString(2, user.getMail());
            ps.setInt(3, user.getId());
        }

    };

    return jdbcTemplate.batchUpdate("update users set name = ?, email = ? where id = ?",
            Arrays.asList(usersToUpdate), batchSize, ppss);
}
项目:spring-jdbctemplate-streams    文件:JdbcPerformanceTest.java   
@Before
public void setUp(){
    logger.info("populating database");

    ParameterizedPreparedStatementSetter<String> ppss = new ParameterizedPreparedStatementSetter<String>() {
        @Override
        public void setValues(PreparedStatement preparedStatement, String s) throws SQLException {
            preparedStatement.setString(1, s);
        }
    };

    jdbcTemplate.batchUpdate("DELETE FROM test_data");

    int batchSize = 10000;
    for(int i=0; i< 5; i++) {
        jdbcTemplate.batchUpdate("INSERT INTO test_data (entry) VALUES (?)",
                Stream.generate(Math::random).map(String::valueOf).limit(1000000).collect(Collectors.toList()),
                batchSize, ppss);
    }

    logger.info("test data populated");
}
项目:spring-jdbc-oracle    文件:OracleJdbcTemplate.java   
@Override
public <T> int[][] batchUpdate(
    String sql, Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> ppss) {

  if (this.logger.isDebugEnabled()) {
    this.logger.debug("Executing SQL batch update [" + sql + "] with a batch size of " + batchSize);
  }

  try {
    return execute(sql, new ParameterizedBatchingPreparedStatementCallback<>(ppss, batchSize, batchArgs));
  } finally {
    if (ppss instanceof ParameterDisposer) {
      ((ParameterDisposer) ppss).cleanupParameters();
    }
  }
}
项目:spring-jdbc-oracle    文件:ParameterizedBatchingPreparedStatementCallbackTest.java   
private void doInPreparedStatement(int batchSize, int batchArgSize) throws SQLException {
  @SuppressWarnings("unchecked")
  ParameterizedPreparedStatementSetter<String> ppss = mock(ParameterizedPreparedStatementSetter.class);

  // Create the arguments for the batch update
  ArrayList<String> batchArgs = new ArrayList<>(batchArgSize);
  for (int i = 0; i < batchArgSize; i++) {
    batchArgs.add(Integer.toString(i));
  }

  ParameterizedBatchingPreparedStatementCallback<String> psc =
      new ParameterizedBatchingPreparedStatementCallback<>(ppss, batchSize, batchArgs);
  int[][] result = psc.doInPreparedStatement(this.ops);

  assertThat(result, matchesBatchedRowCounts(batchSize, batchArgSize));
  verifyPreparedStatementCalls(batchArgSize, ppss);
}
项目:test    文件:StockServiceImpl.java   
@Override
public void batchInsertUpdate(List<StockModelInfo> dtos) {
    template.batchUpdate(BATCH_INSERT, dtos, 100, new ParameterizedPreparedStatementSetter<StockModelInfo>() {
        @Override
        public void setValues(PreparedStatement ps, StockModelInfo dto) throws SQLException {
            ps.setInt(1, dto.getMarket());
            ps.setString(2, dto.getStockCode());
            ps.setBoolean(3, dto.getIsDel());
            Date updateDate = new Date(dto.getUpdateDate().getTime());
            ps.setDate(4, updateDate);
            ps.setString(5, dto.getStockDescription());
        }
    });
}
项目:test    文件:UserUrlServiceImpl.java   
@Override
public void batchInsertUpdate(List<UserUrlMassage> dtos) {
    template.batchUpdate(BATCH_INSERT, dtos, 10, new ParameterizedPreparedStatementSetter<UserUrlMassage>() {
        @Override
        public void setValues(PreparedStatement ps, UserUrlMassage dto) throws SQLException {
            ps.setString(1, dto.getBoardId());
            ps.setString(2, dto.getUrlId());
            Date updateDate = new Date(dto.getDate().getTime());
            ps.setDate(3, updateDate);
            ps.setBoolean(4, dto.getIsDel());
            ps.setInt(5, dto.getSection());
            ps.setBoolean(6, dto.getFlag());
        }
    });
}
项目:spring-jdbc-oracle    文件:ParameterizedBatchingPreparedStatementCallback.java   
/**
 * Constructor.
 * @param ppss Parameterized Prepared Statement Setter.
 * @param sendBatchSize Size of the batch that will be sent to the DB.
 * @param batchArgs Batch arguments.
 */
public ParameterizedBatchingPreparedStatementCallback(
    ParameterizedPreparedStatementSetter<T> ppss,
    int sendBatchSize,
    Collection<T> batchArgs) {

  this.ppss = ppss;
  this.sendBatchSize = sendBatchSize < batchArgs.size() ? sendBatchSize : batchArgs.size();
  this.batchArgs = new ArrayList<>(batchArgs);
}
项目:spring-jdbc-oracle    文件:ParameterizedBatchingPreparedStatementCallbackTest.java   
private void verifyPreparedStatementCalls(int batchArgSize, ParameterizedPreparedStatementSetter<String> ppss)
throws SQLException {

  for (int i = 0; i < batchArgSize; i++) {
    verify(ppss).setValues(this.ops, Integer.toString(i));
    verify(this.ops, times(batchArgSize)).executeUpdate();
  }
}
项目:buffer-slayer    文件:BatchJdbcTemplate.java   
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
    ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException {
  return delegate.batchUpdate(sql, batchArgs, batchSize, pss);
}
项目:kratos-1    文件:KratosJdbcTemplate.java   
@Override
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
        ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException {

    return super.batchUpdate(sql, batchArgs, batchSize, pss);
}
项目:sql-utils    文件:LogJdbcTemplate.java   
private void batchUpdateRecordLog(LogOperate operate,String sql, Collection batchArgs, ParameterizedPreparedStatementSetter pss){


    }
项目:sql-utils    文件:LogJdbcTemplate.java   
private void batchInsertRecordLog(LogOperate operate,String sql, Collection batchArgs, ParameterizedPreparedStatementSetter pss){

    }
项目:sql-utils    文件:LogJdbcTemplate.java   
private void batchDeleteRecordLog(LogOperate operate,String sql, Collection batchArgs, ParameterizedPreparedStatementSetter pss){

    }