本文整理了Java中org.sql2o.Query.addToBatch
方法的一些代码示例,展示了Query.addToBatch
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.addToBatch
方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:addToBatch
[英]Adds a set of parameters to this Query
object's batch of commands.
If maxBatchRecords is more than 0, executeBatch is called upon adding that many commands to the batch.
The current number of batched commands is accessible via the getCurrentBatchRecords()
method.
[中]将一组参数添加到此Query
对象的一批命令中。
如果maxBatchRecords大于0,则在向批处理添加那么多命令时调用executeBatch。
当前批处理命令的数量可以通过getCurrentBatchRecords()
方法访问。
代码示例来源:origin: aaberg/sql2o
/**
* Adds a set of parameters to this <code>Query</code>
* object's batch of commands and returns any generated keys. <br/>
*
* If maxBatchRecords is more than 0, executeBatch is called upon adding that many
* commands to the batch. This method will return any generated keys if <code>fetchGeneratedKeys</code> is set. <br/>
*
* The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
* method.
*/
public <A> List<A> addToBatchGetKeys(Class<A> klass){
this.addToBatch();
if (this.currentBatchRecords == 0) {
return this.connection.getKeys(klass);
} else {
return Collections.emptyList();
}
}
代码示例来源:origin: org.sql2o/sql2o
/**
* Adds a set of parameters to this <code>Query</code>
* object's batch of commands and returns any generated keys. <br/>
*
* If maxBatchRecords is more than 0, executeBatch is called upon adding that many
* commands to the batch. This method will return any generated keys if <code>fetchGeneratedKeys</code> is set. <br/>
*
* The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
* method.
*/
public <A> List<A> addToBatchGetKeys(Class<A> klass){
this.addToBatch();
if (this.currentBatchRecords == 0) {
return this.connection.getKeys(klass);
} else {
return Collections.emptyList();
}
}
代码示例来源:origin: biezhi/anima
/**
* Adds a set of parameters to this <code>Query</code>
* object's batch of commands and returns any generated keys. <br/>
* <p>
* If maxBatchRecords is more than 0, executeBatch is called upon adding that many
* commands to the batch. This method will return any generated keys if <code>fetchGeneratedKeys</code> is set. <br/>
* <p>
* The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
* method.
*/
public <A> List<A> addToBatchGetKeys(Class<A> klass) {
this.addToBatch();
if (this.currentBatchRecords == 0) {
return this.connection.getKeys(klass);
} else {
return Collections.emptyList();
}
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!