1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.error.StandardException; 25 26 import org.apache.derby.iapi.sql.execute.CursorResultSet; 27 import org.apache.derby.iapi.sql.execute.ExecRow; 28 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 29 30 import org.apache.derby.iapi.sql.Activation; 31 import org.apache.derby.iapi.sql.ResultSet; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 35 import org.apache.derby.iapi.services.loader.GeneratedMethod; 36 37 import org.apache.derby.iapi.types.RowLocation; 38 39 45 abstract class JoinResultSet extends NoPutResultSetImpl 46 implements CursorResultSet 47 { 48 49 public int rowsSeenLeft; 50 public int rowsSeenRight; 51 public int rowsReturned; 52 public long restrictionTime; 53 54 protected boolean isRightOpen; 55 protected ExecRow leftRow; 56 protected ExecRow rightRow; 57 protected ExecRow mergedRow; 58 59 public NoPutResultSet leftResultSet; 62 protected int leftNumCols; 63 public NoPutResultSet rightResultSet; 64 protected int rightNumCols; 65 protected GeneratedMethod restriction; 66 public boolean oneRowRightSide; 67 public boolean notExistsRightSide; 69 String userSuppliedOptimizerOverrides; 70 71 75 JoinResultSet(NoPutResultSet leftResultSet, 76 int leftNumCols, 77 NoPutResultSet rightResultSet, 78 int rightNumCols, 79 Activation activation, 80 GeneratedMethod restriction, 81 int resultSetNumber, 82 boolean oneRowRightSide, 83 boolean notExistsRightSide, 84 double optimizerEstimatedRowCount, 85 double optimizerEstimatedCost, 86 String userSuppliedOptimizerOverrides) 87 { 88 super(activation, resultSetNumber, optimizerEstimatedRowCount, 89 optimizerEstimatedCost); 90 this.leftResultSet = leftResultSet; 91 this.leftNumCols = leftNumCols; 92 this.rightResultSet = rightResultSet; 93 this.rightNumCols = rightNumCols; 94 this.restriction = restriction; 95 this.oneRowRightSide = oneRowRightSide; 96 this.notExistsRightSide = notExistsRightSide; 97 constructorTime += getElapsedMillis(beginTime); 98 this.userSuppliedOptimizerOverrides = userSuppliedOptimizerOverrides; 99 } 100 101 105 113 void clearScanState() 114 { 115 leftRow = null; 116 rightRow = null; 117 mergedRow = null; 118 } 119 120 137 public void openCore() throws StandardException 138 { 139 clearScanState(); 140 141 beginTime = getCurrentTimeMillis(); 142 if (SanityManager.DEBUG) 143 SanityManager.ASSERT( ! isOpen, "JoinResultSet already open"); 144 145 isOpen = true; 146 leftResultSet.openCore(); 147 leftRow = leftResultSet.getNextRowCore(); 148 if (leftRow != null) 149 { 150 openRight(); 151 rowsSeenLeft++; 152 } 153 numOpens++; 154 155 openTime += getElapsedMillis(beginTime); 156 } 157 158 163 public void reopenCore() throws StandardException 164 { 165 clearScanState(); 166 167 leftResultSet.reopenCore(); 169 leftRow = leftResultSet.getNextRowCore(); 170 if (leftRow != null) 171 { 172 openRight(); 174 rowsSeenLeft++; 175 } 176 else if (isRightOpen) 177 { 178 closeRight(); 179 } 180 181 numOpens++; 182 183 openTime += getElapsedMillis(beginTime); 184 } 185 186 187 198 public void close() throws StandardException 199 { 200 clearScanState(); 201 202 if ( isOpen ) 203 { 204 leftResultSet.close(); 205 if (isRightOpen) 206 { 207 closeRight(); 208 } 209 210 super.close(); 211 } 212 else 213 if (SanityManager.DEBUG) 214 SanityManager.DEBUG("CloseRepeatInfo","Close of JoinResultSet repeated"); 215 216 } 217 218 public void finish() throws StandardException { 219 leftResultSet.finish(); 220 rightResultSet.finish(); 221 super.finish(); 222 } 223 224 235 public RowLocation getRowLocation() { 236 if (SanityManager.DEBUG) 237 SanityManager.THROWASSERT("Join used in positioned update/delete"); 238 return null; 239 } 240 241 249 public ExecRow getCurrentRow() { 250 if (SanityManager.DEBUG) 251 SanityManager.THROWASSERT("Join used in positioned update/delete"); 252 return null; 253 } 254 255 256 257 263 protected void openRight() throws StandardException 264 { 265 if (isRightOpen) 266 { 267 rightResultSet.reopenCore(); 268 } 269 else 270 { 271 rightResultSet.openCore(); 272 isRightOpen = true; 273 } 274 } 275 276 280 protected void closeRight() throws StandardException 281 { 282 if (SanityManager.DEBUG) 283 SanityManager.ASSERT(isRightOpen, "isRightOpen is expected to be true"); 284 rightResultSet.close(); 285 isRightOpen = false; 286 } 287 288 } 289 | Popular Tags |