diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java index fd85ce3..d4b4675 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java @@ -24,6 +24,7 @@ import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.closeR import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.closeStatement; import java.io.UnsupportedEncodingException; +import java.sql.BatchUpdateException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -270,6 +271,7 @@ public class RDBDocumentStoreJDBC { + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); List sortedDocs = sortDocuments(documents); + int[] results; try { for (T document : sortedDocs) { String data = this.ser.asString(document); @@ -297,21 +299,23 @@ public class RDBDocumentStoreJDBC { } stmt.addBatch(); } - int[] results = stmt.executeBatch(); - - Set succesfullyInserted = new HashSet(); - for (int i = 0; i < sortedDocs.size(); i++) { - int result = results[i]; - if (result != 1 && result != Statement.SUCCESS_NO_INFO) { - LOG.error("DB insert failed for {}: {}", tmd.getName(), sortedDocs.get(i).getId()); - } else { - succesfullyInserted.add(sortedDocs.get(i).getId()); - } - } - return succesfullyInserted; + results = stmt.executeBatch(); + } catch (BatchUpdateException e) { + LOG.debug("Some of the batch updates failed", e); + results = e.getUpdateCounts(); } finally { stmt.close(); } + Set succesfullyInserted = new HashSet(); + for (int i = 0; i < results.length; i++) { + int result = results[i]; + if (result != 1 && result != Statement.SUCCESS_NO_INFO) { + LOG.error("DB insert failed for {}: {}", tmd.getName(), sortedDocs.get(i).getId()); + } else { + succesfullyInserted.add(sortedDocs.get(i).getId()); + } + } + return succesfullyInserted; } /** @@ -338,11 +342,12 @@ public class RDBDocumentStoreJDBC { assertNoDuplicatedIds(documents); Set successfulUpdates = new HashSet(); + List updatedKeys = new ArrayList(); + int[] batchResults; PreparedStatement stmt = connection.prepareStatement("update " + tmd.getName() + " set MODIFIED = ?, HASBINARY = ?, DELETEDONCE = ?, MODCOUNT = ?, CMODCOUNT = ?, DSIZE = ?, DATA = ?, BDATA = ? where ID = ? and MODCOUNT = ?"); try { - List updatedKeys = new ArrayList(); for (T document : sortDocuments(documents)) { Long modcount = (Long) document.get(MODCOUNT); if (modcount == 1) { @@ -377,19 +382,21 @@ public class RDBDocumentStoreJDBC { stmt.addBatch(); updatedKeys.add(document.getId()); } - - int[] batchResults = stmt.executeBatch(); - - for (int i = 0; i < batchResults.length; i++) { - int result = batchResults[i]; - if (result == 1 || result == Statement.SUCCESS_NO_INFO) { - successfulUpdates.add(updatedKeys.get(i)); - } - } + batchResults = stmt.executeBatch(); + } catch (BatchUpdateException e) { + LOG.debug("Some of the batch updates failed", e); + batchResults = e.getUpdateCounts(); } finally { stmt.close(); } + for (int i = 0; i < batchResults.length; i++) { + int result = batchResults[i]; + if (result == 1 || result == Statement.SUCCESS_NO_INFO) { + successfulUpdates.add(updatedKeys.get(i)); + } + } + if (upsert) { List remainingDocuments = new ArrayList(documents.size() - successfulUpdates.size()); for (T doc : documents) {