1 24 package org.objectweb.jalisto.se.impl.server; 25 26 import org.objectweb.jalisto.se.api.*; 27 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess; 28 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess; 29 import org.objectweb.jalisto.se.api.internal.*; 30 import org.objectweb.jalisto.se.exception.JalistoException; 31 import org.objectweb.jalisto.se.impl.trace.Trace; 32 import org.objectweb.jalisto.se.impl.InFileAddress; 33 import org.objectweb.jalisto.se.JalistoFactory; 34 35 import java.util.Collection ; 36 37 public class InternalPhysicalFileAccessImpl implements InternalPhysicalFileAccess { 38 39 public InternalPhysicalFileAccessImpl(JalistoProperties properties) { 40 InternalFactory internalFactory = JalistoFactory.getInternalFactory(); 41 this.tracer = internalFactory.getTracer(properties); 42 this.internalAccess = internalFactory.getPhysicalAccess(properties); 43 this.baseImage = internalFactory.getAInTransactionBaseImage(internalAccess, properties); 44 this.sessionCounter = 0; 45 } 46 47 48 public boolean isNewBase() { 49 return internalAccess.isNewBase(); 50 } 51 52 53 public void insertFileObject(JalistoObject fo) { 54 tracer.println(Trace.PHYSICAL, "insertFileObject({0})", fo); 55 try { 56 baseImage.insertFileObject(fo.getIfa(), fo); 57 } catch (Exception e) { 58 throw new JalistoException("could not insert object " + fo, e); 59 } 60 } 61 62 public JalistoObject readFileObjectAt(InFileAddress ifa) { 63 tracer.println(Trace.PHYSICAL, "readFileObjectAt({0})", ifa); 64 try { 65 return baseImage.readFileObjectAt(ifa); 66 } catch (Exception e) { 67 throw new JalistoException("could not read object at " + ifa, e); 68 } 69 } 70 71 public void updateFileObject(JalistoObject fo) { 72 tracer.println(Trace.PHYSICAL, "updateFileObject({0})", fo); 73 try { 74 baseImage.updateFileObject(fo.getIfa(), fo); 75 } catch (Exception e) { 76 throw new JalistoException("could not update object " + fo, e); 77 } 78 } 79 80 public void deleteFileObject(InFileAddress ifa) { 81 tracer.println(Trace.PHYSICAL, "deleteFileObject({0})", ifa); 82 try { 83 baseImage.deleteFileObject(ifa); 84 } catch (Exception e) { 85 throw new JalistoException("could not delete object at " + ifa, e); 86 } 87 } 88 89 public void writeObjectInBase(InFileAddress ifa, Object o, boolean isUpdate) { 90 JalistoObject objectInBase = new JalistoObjectImpl(); 91 objectInBase.setIfa(ifa); 92 objectInBase.setData(o); 93 if (isUpdate) { 94 updateFileObject(objectInBase); 95 } else { 96 insertFileObject(objectInBase); 97 } 98 } 99 100 101 public PluggablePhysicalFileAccess getInternalAccess() { 102 return internalAccess; 103 } 104 105 106 public void begin() { 107 tracer.println(Trace.PHYSICAL, "begin()"); 108 } 109 110 public void commit() { 111 tracer.println(Trace.PHYSICAL, "commit()"); 112 baseImage.commit(); 113 } 114 115 public void rollback() { 116 tracer.println(Trace.PHYSICAL, "rollback()"); 117 baseImage.rollback(); 118 } 119 120 public void open() { 121 if (sessionCounter == 0) { 122 internalAccess.open(); 123 } 124 sessionCounter++; 125 } 126 127 public void close() { 128 if (sessionCounter > 0) { 129 sessionCounter--; 130 } else { 131 throw new JalistoException("invalid close call : sessionCounter = " + sessionCounter); 132 } 133 if (sessionCounter == 0) { 134 internalAccess.close(); 135 } 136 } 137 138 public Collection getKeysStartingWith(String filter, boolean withOrder) { 139 return baseImage.getKeysStartingWith(filter, withOrder); 140 } 141 142 143 public InTransactionBaseImage getBaseImage() { 144 return baseImage; 145 } 146 147 public String toString() { 148 return internalAccess.toString(); 149 } 150 151 private InTransactionBaseImage baseImage; 152 private PluggablePhysicalFileAccess internalAccess; 153 private int sessionCounter; 154 private Trace tracer; 155 156 157 } 158 | Popular Tags |