Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public CrossIterator(SQLStatement stmt) throws DatabaseException {
- /* not yet implemented */
- int numTables = stmt.numTables();
- int colCTR = 0;
- int refMark = 0; // refMark is used to set the for loop iterator at the
- // correct index to store the next column object
- int ctr = 0;
- int sizeOfcolArry = 0;
- int colAdvance = 0;
- /**
- * loop to get sum of columns from each table
- * in order to dynamically size columns array
- */
- for (int i = 0; i < numTables; i++) {
- sizeOfcolArry += stmt.getTable(i).numColumns(); // count number of columns in each table
- }
- this.columns = new Column[sizeOfcolArry];
- this.tableIter = new TableIterator[stmt.numTables()];
- /* *
- * loop over num tables in the stmt
- */
- for (int i = 0; i < numTables; i++) {
- Table table = new Table(stmt.getTable(i).getName()); // create table object to store table info
- table.open();
- TableIterator iter = new TableIterator(stmt,table,false);
- colCTR = ctr + table.numColumns(); // count number of columns in each table
- tableIter[i] = iter; // assign iter to tableIter array
- /**
- * loop to store column objects into column array
- */
- ctr = 0;
- for (int j = refMark; j < colCTR; j++) {
- this.columns[j] = table.getColumn(colAdvance);
- colAdvance++;
- ctr++;
- }
- colAdvance = 0;
- refMark = ctr ; // update refMark
- }
- this.where = stmt.getWhere();
- if (this.where == null)
- this.where = new TrueExpression(); // set were clause
- this.numTuples = 0;
- }
- public boolean next() throws DeadlockException, DatabaseException {
- /* not yet implemented */
- // for (int i = 0; i < tableIter.length-1; i++) {
- // tableIter[i].first(); // set all iterators to first row
- // }
- if (tableIter.length > 1){
- for (int i = tableIter.length; i > 0 ; i--) { // start at the right most cell
- // If this is the first time the method has been called,
- // preload the first row of R.
- if (numTuples == 0) {
- if (!tableIter[0].first())
- return false; // R is empty
- }
- // Advance the table iterators as much as needed to get
- // to a combination of rows from R and S that satisfies the
- // WHERE clause.
- do {
- if (!tableIter[i].next()) {
- // We've paired all rows of S with the current row of R,
- // so reset S to its first row...
- if (!tableIter[i].first())
- return false; // S is empty
- // ...and advance to R's next row (if any).
- if (!tableIter[i-1].next())
- return false; // no more rows in R, so we're done
- }
- } while(!this.where.isTrue());
- }
- }
- this.numTuples++;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement