1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 import com.db4o.inside.marshall.*; 25 import com.db4o.reflect.*; 26 27 30 public class YapClassPrimitive extends YapClass{ 31 32 public final TypeHandler4 i_handler; 33 34 YapClassPrimitive(YapStream a_stream, TypeHandler4 a_handler) { 35 super(a_stream, a_handler.classReflector()); 36 i_fields = YapField.EMPTY_ARRAY; 37 i_handler = a_handler; 38 } 39 40 void activateFields(Transaction a_trans, Object a_object, int a_depth) { 41 } 44 45 46 final void addToIndex(YapFile a_stream, Transaction a_trans, int a_id) { 47 } 50 51 boolean allowsQueries() { 52 return false; 53 } 54 55 void cacheDirty(Collection4 col) { 56 } 58 59 public boolean canHold(ReflectClass claxx) { 60 return i_handler.canHold(claxx); 63 } 64 65 public ReflectClass classReflector(){ 66 return i_handler.classReflector(); 67 } 68 69 public void deleteEmbedded(MarshallerFamily mf, YapWriter a_bytes) { 70 if(mf._primitive.useNormalClassRead()){ 71 super.deleteEmbedded(mf, a_bytes); 72 return; 73 } 74 75 } 78 79 80 public void deleteEmbedded1(MarshallerFamily mf, YapWriter a_bytes, int a_id) { 81 82 if(i_handler instanceof YapArray){ 83 YapArray ya = (YapArray)i_handler; 84 85 93 97 if(ya.i_isPrimitive){ 98 ya.deletePrimitiveEmbedded(a_bytes, this); 99 a_bytes.slotDelete(); 100 return; 101 } 102 } 103 104 if(i_handler instanceof YapClassAny){ 105 a_bytes.incrementOffset(i_handler.linkLength()); 107 }else{ 108 i_handler.deleteEmbedded(mf, a_bytes); 109 } 110 111 114 free(a_bytes, a_id); 115 116 } 117 118 void deleteMembers(MarshallerFamily mf, ObjectHeaderAttributes attributes, YapWriter a_bytes, int a_type, boolean isUpdate) { 119 if (a_type == YapConst.TYPE_ARRAY) { 120 new YapArray(a_bytes.getStream(),this, true).deletePrimitiveEmbedded(a_bytes, this); 121 } else if (a_type == YapConst.TYPE_NARRAY) { 122 new YapArrayN(a_bytes.getStream(),this, true).deletePrimitiveEmbedded(a_bytes, this); 123 } 124 } 125 126 final void free(Transaction a_trans, int a_id, int a_address, int a_length) { 127 a_trans.slotFreePointerOnCommit(a_id, a_address, a_length); 128 } 129 130 final void free(YapWriter a_bytes, int a_id) { 131 a_bytes.getTransaction().slotFreePointerOnCommit(a_id, a_bytes.getAddress(), a_bytes.getLength()); 132 } 133 134 public boolean hasIndex() { 135 return false; 136 } 137 138 Object instantiate(YapObject a_yapObject, Object a_object, MarshallerFamily mf, ObjectHeaderAttributes attributes, YapWriter a_bytes, boolean a_addToIDTree) { 139 if (a_object == null) { 140 try { 141 a_object = i_handler.read(mf, a_bytes, true); 142 } catch (CorruptionException ce) { 143 return null; 144 } 145 a_yapObject.setObjectWeak(a_bytes.getStream(), a_object); 146 } 147 a_yapObject.setStateClean(); 148 return a_object; 149 } 150 151 Object instantiateTransient(YapObject a_yapObject, Object a_object, MarshallerFamily mf, ObjectHeaderAttributes attributes, YapWriter a_bytes) { 152 try { 153 return i_handler.read(mf, a_bytes, true); 154 } catch (CorruptionException ce) { 155 return null; 156 } 157 } 158 159 void instantiateFields(YapObject a_yapObject, Object a_onObject, MarshallerFamily mf, ObjectHeaderAttributes attributes, YapWriter a_bytes) { 160 Object obj = null; 161 try { 162 obj = i_handler.read(mf, a_bytes, true); 163 } catch (CorruptionException ce) { 164 165 } 166 if (obj != null) { 167 i_handler.copyValue(obj, a_onObject); 168 } 169 } 170 171 public boolean isArray() { 172 return i_id == YapHandlers.ANY_ARRAY_ID || i_id == YapHandlers.ANY_ARRAY_N_ID; 173 } 174 175 public boolean isPrimitive(){ 176 return true; 177 } 178 179 public int isSecondClass(){ 180 return YapConst.UNKNOWN; 181 } 182 183 boolean isStrongTyped(){ 184 return false; 185 } 186 187 public void calculateLengths(Transaction trans, ObjectHeaderAttributes header, boolean topLevel, Object obj, boolean withIndirection) { 188 i_handler.calculateLengths(trans, header, topLevel, obj, withIndirection); 189 } 190 191 public YapComparable prepareComparison(Object a_constraint) { 192 i_handler.prepareComparison(a_constraint); 193 return i_handler; 194 } 195 196 public final ReflectClass primitiveClassReflector(){ 197 return i_handler.primitiveClassReflector(); 198 } 199 200 public Object read(MarshallerFamily mf, YapWriter a_bytes, boolean redirect) throws CorruptionException{ 201 if(mf._primitive.useNormalClassRead()){ 202 return super.read(mf, a_bytes, redirect); 203 } 204 return i_handler.read(mf, a_bytes, false); 205 } 206 207 public TypeHandler4 readArrayHandler(Transaction a_trans, MarshallerFamily mf, YapReader[] a_bytes) { 208 if (isArray()) { 209 return i_handler; 210 } 211 return null; 212 } 213 214 public Object readQuery(Transaction trans, MarshallerFamily mf, boolean withRedirection, YapReader reader, boolean toArray) throws CorruptionException{ 215 if(mf._primitive.useNormalClassRead()){ 216 return super.readQuery(trans, mf, withRedirection, reader, toArray); 217 } 218 return i_handler.readQuery(trans, mf, withRedirection, reader, toArray); 219 } 220 221 222 public QCandidate readSubCandidate(MarshallerFamily mf, YapReader reader, QCandidates candidates, boolean withIndirection) { 223 return i_handler.readSubCandidate(mf, reader, candidates, withIndirection); 224 } 225 226 void removeFromIndex(Transaction ta, int id) { 227 } 229 230 public boolean supportsIndex() { 231 return true; 232 } 233 234 public final boolean writeObjectBegin() { 235 return false; 236 } 237 238 public Object writeNew(MarshallerFamily mf, Object a_object, boolean topLevel, YapWriter a_bytes, boolean withIndirection, boolean restoreLinkOffset) { 239 mf._primitive.writeNew(a_bytes.getTransaction(), this, a_object, topLevel, a_bytes, withIndirection, restoreLinkOffset); 240 return a_object; 241 } 242 243 public String toString(){ 244 return "Wraps " + i_handler.toString() + " in YapClassPrimitive"; 245 } 246 247 public void defrag(MarshallerFamily mf, ReaderPair readers, boolean redirect) { 248 if(mf._primitive.useNormalClassRead()){ 249 super.defrag(mf,readers, redirect); 250 } 251 else { 252 i_handler.defrag(mf, readers, false); 253 } 254 } 255 } 256 | Popular Tags |