1 21 package com.db4o; 22 23 import com.db4o.inside.*; 24 import com.db4o.inside.replication.*; 25 26 31 public class P1Object implements Db4oTypeImpl{ 32 33 private transient Transaction i_trans; 34 private transient YapObject i_yapObject; 35 36 public P1Object(){ 37 } 38 39 P1Object(Transaction a_trans){ 40 i_trans = a_trans; 41 } 42 43 public void activate (Object a_obj, int a_depth){ 44 if(i_trans == null){ 45 return; 46 } 47 if(a_depth < 0){ 48 stream().activate1(i_trans, a_obj); 49 }else{ 50 stream().activate1(i_trans, a_obj, a_depth); 51 } 52 } 53 54 public int activationDepth(){ 55 return 1; 56 } 57 58 public int adjustReadDepth(int a_depth) { 59 return a_depth; 60 } 61 62 public boolean canBind() { 63 return false; 64 } 65 66 public void checkActive(){ 67 if(i_trans == null){ 68 return; 69 } 70 if(i_yapObject == null){ 71 i_yapObject = stream().getYapObject(this); 72 if(i_yapObject == null){ 73 stream().set(this); 74 i_yapObject = stream().getYapObject(this); 75 } 76 } 77 if(validYapObject()){ 78 i_yapObject.activate(i_trans, this, activationDepth(), false); 79 } 80 } 81 82 public Object createDefault(Transaction a_trans) { 83 throw Exceptions4.virtualException(); 84 } 85 86 void deactivate(){ 87 if(validYapObject()){ 88 i_yapObject.deactivate(i_trans, activationDepth()); 89 } 90 } 91 92 void delete(){ 93 if(i_trans == null){ 94 return; 95 } 96 if(i_yapObject == null){ 97 i_yapObject = stream().getYapObject(this); 98 } 99 if(validYapObject()){ 100 stream().delete2(i_trans,i_yapObject,this, 0, false); 101 } 102 } 103 104 protected void delete(Object a_obj){ 105 if(i_trans != null){ 106 stream().delete(a_obj); 107 } 108 } 109 110 protected long getIDOf(Object a_obj){ 111 if(i_trans == null){ 112 return 0; 113 } 114 return stream().getID(a_obj); 115 } 116 117 protected Transaction getTrans(){ 118 return i_trans; 119 } 120 121 public boolean hasClassIndex() { 122 return false; 123 } 124 125 public void preDeactivate(){ 126 } 128 129 protected Object replicate(Transaction fromTrans, Transaction toTrans) { 130 131 YapStream fromStream = fromTrans.stream(); 132 YapStream toStream = toTrans.stream(); 133 134 MigrationConnection mgc = fromStream.i_handlers.i_migration; 135 136 synchronized(fromStream.lock()){ 137 138 int id = toStream.oldReplicationHandles(this); 139 140 if(id == -1){ 141 return this; 143 } 144 145 if(id > 0) { 146 return toStream.getByID(id); 148 } 149 150 if(mgc != null){ 151 Object otherObj = mgc.identityFor(this); 152 if(otherObj != null){ 153 return otherObj; 154 } 155 } 156 157 P1Object replica = (P1Object)createDefault(toTrans); 158 159 if(mgc != null){ 160 mgc.mapReference(replica, i_yapObject); 161 mgc.mapIdentity(this, replica); 162 } 163 164 replica.store(0); 165 166 return replica; 167 } 168 } 169 170 public void replicateFrom(Object obj) { 171 } 173 174 public void setTrans(Transaction a_trans){ 175 i_trans = a_trans; 176 } 177 178 public void setYapObject(YapObject a_yapObject) { 179 i_yapObject = a_yapObject; 180 } 181 182 protected void store(Object a_obj){ 183 if(i_trans != null){ 184 stream().setInternal(i_trans, a_obj, true); 185 } 186 } 187 188 public Object storedTo(Transaction a_trans){ 189 i_trans = a_trans; 190 return this; 191 } 192 193 Object streamLock(){ 194 if(i_trans != null){ 195 stream().checkClosed(); 196 return stream().lock(); 197 } 198 return this; 199 } 200 201 public void store(int a_depth){ 202 if(i_trans == null){ 203 return; 204 } 205 if(i_yapObject == null){ 206 i_yapObject = i_trans.stream().getYapObject(this); 207 if(i_yapObject == null){ 208 i_trans.stream().setInternal(i_trans, this, true); 209 i_yapObject = i_trans.stream().getYapObject(this); 210 return; 211 } 212 } 213 update(a_depth); 214 } 215 216 void update(){ 217 update(activationDepth()); 218 } 219 220 void update(int depth){ 221 if(validYapObject()){ 222 stream().beginTopLevelSet(); 223 try{ 224 i_yapObject.writeUpdate(i_trans, depth); 225 stream().checkStillToSet(); 226 } finally{ 227 stream().endTopLevelSet(i_trans); 228 } 229 } 230 } 231 232 void updateInternal(){ 233 updateInternal(activationDepth()); 234 } 235 236 void updateInternal(int depth){ 237 if(validYapObject()){ 238 i_yapObject.writeUpdate(i_trans, depth); 239 stream().flagAsHandled(i_yapObject); 240 stream().checkStillToSet(); 241 } 242 } 243 244 private boolean validYapObject(){ 245 return (i_trans != null) && (i_yapObject != null) && (i_yapObject.getID() > 0); 246 } 247 248 private YapStream stream(){ 249 return i_trans.stream(); 250 } 251 252 } 253 | Popular Tags |