Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320413

Summary: UPDATE batching on MySQL appears to be broken
Product: z_Archived Reporter: Adrian Goerler <adrian.goerler>
Component: EclipselinkAssignee: Project Inbox <eclipselink.foundation-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sabine.heider
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: MySQL
Bug Depends on: 320643    
Bug Blocks:    
Attachments:
Description Flags
proposed patch and regression test
none
proposed patch none

Description Adrian Goerler CLA 2010-07-20 12:05:04 EDT
UPDATE batching on MySQL appears to be broken:

1) In the MySQLPlatform, the method

canBatchWriteWithOptimisticLocking() does not override the method DatabasePlatform.canBatchWriteWithOptimisticLocking(DatabaseCall call).

2) The executeBatch does not seem to be able to properly determine the number of rows changed:

public int executeBatch(Statement statement, boolean isStatementPrepared) throws java.sql.SQLException {
       int[] updateResult = statement.executeBatch();
       int updateCount = 0;
       for (int count : updateResult){
           if (count == Statement.SUCCESS_NO_INFO){
               count = 1;
           }
           updateCount+=count;
       }
       return updateCount;
    }

I assume that rows, for which the optimistic verification fails, will also yield SUCCESS_NO_INFO.
Comment 1 Adrian Goerler CLA 2010-07-22 10:39:39 EDT
An investigation showed that while issue 1) is valid, issue 2) seems not to occur as the updateResult[] does not contain SUCCESS_NO_INFO but non-negative values.
Comment 2 Adrian Goerler CLA 2010-07-22 10:58:02 EDT
Created attachment 174990 [details]
proposed patch and regression test

As a regresssion test, the patch enables JDBC-batching in the eclipselink.jpa.wdf.test testsuite.

The test TestDeleteQuery had to be modified:
if JDBC batching is enabled EclipseLink also batches statements generated by a JPQL delete query. Due to the batching, it is not possible any longer to determine the exact update count. Hence, checking the update count is disabled in the test.

Also, the executeUpdate method of the MySQL Platform needs to be modified for Statement batches: here, the update count is just the number of statements in the batch.
Comment 3 Adrian Goerler CLA 2010-07-23 08:33:51 EDT
Created attachment 175060 [details]
proposed patch

Moved the regression tests to bug 320643.
Comment 4 Adrian Goerler CLA 2010-09-20 08:32:44 EDT
Checked in in trunk at #8217

Reviewed by Gordon
Tests on MySQL (core, jpa, jpa.wdf): OK
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:02:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink