Commit 15f19d80 authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #686 from akrherz/of1229

OF-1229 Safeguard JDBC.executeBatch() calls on empty batch
parents 626417c6 476ab027
......@@ -1314,9 +1314,10 @@ public class PubSubPersistenceManager {
try {
LinkedListNode<PublishedItem> delHead = delItem.previous;
pstmt = con.prepareStatement(DELETE_ITEM);
Boolean hasBatchItems = false;
while (delItem != delHead)
{
hasBatchItems = true;
PublishedItem item = delItem.object;
pstmt.setString(1, item.getNode().getService().getServiceID());
pstmt.setString(2, encodeNodeID(item.getNode().getNodeID()));
......@@ -1325,7 +1326,7 @@ public class PubSubPersistenceManager {
delItem = delItem.next;
}
pstmt.executeBatch();
if (hasBatchItems) pstmt.executeBatch();
} catch (SQLException ex) {
log.error("Failed to delete published item(s) from DB", ex);
// do not re-throw here; continue with insert operation if possible
......@@ -1359,8 +1360,10 @@ public class PubSubPersistenceManager {
PublishedItem item = null;
try {
pstmt = con.prepareStatement(ADD_ITEM);
Boolean hasBatchItems = false;
while (addItem != addHead)
{
hasBatchItems = true;
wrappedItem = addItem.object;
item = wrappedItem.get();
pstmt.setString(1, item.getNode().getService().getServiceID());
......@@ -1386,7 +1389,7 @@ public class PubSubPersistenceManager {
}
addItem = addItem.next;
}
if (batch) { pstmt.executeBatch(); }
if (batch && hasBatchItems) { pstmt.executeBatch(); }
} catch (SQLException se) {
log.error("Failed to persist published items as batch; will retry individually", se);
// caught by caller; should not cause a transaction rollback
......@@ -1880,8 +1883,10 @@ public class PubSubPersistenceManager {
PreparedStatement purgeNode = con
.prepareStatement(getPurgeStatement(DbConnectionManager.getDatabaseType()));
Boolean hasBatchItems = false;
while (rs.next())
{
hasBatchItems = true;
String svcId = rs.getString(1);
String nodeId = rs.getString(2);
int maxItems = rs.getInt(3);
......@@ -1890,7 +1895,7 @@ public class PubSubPersistenceManager {
purgeNode.addBatch();
}
purgeNode.executeBatch();
if (hasBatchItems) purgeNode.executeBatch();
}
catch (Exception sqle)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment