1 24 25 package org.objectweb.perseus; 26 27 import org.objectweb.perseus.persistence.api.StorageManager; 28 import org.objectweb.perseus.persistence.api.ConnectionHolder; 29 import org.objectweb.perseus.persistence.api.PersistenceException; 30 import org.objectweb.perseus.persistence.api.WorkingSet; 31 import org.objectweb.perseus.persistence.api.State; 32 33 import java.util.HashSet ; 34 35 public class StorageManagerTestImpl implements StorageManager { 36 37 38 HashSet persObjs; 39 40 public StorageManagerTestImpl() { 41 persObjs = new HashSet (); 42 } 43 44 public Object export(ConnectionHolder context, Object obj) throws PersistenceException { 45 Object id; 46 if (obj instanceof PString) { 47 id = new PString((PString) obj); 48 } else if (obj instanceof PInteger) { 49 id = new PInteger((PInteger) obj); 50 } else 51 throw new PersistenceException("Illegal persistent type"); 52 persObjs.add(id); 53 return id; 54 } 55 56 public Object export(ConnectionHolder context, Object obj, Object hints) throws PersistenceException { 57 return export(context, obj); 58 } 59 60 public void unexport(ConnectionHolder context, Object oid) throws PersistenceException { 61 if (!persObjs.remove(oid)) 62 throw new PersistenceException("Not a persistent object"); 63 } 64 65 public void unexport(ConnectionHolder context, Object oid, Object hints) throws PersistenceException { 66 unexport(context, oid); 67 } 68 69 public void read(ConnectionHolder context, Object oid, State state) throws PersistenceException { 70 if (state instanceof PStringState) { 71 ((PStringState) state).set((PString) oid); 72 } else if (state instanceof PIntegerState) { 73 ((PIntegerState) state).set((PInteger) oid); 74 } else 75 throw new PersistenceException("Illegal persistent type"); 76 } 77 78 public void read(WorkingSet context, Object oid, State state) throws PersistenceException { 79 if (state instanceof PStringState) { 80 ((PStringState) state).set((PString) oid); 81 } else if (state instanceof PIntegerState) { 82 ((PIntegerState) state).set((PInteger) oid); 83 } else 84 throw new PersistenceException("Illegal persistent type"); 85 } 86 87 public void write(ConnectionHolder context, Object oid, State state) throws PersistenceException { 88 if (state instanceof PStringState) { 89 ((PString) oid).set((PString) state); 90 } else if (state instanceof PIntegerState) { 91 ((PInteger) oid).set((PInteger) state); 92 } else 93 throw new PersistenceException("Illegal persistent type"); 94 } 95 96 public void beginWS(WorkingSet ws) { 97 } 98 99 public void endWS(WorkingSet ws) { 100 } 101 } 102 | Popular Tags |