private void update(Event event) throws SQLException { boolean isPossibleDuplicate = event.isPossibleDuplicate(); int count = 0; String sql = getSql(event); // add where clause sql += " where oid = " + event.getPrimaryKey()[0]; Log.getLogWriter().info("update to derby: " + sql); try { count = stmt.get().executeUpdate(sql); } catch (SQLException se) { if (se.getSQLState().equals("23503")) { Log.getLogWriter() .info( "get foreign key constraint violation, " + "let gemfirexd perform the constraint check as well"); // it is possible to update the foreign key field return; } else throw se; } if (count != 1 && !isPossibleDuplicate && !SQLTest.setTx) // with default txn isolation, #43725 may be hit (some rows have been updated/deleted // in the back end thru writer but still exist in gfxd due to txn roll back // another update will cause the update to backend to fail to update any throw new TestException( "update from writer does not " + "update the corresponding row in back_end, updated row is " + count); }
@Override public void onEvent(Event event) throws SQLException { Event.Type type = event.getType(); String eventType = null; boolean isPossibleDuplicate = event.isPossibleDuplicate(); if (isPossibleDuplicate && !SQLTest.isHATest) { throw new TestException("Got possible duplicate event but it is " + "not a HA Test"); } switch (type) { case BEFORE_DELETE: delete(event); break; case BEFORE_INSERT: insert(event); break; case BEFORE_UPDATE: update(event); break; case AFTER_UPDATE: eventType = "AFTER_UPDATE"; // fall through case AFTER_INSERT: eventType = "AFTER_INSERT"; // fall through case AFTER_DELETE: eventType = "AFTER_DELETE"; // fall through default: throw new TestException("Writer got a 'none_before' callback event: " + eventType); } dConn.get().commit(); // do not hold the lock }
private void delete(Event event) throws SQLException { List<Object> newRow = event.getNewRow(); boolean isPossibleDuplicate = event.isPossibleDuplicate(); int count = 0; if (newRow != null) throw new TestException("BEFORE_DELETE is invoked, but " + "newRow is not null: " + newRow); deleteStmt.get().setInt(1, (Integer) event.getPrimaryKey()[0]); // through primary key Log.getLogWriter() .info("deleting from buyorders in derby where oid =" + (Integer) event.getPrimaryKey()[0]); count = deleteStmt.get().executeUpdate(); Log.getLogWriter().info("deleted " + count + " row"); if (count != 1 && !isPossibleDuplicate && !SQLTest.setTx) throw new TestException( "delete from writer does not " + "delete the corresponding row in back_end, deleted row is " + count); }
private void insert(Event event) throws SQLException { List<Object> oldRow = event.getOldRow(); List<Object> newRow = event.getNewRow(); boolean isPossibleDuplicate = event.isPossibleDuplicate(); // for HA case, before insert check if record has been inserted already to avoid duplicate if (isPossibleDuplicate) { ResultSet rs = stmt.get() .executeQuery( "select * from trade.buyorders where oid = " + (Integer) event.getPrimaryKey()[0]); if (rs.next()) { Log.getLogWriter().info("this row has been inserted already " + newRow); // if it is there, do not insert again } else { doInsert(oldRow, newRow, isPossibleDuplicate); } } else doInsert(oldRow, newRow, isPossibleDuplicate); }