net.walend.collection.lyophil.jdbc
Class JDBCBackedMutableSet

java.lang.Object
  |
  +--net.walend.collection.lyophil.jdbc.JDBCBackedMutableSet
All Implemented Interfaces:
Collection, CollectionOfFreezables, Freezable, FreezableSet, HasState, MutableCollection, MutableCollectionOfFreezables, MutableSet, MutableSetOfFreezables, java.io.Serializable, Set, SetOfFreezables

public class JDBCBackedMutableSet
extends java.lang.Object
implements FreezableSet

This class implements FreezableSet directly on top of a database table.

Since:
20010213
Author:
David Walend

Field Summary
private  java.io.Serializable ident
           
private  java.lang.String role
           
private  JDBCBackedMutableSetTray tray
           
 
Fields inherited from interface net.walend.collection.lyophil.FreezableSet
FREEZABLESET
 
Fields inherited from interface net.walend.lyophil.collection.SetOfFreezables
EMPTY
 
Constructor Summary
JDBCBackedMutableSet(java.io.Serializable identifier, java.lang.String role, Mother mom)
           
JDBCBackedMutableSet(java.io.Serializable identifier, java.lang.String role, Mother mom, Collection c)
           
JDBCBackedMutableSet(java.io.Serializable identifier, java.lang.String role, Mother mom, JDBCBackedMutableSet c)
          Creates a new Set that is a copy of c
 
Method Summary
 boolean add(java.lang.Object object)
          Adds a Object to the MutableCollection.
 boolean addAll(Collection c)
          Adds all the Objects in c to this MutableCollection by using the add() method.
 boolean addAllIdentifiedBy(Collection c)
          Adds all the Freezables identified by c to this MutableCollection using the addIdentifiedBy method.
 boolean addIdentifiedBy(java.io.Serializable id)
          Adds a Freezable to the MutableCollection.
private  Freezable checkFreezable(java.lang.Object o)
           
 void clear()
          Removes all of the Objects in this collection.
 boolean contains(java.lang.Object object)
          Returns true if this collection contains the specified Object.
 boolean containsAll(Collection c)
          Returns true if this collection contains all of the Objects in the specified collection.
 boolean containsAllIdentifiedBy(Collection collectionOfIdentifiers)
          Returns true if this collection contains the specified Freezables.
 boolean containsIdentifiedBy(java.io.Serializable id)
          Returns true if this collection contains the specified Freezable.
 Freezable createEvilClone(Mother mom, java.lang.String role)
          Returns a new instance of a Freezable with the same internal state as this Freezable, but with the new id.
 FreezableIterator freezableIterator()
          Returns an iterator over the Freezables in this collection.
 java.io.Serializable getIdentifier()
          Get the identifier for this instance.
 Collection getIdentifiers()
          Returns a Collection of all the identifiers in this collection.
 Identitor getIdentitor()
          Returns the Identitor for this Collection.
 java.util.Collection getJavaCollection()
          Return a java.util.Collection of these Objects.
 java.util.Set getJavaSet()
          Return a java.util.Collection of these Objects.
 java.lang.Class getPrincipleInterface()
          Returns the class's principle interface for state comparisons.
 java.lang.String getRole()
          Get the role for this instance.
 java.util.Iterator identifierIterator()
          Returns an iterator over the identifiers in this collection.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the Objects in this collection.
 boolean remove(java.lang.Object object)
          Removes a Object from the MutableCollection.
 boolean removeAll(Collection c)
          Removes all the Objects in c from this MutableCollection by using the remove() method.
 boolean removeAllIdentifiedBy(Collection c)
          Removes all the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
 boolean removeIdentifiedBy(java.io.Serializable id)
          Removes a Freezable from the MutableCollection, based on that Freezable's identifier.
 boolean retainAll(Collection c)
          Retains only the Objects in this collection that are contained in c by using the contains() and remove() methods.
 boolean retainAllIdentifiedBy(Collection c)
          Removes all but the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
 boolean sameAs(Freezable object)
          Returns true if this Freezable represents the samee information as object, and their internal state matches.
 boolean sameContentsAs(Collection c)
          Returns true if this Collection's contents are equal to c's.
 boolean sameIdentifierAs(Freezable object)
          Returns true if this Freezable represents the same information as the Freezable object, ie if they have the same identifier.
 boolean sameStateAs(HasState victem)
          If two HasStates have the same internal state, return true.
 int size()
          Returns the number of elements in this collection.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ident

