Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-159

Sql batch execution returns only one int with the total row count. Change it to int array, like it is made in java.sql.Statement.executeBatch()

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.8, 2.0.9, 2.0.9b, 2.1.0
    • 2.2.0
    • Core
    • None
    • WinXp

    Description

      The method "executeBatch" of "SqlMapExecutor" does only return one int value with summerized update counts. By this way we can say which batch statement(s) has produced a failure. Also the possibly thrown exception does not satisfy. I've added a method "executeBatchDetailed" in each necessary interface and class and have improved the thrown exceptions. For example the new usage would looks like in the following example:

      com.ibatis.sqlmap.client.SqlMapExecutor executor = ...
      executor.startBatch();
      executor.update("insertSomething", "myParamValue1");
      executor.update("insertSomething", "myParamValue2");
      executor.update("insertSomething", "myParamValue3");
      executor.update("insertSomethingElse", "myOtherParamValue1");
      executor.update("insertSomethingElse", "myOtherParamValue2");

      try

      { int[] rowCount = executor.executeBatchDetailed(); /** * At this position the rowCount array contains five integers * which represents the number of rows affected or the value * java.sql.Statement.SUCCESS_NO_INFO if a batch statement could * be executed successfully but no information was available * (bad implemented jdbc driver). */ ... }

      catch (MoreBatchUpdateException e)

      { int[] rowCountsOfMostAllBatchStatements = e.getMoreUpdateCounts(); /** * At this position the rowCountsOfMostAllBatchStatements array * contains up to five integers and at minimum one integer has * the value java.sql.Statement.EXECUTE_FAILED. Normally a jdbc driver * throws a BatchUpdateException if a batch statement fails, but * in this case the jdbc driver has tried to execute all batch * statements of the same group. Groups could be "insertSomething" * and "insertSomethingElse" in this example. If a batch statement * of group "insertSomething" would fail, the array * rowCountsOfMostAllBatchStatements could contain three integers. */ }

      catch (BatchUpdateException e)

      { int[] rowCountsOfOnlySuccessfulBatchStatements = e.getUpdateCounts(); /** * At this position the rowCountsOfOnlySuccessfulBatchStatements * array contains only row counts of the successful executed * batch statement. If the last batch statement would fail, the * array would contain four integers in this example. This exception * was thrown by the jdbc driver and is the standard behaviour * how it should be. */ }

      catch (SQLException e)

      { ... }

      I would be very glad if you would take over this improvement in next release.
      For added/changed files please have a look at attached "patch.txt" file.

      Cheers,
      Martin

      Attachments

        1. patch_19-08-2005.txt
          14 kB
          Martin Zeltner
        2. patch.txt
          12 kB
          Martin Zeltner

        Activity

          People

            Unassigned Unassigned
            swisswheel Martin Zeltner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: