Class IndirectSet<E>

Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>, ChangeTracker, CollectionChangeTracker, IndirectCollection<E,Set<E>>, IndirectContainer<Set<E>>

public class IndirectSet<E> extends Object implements CollectionChangeTracker, Set<E>, IndirectCollection<E,Set<E>>, Cloneable, Serializable
IndirectSet is an example implementation of the Set protocol that allows a domain class to take advantage of TopLink Indirection without having to declare its instance variable as a ValueHolderInterface.

To use an IndirectSet:

  • Declare the appropriate instance variable with type Set (or Collection).
  • Send the message #useTransparentCollection() to the appropriate CollectionMapping.
  • Send the message #useCollectionClass(IndirectSet.class) to the same CollectionMapping. (The order of these two message sends is significant.)
TopLink will place an IndirectSet in the instance variable when the containing domain object is read from the database. With the first message sent to the IndirectSet, the contents are fetched from the database and normal Set behavior is resumed.

Implementation notes:

  • The Set interface is implemented by delegating nearly every message to the Set held on to by the 'delegate' instance variable. (The 'delegate' will be either a HashSet or yet another IndirectSet.)
  • The IndirectContainer interface is implemented in a straightforward fashion:
    • #get- and #setValueHolder() are implemented as simple accessors for the 'valueHolder' instance variable. (Note that #setValueHolder() clears out the 'delegate' instance variable, since its contents are invalidated by the arrival of a new value holder.)
    • #isInstantiated() is simply delegated to the value holder.
  • TopLink requires that the Cloneable interface be implemented. The #clone() method must clone the 'delegate'. (The implementation here uses reflection to invoke the #clone() method because it is not included in the common interface shared by IndirectSet and its base delegate class, HashSet; namely, Set.)
  • TopLink requires that the Serializable interface be implemented.
  • The database read is ultimately triggered when one of the "delegated" methods makes the first call to #getDelegate(), which in turn calls #buildDelegate(), which sends the message #getValue() to the value holder. The value holder performs the database read.
  • For debugging purposes, #toString() will not trigger a database read. This is not required behavior.
See Also:
Big Country