1 7 package com.jofti.store; 8 9 import java.nio.ByteBuffer ; 10 import java.util.Arrays ; 11 12 import com.jofti.btree.IPage; 13 import com.jofti.btree.LeafNodeEntry; 14 import com.jofti.core.IStoreManager; 15 16 17 23 public class CachedPage implements IPage { 24 25 30 31 LeafNodeEntry[] entries =null; 32 IPage page =null; 33 int references=0; 34 35 public CachedPage( IPage page) { 36 this.page =page; 37 38 } 39 42 43 44 public LeafNodeEntry getEntry(int position) { 45 LeafNodeEntry entry =null; 46 47 entry = entries[position]; 48 if (entry ==null){ 49 entry = page.getEntry(position); 50 51 entries[position]=entry; 52 } 53 return entry; 54 } 55 58 public void setEntry(int position, LeafNodeEntry entry) { 59 60 61 System.arraycopy(entries,position,entries,position+1,(entries.length-1) -position); 62 entries[position]=entry; 63 64 page.setEntry(position, entry); 65 66 } 67 70 public void removeEntry(int position) { 71 72 Arrays.fill(entries,null); 73 74 page.removeEntry(position); 75 76 } 77 80 public void updateEntry(int location, LeafNodeEntry entry) { 81 entries[location]=entry; 82 83 page.updateEntry(location, entry); 84 85 } 86 87 90 public ByteBuffer copyBuffer(ByteBuffer newBuf) { 91 return page.copyBuffer(newBuf); 92 } 93 96 public void reset() { 97 for (int i=0;i<entries.length;i++){ 98 entries[i]=null; 99 } 100 page.reset(); 101 102 } 103 106 public ByteBuffer getBuffer() { 107 108 return page.getBuffer(); 109 } 110 113 public int[] getPointers() { 114 115 return page.getPointers(); 116 } 117 120 public void setManager(IStoreManager manager) { 121 page.setManager(manager); 122 123 } 124 125 public synchronized void acquireReference(){ 126 ++references; 127 } 128 129 public synchronized void releaseReference(){ 130 --references; 131 } 132 133 public synchronized boolean hasReferences(){ 134 return references>0; 135 } 136 } 137 | Popular Tags |