Commit 476ab027 authored by akrherz's avatar akrherz

OF-1229 Safeguard JDBC.executeBatch() calls on empty batch

OF-955 updated the HSQL library and it introduced a JDBC requirement that
executeBatch() calls actually have batched items to do.  It appears there
is no API available to check for if batched statements have been added, so
we hack in a simple sentinal to safegaurd calls to `executeBatch`.  Thankfully,
only PubSubPersistenceManager.java uses this API.  Otherwise, an option is to
set `allow_empty_batch` on the connection parameters.
parent 626417c6
......@@ -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