org.erowid.sperowider.hsqldb
Class TwoWayMapTable

java.lang.Object
  extended byorg.erowid.sperowider.hsqldb.BasicTable
      extended byorg.erowid.sperowider.hsqldb.TwoWayMapTable

public class TwoWayMapTable
extends BasicTable

This is a wrapper around a many-to-many table. The first implementation is likely to be inefficient (no lookup tables, for example), but later versions will actually incorporate multiple tables for efficiency.

The map does have the idea of directionality so it distinguishes between the first and second elements in each mapping, but to keep the model generic, the first element is called "first" and the second "second" (as opposed to "from" and "to", or "parent" and "child").

Most methods on this class should therefore typically appear in triplicate ... once for "first", once for "second", and once that aggregates the two. Therefore containsFirst(String), containsSecond(String), and contains(String).

Version:
: $Header: /cvsroot/sperowider/SPEROWIDER_MODULE/javasource/org/erowid/sperowider/hsqldb/TwoWayMapTable.java,v 1.4 2005/05/16 01:20:33 gurustu Exp $
Author:
: $Author: gurustu $

Field Summary
 
Fields inherited from class org.erowid.sperowider.hsqldb.BasicTable
CACHED, MEMORY
 
Constructor Summary
TwoWayMapTable(String name, Connection connection, int mode)
          Constructor, gets everything ready for usage.
 
Method Summary
 void add(String firstValue, String secondValue)
          Adds a mapping from one value to another value to this map.
 boolean contains(String value)
          Returns true if either column has this value.
 boolean containsFirst(String value)
          Returns true if the first column has this value.
 boolean containsSecond(String value)
          Returns true if the second column has this value.
 void create()
          Creates a new table in the backing database corresponding to this object.
 String map(String value)
          A weird outlier of a method, this provides the same functionality as MapTable.map(String), allowing this to be used as a simple map.
 List mapFirst(String value)
          Returns the second values mapped to this first value.
 List mapSecond(String value)
          Returns the first values mapped to this second value.
 void remove(String value)
          Removes all mappings where the passed in value is either column
 void remove(String firstValue, String secondValue)
          Removes the mappings from the passed in first value to the passed in second value.
 void removeFirst(String value)
          Removes all mappings where the passed in value is in the first column
 void removeSecond(String value)
          Removes all mappings where the passed in value is in the second column
 
Methods inherited from class org.erowid.sperowider.hsqldb.BasicTable
execSQL, getConnection, getMode, getName, getTableCreatePrefix, prepareStatement, tableExists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwoWayMapTable

public TwoWayMapTable(String name,
                      Connection connection,
                      int mode)
               throws SQLException
Constructor, gets everything ready for usage.

Method Detail

create

public void create()
            throws SQLException
Creates a new table in the backing database corresponding to this object.

Throws:
SQLException

containsFirst

public boolean containsFirst(String value)
Returns true if the first column has this value.


containsSecond

public boolean containsSecond(String value)
Returns true if the second column has this value.


contains

public boolean contains(String value)
Returns true if either column has this value.


add

public void add(String firstValue,
                String secondValue)
Adds a mapping from one value to another value to this map.


removeFirst

public void removeFirst(String value)
Removes all mappings where the passed in value is in the first column


removeSecond

public void removeSecond(String value)
Removes all mappings where the passed in value is in the second column


remove

public void remove(String value)
Removes all mappings where the passed in value is either column


remove

public void remove(String firstValue,
                   String secondValue)
Removes the mappings from the passed in first value to the passed in second value. Note that this is directional. If you have the mappings A->B and B->A, a call to this method to (A,B) will only remove the first of those two.


map

public String map(String value)
A weird outlier of a method, this provides the same functionality as MapTable.map(String), allowing this to be used as a simple map.


mapFirst

public List mapFirst(String value)
Returns the second values mapped to this first value.


mapSecond

public List mapSecond(String value)
Returns the first values mapped to this second value.


spero logo small Sperowider is
© 2005 Erowid.org