1 9 package org.ozoneDB; 10 11 import org.ozoneDB.DxLib.DxCollection; 12 import org.ozoneDB.core.*; 13 import org.ozoneDB.io.stream.ResolvingObjectInputStream; 14 15 import java.io.*; 16 import java.lang.reflect.Constructor ; 17 18 19 28 public final class CacheObjectContainer implements ObjectContainer, Serializable { 29 30 private static long touchCount; 31 32 private transient ClientCacheDatabase db; 33 34 protected transient AbstractTransaction tx; 35 36 private transient long lastTouched; 37 38 41 private transient boolean dirty; 42 43 private int state; 44 45 49 private long modTime; 50 51 private OzoneCompatible target; 52 53 private ObjectID id; 54 55 private String name; 56 57 private int access; 58 59 60 public CacheObjectContainer( ObjectContainer rhs ) { 61 this( rhs.target(), rhs.id(), rhs.name(), OzoneInterface.Public ); 62 modTime = rhs.modTime(); 63 } 64 65 66 public CacheObjectContainer( OzoneCompatible _target, ObjectID _id, String _name, int _access ) { 67 target = _target; 68 target.setContainer( this ); 69 id = _id; 70 name = _name; 71 access = _access; 72 state = STATE_CLEAN; 73 74 touch(); 75 } 76 77 78 public int access() { 79 return access; 80 } 81 82 83 public int state() { 84 return state; 85 } 86 87 88 public boolean dirty() { 89 return dirty; 90 } 91 92 93 public void setDirty( boolean _dirty ) { 94 dirty = _dirty; 95 } 96 97 98 public void raiseState( int newState ) { 99 int oldState = state; 100 state = newState > state ? newState : state; 101 102 if (state >= STATE_MODIFIED) { 103 dirty = true; 104 } 105 106 if (state == STATE_DELETED && oldState == STATE_CREATED) { 109 dirty = false; 110 } 111 } 112 113 114 public void clearState() { 115 state = STATE_CLEAN; 116 dirty = false; 117 } 118 119 120 public void touch() { 121 touchCount++; 122 } 123 124 125 public long lastTouched() { 126 return lastTouched; 127 } 128 129 130 public long modTime() { 131 return modTime; 132 } 133 134 135 protected void setModTime( long _modTime ) { 136 modTime = _modTime; 137 } 138 139 140 public Lock lock() { 141 throw new RuntimeException ( "Method not implemented." ); 142 } 143 144 145 public DxCollection allLockers() { 146 throw new RuntimeException ( "Method not implemented." ); 147 } 148 149 150 public void setTarget( OzoneCompatible _target ) { 151 if (target != null) { 152 target.setContainer( null ); 153 } 154 155 target = _target; 156 target.setContainer( this ); 157 } 158 159 160 public OzoneCompatible target() { 161 return target; 162 } 163 164 165 public Class targetClass() { 166 return target.getClass(); 167 } 168 169 170 public void setDatabase( ClientCacheDatabase _db ) { 171 db = _db; 172 } 173 174 175 public OzoneInterface database() { 176 return db; 177 } 178 179 180 public ObjectID id() { 181 return id; 182 } 183 184 185 public Permissions permissions() { 186 throw new RuntimeException ( "Method not implemented." ); 187 } 188 189 190 public String name() { 191 return name; 192 } 193 194 195 public void setName( String _name ) { 196 name = _name; 197 } 198 199 200 public OzoneProxy ozoneProxy() { 201 try { 202 String implName = targetClass().getName(); 203 String proxyName; 204 if (implName.endsWith( ObjectContainer.IMPLNAME_POSTFIX )) { 205 proxyName = implName.substring( 0, implName.length() - 5 ); 206 } else { 207 proxyName = implName + PROXYNAME_POSTFIX; 208 } 209 210 Class cl = Env.currentEnv().classManager.classForName(proxyName); 213 214 Class [] argTypes = {ObjectID.class, OzoneInterface.class}; 215 Constructor ctor = cl.getConstructor( argTypes ); 216 217 Object [] args = {id(), database()}; 219 return (OzoneProxy)ctor.newInstance( args ); 220 } catch (Exception e) { 221 throw new RuntimeException ( e.toString() ); 222 } 223 } 224 225 226 public OzoneCompatible targetClone() throws Exception { 227 ByteArrayOutputStream bout = new ByteArrayOutputStream( 2048 ); 228 ObjectOutputStream out = new ObjectOutputStream( bout ); 229 out.writeObject( target() ); 230 out.close(); 231 ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) ); 232 Object targetClone = in.readObject(); 233 in.close(); 234 return (OzoneCompatible)targetClone; 235 } 236 237 238 public Object invokeTarget( Env env, String methodName, String sig, Object [] args ) throws Exception { 239 throw new RuntimeException ( "Method not implemented." ); 240 } 241 242 243 public Object invokeTarget( Env env, int methodIndex, Object [] args ) throws Exception { 244 throw new RuntimeException ( "Method not implemented." ); 245 } 246 247 248 public void createTarget( Env env, Class cl, String sig, Object [] args ) throws Exception { 249 throw new RuntimeException ( "Method not implemented." ); 250 } 251 252 253 public void deleteTarget() { 254 throw new RuntimeException ( "Method not implemented." ); 255 } 256 257 258 public void nameTarget( String _name ) { 259 throw new RuntimeException ( "Method not implemented." ); 260 } 261 262 263 public void finalizeTarget() throws Exception { 264 throw new RuntimeException ( "Method not implemented." ); 265 } 266 267 268 273 public void pin() { 274 throw new RuntimeException ("Method not implemented."); 275 } 276 277 281 public void unpin() { 282 throw new RuntimeException ("Method not implemented."); 283 } 284 285 288 public boolean isPinned() { 289 throw new RuntimeException ("Method not implemented."); 290 } 291 292 305 public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) { 306 throw new RuntimeException ("Method not implemented."); 307 } 308 309 312 public int getGarbageCollectionLevel() { 313 throw new RuntimeException ("Method not implemented."); 314 } 315 316 public void invokeOnActivate() { 317 throw new RuntimeException ("Method not implemented."); 318 } 319 320 public boolean shouldOnActivateBeCalled() { 321 throw new RuntimeException ("Method not implemented."); 322 } 323 324 public void invokeOnPassivate() { 325 throw new RuntimeException ("Method not implemented."); 326 } 327 328 public boolean shouldOnPassivateBeCalled() { 329 throw new RuntimeException ("Method not implemented."); 330 } 331 332 public void setShouldCallOnPassivate(boolean shouldOnPassivateBeCalled) { 333 throw new RuntimeException ("Method not implemented."); 334 } 335 336 public void setShouldCallOnActivate(boolean shouldOnActivateBeCalled) { 337 throw new RuntimeException ("Method not implemented."); 338 } 339 340 public void requireWriteLocking() { 341 throw new RuntimeException ("Method not implemented."); 342 } 343 } 344 345 | Popular Tags |