1 19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage; 20 21 import java.io.ByteArrayInputStream ; 22 import org.netbeans.mdr.persistence.*; 23 import org.netbeans.mdr.persistence.btreeimpl.btreeindex.*; 24 25 31 public class BtreeMDRSource extends Object implements BtreePageSource { 32 33 BtreeStorage storage; 34 MofidGenerator gen; 35 private int pageSize; 36 private EntryTypeInfo pageIdInfo; 37 private byte[] noPageId; 38 39 public BtreeMDRSource(BtreeStorage storage, int pageSize) throws StorageException { 40 this.storage = storage; 41 this.pageSize = pageSize; 42 gen = ((BtreeDatabase) storage.getPrimaryIndex()).getMofidGenerator(); 43 pageIdInfo = EntryTypeInfo.getEntryTypeInfo(Storage.EntryType.MOFID, storage); 44 noPageId = this.storage.getMOFIDData (BtreeFactory.nullMOFID); 45 } 46 47 public BigKeyPage newBigKeyPage(Btree btree) throws StorageException { 48 BigKeyPage page = new BigKeyPage(); 49 initNewPage(page, btree); 50 return page; 51 } 52 53 public BtreePage newPage(Btree btree) throws StorageException { 54 55 BtreePage page = btree.pageFactory(); 56 initNewPage(page, btree); 57 return page; 58 } 59 60 private void initNewPage(BtreePage page, Btree btree) throws StorageException { 61 62 MOFID pageMOFID = new MOFID((BtreeStorage)this.storage); 63 byte[] mofBytes = this.storage.getMOFIDData (pageMOFID); 64 page.init(btree, mofBytes, new byte[pageSize], true); 65 BtreeDatabase repos = (BtreeDatabase) storage.getPrimaryIndex(); 66 repos.add(pageMOFID, page); 67 repos.objectStateChanged(pageMOFID); 68 } 69 70 public BtreePage getPage(byte[] pageId, Btree btree) 71 throws StorageException { 72 BtreePage page; 73 MOFID mofId = this.storage.readMOFIDData (new ByteArrayInputStream (pageId)); 74 page = (BtreePage) ((BtreeDatabase) storage.getPrimaryIndex()).get(mofId); 75 page.init(btree, pageId, page.pageBuffer, false); 76 return page; 77 } 78 79 public BtreePage getRootPage(Btree btree) throws StorageException { 80 return newPage(btree); 81 } 82 83 public void unpinPage(BtreePage page) { 84 85 } 86 87 public void unpinPage(BigKeyPage page) { 88 89 } 90 91 public void dirtyPage(BtreePage page) throws StorageException { 92 MOFID mofId = this.storage.readMOFIDData (new ByteArrayInputStream (page.pageId)); 93 ((BtreeDatabase) storage.getPrimaryIndex()).objectStateChanged(mofId); 94 } 95 96 public EntryTypeInfo getPageIdInfo() { 97 return pageIdInfo; 98 } 99 100 public int getPageIdLength() { 101 return MOFID.LENGTH; 102 } 103 104 public int getPageSize() { 105 return pageSize; 106 } 107 108 111 public void setNoPage(byte[] pageId) { 112 113 System.arraycopy(noPageId, 0, pageId, 0, pageId.length); 114 } 115 116 119 public boolean isNoPage(byte[] pageId) { 120 121 for (int i = 0; i < pageId.length; i++) { 122 if (pageId[i] != noPageId[i]) { 123 return false; 124 } 125 } 126 return true; 127 } 128 129 130 public long getNextMofid() { 131 return gen.getNextMofid(); 132 } 133 134 135 public String getMofidPrefix() { 136 return gen.getMofidPrefix(); 137 } 138 139 public BtreeStorage getStorage() { 140 return storage; 141 } 142 143 } 144 | Popular Tags |