1 21 22 package org.apache.derbyTesting.unitTests.store; 23 24 import org.apache.derby.iapi.store.access.*; 25 26 import org.apache.derby.iapi.types.SQLInteger; 27 28 import org.apache.derby.iapi.services.io.FormatableBitSet; 29 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.store.raw.Transaction; 33 34 import org.apache.derby.iapi.types.DataValueDescriptor; 35 36 import org.apache.derby.iapi.types.RowLocation; 37 38 39 50 public class T_RowSource implements RowSource { 51 52 static public final int INTEGER_ROW_TYPE = 1; 53 static public final int STRING_ROW_TYPE = 2; 54 55 static protected final String REC_001 = "McLaren"; 56 static protected final String REC_002 = "Ferrari"; 57 static protected final String REC_003 = "Benetton"; 58 static protected final String REC_004 = "Prost"; 59 static protected final String REC_005 = "Tyrell"; 60 static protected final String REC_006 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; 61 static protected final String REC_007 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; 62 static protected final String REC_008 = "z"; 63 64 static protected final int DEFAULT_ROW_COUNT = 500000; 65 static protected final int DEFAULT_COLUMN_COUNT = 13; 66 static protected final int DEFAULT_SEED = 53; 68 private int rowCount; 69 private int columnCount; 70 private DataValueDescriptor row[]; 71 private FormatableBitSet validColumns; 72 private boolean forceAbort; 73 private Transaction t; 74 75 78 public T_RowSource() { 79 80 this.rowCount = DEFAULT_ROW_COUNT; 84 this.columnCount = DEFAULT_COLUMN_COUNT; 85 this.row = new DataValueDescriptor[DEFAULT_COLUMN_COUNT]; 86 row = setStringRow(); 87 } 88 89 public T_RowSource(int count, int columnCount, int rowType, boolean forceAbort, Transaction t) { 91 92 this.rowCount = count; 93 this.columnCount = columnCount; 94 validColumns = new FormatableBitSet(columnCount); 95 for (int i = 0; i < columnCount; i++) 96 validColumns.set(i); 97 98 this.row = new DataValueDescriptor[columnCount]; 99 if (rowType == INTEGER_ROW_TYPE) 100 setIntegerRow(); 101 else 102 row = setStringRow(); 103 104 this.forceAbort = forceAbort; 105 this.t = t; 106 } 107 108 public T_RowSource(int count, int columnCount, int rowType, FormatableBitSet validColumns) { 110 111 this.rowCount = count; 112 this.columnCount = columnCount; 113 this.validColumns = validColumns; 114 115 this.row = new DataValueDescriptor[columnCount]; 116 if (rowType == INTEGER_ROW_TYPE) 117 setIntegerRow(); 118 else 119 row = setStringRow(); 120 } 121 122 125 126 131 public boolean hasMoreRows() throws StandardException { 132 if (rowCount > 0) 133 return true; 134 else 135 return false; 136 } 137 138 145 public DataValueDescriptor[] getNextRowFromRowSource() 146 throws StandardException { 147 148 if (this.rowCount <= 0) 149 return null; 150 151 if (forceAbort && (this.rowCount < 3)) 153 t.abort(); 154 155 this.rowCount--; 156 return row; 157 } 158 159 163 public FormatableBitSet getValidColumns() { 164 return validColumns; 165 } 166 167 173 public void closeRowSource() { 174 175 this.rowCount = 0; 176 } 177 178 179 188 public boolean needsRowLocation() { 189 return false; 190 } 191 192 195 public boolean needsToClone() 196 { 197 return true; 198 } 199 200 203 public void rowLocation(RowLocation rl) { 204 205 rl = null; 206 } 207 208 214 public DataValueDescriptor[] getTemplate() throws StandardException { 215 216 return row; 217 218 } 219 220 private void setIntegerRow() { 222 for (int i = 0; i < columnCount; i++) 223 this.row[i] = new SQLInteger(i + DEFAULT_SEED); 224 } 225 226 private DataValueDescriptor[] setStringRow() { 227 228 T_RawStoreRow row = new T_RawStoreRow(columnCount); 229 230 for (int i = 0; i < columnCount; i++) { 231 switch (i % 13) { 232 case 0: 233 row.setColumn(i, (String ) null); 234 break; 235 case 1: 236 row.setColumn(i, REC_001); 237 break; 238 case 2: 239 row.setColumn(i, REC_002); 240 break; 241 case 3: 242 row.setColumn(i, REC_003); 243 break; 244 case 4: 245 row.setColumn(i, REC_004); 246 break; 247 case 5: 248 row.setColumn(i, REC_005); 249 break; 250 case 6: 251 row.setColumn(i, REC_006); 252 break; 253 case 7: 254 row.setColumn(i, REC_007); 255 break; 256 case 8: 257 row.setColumn(i, (String ) null); 258 break; 259 case 9: 260 row.setColumn(i, REC_008); 261 break; 262 case 10: 263 row.setColumn(i, REC_007); 264 break; 265 case 11: 266 row.setColumn(i, (String ) null); 267 break; 268 case 12: 269 row.setColumn(i, REC_006); 270 break; 271 default: 272 row.setColumn(i, REC_008); 273 } 274 } 275 return row.getRow(); 276 } 277 } 278 | Popular Tags |