private java.io.Serializable ident

role

private java.lang.String role

tray

private JDBCBackedMutableSetTray tray
Constructor Detail

JDBCBackedMutableSet

public JDBCBackedMutableSet(java.io.Serializable identifier,
                            java.lang.String role,
                            Mother mom)

JDBCBackedMutableSet

public JDBCBackedMutableSet(java.io.Serializable identifier,
                            java.lang.String role,
                            Mother mom,
                            Collection c)

JDBCBackedMutableSet

public JDBCBackedMutableSet(java.io.Serializable identifier,
                            java.lang.String role,
                            Mother mom,
                            JDBCBackedMutableSet c)
Creates a new Set that is a copy of c

Method Detail

getPrincipleInterface

public java.lang.Class getPrincipleInterface()
Returns the class's principle interface for state comparisons. If two objects have different principle interfaces, they never have the same state.

Specified by:
getPrincipleInterface in interface HasState

sameStateAs

public boolean sameStateAs(HasState victem)
If two HasStates have the same internal state, return true.

For objects with subobjects, Generally this method should only return true if the internal objects are equal. Implement a contentsHaveSameState() method to determine if the contents have the same state.

Specified by:
sameStateAs in interface HasState

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getIdentifier

public java.io.Serializable getIdentifier()
Description copied from interface: Freezable
Get the identifier for this instance. I've always used a Long, but the ejb spec says it can be anything. Try to use something immutable. Note that you will only have this Object plus metadetails of the class to use for identifier information. All you should need is the identifier.

Specified by:
getIdentifier in interface Freezable

getRole

public java.lang.String getRole()
Description copied from interface: Freezable
Get the role for this instance.

Specified by:
getRole in interface Freezable

sameIdentifierAs

public boolean sameIdentifierAs(Freezable object)
Description copied from interface: Freezable
Returns true if this Freezable represents the same information as the Freezable object, ie if they have the same identifier.

Specified by:
sameIdentifierAs in interface Freezable

sameAs

public boolean sameAs(Freezable object)
Description copied from interface: Freezable
Returns true if this Freezable represents the samee information as object, and their internal state matches.

Specified by:
sameAs in interface Freezable

createEvilClone

public Freezable createEvilClone(Mother mom,
                                 java.lang.String role)
Description copied from interface: Freezable
Returns a new instance of a Freezable with the same internal state as this Freezable, but with the new id. This method should only be called by Mother.

Specified by:
createEvilClone in interface Freezable

getIdentitor

public Identitor getIdentitor()
Returns the Identitor for this Collection.

Specified by:
getIdentitor in interface Collection

size

public int size()
Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Collection

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface Collection

contains

public boolean contains(java.lang.Object object)
Returns true if this collection contains the specified Object.

Specified by:
contains in interface Collection

iterator

public java.util.Iterator iterator()
Returns an iterator over the Objects in this collection.

Specified by:
iterator in interface Collection

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the Objects in the specified collection. This method uses the contains() method.

Specified by:
containsAll in interface Collection

sameContentsAs

public boolean sameContentsAs(Collection c)
Returns true if this Collection's contents are equal to c's.

Specified by:
sameContentsAs in interface Collection

getJavaCollection

public java.util.Collection getJavaCollection()
Return a java.util.Collection of these Objects. Danger! This method creates a java.util.Set containing all the Freezables in memory. The usual reason for using a JDBCBackedMutableSet is to avoid having all these Freezables in memory at once.

Specified by:
getJavaCollection in interface Collection

checkFreezable

private Freezable checkFreezable(java.lang.Object o)

add

public boolean add(java.lang.Object object)
Adds a Object to the MutableCollection. Sets will only add it to the Set if it's not already there.

