@@ -368,8 +368,9 @@ public static SQLResult getUpdateResult(Connection connection, String query, Obj
368368 * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
369369 * @throws UnsupportedOperationException if not implemented by the driver.
370370 * @since 1.1.0
371+ * @since 1.2.0, returns <code>int[]</code>. See {@link #getUpdateLargeBatch(Connection, String, Object[][])} for <code>long[]</code>.
371372 */
372- public static long [] getUpdateBatch (Connection connection , String query , Object [][] parameterList )
373+ public static int [] getUpdateBatch (Connection connection , String query , Object [][] parameterList )
373374 {
374375 return getUpdateBatch (connection , query , SQLCallable .DEFAULT_BATCH_SIZE , Arrays .asList (parameterList ));
375376 }
@@ -384,8 +385,9 @@ public static long[] getUpdateBatch(Connection connection, String query, Object[
384385 * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
385386 * @throws UnsupportedOperationException if not implemented by the driver.
386387 * @since 1.1.0
388+ * @since 1.2.0, returns <code>int[]</code>. See {@link #getUpdateLargeBatch(Connection, String, int, Object[][])} for <code>long[]</code>.
387389 */
388- public static long [] getUpdateBatch (Connection connection , String query , int granularity , Object [][] parameterList )
390+ public static int [] getUpdateBatch (Connection connection , String query , int granularity , Object [][] parameterList )
389391 {
390392 return getUpdateBatch (connection , query , granularity , Arrays .asList (parameterList ));
391393 }
@@ -399,8 +401,9 @@ public static long[] getUpdateBatch(Connection connection, String query, int gra
399401 * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
400402 * @throws UnsupportedOperationException if not implemented by the driver.
401403 * @since 1.1.0
404+ * @since 1.2.0, returns <code>int[]</code>. See {@link #getUpdateLargeBatch(Connection, String, int, Collection)} for <code>long[]</code>.
402405 */
403- public static long [] getUpdateBatch (Connection connection , String query , Collection <Object []> parameterList )
406+ public static int [] getUpdateBatch (Connection connection , String query , Collection <Object []> parameterList )
404407 {
405408 return getUpdateBatch (connection , query , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
406409 }
@@ -415,8 +418,9 @@ public static long[] getUpdateBatch(Connection connection, String query, Collect
415418 * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
416419 * @throws UnsupportedOperationException if not implemented by the driver.
417420 * @since 1.1.0
421+ * @since 1.2.0, returns <code>int[]</code>. See {@link #getUpdateLargeBatch(Connection, String, int, Collection)} for <code>long[]</code>.
418422 */
419- public static long [] getUpdateBatch (Connection connection , String query , int granularity , Collection <Object []> parameterList )
423+ public static int [] getUpdateBatch (Connection connection , String query , int granularity , Collection <Object []> parameterList )
420424 {
421425 try (PreparedStatement statement = connection .prepareStatement (query , Statement .RETURN_GENERATED_KEYS ))
422426 {
@@ -428,6 +432,75 @@ public static long[] getUpdateBatch(Connection connection, String query, int gra
428432 }
429433 }
430434
435+ /**
436+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
437+ * @param connection the connection to create a prepared statement and execute from.
438+ * @param query the query statement to execute.
439+ * @param parameterList the list of parameter sets to pass to the query for each update.
440+ * @return the update result returned (usually number of rows affected and or generated ids).
441+ * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
442+ * @throws UnsupportedOperationException if not implemented by the driver.
443+ * @since 1.2.0
444+ */
445+ public static long [] getUpdateLargeBatch (Connection connection , String query , Object [][] parameterList )
446+ {
447+ return getUpdateLargeBatch (connection , query , SQLCallable .DEFAULT_BATCH_SIZE , Arrays .asList (parameterList ));
448+ }
449+
450+ /**
451+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
452+ * @param connection the connection to create a prepared statement and execute from.
453+ * @param query the query statement to execute.
454+ * @param granularity the amount of statements to execute at a time. If 0 or less, no granularity.
455+ * @param parameterList the list of parameter sets to pass to the query for each update.
456+ * @return the update result returned (usually number of rows affected and or generated ids).
457+ * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
458+ * @throws UnsupportedOperationException if not implemented by the driver.
459+ * @since 1.2.0
460+ */
461+ public static long [] getUpdateLargeBatch (Connection connection , String query , int granularity , Object [][] parameterList )
462+ {
463+ return getUpdateLargeBatch (connection , query , granularity , Arrays .asList (parameterList ));
464+ }
465+
466+ /**
467+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
468+ * @param connection the connection to create a prepared statement and execute from.
469+ * @param query the query statement to execute.
470+ * @param parameterList the list of parameter sets to pass to the query for each update.
471+ * @return the update result returned (usually number of rows affected and or generated ids).
472+ * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
473+ * @throws UnsupportedOperationException if not implemented by the driver.
474+ * @since 1.2.0
475+ */
476+ public static long [] getUpdateLargeBatch (Connection connection , String query , Collection <Object []> parameterList )
477+ {
478+ return getUpdateLargeBatch (connection , query , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
479+ }
480+
481+ /**
482+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
483+ * @param connection the connection to create a prepared statement and execute from.
484+ * @param query the query statement to execute.
485+ * @param granularity the amount of statements to execute at a time. If 0 or less, no granularity.
486+ * @param parameterList the list of parameter sets to pass to the query for each update.
487+ * @return the update result returned (usually number of rows affected and or generated ids).
488+ * @throws SQLRuntimeException if the query cannot be executed or the query causes an error.
489+ * @throws UnsupportedOperationException if not implemented by the driver.
490+ * @since 1.2.0
491+ */
492+ public static long [] getUpdateLargeBatch (Connection connection , String query , int granularity , Collection <Object []> parameterList )
493+ {
494+ try (PreparedStatement statement = connection .prepareStatement (query , Statement .RETURN_GENERATED_KEYS ))
495+ {
496+ return callLargeBatch (statement , granularity , parameterList );
497+ }
498+ catch (SQLException e )
499+ {
500+ throw new SQLRuntimeException (e );
501+ }
502+ }
503+
431504 /**
432505 * Performs an update query (INSERT, DELETE, UPDATE, or other commands that do not return rows)
433506 * and extracts each set of result data into a SQLResult.
@@ -684,8 +757,9 @@ public static SQLResult callStatement(PreparedStatement statement, boolean updat
684757 * @throws SQLException if a SQL exception occurs.
685758 * @throws UnsupportedOperationException if not implemented by the driver.
686759 * @since 1.1.0
760+ * @since 1.2.0, returns <code>int[]</code>. See {@link #callLargeBatch(PreparedStatement, Object[][])} for <code>long[]</code>.
687761 */
688- public static long [] callBatch (PreparedStatement statement , Object [][] parameterList ) throws SQLException
762+ public static int [] callBatch (PreparedStatement statement , Object [][] parameterList ) throws SQLException
689763 {
690764 return callBatch (statement , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
691765 }
@@ -700,8 +774,9 @@ public static long[] callBatch(PreparedStatement statement, Object[][] parameter
700774 * @throws SQLException if a SQL exception occurs.
701775 * @throws UnsupportedOperationException if not implemented by the driver.
702776 * @since 1.1.0
777+ * @since 1.2.0, returns <code>int[]</code>. See {@link #callLargeBatch(PreparedStatement, int, Object[][])} for <code>long[]</code>.
703778 */
704- public static long [] callBatch (PreparedStatement statement , int granularity , Object [][] parameterList ) throws SQLException
779+ public static int [] callBatch (PreparedStatement statement , int granularity , Object [][] parameterList ) throws SQLException
705780 {
706781 return callBatch (statement , granularity , Arrays .asList (parameterList ));
707782 }
@@ -716,8 +791,9 @@ public static long[] callBatch(PreparedStatement statement, int granularity, Obj
716791 * @throws SQLException if a SQL exception occurs.
717792 * @throws UnsupportedOperationException if not implemented by the driver.
718793 * @since 1.1.0
794+ * @since 1.2.0, returns <code>int[]</code>. See {@link #callLargeBatch(PreparedStatement, Collection)} for <code>long[]</code>.
719795 */
720- public static long [] callBatch (PreparedStatement statement , Collection <Object []> parameterList ) throws SQLException
796+ public static int [] callBatch (PreparedStatement statement , Collection <Object []> parameterList ) throws SQLException
721797 {
722798 return callBatch (statement , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
723799 }
@@ -732,8 +808,101 @@ public static long[] callBatch(PreparedStatement statement, Collection<Object[]>
732808 * @throws SQLException if a SQL exception occurs.
733809 * @throws UnsupportedOperationException if not implemented by the driver.
734810 * @since 1.1.0
811+ * @since 1.2.0, returns <code>int[]</code>. See {@link #callLargeBatch(PreparedStatement, int, Collection)} for <code>long[]</code>.
812+ */
813+ public static int [] callBatch (PreparedStatement statement , int granularity , Collection <Object []> parameterList ) throws SQLException
814+ {
815+ int [] out = new int [parameterList .size ()];
816+ int cursor = 0 ;
817+ int batch = 0 ;
818+
819+ for (Object [] parameters : parameterList )
820+ {
821+ int n = 1 ;
822+ for (Object obj : parameters )
823+ statement .setObject (n ++, obj );
824+
825+ statement .addBatch ();
826+ batch ++;
827+
828+ if (batch == granularity )
829+ {
830+ int [] execute = statement .executeBatch ();
831+ System .arraycopy (execute , 0 , out , cursor , execute .length );
832+ cursor += execute .length ;
833+ batch = 0 ;
834+ }
835+ }
836+
837+ if (batch != 0 )
838+ {
839+ int [] execute = statement .executeBatch ();
840+ System .arraycopy (execute , 0 , out , cursor , execute .length );
841+ }
842+
843+ return out ;
844+ }
845+
846+ /**
847+ * Performs a series of update queries on a single statement on a connection and returns the batch result,
848+ * using a default batching amount ({@value SQLCallable#DEFAULT_BATCH_SIZE}).
849+ * @param statement the statement to execute.
850+ * @param parameterList the list of parameter sets to pass to the query for each update.
851+ * @return the amount of affected rows of each of the updates, each index corresponding to the index of the set of parameters used.
852+ * May also return {@link Statement#SUCCESS_NO_INFO} or {@link Statement#EXECUTE_FAILED} per update.
853+ * @throws SQLException if a SQL exception occurs.
854+ * @throws UnsupportedOperationException if not implemented by the driver.
855+ * @since 1.2.0
856+ */
857+ public static long [] callLargeBatch (PreparedStatement statement , Object [][] parameterList ) throws SQLException
858+ {
859+ return callLargeBatch (statement , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
860+ }
861+
862+ /**
863+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
864+ * @param statement the statement to execute.
865+ * @param granularity the amount of statements to execute at a time. If 0 or less, no granularity.
866+ * @param parameterList the list of parameter sets to pass to the query for each update.
867+ * @return the amount of affected rows of each of the updates, each index corresponding to the index of the set of parameters used.
868+ * May also return {@link Statement#SUCCESS_NO_INFO} or {@link Statement#EXECUTE_FAILED} per update.
869+ * @throws SQLException if a SQL exception occurs.
870+ * @throws UnsupportedOperationException if not implemented by the driver.
871+ * @since 1.2.0
872+ */
873+ public static long [] callLargeBatch (PreparedStatement statement , int granularity , Object [][] parameterList ) throws SQLException
874+ {
875+ return callLargeBatch (statement , granularity , Arrays .asList (parameterList ));
876+ }
877+
878+ /**
879+ * Performs a series of update queries on a single statement on a connection and returns the batch result,
880+ * using a default batching amount ({@value SQLCallable#DEFAULT_BATCH_SIZE}).
881+ * @param statement the statement to execute.
882+ * @param parameterList the list of parameter sets to pass to the query for each update.
883+ * @return the amount of affected rows of each of the updates, each index corresponding to the index of the set of parameters used.
884+ * May also return {@link Statement#SUCCESS_NO_INFO} or {@link Statement#EXECUTE_FAILED} per update.
885+ * @throws SQLException if a SQL exception occurs.
886+ * @throws UnsupportedOperationException if not implemented by the driver.
887+ * @since 1.2.0
888+ */
889+ public static long [] callLargeBatch (PreparedStatement statement , Collection <Object []> parameterList ) throws SQLException
890+ {
891+ return callLargeBatch (statement , SQLCallable .DEFAULT_BATCH_SIZE , parameterList );
892+ }
893+
894+ /**
895+ * Performs a series of update queries on a single statement on a connection and returns the batch result.
896+ * @param statement the statement to execute.
897+ * @param granularity the amount of statements to execute at a time. If 0 or less, no granularity.
898+ * @param parameterList the list of parameter sets to pass to the query for each update.
899+ * @return the amount of affected rows of each of the updates, each index corresponding to the index of the set of parameters used.
900+ * May also return {@link Statement#SUCCESS_NO_INFO} or {@link Statement#EXECUTE_FAILED} per update.
901+ * @throws SQLException if a SQL exception occurs.
902+ * @throws UnsupportedOperationException if not implemented by the driver.
903+ * @since 1.2.0
735904 */
736- public static long [] callBatch (PreparedStatement statement , int granularity , Collection <Object []> parameterList ) throws SQLException
905+ public static long [] callLargeBatch (PreparedStatement statement , int granularity , Collection <Object []> parameterList ) throws SQLException
737906 {
738907 long [] out = new long [parameterList .size ()];
739908 int cursor = 0 ;
0 commit comments