1 21 package com.db4o.inside.marshall; 22 23 import com.db4o.*; 24 import com.db4o.inside.btree.*; 25 26 29 public class FieldMarshaller1 extends FieldMarshaller0 { 30 31 private boolean hasBTreeIndex(YapField field){ 32 return ! field.isVirtual(); 33 } 34 35 public void write(Transaction trans, YapClass clazz, YapField field, YapReader writer) { 36 super.write(trans, clazz, field, writer); 37 if(! hasBTreeIndex(field)){ 38 return; 39 } 40 writer.writeIDOf(trans, field.getIndex(trans)); 41 } 42 43 public RawFieldSpec readSpec(YapStream stream, YapReader reader) { 44 RawFieldSpec spec=super.readSpec(stream, reader); 45 if(spec==null) { 46 return null; 47 } 48 if (spec.isVirtual()) { 49 return spec; 50 } 51 int indexID = reader.readInt(); 52 spec.indexID(indexID); 53 return spec; 54 } 55 56 protected YapField fromSpec(RawFieldSpec spec, YapStream stream, YapField field) { 57 YapField actualField = super.fromSpec(spec, stream, field); 58 if(spec==null) { 59 return field; 60 } 61 if (spec.indexID() != 0) { 62 actualField.initIndex(stream.getSystemTransaction(), spec.indexID()); 63 } 64 return actualField; 65 } 66 67 public int marshalledLength(YapStream stream, YapField field) { 68 int len = super.marshalledLength(stream, field); 69 if(! hasBTreeIndex(field)){ 70 return len; 71 } 72 final int BTREE_ID = YapConst.ID_LENGTH; 73 return len + BTREE_ID; 74 } 75 76 public void defrag(YapClass yapClass, YapField yapField, YapStringIO sio, 77 final ReaderPair readers) 78 throws CorruptionException { 79 super.defrag(yapClass, yapField, sio, readers); 80 if(yapField.isVirtual()) { 81 return; 82 } 83 if(yapField.hasIndex()) { 84 BTree index = yapField.getIndex(readers.systemTrans()); 85 int targetIndexID=readers.copyID(); 86 if(targetIndexID!=0) { 87 index.defragBTree(readers.context()); 88 } 89 } 90 else { 91 readers.writeInt(0); 92 } 93 } 94 } 95 | Popular Tags |