com.triactive.jdo.sco
Class Set

java.lang.Object
  extended bycom.triactive.jdo.sco.Set
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, Queryable, SCO, java.util.Set

public class Set
extends java.lang.Object
implements java.util.Set, SCO, java.lang.Cloneable, Queryable

A set object which is backed "directly" by the database. SCO fields declared as type java.util.Collection or java.util.Set are populated with objects of this type whenever the field is actively being managed by the state manager.

This class differs from HashSet primarily in the fact that the contents of the set are not mirrored in memory. Operations on the set "pass through" directly to the database.

An instance of this class "disconnects" from it backing storage whenever unsetOwner() is called. This occurs automatically in a variety of scenarios, such as when the object is cloned or when its owning object (the one whose Set field refers to it) transitions to a transient state. When a disconnect occurs, the object switches to being backed by a normal in-memory HashSet and subsequently behaves like a normal HashSet. If the disconnect occurs during a transaction the contents of the set are fully loaded from the database. Subsequent changes to the set affect only the in-memory copy. Once disconnected from its owner, an instance is never reconnected.

Author:
Mike Martin

Constructor Summary
  Set(StateManager ownerSM, java.lang.String fieldName)
           
(package private) Set(StateManager ownerSM, java.lang.String fieldName, boolean allowNulls, SetStore setStore)
           
  Set(StateManager ownerSM, java.lang.String fieldName, java.lang.Class elementType, boolean allowNulls)
           
 
Method Summary
 boolean add(java.lang.Object element)
           
 boolean addAll(java.util.Collection c)
           
 void applyUpdates()
          Applies any pending updates for this object to the data store.
 void clear()
           
 java.lang.Object clone()
          Creates and returns a copy of this object.
 boolean contains(java.lang.Object element)
           
 boolean containsAll(java.util.Collection c)
           
 boolean equals(java.lang.Object o)
           
 java.lang.String getFieldName()
          Returns the field name.
 java.lang.Object getOwner()
          Returns the owner object of the SCO instance.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 void makeDirty()
          Marks object dirty.
 QueryStatement newQueryStatement()
          Returns a prototypical query statement over the underlying collection.
 QueryStatement newQueryStatement(java.lang.Class candidateClass)
          Returns a prototypical query statement over the underlying collection, pre-filtered to include only objects of the specified class.
 Query.ResultObjectFactory newResultObjectFactory(QueryStatement stmt)
          Returns a suitable query result factory for results produced by the specified query.
 boolean remove(java.lang.Object element)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
 void setValueFrom(java.lang.Object o)
          Assigns the value of this second-class object from an existing object of the same or compatible type.
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 java.lang.String toString()
           
 void unsetOwner()
          Nullifies references to the owner Object and Field.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Set

public Set(StateManager ownerSM,
           java.lang.String fieldName)

Set

public Set(StateManager ownerSM,
           java.lang.String fieldName,
           java.lang.Class elementType,
           boolean allowNulls)

Set

Set(StateManager ownerSM,
    java.lang.String fieldName,
    boolean allowNulls,
    SetStore setStore)
Method Detail

setValueFrom

public void setValueFrom(java.lang.Object o)
Description copied from interface: SCO
Assigns the value of this second-class object from an existing object of the same or compatible type.

Specified by:
setValueFrom in interface SCO
Parameters:
o - the object from which to copy the value.

getFieldName

public java.lang.String getFieldName()
Description copied from interface: SCO
Returns the field name.

Specified by:
getFieldName in interface SCO
Returns:
field name

getOwner

public java.lang.Object getOwner()
Description copied from interface: SCO
Returns the owner object of the SCO instance.

Specified by:
getOwner in interface SCO
Returns:
owner object

unsetOwner

public void unsetOwner()
Description copied from interface: SCO
Nullifies references to the owner Object and Field.

Specified by:
unsetOwner in interface SCO

applyUpdates

public void applyUpdates()
Description copied from interface: SCO
Applies any pending updates for this object to the data store.

Specified by:
applyUpdates in interface SCO

makeDirty

public void makeDirty()
Description copied from interface: SCO
Marks object dirty.

Specified by:
makeDirty in interface SCO

newQueryStatement

public QueryStatement newQueryStatement()
Description copied from interface: Queryable
Returns a prototypical query statement over the underlying collection.

The returned query statement selects all applicable rows from the relevant base table(s) and the column that represents the element or element ID. The statement can then be modified to join additional tables, select more columns, add WHERE conditions, etc.

Specified by:
newQueryStatement in interface Queryable
Returns:
The new prototypical query statement.

newQueryStatement

public QueryStatement newQueryStatement(java.lang.Class candidateClass)
Description copied from interface: Queryable
Returns a prototypical query statement over the underlying collection, pre-filtered to include only objects of the specified class.

Specified by:
newQueryStatement in interface Queryable
Returns:
The new prototypical query statement.
See Also:
Queryable.newQueryStatement()

newResultObjectFactory

public Query.ResultObjectFactory newResultObjectFactory(QueryStatement stmt)
Description copied from interface: Queryable
Returns a suitable query result factory for results produced by the specified query.

The stmt argument must have been obtained by a previous call to newQueryStatement() on the same Queryable.

Specified by:
newResultObjectFactory in interface Queryable
Returns:
A factory for creating PersistenceCapable objects from query results.

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Mutable second-class Objects are required to provide a public clone method in order to allow for copying PersistenceCapable objects. In contrast to Object.clone(), this method must not throw a CloneNotSupportedException.


equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Set

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Set

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.Set

size

public int size()
Specified by:
size in interface java.util.Set

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Set

contains

public boolean contains(java.lang.Object element)
Specified by:
contains in interface java.util.Set

add

public boolean add(java.lang.Object element)
Specified by:
add in interface java.util.Set

remove

public boolean remove(java.lang.Object element)
Specified by:
remove in interface java.util.Set

clear

public void clear()
Specified by:
clear in interface java.util.Set

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Set

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Set

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Set

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Set

toString

public java.lang.String toString()


Copyright © 2001 TriActive, Inc. All Rights Reserved.