Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.access.util
Class DistinctResultIterator

    java.lang.Object
      org.apache.cayenne.access.util.DistinctResultIterator

All Implemented Interfaces:
  ResultIterator

    public class DistinctResultIterator

extends Object
implements ResultIterator

A ResultIterator that does in-memory filtering of rows to return only distinct rows. Distinct comparison is done by comparing ObjectIds created from each row. Internally DistinctResultIterator wraps another ResultIterator that provides the actual rows. The current limitation is that once switched to reading ids instead of rows (i.e. when "nextObjectId()" is called for the first time), it can't be used to read data rows again. This is pretty sensible for most things in Cayenne.

Since:
  1.2
Author:
  Andrus Adamchik

Field Summary
`protected boolean` | `compareFullRows`
`protected DbEntity` | `defaultEntity`
`protected Set<Map<String,Object>>` | `fetchedIds`
`protected Map<String,Object>` | `nextDataRow`
`protected boolean` | `readingIds`
`protected ResultIterator` | `wrappedIterator`

Constructor Summary
`DistinctResultIterator(ResultIterator wrappedIterator, DbEntity defaultEntity, boolean compareFullRows)` Creates new DistinctResultIterator wrapping another ResultIterator.

Method Summary
`void` | `close()` CLoses underlying ResultIterator.
`List` | `dataRows(boolean close)` Returns all data rows.
`int` | `getDataRowWidth()` Returns the number of columns in the result row.
`boolean` | `hasNextRow()` Returns true if there is at least one more record that can be read from the iterator.
`Map` | `nextDataRow()` Returns the next result row as a Map.
`Object` | `nextId(DbEntity entity)` Reads and returns an id column or columns for the DbEntity.
`Map` | `nextObjectId(DbEntity entity)` Returns a Map for the next ObjectId.
`void` | `skipDataRow()` Skips current data row instead of reading it.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### wrappedIterator

    protected ResultIterator wrappedIterator

### fetchedIds

    protected Set<Map<String,Object>> fetchedIds

### nextDataRow

    protected Map<String,Object> nextDataRow

### defaultEntity

    protected DbEntity defaultEntity

### compareFullRows

    protected boolean compareFullRows

### readingIds

    protected boolean readingIds

Constructor Detail

### DistinctResultIterator

    public DistinctResultIterator(ResultIterator wrappedIterator,
                                  DbEntity defaultEntity,
                                  boolean compareFullRows)
                           throws CayenneException

  Creates new DistinctResultIterator wrapping another ResultIterator.

  Parameters:
    `wrappedIterator` -
    `defaultEntity` - an entity needed to build ObjectIds for distinct comparison.
  Throws:
    `CayenneException`

Method Detail

### close

    public void close()
               throws CayenneException

  CLoses underlying ResultIterator.

  Specified by:
    `close` in interface `ResultIterator`
  Throws:
    `CayenneException`

### dataRows

    public List dataRows(boolean close)
                  throws CayenneException

  Returns all data rows.

  Specified by:
    `dataRows` in interface `ResultIterator`
  Throws:
    `CayenneException`

### getDataRowWidth

    public int getDataRowWidth()

  Description copied from interface: `ResultIterator`
  Returns the number of columns in the result row.

  Specified by:
    `getDataRowWidth` in interface `ResultIterator`

### hasNextRow

    public boolean hasNextRow()
                       throws CayenneException

  Description copied from interface: `ResultIterator`
  Returns true if there is at least one more record that can be read from the iterator.

  Specified by:
    `hasNextRow` in interface `ResultIterator`
  Throws:
    `CayenneException`

### nextDataRow

    public Map nextDataRow()
                    throws CayenneException

  Description copied from interface: `ResultIterator`
  Returns the next result row as a Map.

  Specified by:
    `nextDataRow` in interface `ResultIterator`
  Throws:
    `CayenneException`

### nextObjectId

    public Map nextObjectId(DbEntity entity)
                     throws CayenneException

  Returns a Map for the next ObjectId. After calling this method, calls to "nextDataRow()" will result in exceptions.

  Specified by:
    `nextObjectId` in interface `ResultIterator`
  Throws:
    `CayenneException`

### nextId

    public Object nextId(DbEntity entity)
                  throws CayenneException

  Description copied from interface: `ResultIterator`
  Reads and returns an id column or columns for the DbEntity. If an entity has a single column id, the return value is an Object matching the column type (e.g. java.lang.Long). If an entity has a compound PK, the return value is a DataRow (i.e. equivalent to `ResultIterator.nextObjectId(DbEntity)`).

  Specified by:
    `nextId` in interface `ResultIterator`
  Throws:
    `CayenneException`
  Since:
    3.0

### skipDataRow

    public void skipDataRow()
                     throws CayenneException

  Description copied from interface: `ResultIterator`
  Skips current data row instead of reading it.

  Specified by:
    `skipDataRow` in interface `ResultIterator`
  Throws:
    `CayenneException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2008 Apache Cayenne. All Rights Reserved.