@Override public String put(String key, String value) throws IllegalArgumentException { if (key == null || key.isEmpty() || key.contains("\n") || key.trim().isEmpty()) { throw new IllegalArgumentException(table.getTableName() + ": put: key is null"); } if (value == null || value.isEmpty() || value.trim().isEmpty() || value.contains("\n") || value.contains(" ")) { throw new IllegalArgumentException(table.getTableName() + ": put: value is null"); } String result; try { result = table.put(key, value); } catch (InvalidWorkingException e) { throw new IllegalArgumentException(e.getMessage()); } if (values.containsKey(key) && value.equals(values.get(key))) { changes.remove(key); } else { changes.put(key, value); } return result; }
public void rollChanges() { String oldValue; String newValue; for (String key : changes.keySet()) { oldValue = values.get(key); newValue = changes.get(key); if (oldValue != null && !oldValue.equals(newValue)) { try { table.put(key, oldValue); } catch (InvalidWorkingException e) { System.err.println( "Can not roll back key = \'" + key + "\' and value = \'" + newValue + "\'"); } } else if (oldValue == null && newValue != null) { try { table.remove(key); } catch (InvalidWorkingException e) { System.err.println( "Can not roll back deleting key = \'" + key + "\' and value = \'" + oldValue + "\'"); } } } }