@@ -425,8 +425,9 @@ public synchronized boolean sendBatch() {
425425 Iterator <Entry <Plot , Queue <UniqueStatement >>> iterator =
426426 this .plotTasks .entrySet ().iterator ();
427427 while (iterator .hasNext ()) {
428+ Entry <Plot , Queue <UniqueStatement >> entry = null ;
428429 try {
429- Entry < Plot , Queue < UniqueStatement >> entry = iterator .next ();
430+ entry = iterator .next ();
430431 Queue <UniqueStatement > tasks = entry .getValue ();
431432 if (tasks .isEmpty ()) {
432433 iterator .remove ();
@@ -458,6 +459,9 @@ public synchronized boolean sendBatch() {
458459 LOGGER .error ("============ DATABASE ERROR ============" );
459460 LOGGER .error ("There was an error updating the database." );
460461 LOGGER .error (" - It will be corrected on shutdown" );
462+ LOGGER .error (" - Task: {}, Plot: {}" ,
463+ task != null ? task .method : "null" ,
464+ entry != null ? entry .getKey ().getId ().toCommaSeparatedString () : "unknown" );
461465 LOGGER .error ("========================================" );
462466 e .printStackTrace ();
463467 LOGGER .error ("========================================" );
@@ -1097,7 +1101,12 @@ public void execute(PreparedStatement statement) {
10971101
10981102 @ Override
10991103 public void addBatch (PreparedStatement statement ) throws SQLException {
1100- if (statement .execute () || statement .getUpdateCount () > 0 ) {
1104+ int updateCount = 0 ;
1105+ boolean hasResultSet = statement .execute ();
1106+ if (!hasResultSet ) {
1107+ updateCount = statement .getUpdateCount ();
1108+ }
1109+ if (hasResultSet || updateCount > 0 ) {
11011110 try (ResultSet keys = supportsGetGeneratedKeys ? statement .getGeneratedKeys () : statement .getResultSet ()) {
11021111 if (keys .next ()) {
11031112 plot .temp = keys .getInt (1 );
@@ -1121,7 +1130,21 @@ public PreparedStatement get() throws SQLException {
11211130 }
11221131 return ;
11231132 }
1133+ LOGGER .warn (
1134+ "createPlotSafe: INSERT succeeded (updateCount={}) but no generated key returned for plot {} in area {} (attempted owner: {})" ,
1135+ updateCount ,
1136+ plot .getId ().toCommaSeparatedString (),
1137+ plot .getArea (),
1138+ plot .getOwnerAbs ()
1139+ );
11241140 }
1141+ } else {
1142+ LOGGER .warn (
1143+ "createPlotSafe: plot {} in area {} already exists in database, INSERT was no-op (attempted owner: {})" ,
1144+ plot .getId ().toCommaSeparatedString (),
1145+ plot .getArea (),
1146+ plot .getOwnerAbs ()
1147+ );
11251148 }
11261149 if (failure != null ) {
11271150 failure .run ();
0 commit comments