1 24 package org.objectweb.jalisto.se.storage.memory; 25 26 import org.objectweb.jalisto.se.api.internal.JalistoObject; 27 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess; 28 import org.objectweb.jalisto.se.api.JalistoProperties; 29 import org.objectweb.jalisto.se.exception.JalistoException; 30 import org.objectweb.jalisto.se.impl.InFileAddress; 31 import org.objectweb.jalisto.se.JalistoFactory; 32 import org.objectweb.jalisto.se.impl.trace.Trace; 33 34 import java.util.*; 35 36 public class PhysicalFileAccessMemoryImpl implements PluggablePhysicalFileAccess { 37 38 public PhysicalFileAccessMemoryImpl() { 39 } 40 41 public void init(JalistoProperties properties) { 42 file = new HashMap(); 43 this.trace = JalistoFactory.getInternalFactory().getTracer(properties); 44 trace.println(Trace.TRACE_ON, "USE IN MEMORY PHYSICAL IMPLEMENTATION"); 45 } 46 47 public boolean isNewBase() { 48 return true; 49 } 50 51 public void reorganize() { 52 } 53 54 public void deleteFileObject(InFileAddress ifa) { 55 trace.println(Trace.PHYSICAL, "memory deleteFileObject : ifa = {0}", ifa); 56 if (!file.containsKey(ifa.getAddress())) { 57 throw new JalistoException("could not delete object at " + ifa); 58 } 59 file.remove(ifa.getAddress()); 60 } 61 62 public void insertFileObject(InFileAddress ifa, JalistoObject fo) { 63 trace.println(Trace.PHYSICAL, "memory insertFileObject : ifa = {0}", ifa); 64 if (file.containsKey(ifa.getAddress())) { 65 throw new JalistoException("already contains object at " + ifa + " : could not insert value"); 66 } 67 file.put(ifa.getAddress(), fo); 68 } 69 70 public JalistoObject readFileObjectAt(InFileAddress ifa) { 71 trace.println(Trace.PHYSICAL, "memory readFileObjectAt : ifa = {0}", ifa); 72 if (file.containsKey(ifa.getAddress())) { 73 return (JalistoObject) file.get(ifa.getAddress()); 74 } 75 throw new JalistoException("could not read object at " + ifa); 76 } 77 78 public void updateFileObject(InFileAddress ifa, JalistoObject fo) { 79 trace.println(Trace.PHYSICAL, "memory updateFileObject : ifa = {0}", ifa); 80 if (!file.containsKey(ifa.getAddress())) { 81 throw new JalistoException("could not update object " + fo); 82 } 83 file.put(ifa.getAddress(), fo); 84 } 85 86 public void startCommit() { 87 } 88 89 public void commit() { 90 } 91 92 public void rollback() { 93 throw new JalistoException("don't support rollback with Memory physical access"); 94 } 95 96 public void close() { 97 } 98 99 public void open() { 100 } 101 102 public Collection getKeysStartingWith(String filter) { 103 trace.println(Trace.PHYSICAL, "memory getKeysStartingWith : filter = {0}", filter); 104 Collection result = new ArrayList(); 105 Iterator keys = file.keySet().iterator(); 106 while (keys.hasNext()) { 107 String key = (String ) keys.next(); 108 if (key.startsWith(filter)) { 109 result.add(key); 110 } 111 } 112 return result; 113 } 114 115 116 private Map file; 117 private Trace trace; 118 } 119 | Popular Tags |