@Override public void rollback(Change change) { OperationType operationType = change.getOperationType(); try { switch (operationType) { case CREATE: { Object targetObject = change.getNewObject(); Query removeQuery = createFindQuery(targetObject); Object removedObject = mongoOperations.findOne(removeQuery, targetObject.getClass()); if (removedObject != null) { mongoOperations.remove(removedObject); } break; } case UPDATE: case DELETE: { mongoOperations.save(change.getOldObject()); break; } } } catch (Exception exc) { exc.printStackTrace(); } }
@Override public void commit(Change change) { if (change.getOperationType() != OperationType.DELETE) { try { Object targetObject = change.getNewObject(); Query removeQuery = createFindQuery(targetObject); Update update = new Update().unset("tid"); mongoOperations.findAndModify(removeQuery, update, targetObject.getClass()); } catch (Exception exc) { throw new RuntimeException(exc); } } }