]> source.dussan.org Git - jackcess.git/commitdiff
consolidate custom iteration configuration into iterable builders
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 29 Mar 2013 12:46:23 +0000 (12:46 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 29 Mar 2013 12:46:23 +0000 (12:46 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@700 f203690c-595d-4dc9-a70b-905162fa7fd2

14 files changed:
TODO.txt
src/java/com/healthmarketscience/jackcess/Cursor.java
src/java/com/healthmarketscience/jackcess/CursorBuilder.java
src/java/com/healthmarketscience/jackcess/IndexCursor.java
src/java/com/healthmarketscience/jackcess/Table.java
src/java/com/healthmarketscience/jackcess/impl/CursorImpl.java
src/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java
src/java/com/healthmarketscience/jackcess/impl/TableImpl.java
src/java/com/healthmarketscience/jackcess/impl/complex/ComplexColumnInfoImpl.java
src/java/com/healthmarketscience/jackcess/util/Joiner.java
test/src/java/com/healthmarketscience/jackcess/CursorTest.java
test/src/java/com/healthmarketscience/jackcess/IndexTest.java
test/src/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java

index 4c86b7ab656b2399cd553cf0fdabc2168229440e..a8187f33e3485c67f0dc55e5a3fd24b73da201f2 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -31,7 +31,7 @@ Refactor goals:
 * move database open/create options to DBBuilder
 * tweak how import filters work to make them more flexible?
 - tweak lookup apis (specify column vs column name)
-- separate classes into more packages (api,builder,util,impl)
+* separate classes into more packages (api,builder,util,impl)
 * remove debug log blocks
 * add Row interface
 * change savepoint to use table number instead of name?
index f2a0de24594381465c47552c897e9552d987ab35..5c6d12f2291903f982bc1e8ed3e63b2cd5a0b59b 100644 (file)
@@ -24,8 +24,9 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 
-import com.healthmarketscience.jackcess.util.ErrorHandler;
 import com.healthmarketscience.jackcess.util.ColumnMatcher;
+import com.healthmarketscience.jackcess.util.ErrorHandler;
+import com.healthmarketscience.jackcess.util.IterableBuilder;
 
 /**
  * Manages iteration for a Table.  Different cursors provide different methods
@@ -125,101 +126,24 @@ public interface Cursor extends Iterable<Row>
    */
   public boolean isCurrentRowDeleted() throws IOException;
 
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #afterLast} on
-   * this cursor and returns a modifiable Iterator which will iterate through
-   * all the rows of this table in reverse order.  Use of the Iterator follows
-   * the same restrictions as a call to {@link #getPreviousRow}.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> reverseIterable();
-  
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #afterLast} on
-   * this table and returns a modifiable Iterator which will iterate through
-   * all the rows of this table in reverse order, returning only the given
-   * columns.  Use of the Iterator follows the same restrictions as a call to
-   * {@link #getPreviousRow}.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> reverseIterable(
-      Collection<String> columnNames);
-
   /**
    * Calls {@link #beforeFirst} on this cursor and returns a modifiable
    * Iterator which will iterate through all the rows of this table.  Use of
    * the Iterator follows the same restrictions as a call to
    * {@link #getNextRow}.
+   * <p/>
+   * For more flexible iteration see {@link #newIterable}.
    * @throws RuntimeIOException if an IOException is thrown by one of the
    *         operations, the actual exception will be contained within
    */
   public Iterator<Row> iterator();
 
   /**
-   * Returns an Iterable whose iterator() method calls {@link #beforeFirst} on
-   * this table and returns a modifiable Iterator which will iterate through
-   * all the rows of this table, returning only the given columns.  Use of the
-   * Iterator follows the same restrictions as a call to {@link #getNextRow}.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> iterable(
-      Collection<String> columnNames);
-
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #beforeFirst} on
-   * this cursor and returns a modifiable Iterator which will iterate through
-   * all the rows of this table which match the given column pattern.  Use of
-   * the Iterator follows the same restrictions as a call to {@link
-   * #getNextRow}.  See {@link #findFirstRow(Column,Object)} for details on
-   * #the columnPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> columnMatchIterable(
-      Column columnPattern, Object valuePattern);
-
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #beforeFirst} on
-   * this table and returns a modifiable Iterator which will iterate through
-   * all the rows of this table which match the given column pattern,
-   * returning only the given columns.  Use of the Iterator follows the same
-   * restrictions as a call to {@link #getNextRow}.  See {@link
-   * #findFirstRow(Column,Object)} for details on the columnPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> columnMatchIterable(
-      Collection<String> columnNames,
-      Column columnPattern, Object valuePattern);
-
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #beforeFirst} on
-   * this cursor and returns a modifiable Iterator which will iterate through
-   * all the rows of this table which match the given row pattern.  Use of the
-   * Iterator follows the same restrictions as a call to {@link #getNextRow}.
-   * See {@link #findFirstRow(Map)} for details on the rowPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> rowMatchIterable(
-      Map<String,?> rowPattern);
-
-  /**
-   * Returns an Iterable whose iterator() method calls {@link #beforeFirst} on
-   * this table and returns a modifiable Iterator which will iterate through
-   * all the rows of this table which match the given row pattern, returning
-   * only the given columns.  Use of the Iterator follows the same
-   * restrictions as a call to {@link #getNextRow}.  See {@link
-   * #findFirstRow(Map)} for details on the rowPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
+   * Convenience method for constructing a new IterableBuilder for this
+   * cursor.  An IterableBuilder provides a variety of options for more
+   * flexible iteration.
    */
-  public Iterable<Row> rowMatchIterable(
-      Collection<String> columnNames,
-      Map<String,?> rowPattern);
+  public IterableBuilder newIterable();
 
   /**
    * Delete the current row.
index 92a9604ba0ac0505a206ff859f28f3f7607240ec..9485090604aba82d6d0d1a04ecba9da812d96de3 100644 (file)
@@ -315,7 +315,7 @@ public class CursorBuilder {
    * @param table the table over which this cursor will traverse
    */
   public static Cursor createCursor(Table table) throws IOException {
-    return new CursorBuilder(table).toCursor();
+    return table.newCursor().toCursor();
   }
 
   /**
@@ -332,7 +332,7 @@ public class CursorBuilder {
   public static IndexCursor createCursor(Table table, Index index)
     throws IOException
   {
-    return new CursorBuilder(table).setIndex(index).toIndexCursor();
+    return table.newCursor().setIndex(index).toIndexCursor();
   }
   
   /**
@@ -355,7 +355,7 @@ public class CursorBuilder {
                                          Object[] startRow, Object[] endRow)
     throws IOException
   {
-    return new CursorBuilder(table).setIndex(index)
+    return table.newCursor().setIndex(index)
       .setStartRow(startRow)
       .setEndRow(endRow)
       .toIndexCursor();
@@ -386,7 +386,7 @@ public class CursorBuilder {
                                          boolean endInclusive)
     throws IOException
   {
-    return new CursorBuilder(table).setIndex(index)
+    return table.newCursor().setIndex(index)
       .setStartRow(startRow)
       .setStartRowInclusive(startInclusive)
       .setEndRow(endRow)
index 6e1d0c97d3943f9bd3d46b587d494b191dc32a20..7871b65d78b52a055cf6ca62d427cd130489450e 100644 (file)
@@ -20,9 +20,8 @@ USA
 package com.healthmarketscience.jackcess;
 
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
+
+import com.healthmarketscience.jackcess.util.EntryIterableBuilder;
 
 /**
  * Cursor backed by an index with extended traversal options.
@@ -68,38 +67,11 @@ public interface IndexCursor extends Cursor
     throws IOException;
 
   /**
-   * Returns a modifiable Iterator which will iterate through all the rows of
-   * this table which match the given index entries.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> entryIterator(Object... entryValues);
-
-  /**
-   * Returns a modifiable Iterator which will iterate through all the rows of
-   * this table which match the given index entries, returning only the given
-   * columns.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> entryIterator(
-      Collection<String> columnNames, Object... entryValues);
-
-  /**
-   * Returns an Iterable whose iterator() method returns the result of a call
-   * to {@link #entryIterator(Object...)}
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterable<Row> entryIterable(Object... entryValues);
-
-  /**
-   * Returns an Iterable whose iterator() method returns the result of a call
-   * to {@link #entryIterator(Collection,Object...)}
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
+   * Convenience method for constructing a new EntryIterableBuilder for this
+   * cursor.  An EntryIterableBuilder provides a variety of options for more
+   * flexible iteration based on a specific index entry.
+   * 
+   * @param entryValues the column values for the index's columns.
    */
-  public Iterable<Row> entryIterable(
-      Collection<String> columnNames, Object... entryValues);
-
+  public EntryIterableBuilder newEntryIterable(Object... entryValues);
 }
index 12e9a3494b18b126ed87e45cc78efba1a94d141d..25b91c8dba39c112d2d0103cd7b08f49b215c05c 100644 (file)
@@ -274,4 +274,9 @@ public interface Table extends Iterable<Row>
    *         use the Cursor directly.
    */
   public Cursor getDefaultCursor();
+
+  /**
+   * Convenience method for constructing a new CursorBuilder for this Table.
+   */
+  public CursorBuilder newCursor();
 }
index e0d39386af373ea53e4014f8257899356c681a91..b0c228a873dd65db246967c15381e4a199129bec 100644 (file)
@@ -34,17 +34,18 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
-import com.healthmarketscience.jackcess.impl.TableImpl.RowState;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.Cursor;
 import com.healthmarketscience.jackcess.CursorBuilder;
-import com.healthmarketscience.jackcess.util.ErrorHandler;
-import com.healthmarketscience.jackcess.util.ColumnMatcher;
-import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.RuntimeIOException;
+import com.healthmarketscience.jackcess.impl.TableImpl.RowState;
+import com.healthmarketscience.jackcess.util.ColumnMatcher;
+import com.healthmarketscience.jackcess.util.ErrorHandler;
+import com.healthmarketscience.jackcess.util.IterableBuilder;
 import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Manages iteration for a Table.  Different cursors provide different methods
@@ -201,22 +202,21 @@ public abstract class CursorImpl implements Cursor
     reset(MOVE_REVERSE);
   }
 
