org.sql2o.Query.executeBatch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中org.sql2o.Query.executeBatch方法的一些代码示例,展示了Query.executeBatch的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeBatch方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:executeBatch

Query.executeBatch介绍

暂无

代码示例

代码示例来源:origin: aaberg/sql2o

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 *
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 *
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch(){
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0){
      if(++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: org.sql2o/sql2o

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 *
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 *
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch(){
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0){
      if(++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: biezhi/anima

/**
 * Adds a set of parameters to this <code>Query</code>
 * object's batch of commands. <br/>
 * <p>
 * If maxBatchRecords is more than 0, executeBatch is called upon adding that many
 * commands to the batch. <br/>
 * <p>
 * The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
 * method.
 */
public Query addToBatch() {
  try {
    buildPreparedStatement(false).addBatch();
    if (this.maxBatchRecords > 0) {
      if (++this.currentBatchRecords % this.maxBatchRecords == 0) {
        this.executeBatch();
      }
    }
  } catch (SQLException e) {
    throw new Sql2oException("Error while adding statement to batch", e);
  }
  return this;
}

代码示例来源:origin: iNPUTmice/caas

/**
 * @param connection
 * @param domain
 * @param results
 * @param timestamp
 * @return
 */
public static boolean addCurrentResults(Connection connection, String domain, List<Result> results, Instant timestamp) {
  String queryText = "insert into current_tests(domain,test,success,timestamp) " +
      "values(:domain,:test,:success,:timestamp)";
  Query query = connection.createQuery(queryText);
  results.forEach(
      result -> query
          .addParameter("test", result.getTest().short_name())
          .addParameter("success", result.isSuccess())
          .addParameter("domain", domain)
          .addParameter("timestamp", timestamp)
          .addToBatch()
  );
  query.executeBatch();
  return true;
}

代码示例来源:origin: iNPUTmice/caas

/**
 * @param connection should be a transaction of type java.sql.Connection.TRANSACTION_SERIALIZABLE for sqlite database
 * @param rdpList
 * @param beginTime
 * @param endTime
 * @return
 */
public static boolean addPeriodicResults(Connection connection, List<ResultDomainPair> rdpList, Instant beginTime, Instant endTime) {
  //Add the iteration to iterations list
  String query = "insert into periodic_tests(domain,test,success,iteration_number)" +
      "values(:domain,:test,:success,:iteration)";
  int iterationNumber = getNextIterationNumber(connection);
  addIteration(connection, iterationNumber, beginTime, endTime);
  Query resultInsertQuery = connection.createQuery(query);
  rdpList.forEach(rdp -> {
    String domain = rdp.getDomain();
    rdp.getResults().forEach(
        result -> resultInsertQuery
            .addParameter("test", result.getTest().short_name())
            .addParameter("success", result.isSuccess())
            .addParameter("domain", domain)
            .addParameter("iteration", iterationNumber)
            .addToBatch());
  });
  resultInsertQuery.executeBatch();
  for (ResultDomainPair rdp : rdpList) {
    addCurrentResults(connection, rdp.getDomain(), rdp.getResults(), beginTime);
  }
  return true;
}

代码示例来源:origin: making/spring-boot-db-samples

public Pizza save(Pizza pizza) {
  try (Connection con = sql2o.beginTransaction()) {
    long pizzaId = (long) con.createQuery("INSERT INTO pizza (base_id, name, price) VALUES (:baseId, :name, :price)", true)
        .addParameter("baseId", pizza.getBase().getId())
        .addParameter("name", pizza.getName())
        .addParameter("price", pizza.getPrice())
        .executeUpdate()
        .getKey();
    Query queryForPt = con.createQuery("INSERT INTO pizza_toppings (pizza_id, toppings_id) VALUES (:pizzaId, :toppingsId)");
    pizza.getToppings().forEach(t ->
        queryForPt
            .addParameter("pizzaId", pizzaId)
            .addParameter("toppingsId", t.getId())
            .addToBatch());
    queryForPt.executeBatch();
    con.commit();
  }
  return pizza;
}

相关文章