1 24 package org.objectweb.jalisto.se.impl.readonly; 25 26 import org.objectweb.jalisto.se.JalistoFactory; 27 import org.objectweb.jalisto.se.api.*; 28 import org.objectweb.jalisto.se.api.internal.*; 29 import org.objectweb.jalisto.se.api.internal.multi.LockManager; 30 import org.objectweb.jalisto.se.api.query.QueryManager; 31 import org.objectweb.jalisto.se.exception.IdentityException; 32 import org.objectweb.jalisto.se.exception.SchemaException; 33 import org.objectweb.jalisto.se.exception.TransactionException; 34 import org.objectweb.jalisto.se.impl.*; 35 import org.objectweb.jalisto.se.impl.InFileAddress; 36 import org.objectweb.jalisto.se.impl.server.PhysicalOid; 37 import org.objectweb.jalisto.se.impl.trace.Trace; 38 39 import java.util.ArrayList ; 40 import java.util.Collection ; 41 import java.util.Iterator ; 42 43 public class SessionReadOnlyImpl implements SessionInternal { 44 45 public SessionReadOnlyImpl(JalistoProperties properties) { 46 InternalFactory internalFactory = JalistoFactory.getInternalFactory(); 47 trace = internalFactory.getTracer(properties); 48 sessionId = internalFactory.getSessionId(properties, this); 49 trace.println(Trace.DEBUG, "CREATE A READ ONLY SESSION, id = {0}", sessionId); 50 trace.println(Trace.SESSION, "{0} : create new instance with properties : {1}", sessionId, properties); 51 fileAccess = internalFactory.getLogicalAccess(properties); 52 oidTable = internalFactory.getOidTable(properties); 53 repository = internalFactory.getMetaRepository(properties); 54 props = properties; 55 transaction = createTransaction(); 56 } 57 58 59 public void defineClass(ClassDescription classMetaDescription) { 60 throw new UnsupportedOperationException (); 61 } 62 63 public void removeClass(String fullClassName) { 64 throw new UnsupportedOperationException (); 65 } 66 67 public Collection getAllClassNames() { 68 return repository.getAllClassNames(); 69 } 70 71 public boolean isClassDefined(String fullQualifiedClassName) { 72 try { 73 repository.getClidFromClassName(fullQualifiedClassName); 74 return true; 75 } catch (SchemaException e) { 76 } 77 return false; 78 } 79 80 public String getClassNameFor(Object oid) { 81 trace.println(Trace.SESSION, "{0} : getClassNameFor({1})", sessionId, oid); 82 LogicalOid floid = getFloidFromOid(oid); 83 return repository.getClassNameFromClid(new Short (floid.getClid())); 84 } 85 86 public Object createObject(Object [] objectToCreate, Class objectClass) { 87 throw new UnsupportedOperationException (); 88 } 89 90 public Object createObject(Object [] objectToCreate, String objectClassName) { 91 throw new UnsupportedOperationException (); 92 } 93 94 public Object [] readObjectByOid(Object oid) { 95 return readObjectByOid(oid, true); 96 } 97 98 public Collection readObjectsByOids(Collection oids) { 99 Iterator oidsIterator = oids.iterator(); 100 ArrayList result = new ArrayList (); 101 while(oidsIterator.hasNext()) { 102 result.add(readObjectByOid(oidsIterator.next(), true)); 103 } 104 return result; 105 } 106 107 public boolean contains(Object oid) { 108 trace.println(Trace.SESSION, "{0} contains({1})", sessionId, oid); 109 checkValidity("contains", true); 110 return oidTable.containsFloid(sessionId, (LogicalOid) oid); 111 } 112 113 public Extent getExtent(Class theClass) { 114 String fullClassName = theClass.getName(); 115 return getExtent(fullClassName); 116 } 117 118 public Collection getFloidsFromClid(Object sessionId, Object clid) { 119 return oidTable.getFloidsFromClid(sessionId, clid, false); 120 } 121 122 public Long reserveFloids(short clid, int number) { 123 throw new UnsupportedOperationException (); 124 } 125 126 127 public void setOptimistic() { 128 throw new UnsupportedOperationException (); 129 } 130 131 public void setPessimistic() { 132 throw new UnsupportedOperationException (); 133 } 134 135 public void begin() { 136 trace.println(Trace.SESSION, "{0} : begin()", sessionId); 137 fileAccess.begin(sessionId); 138 } 139 140 public void commit() { 141 trace.println(Trace.SESSION, "{0} : commit()", sessionId); 142 fileAccess.commit(sessionId); 143 } 144 145 public void rollback() { 146 trace.println(Trace.SESSION, "{0} : rollback()", sessionId); 147 fileAccess.rollback(sessionId); 148 } 149 150 public void openSession() { 151 repository.addSession(this); 152 isOpen = true; 153 } 154 155 public void closeSession() { 156 repository.removeSession(this); 157 isOpen = false; 158 } 159 160 public boolean isOpen() { 161 return isOpen; 162 } 163 164 public QueryManager getQueryManager() { 165 if (queryManager == null) { 166 try { 167 String queryManagerClassName = props.getProperty(JalistoProperties.QUERY_MANAGER_CLASS_KEY); 168 queryManager = (QueryManager) Class.forName(queryManagerClassName).newInstance(); 169 queryManager.init(this); 170 } catch (InstantiationException e) { 171 trace.println(Trace.TRACE_ON, "cannot instanciate query manager : {0}", e.getMessage()); 172 } catch (IllegalAccessException e) { 173 trace.println(Trace.TRACE_ON, "cannot initialize query manager : {0}", e.getMessage()); 174 } catch (ClassNotFoundException e) { 175 trace.println(Trace.TRACE_ON, "cannot find query manager class : {0}", e.getMessage()); 176 } 177 } 178 return queryManager; 179 } 180 181 public Transaction currentTransaction() { 182 return transaction; 183 } 184 185 public LogicalSystemPageAccess getFileAccess() { 186 return fileAccess; 187 } 188 189 public MetaRepository getMetaRepository() { 190 return repository; 191 } 192 193 public SessionInternal getInternalSession() { 194 return this; 195 } 196 197 public JalistoProperties getProperties() { 198 return props; 199 } 200 201 public OidTable getOidTable() { 202 return oidTable; 203 } 204 205 public LockManager getLockManager() { 206 throw new UnsupportedOperationException (); 207 } 208 209 public boolean isNewBase() { 210 return fileAccess.getPhysicalAccess().isNewBase(); 211 } 212 213 public Object getSessionId() { 214 return sessionId; 215 } 216 217 public void clearObjectCache() { 218 } 219 220 public Object makeNewFileOid(LogicalOid floid) { 221 throw new UnsupportedOperationException (); 222 } 223 224 public void reorganize() { 225 throw new UnsupportedOperationException (); 226 } 227 228 public String toString() { 229 return "session " + sessionId; 230 } 231 232 public void checkValidity(String message, boolean mustBeActive) { 233 if (mustBeActive) { 234 if (!transaction.isActive()) { 235 throw new TransactionException("Transaction must be active during " + message); 236 } 237 } else { 238 if (transaction.isActive()) { 239 throw new TransactionException("Transaction must not be active during " + message); 240 } 241 } 242 } 243 244 public boolean isRemoteSession() { 245 return false; 246 } 247 248 251 252 public Object [] readObjectByOid(Object oid, boolean withCache) { 253 trace.println(Trace.SESSION, "{0} : readObjectByOid({1})", sessionId, oid); 254 checkValidity("readObjectByOid", true); 255 LogicalOid floid = getFloidFromOid(oid); 256 PhysicalOid fpoid = oidTable.getFpoid(sessionId, floid); 257 if (fpoid != null) { 258 DataWrapper datas = fileAccess.readDatas(sessionId, fpoid); 259 if (datas != null) { 260 return datas.getDatas(); 261 } 262 } 263 throw new IdentityException("the given oid " + oid + " doesn't exist in base"); 264 } 265 266 public Object [] refreshObjectByOid(Object oid) { 267 return readObjectByOid(oid); 268 } 269 270 public Object createObject(Object oid, Object [] objectToCreate) { 271 throw new UnsupportedOperationException (); 272 } 273 274 public void deleteObjectByOid(Object oid) { 275 throw new UnsupportedOperationException (); 276 } 277 278 public Extent getExtent(String fullClassName) { 279 trace.println(Trace.SESSION, "{0} : getExtent({1})", sessionId, fullClassName); 280 checkValidity("getExtent", true); 281 return new ExtentImpl(repository.getClidFromClassName(fullClassName), this); 282 } 283 284 public Object makeNewFileOid(Class objectClass) { 285 throw new UnsupportedOperationException (); 286 } 287 288 public Object makeNewFileOid(String objectClassName) { 289 throw new UnsupportedOperationException (); 290 } 291 292 public Object updateObjectByOid(Object oid, Object [] objectToUpdate) { 293 throw new UnsupportedOperationException (); 294 } 295 296 public void eraseStorage() { 297 throw new UnsupportedOperationException (); 298 } 299 300 303 304 private LogicalOid getFloidFromOid(Object oid) { 305 try { 307 return (LogicalOid) oid; 308 } catch (ClassCastException cce) { 309 throw new IdentityException("oid is not a FileLoid but a " + oid.getClass().getName()); 310 } 311 } 312 313 protected Transaction createTransaction() { 314 return new TransactionImpl(this); 315 } 316 317 private OidTable oidTable; 318 private LogicalSystemPageAccess fileAccess; 319 private InternalMetaRepository repository; 320 private QueryManager queryManager; 321 private Transaction transaction; 322 private boolean isOpen = false; 323 324 protected JalistoProperties props; 325 private Object sessionId; 326 327 protected Trace trace; 328 329 public static final InFileAddress BSTATE_IFA = new InFileAddress("bState"); 330 } 331 | Popular Tags |