-  public boolean isBeforeFirst() throws IOException
-  {
-    if(getFirstPosition().equals(_curPos)) {
-      return !recheckPosition(MOVE_REVERSE);
-    }
-    return false;
+  public boolean isBeforeFirst() throws IOException {
+    return isAtBeginning(MOVE_FORWARD);
   }
   
-  public boolean isAfterLast() throws IOException
-  {
-    if(getLastPosition().equals(_curPos)) {
-      return !recheckPosition(MOVE_FORWARD);
+  public boolean isAfterLast() throws IOException {
+    return isAtBeginning(MOVE_REVERSE);
+  }
+
+  protected boolean isAtBeginning(boolean moveForward) throws IOException {
+    if(getDirHandler(moveForward).getBeginningPosition().equals(_curPos)) {
+      return !recheckPosition(!moveForward);
     }
     return false;
   }
-
+  
   public boolean isCurrentRowDeleted() throws IOException
   {
     // we need to ensure that the "deleted" flag has been read for this row
@@ -233,176 +233,43 @@ public abstract class CursorImpl implements Cursor
     _prevPos = _curPos;
     _rowState.reset();
   }  
-
-  public Iterable<Row> reverseIterable() {
-    return reverseIterable(null);
-  }
-  
-  public Iterable<Row> reverseIterable(
-      final Collection<String> columnNames)
-  {
-    return new Iterable<Row>() {
-      public Iterator<Row> iterator() {
-        return new RowIterator(columnNames, MOVE_REVERSE);
-      }
-    };
-  }
-  
-  public Iterator<Row> iterator()
-  {
-    return iterator(null);
-  }
   
-  public Iterable<Row> iterable(
-      final Collection<String> columnNames)
-  {
-    return new Iterable<Row>() {
-      public Iterator<Row> iterator() {
-        return CursorImpl.this.iterator(columnNames);
-      }
-    };
-  }
-  
-  /**
-   * Calls <code>beforeFirst</code> on this table and returns a modifiable
-   * Iterator which will iterate through all the rows of this table, returning
-   * only the given columns.  Use of the Iterator follows the same
-   * restrictions as a call to <code>getNextRow</code>.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> iterator(Collection<String> columnNames)
-  {
-    return new RowIterator(columnNames, MOVE_FORWARD);
-  }
-
-  public Iterable<Row> columnMatchIterable(
-      Column columnPattern, Object valuePattern)
-  {
-    return columnMatchIterable((ColumnImpl)columnPattern, valuePattern);
-  }
-
-  public Iterable<Row> columnMatchIterable(
-      ColumnImpl columnPattern, Object valuePattern)
-  {
-    return columnMatchIterable(null, columnPattern, valuePattern);
-  }
-
-  /**
-   * Calls <code>beforeFirst</code> on this cursor and returns a modifiable
-   * Iterator which will iterate through all the rows of this table which
-   * match the given column pattern.  Use of the Iterator follows the same
-   * restrictions as a call to <code>getNextRow</code>.  See
-   * {@link #findFirstRow(Column,Object)} for details on the columnPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> columnMatchIterator(
-      Column columnPattern, Object valuePattern)
-  {
-    return columnMatchIterator((ColumnImpl)columnPattern, valuePattern);
-  } 
-  public Iterator<Row> columnMatchIterator(
-      ColumnImpl columnPattern, Object valuePattern)
-  {
-    return columnMatchIterator(null, columnPattern, valuePattern);
+  public Iterator<Row> iterator() {
+    return new RowIterator(null, true, MOVE_FORWARD);
   }
 
-  public Iterable<Row> columnMatchIterable(
-      Collection<String> columnNames,
-      Column columnPattern, Object valuePattern)
-  {
-    return columnMatchIterable(columnNames, (ColumnImpl)columnPattern, 
-                               valuePattern);
-  } 
-  public Iterable<Row> columnMatchIterable(
-      final Collection<String> columnNames,
-      final ColumnImpl columnPattern, final Object valuePattern)
-  {
-    return new Iterable<Row>() {
-      public Iterator<Row> iterator() {
-        return CursorImpl.this.columnMatchIterator(
-            columnNames, columnPattern, valuePattern);
-      }
-    };
+  public IterableBuilder newIterable() {
+    return new IterableBuilder(this);
   }
 
-  /**
-   * Calls <code>beforeFirst</code> on this table and returns a modifiable
-   * Iterator which will iterate through all the rows of this table which
-   * match the given column pattern, returning only the given columns.  Use of
-   * the Iterator follows the same restrictions as a call to
-   * <code>getNextRow</code>.  See {@link #findFirstRow(Column,Object)} for
-   * details on the columnPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> columnMatchIterator(
-      Collection<String> columnNames, Column columnPattern, 
-      Object valuePattern)
-  {
-    return columnMatchIterator(columnNames, (ColumnImpl)columnPattern, 
-                               valuePattern);
-  } 
-  public Iterator<Row> columnMatchIterator(
-      Collection<String> columnNames, ColumnImpl columnPattern, 
-      Object valuePattern)
-  {
-    return new ColumnMatchIterator(columnNames, columnPattern, valuePattern);
-  }
+  public Iterator<Row> iterator(IterableBuilder iterBuilder) {
 
-  public Iterable<Row> rowMatchIterable(
-      Map<String,?> rowPattern)
-  {
-    return rowMatchIterable(null, rowPattern);
-  }
-  
-  /**
-   * Calls <code>beforeFirst</code> on this cursor and returns a modifiable
-   * Iterator which will iterate through all the rows of this table which
-   * match the given row pattern.  Use of the Iterator follows the same
-   * restrictions as a call to <code>getNextRow</code>.  See
-   * {@link #findFirstRow(Map)} for details on the rowPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> rowMatchIterator(
-      Map<String,?> rowPattern)
-  {
-    return rowMatchIterator(null, rowPattern);
-  }
-  
-  public Iterable<Row> rowMatchIterable(
-      final Collection<String> columnNames,
-      final Map<String,?> rowPattern)
-  {
-    return new Iterable<Row>() {
-      public Iterator<Row> iterator() {
-        return CursorImpl.this.rowMatchIterator(
-            columnNames, rowPattern);
-      }
-    };
+    switch(iterBuilder.getType()) {
+    case SIMPLE:
+      return new RowIterator(iterBuilder.getColumnNames(),
+                             iterBuilder.isReset(), iterBuilder.isForward());
+    case COLUMN_MATCH: {
+      @SuppressWarnings("unchecked")
+      Map.Entry<Column,Object> matchPattern = (Map.Entry<Column,Object>)
+        iterBuilder.getMatchPattern();
+      return new ColumnMatchIterator(
+          iterBuilder.getColumnNames(), (ColumnImpl)matchPattern.getKey(), 
+          matchPattern.getValue(), iterBuilder.isReset(), 
+          iterBuilder.isForward(), iterBuilder.getColumnMatcher());
+    }
+    case ROW_MATCH: {
+      @SuppressWarnings("unchecked")
+      Map<String,?> matchPattern = (Map<String,?>)
+        iterBuilder.getMatchPattern();
+      return new RowMatchIterator(
+          iterBuilder.getColumnNames(), matchPattern,iterBuilder.isReset(), 
+          iterBuilder.isForward(), iterBuilder.getColumnMatcher());
+    }
+    default:
+      throw new RuntimeException("unknown match type " + iterBuilder.getType());
+    }
   }
   
-  /**
-   * Calls <code>beforeFirst</code> on this table and returns a modifiable
-   * Iterator which will iterate through all the rows of this table which
-   * match the given row pattern, returning only the given columns.  Use of
-   * the Iterator follows the same restrictions as a call to
-   * <code>getNextRow</code>.  See {@link #findFirstRow(Map)} for details on
-   * the rowPattern.
-   * @throws RuntimeIOException if an IOException is thrown by one of the
-   *         operations, the actual exception will be contained within
-   */
-  public Iterator<Row> rowMatchIterator(
-      Collection<String> columnNames, Map<String,?> rowPattern)
-  {
-    return new RowMatchIterator(columnNames, rowPattern);
-  }
-
   public void deleteCurrentRow() throws IOException {
     _table.deleteRow(_rowState, _curPos.getRowId());
   }
@@ -471,7 +338,7 @@ public abstract class CursorImpl implements Cursor
    * @return {@code true} if another valid row was found in the given
    *         direction, {@code false} otherwise
    */
-  private boolean moveToAnotherRow(boolean moveForward)
+  protected boolean moveToAnotherRow(boolean moveForward)
     throws IOException
   {
     if(_curPos.equals(getDirHandler(moveForward).getEndPosition())) {
@@ -559,22 +426,8 @@ public abstract class CursorImpl implements Cursor
   public boolean findFirstRow(ColumnImpl columnPattern, Object valuePattern)
     throws IOException
   {
-    PositionImpl curPos = _curPos;
-    PositionImpl prevPos = _prevPos;
-    boolean found = false;
-    try {
-      beforeFirst();
-      found = findNextRowImpl(columnPattern, valuePattern);
-      return found;
-    } finally {
-      if(!found) {
-        try {
-          restorePosition(curPos, prevPos);
-        } catch(IOException e) {
-          LOG.error("Failed restoring position", e);
-        }
-      }
-    }
+    return findAnotherRow(columnPattern, valuePattern, true, MOVE_FORWARD,
+                          _columnMatcher);
   }
 
   public boolean findNextRow(Column columnPattern, Object valuePattern)
@@ -585,12 +438,25 @@ public abstract class CursorImpl implements Cursor
  
   public boolean findNextRow(ColumnImpl columnPattern, Object valuePattern)
     throws IOException
+  {
+    return findAnotherRow(columnPattern, valuePattern, false, MOVE_FORWARD,
+                          _columnMatcher);
+  }
+  
+  protected boolean findAnotherRow(ColumnImpl columnPattern, Object valuePattern,
+                                   boolean reset, boolean moveForward,
+                                   ColumnMatcher columnMatcher)
+    throws IOException
   {
     PositionImpl curPos = _curPos;
     PositionImpl prevPos = _prevPos;
     boolean found = false;
     try {
-      found = findNextRowImpl(columnPattern, valuePattern);
+      if(reset) {
+        reset(moveForward);
+      }
+      found = findAnotherRowImpl(columnPattern, valuePattern, moveForward,
+                                 columnMatcher);
       return found;
     } finally {
       if(!found) {
@@ -605,32 +471,28 @@ public abstract class CursorImpl implements Cursor
   
   public boolean findFirstRow(Map<String,?> rowPattern) throws IOException
   {
-    PositionImpl curPos = _curPos;
-    PositionImpl prevPos = _prevPos;
-    boolean found = false;
-    try {
-      beforeFirst();
-      found = findNextRowImpl(rowPattern);
-      return found;
-    } finally {
-      if(!found) {
-        try {
-          restorePosition(curPos, prevPos);
-        } catch(IOException e) {
-          LOG.error("Failed restoring position", e);
-        }
-      }
-    }
+    return findAnotherRow(rowPattern, true, MOVE_FORWARD, _columnMatcher);
   }
 
   public boolean findNextRow(Map<String,?> rowPattern)
     throws IOException
+  {
+    return findAnotherRow(rowPattern, false, MOVE_FORWARD, _columnMatcher);
+  }
+
+  protected boolean findAnotherRow(Map<String,?> rowPattern, boolean reset,
+                                   boolean moveForward, 
+                                   ColumnMatcher columnMatcher)
+    throws IOException
   {
     PositionImpl curPos = _curPos;
     PositionImpl prevPos = _prevPos;
     boolean found = false;
     try {
-      found = findNextRowImpl(rowPattern);
+      if(reset) {
+        reset(moveForward);
+      }
+      found = findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
       return found;
     } finally {
       if(!found) {
@@ -652,13 +514,28 @@ public abstract class CursorImpl implements Cursor
   public boolean currentRowMatches(ColumnImpl columnPattern, Object valuePattern)
     throws IOException
   {
-    return _columnMatcher.matches(getTable(), columnPattern.getName(),
-                                  valuePattern,
-                                  getCurrentRowValue(columnPattern));
+    return currentRowMatchesImpl(columnPattern, valuePattern, _columnMatcher);
+  }
+  
+  protected boolean currentRowMatchesImpl(ColumnImpl columnPattern, 
+                                          Object valuePattern,
+                                          ColumnMatcher columnMatcher)
+    throws IOException
+  {
+    return columnMatcher.matches(getTable(), columnPattern.getName(),
+                                 valuePattern,
+                                 getCurrentRowValue(columnPattern));
   }
   
   public boolean currentRowMatches(Map<String,?> rowPattern)
     throws IOException
+  {
+    return currentRowMatchesImpl(rowPattern, _columnMatcher);
+  }
+
+  protected boolean currentRowMatchesImpl(Map<String,?> rowPattern,
+                                          ColumnMatcher columnMatcher)
+    throws IOException
   {
     Row row = getCurrentRow(rowPattern.keySet());
 
@@ -668,8 +545,8 @@ public abstract class CursorImpl implements Cursor
 
     for(Map.Entry<String,Object> e : row.entrySet()) {
       String columnName = e.getKey();
-      if(!_columnMatcher.matches(getTable(), columnName,
-                                 rowPattern.get(columnName), e.getValue())) {
+      if(!columnMatcher.matches(getTable(), columnName,
+                                rowPattern.get(columnName), e.getValue())) {
         return false;
       }
     }
@@ -690,11 +567,13 @@ public abstract class CursorImpl implements Cursor
    * @return {@code true} if a valid row was found with the given value,
    *         {@code false} if no row was found
    */
-  protected boolean findNextRowImpl(ColumnImpl columnPattern, Object valuePattern)
+  protected boolean findAnotherRowImpl(
+      ColumnImpl columnPattern, Object valuePattern, boolean moveForward,
+      ColumnMatcher columnMatcher)
     throws IOException
   {
-    while(moveToNextRow()) {
-      if(currentRowMatches(columnPattern, valuePattern)) {
+    while(moveToAnotherRow(moveForward)) {
+      if(currentRowMatchesImpl(columnPattern, valuePattern, columnMatcher)) {
         return true;
       }
     }
@@ -712,11 +591,13 @@ public abstract class CursorImpl implements Cursor
    * @return {@code true} if a valid row was found with the given values,
    *         {@code false} if no row was found
    */
-  protected boolean findNextRowImpl(Map<String,?> rowPattern)
+  protected boolean findAnotherRowImpl(Map<String,?> rowPattern, 
+                                       boolean moveForward, 
+                                       ColumnMatcher columnMatcher)
     throws IOException
   {
-    while(moveToNextRow()) {
-      if(currentRowMatches(rowPattern)) {
+    while(moveToAnotherRow(moveForward)) {
+      if(currentRowMatchesImpl(rowPattern, columnMatcher)) {
         return true;
       }
     }
@@ -821,16 +702,24 @@ public abstract class CursorImpl implements Cursor
   /**
    * Base implementation of iterator for this cursor, modifiable.
    */
-  protected abstract class BaseIterator
-    implements Iterator<Row>
+  protected abstract class BaseIterator implements Iterator<Row>
   {
     protected final Collection<String> _columnNames;
+    protected final boolean _moveForward;
+    protected final ColumnMatcher _colMatcher;
     protected Boolean _hasNext;
     protected boolean _validRow;
     
-    protected BaseIterator(Collection<String> columnNames)
+    protected BaseIterator(Collection<String> columnNames,
+                           boolean reset, boolean moveForward,
+                           ColumnMatcher columnMatcher)
     {
       _columnNames = columnNames;
+      _moveForward = moveForward;
+      _colMatcher = ((columnMatcher != null) ? columnMatcher : _columnMatcher);
+      if(reset) {
+        reset(_moveForward);
+      } 
     }
 
     public boolean hasNext() {
@@ -880,13 +769,10 @@ public abstract class CursorImpl implements Cursor
    */
   private final class RowIterator extends BaseIterator
   {
-    private final boolean _moveForward;
-    
-    private RowIterator(Collection<String> columnNames, boolean moveForward)
+    private RowIterator(Collection<String> columnNames, boolean reset,
+                        boolean moveForward)
     {
-      super(columnNames);
-      _moveForward = moveForward;
-      reset(_moveForward);
+      super(columnNames, reset, moveForward, null);
     }
 
     @Override
@@ -905,17 +791,19 @@ public abstract class CursorImpl implements Cursor
     private final Object _valuePattern;
     
     private ColumnMatchIterator(Collection<String> columnNames,
-                                ColumnImpl columnPattern, Object valuePattern)
+                                ColumnImpl columnPattern, Object valuePattern,
+                                boolean reset, boolean moveForward,
+                                ColumnMatcher columnMatcher)
     {
-      super(columnNames);
+      super(columnNames, reset, moveForward, columnMatcher);
       _columnPattern = columnPattern;
       _valuePattern = valuePattern;
-      beforeFirst();
     }
 
     @Override
     protected boolean findNext() throws IOException {
-      return findNextRow(_columnPattern, _valuePattern);
+      return findAnotherRow(_columnPattern, _valuePattern, false, _moveForward,
+                            _colMatcher);
     }
   }
 
@@ -928,16 +816,17 @@ public abstract class CursorImpl implements Cursor
     private final Map<String,?> _rowPattern;
     
     private RowMatchIterator(Collection<String> columnNames,
-                             Map<String,?> rowPattern)
+                             Map<String,?> rowPattern,
+                             boolean reset, boolean moveForward,
+                             ColumnMatcher columnMatcher)
     {
-      super(columnNames);
+      super(columnNames, reset, moveForward, columnMatcher);
       _rowPattern = rowPattern;
-      beforeFirst();
     }
 
     @Override
     protected boolean findNext() throws IOException {
-      return findNextRow(_rowPattern);
+      return findAnotherRow(_rowPattern, false, _moveForward, _colMatcher);
     }
   }
 
index 5c193b3304522f9cfd125d5d0a3da2c4c0408253..9d513af8f32fb154b74c301f566e7e2b471752c1 100644 (file)
@@ -828,7 +828,7 @@ public class DatabaseImpl implements Database
 
     try {
       _tableFinder = new DefaultTableFinder(
-          new CursorBuilder(_systemCatalog)
+          _systemCatalog.newCursor()
             .setIndexByColumnNames(CAT_COL_PARENT_ID, CAT_COL_NAME)
             .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)
             .toIndexCursor());
@@ -837,7 +837,7 @@ public class DatabaseImpl implements Database
                _systemCatalog.getName());
       // use table scan instead
       _tableFinder = new FallbackTableFinder(
-          new CursorBuilder(_systemCatalog)
+          _systemCatalog.newCursor()
             .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)
             .toCursor());
     }
@@ -1072,7 +1072,8 @@ public class DatabaseImpl implements Database
     Map<Integer,List<Query.Row>> queryRowMap = 
       new HashMap<Integer,List<Query.Row>>();
     for(Row row :
-          CursorImpl.createCursor(_systemCatalog).iterable(SYSTEM_CATALOG_COLUMNS))
+          CursorImpl.createCursor(_systemCatalog).newIterable().setColumnNames(
+              SYSTEM_CATALOG_COLUMNS))
     {
       String name = (String) row.get(CAT_COL_NAME);
       if (name != null && TYPE_QUERY.equals(row.get(CAT_COL_TYPE))) {
@@ -1405,7 +1406,7 @@ public class DatabaseImpl implements Database
     throws IOException
   {
     try {
-      return new CursorBuilder(table)
+      return table.newCursor()
         .setIndexByColumns(table.getColumn(colName))
         .setSpecificEntry(colValue)
         .toCursor();
@@ -1814,7 +1815,7 @@ public class DatabaseImpl implements Database
                               boolean systemTables)
       throws IOException
     {
-      for(Row row : getTableNamesCursor().iterable(
+      for(Row row : getTableNamesCursor().newIterable().setColumnNames(
               SYSTEM_CATALOG_TABLE_NAME_COLUMNS)) {
 
         String tableName = (String)row.get(CAT_COL_NAME);
@@ -1867,7 +1868,7 @@ public class DatabaseImpl implements Database
     
     private void initIdCursor() throws IOException {
       if(_systemCatalogIdCursor == null) {
-        _systemCatalogIdCursor = new CursorBuilder(_systemCatalog)
+        _systemCatalogIdCursor = _systemCatalog.newCursor()
           .setIndexByColumnNames(CAT_COL_ID)
           .toIndexCursor();
       }
@@ -1916,7 +1917,7 @@ public class DatabaseImpl implements Database
     
     @Override
     protected Cursor getTableNamesCursor() throws IOException {
-      return new CursorBuilder(_systemCatalog)
+      return _systemCatalog.newCursor()
         .setIndex(_systemCatalogCursor.getIndex())
         .setStartEntry(_tableParentId, IndexData.MIN_VALUE)
         .setEndEntry(_tableParentId, IndexData.MAX_VALUE)
@@ -1972,7 +1973,7 @@ public class DatabaseImpl implements Database
     @Override
     public TableInfo lookupTable(String tableName) throws IOException {
 
-      for(Row row : _systemCatalogCursor.iterable(
+      for(Row row : _systemCatalogCursor.newIterable().setColumnNames(
               SYSTEM_CATALOG_TABLE_NAME_COLUMNS)) {
 
         Short type = (Short)row.get(CAT_COL_TYPE);
index 3b76fa80af6f7ebac6ac771378a1dfd42d000f93..f53b9802b62eced5316d45e8f8c94b6fd8ab7e68 100644 (file)
@@ -33,6 +33,7 @@ import com.healthmarketscience.jackcess.RuntimeIOException;
 import com.healthmarketscience.jackcess.impl.TableImpl.RowState;
 import com.healthmarketscience.jackcess.util.CaseInsensitiveColumnMatcher;
 import com.healthmarketscience.jackcess.util.ColumnMatcher;
+import com.healthmarketscience.jackcess.util.EntryIterableBuilder;
 import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -130,7 +131,8 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
     PositionImpl prevPos = _prevPos;
     boolean found = false;
     try {
-      found = findFirstRowByEntryImpl(toRowValues(entryValues), true);
+      found = findFirstRowByEntryImpl(toRowValues(entryValues), true, 
+                                      _columnMatcher);
       return found;
     } finally {
       if(!found) {
@@ -150,7 +152,8 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
     PositionImpl prevPos = _prevPos;
     boolean found = false;
     try {
-      findFirstRowByEntryImpl(toRowValues(entryValues), false);
+      findFirstRowByEntryImpl(toRowValues(entryValues), false,
+                              _columnMatcher);
       found = true;
     } finally {
       if(!found) {
@@ -166,33 +169,17 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
   public boolean currentRowMatchesEntry(Object... entryValues) 
     throws IOException 
   {
-    return currentRowMatchesEntryImpl(toRowValues(entryValues));
+    return currentRowMatchesEntryImpl(toRowValues(entryValues), _columnMatcher);
   }
-  
-  public Iterator<Row> entryIterator(Object... entryValues)
-  {
-    return entryIterator((Collection<String>)null, entryValues);
-  }
-  
-  public Iterator<Row> entryIterator(
-      Collection<String> columnNames, Object... entryValues)
-  {
-    return new EntryIterator(columnNames, toRowValues(entryValues));
-  }
-  
-  public Iterable<Row> entryIterable(Object... entryValues)
-  {
-    return entryIterable((Collection<String>)null, entryValues);
+
+  public EntryIterableBuilder newEntryIterable(Object... entryValues) {
+    return new EntryIterableBuilder(this, entryValues);
   }
-  
-  public Iterable<Row> entryIterable(
-      final Collection<String> columnNames, final Object... entryValues)
-  {
-    return new Iterable<Row>() {
-      public Iterator<Row> iterator() {
-        return new EntryIterator(columnNames, toRowValues(entryValues));
-      }
-    };
+
+  public Iterator<Row> entryIterator(EntryIterableBuilder iterBuilder) {
+    return new EntryIterator(iterBuilder.getColumnNames(),
+                             toRowValues(iterBuilder.getEntryValues()),
+                             iterBuilder.getColumnMatcher());
   }
   
   @Override
@@ -226,12 +213,15 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
   }
 
   @Override
-  protected boolean findNextRowImpl(ColumnImpl columnPattern, Object valuePattern)
+  protected boolean findAnotherRowImpl(
+      ColumnImpl columnPattern, Object valuePattern, boolean moveForward,
+      ColumnMatcher columnMatcher)
     throws IOException
   {
-    if(!isBeforeFirst()) {
+    if(!isAtBeginning(moveForward)) {
       // use the default table scan for finding rows mid-cursor
-      return super.findNextRowImpl(columnPattern, valuePattern);
+      return super.findAnotherRowImpl(columnPattern, valuePattern, moveForward,
+                                      columnMatcher);
     }
 
     // searching for the first match
@@ -240,7 +230,8 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
 
     if(rowValues == null) {
       // bummer, use the default table scan
-      return super.findNextRowImpl(columnPattern, valuePattern);
+      return super.findAnotherRowImpl(columnPattern, valuePattern, moveForward,
+                                      columnMatcher);
     }
       
     // sweet, we can use our index
@@ -250,7 +241,7 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
 
     // either we found a row with the given value, or none exist in the
     // table
-    return currentRowMatches(columnPattern, valuePattern);
+    return currentRowMatchesImpl(columnPattern, valuePattern, columnMatcher);
   }
 
   /**
@@ -263,7 +254,8 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
    *         {@code false} if no row was found
    */
   protected boolean findFirstRowByEntryImpl(Object[] rowValues,
-                                            boolean requireMatch) 
+                                            boolean requireMatch,
+                                            ColumnMatcher columnMatcher) 
     throws IOException 
   {
     if(!findPotentialRow(rowValues, requireMatch)) {
@@ -273,16 +265,18 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
       return true;
     }
 
-    return currentRowMatchesEntryImpl(rowValues);
+    return currentRowMatchesEntryImpl(rowValues, columnMatcher);
   }
 
   @Override
-  protected boolean findNextRowImpl(Map<String,?> rowPattern)
+  protected boolean findAnotherRowImpl(Map<String,?> rowPattern, 
+                                       boolean moveForward,
+                                       ColumnMatcher columnMatcher)
     throws IOException
   {
-    if(!isBeforeFirst()) {
+    if(!isAtBeginning(moveForward)) {
       // use the default table scan for finding rows mid-cursor
-      return super.findNextRowImpl(rowPattern);
+      return super.findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
     }
 
     // searching for the first match
@@ -291,7 +285,7 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
 
     if(rowValues == null) {
       // bummer, use the default table scan
-      return super.findNextRowImpl(rowPattern);
+      return super.findAnotherRowImpl(rowPattern, moveForward, columnMatcher);
     }
 
     // sweet, we can use our index
@@ -321,25 +315,27 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
     // longer match
     do {
 
-      if(!currentRowMatches(indexRowPattern)) {
+      if(!currentRowMatchesImpl(indexRowPattern, columnMatcher)) {
         // there are no more rows which could possibly match
         break;
       }
 
       // note, if rowPattern == indexRowPattern, no need to do an extra
       // comparison with the current row
-      if((rowPattern == indexRowPattern) || currentRowMatches(rowPattern)) {
+      if((rowPattern == indexRowPattern) || 
+         currentRowMatchesImpl(rowPattern, columnMatcher)) {
         // found it!
         return true;
       }
 
-    } while(moveToNextRow());
+    } while(moveToAnotherRow(moveForward));
         
     // none of the potential rows matched
     return false;
   }
 
-  private boolean currentRowMatchesEntryImpl(Object[] rowValues)
+  private boolean currentRowMatchesEntryImpl(Object[] rowValues, 
+                                             ColumnMatcher columnMatcher)
     throws IOException
   {
     if(_indexEntryPattern == null) {
@@ -357,8 +353,7 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
       String columnName = col.getName();
       Object patValue = rowValues[col.getColumnIndex()];
       Object rowValue = row.get(columnName);
-      if(!_columnMatcher.matches(getTable(), columnName,
-                                 patValue, rowValue)) {
+      if(!columnMatcher.matches(getTable(), columnName, patValue, rowValue)) {
         return false;
       }
     }
@@ -490,12 +485,13 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
   {
     private final Object[] _rowValues;
     
-    private EntryIterator(Collection<String> columnNames, Object[] rowValues)
+    private EntryIterator(Collection<String> columnNames, Object[] rowValues,
+                          ColumnMatcher columnMatcher)
     {
-      super(columnNames);
+      super(columnNames, false, MOVE_FORWARD, columnMatcher);
       _rowValues = rowValues;
       try {
-        _hasNext = findFirstRowByEntryImpl(rowValues, true);
+        _hasNext = findFirstRowByEntryImpl(rowValues, true, _columnMatcher);
         _validRow = _hasNext;
       } catch(IOException e) {
           throw new RuntimeIOException(e);
@@ -504,7 +500,8 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor
 
     @Override
     protected boolean findNext() throws IOException {
-      return (moveToNextRow() && currentRowMatchesEntryImpl(_rowValues));
+      return (moveToNextRow() && 
+              currentRowMatchesEntryImpl(_rowValues, _colMatcher));
     }    
   }
 
index ae5a33ae871898fa392a8ac034ae64ee6f278fc6..6d260149e68cd2d053c812b982423d98877ab303 100644 (file)
@@ -44,6 +44,7 @@ import java.util.Set;
 
 import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.IndexBuilder;
@@ -469,6 +470,10 @@ public class TableImpl implements Table
     }
     return _defaultCursor;
   }
+
+  public CursorBuilder newCursor() {
+    return new CursorBuilder(this);
+  }
   
   public void reset() {
     getDefaultCursor().reset();
index 10d4ef51dc18879a0799ab064439495cb354309e..97734960f1ffeef8b0180707264ef2ec634f838b 100644 (file)
@@ -142,12 +142,13 @@ public abstract class ComplexColumnInfoImpl<V extends ComplexValue>
     throws IOException
   {
     if(_complexValIdCursor == null) {
-      _complexValIdCursor = new CursorBuilder(_flatTable)
+      _complexValIdCursor = _flatTable.newCursor()
         .setIndexByColumns(_complexValFkCol)
         .toIndexCursor();
     }
 
-    return _complexValIdCursor.entryIterator(columnNames, complexValueFk);
+    return _complexValIdCursor.newEntryIterable(complexValueFk)
+      .setColumnNames(columnNames).iterator();
   }
   
   public List<Row> getRawValues(int complexValueFk,
index 91794db45371fdfad044f60f2b40dd879191198c..02aa051581b823d72682ba51899eec62b9c99fee 100644 (file)
@@ -195,7 +195,8 @@ public class Joiner
                                 Collection<String> columnNames)
   {
     toEntryValues(fromRow);
-    return _toCursor.entryIterator(columnNames, _entryValues);
+    return _toCursor.newEntryIterable(_entryValues)
+      .setColumnNames(columnNames).iterator();
   }
 
   /**
@@ -211,7 +212,8 @@ public class Joiner
                                 Collection<String> columnNames)
   {
     toEntryValues(fromRow);
-    return _toCursor.entryIterator(columnNames, _entryValues);
+    return _toCursor.newEntryIterable(_entryValues)
+      .setColumnNames(columnNames).iterator();
   }
 
   /**
index 49a5fc9c91ff68f52cf529c7ef6df3952df07f11..0a5e551cbf2a7d224f254338b3cc03e6c2580281 100644 (file)
@@ -176,7 +176,7 @@ public class CursorTest extends TestCase {
                                                   int type)
     throws Exception
   {
-    return new CursorBuilder(table)
+    return table.newCursor()
       .setIndex(idx)
       .setStartEntry(3 - type)
       .setStartRowInclusive(type == 0)
@@ -394,7 +394,7 @@ public class CursorTest extends TestCase {
 
     List<Map<String, Object>> foundRows =
       new ArrayList<Map<String, Object>>();
-    for(Map<String, Object> row : cursor.reverseIterable()) {
+    for(Map<String, Object> row : cursor.newIterable().reverse()) {
       foundRows.add(row);
     }
     assertEquals(expectedRows, foundRows);    
@@ -766,9 +766,8 @@ public class CursorTest extends TestCase {
   private static void doTestFindAll(Table table, Cursor cursor, Index index)
     throws Exception
   {
-    Column valCol = table.getColumn("value");
     List<? extends Map<String,Object>> rows = RowFilterTest.toList(
-        cursor.columnMatchIterable(valCol, "data2"));
+        cursor.newIterable().setMatchPattern("value", "data2"));
 
     List<? extends Map<String, Object>> expectedRows = null;
 
@@ -801,8 +800,9 @@ public class CursorTest extends TestCase {
     }
     assertEquals(expectedRows, rows);
 
+    Column valCol = table.getColumn("value");
     rows = RowFilterTest.toList(
-        cursor.columnMatchIterable(valCol, "data4"));
+        cursor.newIterable().setMatchPattern(valCol, "data4"));
 
     if(index == null) {
       expectedRows =
@@ -822,12 +822,13 @@ public class CursorTest extends TestCase {
     assertEquals(expectedRows, rows);
 
     rows = RowFilterTest.toList(
-        cursor.columnMatchIterable(valCol, "data9"));
+        cursor.newIterable().setMatchPattern(valCol, "data9"));
 
     assertTrue(rows.isEmpty());
 
     rows = RowFilterTest.toList(
-        cursor.rowMatchIterable(Collections.singletonMap("id", 8)));
+        cursor.newIterable().setMatchPattern(
+            Collections.singletonMap("id", 8)));
     
     expectedRows =
       createExpectedTable(
@@ -848,14 +849,14 @@ public class CursorTest extends TestCase {
       expectedRows = tmpRows;
       assertFalse(expectedRows.isEmpty());
       
-      rows = RowFilterTest.toList(cursor.rowMatchIterable(row));
+      rows = RowFilterTest.toList(cursor.newIterable().setMatchPattern(row));
 
       assertEquals(expectedRows, rows);
     }
 
     rows = RowFilterTest.toList(
-        cursor.rowMatchIterable(createExpectedRow(
-                                    "id", 8, "value", "data13")));    
+        cursor.newIterable().addMatchPattern("id", 8)
+        .addMatchPattern("value", "data13"));
     assertTrue(rows.isEmpty());
   }
 
@@ -997,6 +998,28 @@ public class CursorTest extends TestCase {
                                      "value", "data" + 4),
                    cursor.getCurrentRow());
     }
+
+    assertEquals(Arrays.asList(createExpectedRow("id", 4,
+                                                 "value", "data" + 4)),
+                 RowFilterTest.toList(
+                     cursor.newIterable()
+                     .setMatchPattern("value", "data4")
+                     .setColumnMatcher(SimpleColumnMatcher.INSTANCE)));
+
+    assertEquals(Arrays.asList(createExpectedRow("id", 3,
+                                                 "value", "data" + 3)),
+                 RowFilterTest.toList(
+                     cursor.newIterable()
+                     .setMatchPattern("value", "DaTa3")
+                     .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)));
+
+    assertEquals(Arrays.asList(createExpectedRow("id", 2,
+                                                 "value", "data" + 2)),
+                 RowFilterTest.toList(
+                     cursor.newIterable()
+                     .addMatchPattern("value", "DaTa2")
+                     .addMatchPattern("id", 2)
+                     .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)));
   }
 
   public void testIndexCursor() throws Exception
@@ -1036,15 +1059,16 @@ public class CursorTest extends TestCase {
       IndexCursor cursor = CursorBuilder.createCursor(t1, idx);
 
       List<String> expectedData = new ArrayList<String>();
-      for(Map<String,Object> row : cursor.entryIterable(
-              Arrays.asList("data"), 1)) {
+      for(Map<String,Object> row : cursor.newEntryIterable(1)
+            .addColumnNames("data")) {
         expectedData.add((String)row.get("data"));
       }
 
       assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
 
       expectedData = new ArrayList<String>();
-      for(Iterator<? extends Map<String,Object>> iter = cursor.entryIterator(1);
+      for(Iterator<? extends Map<String,Object>> iter = 
+            cursor.newEntryIterable(1).iterator();
           iter.hasNext(); ) {
         expectedData.add((String)iter.next().get("data"));
         iter.remove();
@@ -1068,8 +1092,8 @@ public class CursorTest extends TestCase {
       assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
       
       expectedData = new ArrayList<String>();
-      for(Map<String,Object> row : cursor.entryIterable(
-              Arrays.asList("data"), 1)) {
+      for(Map<String,Object> row : cursor.newEntryIterable(1)
+            .addColumnNames("data")) {
         expectedData.add((String)row.get("data"));
       }
 
@@ -1088,7 +1112,7 @@ public class CursorTest extends TestCase {
       Cursor cursor = CursorBuilder.createCursor(t1);
 
       List<String> expectedData = new ArrayList<String>();
-      for(Map<String,Object> row : cursor.iterable(
+      for(Map<String,Object> row : cursor.newIterable().setColumnNames(
               Arrays.asList("otherfk1", "data"))) {
         if(row.get("otherfk1").equals(1)) {
           expectedData.add((String)row.get("data"));
@@ -1125,7 +1149,7 @@ public class CursorTest extends TestCase {
       assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
       
       expectedData = new ArrayList<String>();
-      for(Map<String,Object> row : cursor.iterable(
+      for(Map<String,Object> row : cursor.newIterable().setColumnNames(
               Arrays.asList("otherfk1", "data"))) {
         if(row.get("otherfk1").equals(1)) {
           expectedData.add((String)row.get("data"));
index 8eb7cd18f7095048eb828b6407c3d638a6bb031e..8c6284a19d961ad14c0165195f02e46b25bca7a2 100644 (file)
@@ -452,7 +452,7 @@ public class IndexTest extends TestCase {
       t.addRow(1, "row1");
       t.addRow(3, "row3");
 
-      Cursor c = new CursorBuilder(t)
+      Cursor c = t.newCursor()
         .setIndexByName(IndexBuilder.PRIMARY_KEY_NAME).toCursor();
 
       for(int i = 1; i <= 3; ++i) {
index 75d869dcb436d6d17692ca0a0055b2a88fff026e..e3cf49919428df7bf465fa83311c05aa20c0029f 100644 (file)
@@ -129,13 +129,13 @@ public class CodecHandlerTest extends TestCase
         t2.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
       }
 
-      Cursor c1 = new CursorBuilder(t1).setIndex(t1.getPrimaryKeyIndex())
+      Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex())
         .toCursor();
-      Cursor c2 = new CursorBuilder(t2).setIndex(t2.getPrimaryKeyIndex())
+      Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex())
         .toCursor();
 
       Iterator<? extends Map<String,Object>> i1 = c1.iterator();
-      Iterator<? extends Map<String,Object>> i2 = c2.reverseIterable().iterator();
+      Iterator<? extends Map<String,Object>> i2 = c2.newIterable().reverse().iterator();
 
       int t1rows = 0;
       int t2rows = 0;