1 24 package org.objectweb.jalisto.se.impl.mono; 25 26 import org.objectweb.jalisto.se.JalistoFactory; 27 import org.objectweb.jalisto.se.api.ClassDescription; 28 import org.objectweb.jalisto.se.api.JalistoProperties; 29 import org.objectweb.jalisto.se.api.internal.DataWrapper; 30 import org.objectweb.jalisto.se.exception.IdentityException; 31 import org.objectweb.jalisto.se.impl.LogicalOid; 32 import org.objectweb.jalisto.se.impl.server.PhysicalOid; 33 import org.objectweb.jalisto.se.impl.server.SessionImpl; 34 import org.objectweb.jalisto.se.impl.trace.Trace; 35 36 public class SessionMonoImpl extends SessionImpl { 37 public SessionMonoImpl(JalistoProperties properties) { 38 super(properties); 39 trace.println(Trace.DEBUG, "CREATE A MONO SESSION, id = {0}", sessionId); 40 } 41 42 public Object createObject(Object oid, Object [] objectToCreate) { 44 trace.println(Trace.SESSION, "{0} : createObject({1}, {2})", sessionId, oid, objectToCreate); 45 checkValidity("createObject", true); 46 47 DataWrapper datas = JalistoFactory.getInternalFactory().getNewDataWrapper(props, objectToCreate); 48 LogicalOid floid = getFloidFromOid(oid); 49 PhysicalOid fpoid = oidTable.getFpoid(sessionId, floid); 50 cache.put(floid, datas); 51 if (queryManager != null) { 52 ClassDescription meta = repository.getPersistentClassMetaDescription(fpoid.getClid()); 53 queryManager.getIndexManager().createObject(meta, floid, objectToCreate); 54 } 55 fileAccess.insertDatas(sessionId, fpoid, datas); 56 oidTable.markAsCreated(sessionId, floid); 57 return floid; 58 } 59 60 public void deleteObjectByOid(Object oid) { 61 trace.println(Trace.SESSION, "{0} : deleteObjectByOid({1})", sessionId, oid); 62 checkValidity("deleteObjectByOid", true); 63 64 LogicalOid floid = getFloidFromOid(oid); 65 PhysicalOid fpoid = oidTable.getFpoid(sessionId, floid); 66 Object [] objectToRemove = null; 67 if (cache.containsKey(floid)) { 68 objectToRemove = ((DataWrapper) cache.remove(floid)).getDatas(); 69 } 70 if (fpoid != null) { 71 fileAccess.deleteDatas(sessionId, fpoid); 72 if (queryManager != null) { 73 ClassDescription meta = repository.getPersistentClassMetaDescription(fpoid.getClid()); 74 if (objectToRemove == null) { 75 objectToRemove = fileAccess.readDatas(sessionId, fpoid).getDatas(); 76 } 77 queryManager.getIndexManager().removeObject(meta, floid, objectToRemove); 78 } 79 oidTable.removeFloid(sessionId, floid); 80 } 81 } 82 83 public Object makeNewFileOid(Class objectClass) { 85 return makeNewFileOid(objectClass.getName()); 86 } 87 88 public Object makeNewFileOid(String objectClassName) { 89 trace.println(Trace.SESSION, "{0} : makeNewFileOid({1})", sessionId, objectClassName); 90 checkValidity("makeNewFileOid", true); 91 Object theClid = repository.getClidFromClassName(objectClassName); 92 LogicalOid floid = oidTable.allocateNewFloid(((Short ) theClid).shortValue()); 93 PhysicalOid fpoid = fileAccess.allocateNewFpoid(sessionId, theClid); 94 oidTable.insertFpoid(sessionId, floid, fpoid); 95 return floid.getClone(); 96 } 97 98 public Object makeNewFileOid(LogicalOid floid) { 99 trace.println(Trace.SESSION, "{0} : makeNewFileOid({1})", sessionId, floid); 100 checkValidity("makeNewFileOid", true); 101 LogicalOid clone = floid.getClone(); 102 Object theClid = new Short (clone.getClid()); 103 PhysicalOid fpoid = fileAccess.allocateNewFpoid(sessionId, theClid); 104 oidTable.insertFpoid(sessionId, clone, fpoid); 105 return floid; 106 } 107 108 public Object [] readObjectByOid(Object oid, boolean withCache) { 109 trace.println(Trace.SESSION, "{0} : readObjectByOid({1})", sessionId, oid); 110 checkValidity("readObjectByOid", true); 111 112 LogicalOid floid = getFloidFromOid(oid); 113 if (withCache && cache.containsKey(floid)) { 114 return ((DataWrapper) cache.get(floid)).getDatas(); 115 } else { 116 PhysicalOid fpoid = oidTable.getFpoid(sessionId, floid); 117 if (fpoid != null) { 118 DataWrapper datas = fileAccess.readDatas(sessionId, fpoid); 119 if (datas != null) { 120 if (withCache) { 121 cache.put(floid, datas); 122 } 123 return datas.getDatas(); 124 } 125 } 126 throw new IdentityException("the given oid " + oid + " doesn't exist in this Jalisto datastore"); 127 } 128 } 129 130 public Object updateObjectByOid(Object oid, Object [] objectToUpdate) { 131 trace.println(Trace.SESSION, "{0} : readObjectByOid({1}, {2})", sessionId, oid, objectToUpdate); 132 checkValidity("updateObjectByOid", true); 133 checkSerialisable(objectToUpdate); 134 135 LogicalOid floid = getFloidFromOid(oid); 136 PhysicalOid fpoid = oidTable.getFpoid(sessionId, floid); 137 DataWrapper datas = JalistoFactory.getInternalFactory().getNewDataWrapper(props, objectToUpdate); 138 if (fpoid != null) { 139 PhysicalOid updatedFpoid = fileAccess.updateDatas(sessionId, fpoid, datas); 140 cache.put(floid, datas); 141 if (!updatedFpoid.equals(fpoid)) { 142 oidTable.updatePoid(sessionId, floid, updatedFpoid); 143 } 144 if (queryManager != null) { 145 ClassDescription meta = repository.getPersistentClassMetaDescription(fpoid.getClid()); 146 Object [] oldValue = fileAccess.readDatas(sessionId, fpoid).getDatas(); 147 queryManager.getIndexManager().updateObject(meta, floid, oldValue, objectToUpdate); 148 } 149 return floid.getClone(); 150 } 151 throw new IdentityException("the given oid " + oid + " doesn't exist in this Jalisto datastore"); 152 } 153 } 154 | Popular Tags |