1 24 package org.objectweb.jalisto.se.impl.readonly; 25 26 import org.objectweb.jalisto.se.api.JalistoProperties; 27 import org.objectweb.jalisto.se.api.internal.OidTable; 28 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess; 29 import org.objectweb.jalisto.se.exception.JalistoException; 30 import org.objectweb.jalisto.se.impl.*; 31 import org.objectweb.jalisto.se.impl.server.IdentityProvider; 32 import org.objectweb.jalisto.se.impl.InFileAddress; 33 import org.objectweb.jalisto.se.impl.server.PhysicalOid; 34 import org.objectweb.jalisto.se.impl.server.oid.OidInfo; 35 import org.objectweb.jalisto.se.impl.server.page.OidPage; 36 import org.objectweb.jalisto.se.impl.trace.Trace; 37 import org.objectweb.jalisto.se.JalistoFactory; 38 39 import java.util.*; 40 41 public class OidTableReadOnlyImpl implements OidTable { 42 43 private OidTableReadOnlyImpl(InternalPhysicalFileAccess physicalAccess, JalistoProperties properties) { 44 tracer = JalistoFactory.getInternalFactory().getTracer(properties); 45 atSize = properties.getOidTableSize(); 46 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : create new instance with size = {0}", 47 new Integer (atSize)); 48 49 floidTable = JalistoFactory.getInternalFactory().getCache(properties, atSize, "atCache"); 50 this.physicalAccess = physicalAccess; 51 } 52 53 public LogicalOid allocateNewFloid(short clid) { 54 throw new UnsupportedOperationException (); 55 } 56 57 public void insertFpoid(Object sessionId, LogicalOid floid, PhysicalOid fpoid) { 58 throw new UnsupportedOperationException (); 59 } 60 61 public void updatePoid(Object sessionId, LogicalOid floid, PhysicalOid newFpoid) { 62 throw new UnsupportedOperationException (); 63 } 64 65 public void removeFloid(Object sessionId, LogicalOid floid) { 66 throw new UnsupportedOperationException (); 67 } 68 69 public void markAsCreated(Object sessionId, LogicalOid floid) { 70 throw new UnsupportedOperationException (); 71 } 72 73 74 public Collection getFloidsFromClid(Object sessionId, Object clid, boolean fullyTransactionnal) { 75 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : getFloidsFromClid({0})", clid); 76 Collection workingExtent = new ArrayList(); 77 Iterator oidIfaList = physicalAccess.getKeysStartingWith(IFA_PREFIXE + clid, true).iterator(); 78 while (oidIfaList.hasNext()) { 79 InFileAddress ifa = new InFileAddress((String ) oidIfaList.next()); 80 ifa.setFileIndex(JalistoProperties.OID_INDEX); 81 OidPage oidPage = (OidPage) physicalAccess.readFileObjectAt(ifa); 82 Object [] infos = oidPage.getAllDatas(); 83 for (int j = 0; j < infos.length; j++) { 84 OidInfo info = (OidInfo) infos[j]; 85 if (info != null) { 86 if (info.getFpoid().hasClidEqualsWith(clid)) { 87 workingExtent.add(info.getFloid()); 88 } 89 } 90 } 91 } 92 return workingExtent; 93 } 94 95 public Collection getFloidsFromClid(Object sessionId, Object clid, ExtentImpl extent, int number) { 96 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : getFloidsFromClid({0})", clid); 97 Collection workingExtent = new ArrayList(); 98 boolean continueSearching = true; 99 String startingAddress = extent.getStartingAddress(); 100 LogicalOid lastFloid = extent.getLastFloid(); 101 String oidPageAddress = null; 102 Iterator oidIfaList = physicalAccess.getKeysStartingWith(IFA_PREFIXE + clid, true).iterator(); 103 while (oidIfaList.hasNext() && continueSearching) { 104 oidPageAddress = (String ) oidIfaList.next(); 105 if (oidPageAddress.compareTo(startingAddress) >= 0) { 106 InFileAddress ifa = new InFileAddress(oidPageAddress); 107 ifa.setFileIndex(JalistoProperties.OID_INDEX); 108 OidPage oidPage = (OidPage) physicalAccess.readFileObjectAt(ifa); 109 Object [] infos = oidPage.getAllDatas(); 110 for (int j = 0; (j < infos.length) && continueSearching; j++) { 111 OidInfo info = (OidInfo) infos[j]; 112 if (info != null) { 113 LogicalOid floid = info.getFloid(); 114 if (info.getFpoid().hasClidEqualsWith(clid)) { 115 if ((lastFloid == null) || (floid.compareTo(lastFloid) > 0)) { 116 workingExtent.add(floid); 117 } 118 } 119 } 120 if (workingExtent.size() >= number) { 121 continueSearching = false; 122 } 123 } 124 } 125 } 126 extent.setStartingAddress(oidPageAddress); 127 return workingExtent; 128 } 129 130 public synchronized PhysicalOid getFpoid(Object sessionId, LogicalOid floid) { 131 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : getFpoid({0})", floid); 132 if (!floidTable.containsKey(floid)) { 133 if (!loadOidPage(floid)) { 134 return null; 135 } 136 } 137 OidInfo oidInfo = (OidInfo) floidTable.get(floid); 138 if (oidInfo != null) { 139 return oidInfo.getFpoid(); 140 } else { 141 return null; 142 } 143 } 144 145 public boolean containsFloid(Object sessionId, LogicalOid floid) { 146 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : containsFloid({0})", floid); 147 if (!floidTable.containsKey(floid)) { 148 return (!loadOidPage(floid)); 149 } 150 OidInfo oidInfo = (OidInfo) floidTable.get(floid); 151 if (oidInfo != null) { 152 return (!oidInfo.getActionCaller().isDelete()); 153 } else { 154 return false; 155 } 156 } 157 158 public PhysicalOid getDeletedFpoid(Object sessionId, LogicalOid floid) { 159 throw new UnsupportedOperationException (); 160 } 161 162 public void setUpdate(Object sessionId, LogicalOid floid, short value) { 163 throw new UnsupportedOperationException ("should not be used in this implementation"); 164 } 165 166 public short getUpdate(Object sessionId, LogicalOid floid, boolean transactionnal) { 167 throw new UnsupportedOperationException ("should not be used in this implementation"); 168 } 169 170 public synchronized void checkStateFromBase(Object sessionId, JalistoProperties properties) { 171 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : getStateFromBase()"); 172 floidTable = JalistoFactory.getInternalFactory().getCache(properties, atSize, "atCache"); 173 readAtTable(); 174 } 175 176 public Map getOidTable() { 177 return floidTable; 178 } 179 180 181 public String toString() { 182 StringBuffer sb = new StringBuffer (); 183 sb.append("OidTableReadOnlyImpl : \n"); 184 sb.append("\tfloid list : ").append(floidTable).append("\n"); 185 return sb.toString(); 186 } 187 188 189 192 193 private synchronized boolean loadOidPage(LogicalOid floid) { 194 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : loadOidPage({0})", floid); 195 return false; 215 } 216 217 private synchronized void readAtTable() { 218 tracer.println(Trace.OIDTABLE, "OidTableReadOnlyImpl : readAtTable()"); 219 int dataRead = 0; 220 Iterator oidIfaList = physicalAccess.getKeysStartingWith(IFA_PREFIXE, true).iterator(); 221 while (oidIfaList.hasNext()) { 222 InFileAddress ifa = new InFileAddress((String ) oidIfaList.next()); 223 ifa.setFileIndex(JalistoProperties.OID_INDEX); 224 OidPage oidPage = (OidPage) physicalAccess.readFileObjectAt(ifa); 225 Object [] infos = oidPage.getAllDatas(); 226 for (int i = 0; i < infos.length; i++) { 227 OidInfo info = (OidInfo) infos[i]; 228 if (info != null) { 229 floidTable.put(info.getFloid(), info); 230 dataRead++; 231 if (dataRead == atSize) { 232 return; 233 } 234 } 235 } 236 } 237 } 238 239 public void begin(Object sessionId) { 240 } 241 242 public void commit(Object sessionId) { 243 } 244 245 public void rollback(Object sessionId) { 246 } 247 248 public void close(Object sessionId) { 249 } 250 251 public void open(Object sessionId) { 252 } 253 254 public void deleteOidInfoInBase(LogicalOid floid) { 255 } 256 257 public void insertOidInfoInBase(OidInfo info) { 258 } 259 260 public void updateOidInfoInBase(OidInfo info) { 261 } 262 263 public IdentityProvider getIdentityProvider() { 264 return null; 265 } 266 267 268 private InternalPhysicalFileAccess physicalAccess; 269 270 private Map floidTable; 271 272 private int atSize; 273 274 private Trace tracer; 275 276 277 280 281 public static OidTable getAnOidTable(InternalPhysicalFileAccess physicalAccess, JalistoProperties properties) { 282 OidTableReadOnlyImpl oidTable; 283 try { 284 oidTable = new OidTableReadOnlyImpl(physicalAccess, properties); 285 oidTable.readAtTable(); 286 } catch (Exception e) { 287 throw new JalistoException("cannot create a base in read only mode", e); 288 } 289 return oidTable; 290 } 291 292 private static final String IFA_PREFIXE = "id"; 293 } 294 | Popular Tags |