com.healthmarketscience.jackcess
Class Joiner

java.lang.Object
  extended by com.healthmarketscience.jackcess.Joiner

public class Joiner
extends Object

Utility for finding rows based on pre-defined, foreign-key table relationships.

Author:
James Ahlborn

Method Summary
static Joiner create(Index fromIndex)
          Creates a new Joiner based on the given index which backs a foreign-key relationship.
static Joiner create(Table fromTable, Table toTable)
          Creates a new Joiner based on the foreign-key relationship between the given "from"" table and the given "to"" table.
 Joiner createReverse()
          Creates a new Joiner that is the reverse of this Joiner (the "from" and "to" tables are swapped).
 boolean deleteRows(Map<String,?> fromRow)
          Deletes any rows in the "to" table based on the given columns in the "from" table.
 Map<String,Object> findFirstRow(Map<String,?> fromRow)
          Returns the first row in the "to" table based on the given columns in the "from" table if any, null if there is no matching row.
 Map<String,Object> findFirstRow(Map<String,?> fromRow, Collection<String> columnNames)
          Returns selected columns from the first row in the "to" table based on the given columns in the "from" table if any, null if there is no matching row.
 Iterator<Map<String,Object>> findRows(Map<String,?> fromRow)
          Returns an Iterator over all the rows in the "to" table based on the given columns in the "from" table.
 Iterator<Map<String,Object>> findRows(Map<String,?> fromRow, Collection<String> columnNames)
          Returns an Iterator with the selected columns over all the rows in the "to" table based on the given columns in the "from" table.
 Iterable<Map<String,Object>> findRowsIterable(Map<String,?> fromRow)
          Returns an Iterable whose iterator() method returns the result of a call to findRows(Map)
 Iterable<Map<String,Object>> findRowsIterable(Map<String,?> fromRow, Collection<String> columnNames)
          Returns an Iterable whose iterator() method returns the result of a call to findRows(Map,Collection)
 List<IndexData.ColumnDescriptor> getColumns()
           
 Index getFromIndex()
           
 Table getFromTable()
           
 IndexCursor getToCursor()
           
 Index getToIndex()
           
 Table getToTable()
           
 boolean hasRows(Map<String,?> fromRow)
          Returns true if the "to" table has any rows based on the given columns in the "from" table, false otherwise.
 String toFKString()
          Returns a pretty string describing the foreign key relationship backing this Joiner.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static Joiner create(Table fromTable,
                            Table toTable)
                     throws IOException
Creates a new Joiner based on the foreign-key relationship between the given "from"" table and the given "to"" table.

Parameters:
fromTable - the "from" side of the relationship
toTable - the "to" side of the relationship
Throws:
IllegalArgumentException - if there is no relationship between the given tables
IOException

create

public static Joiner create(Index fromIndex)
                     throws IOException
Creates a new Joiner based on the given index which backs a foreign-key relationship. The table of the given index will be the "from" table and the table on the other end of the relationship will be the "to" table.

Parameters:
fromIndex - the index backing one side of a foreign-key relationship
Throws:
IOException

createReverse

public Joiner createReverse()
                     throws IOException
Creates a new Joiner that is the reverse of this Joiner (the "from" and "to" tables are swapped).

Throws:
IOException

getFromTable

public Table getFromTable()

getFromIndex

public Index getFromIndex()

getToTable

public Table getToTable()

getToIndex

public Index getToIndex()

getToCursor

public IndexCursor getToCursor()

getColumns

public List<IndexData.ColumnDescriptor> getColumns()

hasRows

public boolean hasRows(Map<String,?> fromRow)
                throws IOException
Returns true if the "to" table has any rows based on the given columns in the "from" table, false otherwise.

Throws:
IOException

findFirstRow

public Map<String,Object> findFirstRow(Map<String,?> fromRow)
                                throws IOException
Returns the first row in the "to" table based on the given columns in the "from" table if any, null if there is no matching row.

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
Throws:
IOException

findFirstRow

public Map<String,Object> findFirstRow(Map<String,?> fromRow,
                                       Collection<String> columnNames)
                                throws IOException
Returns selected columns from the first row in the "to" table based on the given columns in the "from" table if any, null if there is no matching row.

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
columnNames - desired columns in the from table row
Throws:
IOException

findRows

public Iterator<Map<String,Object>> findRows(Map<String,?> fromRow)
Returns an Iterator over all the rows in the "to" table based on the given columns in the "from" table.

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)

findRows

public Iterator<Map<String,Object>> findRows(Map<String,?> fromRow,
                                             Collection<String> columnNames)
Returns an Iterator with the selected columns over all the rows in the "to" table based on the given columns in the "from" table.

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
columnNames - desired columns in the from table row

findRowsIterable

public Iterable<Map<String,Object>> findRowsIterable(Map<String,?> fromRow)
Returns an Iterable whose iterator() method returns the result of a call to findRows(Map)

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
Throws:
IllegalStateException - if an IOException is thrown by one of the operations, the actual exception will be contained within

findRowsIterable

public Iterable<Map<String,Object>> findRowsIterable(Map<String,?> fromRow,
                                                     Collection<String> columnNames)
Returns an Iterable whose iterator() method returns the result of a call to findRows(Map,Collection)

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
columnNames - desired columns in the from table row
Throws:
IllegalStateException - if an IOException is thrown by one of the operations, the actual exception will be contained within

deleteRows

public boolean deleteRows(Map<String,?> fromRow)
                   throws IOException
Deletes any rows in the "to" table based on the given columns in the "from" table.

Parameters:
fromRow - row from the "from" table (which must include the relevant columns for this join relationship)
Returns:
true if any "to" rows were deleted, false otherwise
Throws:
IOException

toFKString

public String toFKString()
Returns a pretty string describing the foreign key relationship backing this Joiner.



Copyright © 2005-2013 Health Market Science. All Rights Reserved.