예제 #1
0
  @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;
  }
예제 #2
0
 @Override
 public String get(String key) throws IllegalArgumentException {
   if (key == null || key.isEmpty() || key.contains("\n") || key.trim().isEmpty()) {
     throw new IllegalArgumentException(table.getTableName() + ": get: key is null");
   }
   return table.get(key);
 }
예제 #3
0
 @Override
 public void open() throws IOException {
   table.open();
   for (String key : table.keySet()) {
     values.put(key, table.get(key));
   }
 }
예제 #4
0
 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 + "\'");
       }
     }
   }
 }
예제 #5
0
 @Override
 public int size() {
   return table.size();
 }
예제 #6
0
 @Override
 public void close() throws IOException {
   table.close();
   changes.clear();
 }
예제 #7
0
 @Override
 public String getName() {
   return table.getTableName();
 }