| 1 21 package com.db4o.inside.classindex; 22 23 import com.db4o.*; 24 import com.db4o.foundation.*; 25 import com.db4o.inside.Exceptions4; 26 import com.db4o.inside.slots.Slot; 27 28 31 public class ClassIndex extends YapMeta implements ReadWriteable { 32 33 34 private final YapClass _yapClass; 35 36 39 private TreeInt i_root; 40 41 ClassIndex(YapClass yapClass){ 42 _yapClass = yapClass; 43 } 44 45 public void add(int a_id){ 46 i_root = TreeInt.add(i_root, a_id); 47 } 48 49 public final int byteCount() { 50 return YapConst.INT_LENGTH * (Tree.size(i_root) + 1); 51 } 52 53 public final void clear() { 54 i_root = null; 55 } 56 57 void ensureActive(Transaction trans){ 58 if (!isActive()) { 59 setStateDirty(); 60 read(trans); 61 } 62 } 63 64 int entryCount(Transaction ta){ 65 if(isActive() || isNew()){ 66 return Tree.size(i_root); 67 } 68 Slot slot = ((YapFileTransaction)ta).getCurrentSlotOfID(getID()); 69 int length = YapConst.INT_LENGTH; 70 if(Deploy.debug){ 71 length += YapConst.LEADING_LENGTH; 72 } 73 YapReader reader = new YapReader(length); 74 reader.readEncrypt(ta.stream(), slot._address); 75 if (Deploy.debug) { 76 reader.readBegin(getIdentifier()); 77 } 78 return reader.readInt(); 79 } 80 81 public final byte getIdentifier() { 82 return YapConst.YAPINDEX; 83 } 84 85 TreeInt getRoot(){ 86 return i_root; 87 } 88 89 public final int ownLength() { 90 return YapConst.OBJECT_LENGTH + byteCount(); 91 } 92 93 public final Object read(YapReader a_reader) { 94 throw Exceptions4.virtualException(); 95 } 96 97 public final void readThis(Transaction a_trans, YapReader a_reader) { 98 i_root = (TreeInt)new TreeReader(a_reader, new TreeInt(0)).read(); 99 } 100 101 public void remove(int a_id){ 102 i_root = TreeInt.removeLike(i_root, a_id); 103 } 104 105 void setDirty(YapStream a_stream) { 106 a_stream.setDirtyInSystemTransaction(this); 108 } 109 110 public void write(YapReader a_writer) { 111 writeThis(null, a_writer); 112 } 113 114 public final void writeThis(Transaction trans, final YapReader a_writer) { 115 TreeInt.write(a_writer, i_root); 116 } 117 118 public String toString(){ 119 if(! Debug4.prettyToStrings){ 120 return super.toString(); 121 } 122 return _yapClass + " index"; 123 } 124 } | Popular Tags |