|
36 | 36 | import java.util.Collection;
|
37 | 37 | import java.util.LinkedList;
|
38 | 38 | import java.util.UUID;
|
| 39 | +import java.util.concurrent.atomic.AtomicInteger; |
39 | 40 | import java.util.concurrent.atomic.AtomicReference;
|
40 | 41 | import javax.sql.DataSource;
|
41 | 42 | import lombok.EqualsAndHashCode;
|
@@ -158,6 +159,8 @@ public final class JdbcSession {
|
158 | 159 | */
|
159 | 160 | private final transient Collection<Object> args;
|
160 | 161 |
|
| 162 | + private final transient AtomicInteger batchSize; |
| 163 | + |
161 | 164 | /**
|
162 | 165 | * Arguments.
|
163 | 166 | *
|
@@ -196,11 +199,12 @@ public final class JdbcSession {
|
196 | 199 | @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
|
197 | 200 | public JdbcSession(final DataSource src) {
|
198 | 201 | this.args = new LinkedList<>();
|
| 202 | + this.batchSize = new AtomicInteger(0); |
199 | 203 | this.preparations = new LinkedList<>();
|
200 | 204 | this.connection = new AtomicReference<>();
|
201 | 205 | this.auto = true;
|
202 | 206 | this.source = src;
|
203 |
| - this.preparations.add(new PrepareArgs(this.args)); |
| 207 | + this.preparations.add(new PrepareArgs(this.args, this.batchSize)); |
204 | 208 | }
|
205 | 209 |
|
206 | 210 | /**
|
@@ -288,7 +292,8 @@ public JdbcSession clear() {
|
288 | 292 | synchronized (this.args) {
|
289 | 293 | this.args.clear();
|
290 | 294 | this.preparations.clear();
|
291 |
| - this.preparations.add(new PrepareArgs(this.args)); |
| 295 | + this.batchSize.set(0); |
| 296 | + this.preparations.add(new PrepareArgs(this.args, this.batchSize)); |
292 | 297 | }
|
293 | 298 | return this;
|
294 | 299 | }
|
@@ -368,6 +373,16 @@ public <T> T update(final Outcome<T> outcome)
|
368 | 373 | );
|
369 | 374 | }
|
370 | 375 |
|
| 376 | + public <T> T batchInsert(final Outcome<T> outcome, int batchSize) |
| 377 | + throws SQLException { |
| 378 | + this.batchSize.set(batchSize); |
| 379 | + return this.run( |
| 380 | + outcome, |
| 381 | + new Connect.WithKeys(this.query), |
| 382 | + Request.EXECUTE_BATCH_UPDATE |
| 383 | + ); |
| 384 | + } |
| 385 | + |
371 | 386 | /**
|
372 | 387 | * Call an SQL stored procedure.
|
373 | 388 | *
|
|
0 commit comments