1 21 22 package org.apache.derby.impl.store.access.sort; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 import org.apache.derby.iapi.error.StandardException; 28 import org.apache.derby.iapi.store.access.RowSource; 29 import org.apache.derby.iapi.store.access.SortObserver; 30 import org.apache.derby.iapi.types.RowLocation; 31 import org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource; 32 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 33 import org.apache.derby.iapi.store.access.ScanController; 34 35 import org.apache.derby.iapi.types.DataValueDescriptor; 36 37 import org.apache.derby.iapi.services.io.FormatableBitSet; 38 39 47 public class SortBufferRowSource extends Scan 48 implements ScanControllerRowSource 49 { 50 53 SortBuffer sortBuffer = null; 54 55 58 protected TransactionManager tran = null; 59 60 private int maxFreeListSize; 61 private boolean writingToDisk; 62 private SortObserver sortObserver; 63 64 67 68 SortBufferRowSource( 69 SortBuffer sortBuffer, 70 TransactionManager tran, 71 SortObserver sortObserver, 72 boolean writingToDisk, 73 int maxFreeListSize) 74 { 75 super(); 76 this.sortBuffer = sortBuffer; 77 this.tran = tran; 78 this.sortObserver = sortObserver; 79 this.writingToDisk = writingToDisk; 80 this.maxFreeListSize = maxFreeListSize; 81 } 82 83 84 85 86 87 public DataValueDescriptor[] getNextRowFromRowSource() 88 { 89 if (sortBuffer == null) return null; 91 92 DataValueDescriptor[] retval = sortBuffer.removeFirst(); 93 94 if (retval != null && writingToDisk) 96 { 97 sortObserver.addToFreeList(retval, maxFreeListSize); 98 } 99 return retval; 100 } 101 102 public boolean needsRowLocation() 103 { 104 return false; 105 } 106 107 110 public boolean needsToClone() 111 { 112 return false; 113 } 114 115 public void rowLocation(RowLocation rl) 116 { 117 if (SanityManager.DEBUG) 118 SanityManager.THROWASSERT("unexpected call to RowSource.rowLocation"); 119 } 120 121 122 125 public FormatableBitSet getValidColumns() 126 { 127 return null; 128 } 129 130 133 public void close() 134 { 135 if (sortBuffer != null) 136 { 137 sortBuffer.close(); 138 sortBuffer = null; 139 } 140 tran.closeMe(this); 141 } 142 143 146 public boolean closeForEndTransaction(boolean closeHeldScan) 147 { 148 if (SanityManager.DEBUG) 149 SanityManager.ASSERT( 150 closeHeldScan, 151 "Sort scan should not be held open across commit."); 152 153 close(); 154 return(true); 155 } 156 157 160 public void closeRowSource() 161 { 162 close(); 163 } 164 165 168 public boolean next() throws StandardException 169 { 170 throw StandardException.newException( 171 SQLState.SORT_IMPROPER_SCAN_METHOD); 172 } 173 174 183 public void fetchWithoutQualify(DataValueDescriptor[] result) 184 throws StandardException 185 { 186 throw StandardException.newException( 187 SQLState.SORT_IMPROPER_SCAN_METHOD); 188 } 189 190 195 public void fetch(DataValueDescriptor[] result) throws StandardException 196 { 197 throw StandardException.newException( 198 SQLState.SORT_IMPROPER_SCAN_METHOD); 199 } 200 201 public final boolean fetchNext(DataValueDescriptor[] row) 202 throws StandardException 203 { 204 throw StandardException.newException( 205 SQLState.SORT_IMPROPER_SCAN_METHOD); 206 } 207 208 } 209 | Popular Tags |