Specified by:
add in interface MutableCollection
Returns:
true if the MutableCollection changes, false if not.

remove

public boolean remove(java.lang.Object object)
Removes a Object from the MutableCollection.

Specified by:
remove in interface MutableCollection
Returns:
true if the MutableCollection changes, false if not.

addAll

public boolean addAll(Collection c)
Adds all the Objects in c to this MutableCollection by using the add() method. Returns true if this MutableCollection changes.

Specified by:
addAll in interface MutableCollection

removeAll

public boolean removeAll(Collection c)
Removes all the Objects in c from this MutableCollection by using the remove() method. Returns true if this Colleciton changes.

Specified by:
removeAll in interface MutableCollection

retainAll

public boolean retainAll(Collection c)
Retains only the Objects in this collection that are contained in c by using the contains() and remove() methods. Returns true if this Colleciton changes.

Specified by:
retainAll in interface MutableCollection

clear

public void clear()
Removes all of the Objects in this collection.

Specified by:
clear in interface MutableCollection

getJavaSet

public java.util.Set getJavaSet()
Return a java.util.Collection of these Objects.

Specified by:
getJavaSet in interface Set

containsIdentifiedBy

public boolean containsIdentifiedBy(java.io.Serializable id)
Returns true if this collection contains the specified Freezable. This method uses Serializable's equals() method.

Specified by:
containsIdentifiedBy in interface CollectionOfFreezables

containsAllIdentifiedBy

public boolean containsAllIdentifiedBy(Collection collectionOfIdentifiers)
Returns true if this collection contains the specified Freezables. This method uses Serializable's equals() method.

Specified by:
containsAllIdentifiedBy in interface CollectionOfFreezables

freezableIterator

public FreezableIterator freezableIterator()
Returns an iterator over the Freezables in this collection.

Specified by:
freezableIterator in interface CollectionOfFreezables

identifierIterator

public java.util.Iterator identifierIterator()
Returns an iterator over the identifiers in this collection.

Specified by:
identifierIterator in interface CollectionOfFreezables

getIdentifiers

public Collection getIdentifiers()
Returns a Collection of all the identifiers in this collection.

Specified by:
getIdentifiers in interface CollectionOfFreezables

addIdentifiedBy

public boolean addIdentifiedBy(java.io.Serializable id)
Adds a Freezable to the MutableCollection. Sets will only add it to the Set if it's not already there, based on the getIdentifier() and sameIdentifierAs() methods. Lists will tack it on the end of a list.

Specified by:
addIdentifiedBy in interface MutableCollectionOfFreezables
Returns:
true if the MutableCollection changes, false if not.
Throws:
java.lang.ClassCastException - class of the specified element prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of this element prevents it from being added to this collection.
ZombieIdentifierException - if f is not in the Freezer and this implementation checks on add.

removeIdentifiedBy

public boolean removeIdentifiedBy(java.io.Serializable id)
Removes a Freezable from the MutableCollection, based on that Freezable's identifier. This method uses the getIdentifier() and sameIdentifierAs() methods of the Freezables to find the right one.

Specified by:
removeIdentifiedBy in interface MutableCollectionOfFreezables
Returns:
true if the MutableCollection changes, false if not.

addAllIdentifiedBy

public boolean addAllIdentifiedBy(Collection c)
Adds all the Freezables identified by c to this MutableCollection using the addIdentifiedBy method. Returns true if this MutableCollection changes.

Specified by:
addAllIdentifiedBy in interface MutableCollectionOfFreezables
Throws:
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.

removeAllIdentifiedBy

public boolean removeAllIdentifiedBy(Collection c)
Removes all the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method. Returns true if this MutableCollection changes.

Specified by:
removeAllIdentifiedBy in interface MutableCollectionOfFreezables
Throws:
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.

retainAllIdentifiedBy

public boolean retainAllIdentifiedBy(Collection c)
Removes all but the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method. Returns true if this MutableCollection changes.

Specified by:
retainAllIdentifiedBy in interface MutableCollectionOfFreezables
Throws:
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.


Copyright (c) 2000, 2001, David Walend