1 package com.quadcap.sql.file; 2 3 40 41 import java.io.IOException ; 42 43 import com.quadcap.util.Debug; 44 import com.quadcap.util.Util; 45 46 51 public class SubPage implements Page { 52 SubPageManager pm; 53 BlockFile file; 54 long pageNum; 55 int pageOffset; 56 Block block = null; 57 58 61 public SubPage(SubPageManager pm, long pageNum) throws IOException { 62 this.pm = pm; 63 this.file = pm.file; 64 this.pageNum = pageNum; 65 this.pageOffset = pm.pageOffset(pageNum); 66 this.block = file.getBlock(SubPageManager.pageBlock(pageNum)); 67 } 68 69 72 public long getPageNum() { 73 return pageNum; 74 } 75 76 85 public int read(int pos, byte[] pbuf, int offset, int len) { 86 return block.read(pos + pageOffset, pbuf, offset, len); 92 } 93 94 103 public int write(int pos, byte[] pbuf, int offset, int len) { 104 return block.write(pos + pageOffset, pbuf, offset, len); 110 } 111 112 117 public int readInt(int pos) { 118 return block.readInt(pos + pageOffset); 119 } 120 121 127 public void writeInt(int pos, int val) { 128 block.writeInt(pos + pageOffset, val); 129 } 130 131 136 public long readLong(int pos) { 137 return block.readLong(pos + pageOffset); 138 } 139 140 146 public void writeLong(int pos, long val) { 147 block.writeLong(pos + pageOffset, val); 148 } 149 150 154 public void takeData(Page p) { 155 byte[] buf = new byte[pm.pageSize]; 156 p.read(0, buf, 0, pm.pageSize); 157 write(0, buf, 0, pm.pageSize); 158 for (int i = 0; i < buf.length; i++) buf[i] = 0; 159 p.write(0, buf, 0, pm.pageSize); 160 } 161 162 public void clear() { 163 byte[] buf = new byte[pm.pageSize]; 164 for (int i = 0; i < buf.length; i++) buf[i] = 0; 165 write(0, buf, 0, pm.pageSize); 166 } 167 168 public void decrRefCount() { 169 if (block != null) { 170 block.decrRefCount(); 171 block = null; 172 } 173 } 174 175 public String toString() { 177 return "Page(" + SubPageManager.toString(pageNum) + ")"; 178 } 179 181 } 182 | Popular Tags |