01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.persistence.impl;
06:
07: import com.tc.memorydatastore.client.MemoryDataStoreClient;
08: import com.tc.objectserver.persistence.api.PersistentMapStore;
09:
10: public class MemoryStorePersistentMapStore implements
11: PersistentMapStore {
12: private MemoryDataStoreClient memoryStore;
13:
14: public MemoryStorePersistentMapStore(
15: MemoryDataStoreClient memoryStore) {
16: this .memoryStore = memoryStore;
17: }
18:
19: public String get(String key) {
20: if (key == null) {
21: throw new NullPointerException();
22: }
23:
24: byte[] rtn = memoryStore.get(key.getBytes());
25: if (rtn == null)
26: return (null);
27: return (rtn.toString());
28: }
29:
30: public void put(String key, String value) {
31: if (key == null || value == null) {
32: throw new NullPointerException();
33: }
34:
35: memoryStore.put(key.getBytes(), value.getBytes());
36: }
37:
38: public boolean remove(String key) {
39: if (key == null) {
40: throw new NullPointerException();
41: }
42:
43: // check existence before remove
44: if (get(key) != null) {
45: memoryStore.remove(key.getBytes());
46: return (true);
47: } else {
48: return (false);
49: }
50: }
51:
52: }
|