1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.reference.SQLState; 26 27 import org.apache.derby.iapi.store.raw.RecordHandle; 28 29 import org.apache.derby.iapi.types.Resetable; 30 import org.apache.derby.iapi.store.raw.LockingPolicy; 31 import org.apache.derby.iapi.store.access.TransactionController; 32 33 import java.io.InputStream ; 34 import java.io.IOException ; 35 36 40 public class OverflowInputStream 41 extends BufferedByteHolderInputStream 42 implements Resetable 43 { 44 protected BaseContainerHandle owner; 45 protected long overflowPage; 46 protected int overflowId; 47 protected long firstOverflowPage; 49 protected int firstOverflowId; 50 protected RecordHandle recordToLock; 52 53 public OverflowInputStream(ByteHolder bh, BaseContainerHandle owner, 54 long overflowPage, int overflowId, RecordHandle recordToLock) 55 throws IOException , StandardException 56 { 57 super(bh); 58 this.owner = owner; 59 this.overflowPage = overflowPage; 60 this.overflowId = overflowId; 61 this.firstOverflowPage = overflowPage; 62 this.firstOverflowId = overflowId; 63 this.recordToLock = recordToLock; 64 fillByteHolder(); 65 } 66 67 68 public void fillByteHolder() throws IOException 69 { 70 if ((this.bh.available() == 0) && (this.overflowPage != -1)) 71 { 72 this.bh.clear(); 73 74 try 75 { 76 BasePage columnOverflowPage = 78 ((BasePage) this.owner.getPage(overflowPage)); 79 80 if (columnOverflowPage != null) 81 { 82 columnOverflowPage.restorePortionLongColumn(this); 83 columnOverflowPage.unlatch(); 84 columnOverflowPage = null; 85 } 86 } 87 catch (StandardException se) 88 { 89 throw new IOException ( se.toString() ); 90 } 91 this.bh.startReading(); 92 } 93 } 94 95 96 public long getOverflowPage() { 97 return this.overflowPage; 98 } 99 100 public int getOverflowId() { 101 return this.overflowId; 102 } 103 104 public void setOverflowPage(long overflowPage) { 105 this.overflowPage = overflowPage; 106 } 107 108 public void setOverflowId(int overflowId) { 109 this.overflowId = overflowId; 110 } 111 112 113 116 117 120 public void resetStream() throws IOException , StandardException 121 { 122 owner.checkOpen(); 126 this.overflowPage = firstOverflowPage; 128 this.overflowId = firstOverflowId; 129 this.bh.clear(); 131 this.bh.startReading(); 132 fillByteHolder(); 134 } 135 136 142 public void initStream() throws StandardException 143 { 144 if (owner.getTransaction() == null) 149 throw StandardException.newException(SQLState.DATA_CONTAINER_CLOSED); 150 166 167 LockingPolicy lp = 168 owner.getTransaction().newLockingPolicy( 169 LockingPolicy.MODE_RECORD, 170 TransactionController.ISOLATION_REPEATABLE_READ, true); 171 172 owner = (BaseContainerHandle) owner.getTransaction().openContainer( 174 owner.getId(), lp, owner.getMode()); 175 176 owner.getLockingPolicy().lockRecordForRead( 180 owner.getTransaction(), owner, recordToLock, true, false); 181 } 182 183 184 189 public void closeStream() 190 { 191 owner.close(); 192 } 193 194 } 195 | Popular Tags |