Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f314a99

Browse files
authored
Merge pull request aaberg#252 from bharrisau/add-batch-method
Add batch method to return any generated keys
2 parents 6032377 + 2b9c355 commit f314a99

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

core/src/main/java/org/sql2o/Query.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public boolean isExplicitExecuteBatchRequired(){
800800
* Adds a set of parameters to this <code>Query</code>
801801
* object's batch of commands. <br/>
802802
*
803-
* If maxBatchRecords is more than 0, executeBatch is called upon adding that manny
803+
* If maxBatchRecords is more than 0, executeBatch is called upon adding that many
804804
* commands to the batch. <br/>
805805
*
806806
* The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
@@ -821,6 +821,26 @@ public Query addToBatch(){
821821
return this;
822822
}
823823

824+
/**
825+
* Adds a set of parameters to this <code>Query</code>
826+
* object's batch of commands and returns any generated keys. <br/>
827+
*
828+
* If maxBatchRecords is more than 0, executeBatch is called upon adding that many
829+
* commands to the batch. This method will return any generated keys if <code>fetchGeneratedKeys</code> is set. <br/>
830+
*
831+
* The current number of batched commands is accessible via the <code>getCurrentBatchRecords()</code>
832+
* method.
833+
*/
834+
public <A> List<A> addToBatchGetKeys(Class<A> klass){
835+
this.addToBatch();
836+
837+
if (this.currentBatchRecords == 0) {
838+
return this.connection.getKeys(klass);
839+
} else {
840+
return Collections.emptyList();
841+
}
842+
}
843+
824844
public Connection executeBatch() throws Sql2oException {
825845
long start = System.currentTimeMillis();
826846
try {

0 commit comments

Comments
 (0)