ojb.broker.accesslayer
Class CollectionProxy

java.lang.Object
  |
  +--ojb.broker.accesslayer.CollectionProxy
All Implemented Interfaces:
java.util.Collection, ManageableCollection, java.io.Serializable

public class CollectionProxy
extends java.lang.Object
implements java.util.Collection, ManageableCollection

CollectionProxy.
A placeHolder for a whole collection to support deferred loading of relationships. The complete relationship is loaded on request.

Version:
1.0
Author:
jakob braeuchi
See Also:
Serialized Form

Constructor Summary
CollectionProxy(java.lang.Class aCollClass, PersistenceBroker aBroker, Query aQuery)
           
CollectionProxy(PersistenceBroker aBroker, Query aQuery)
           
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
protected  void calculateSize()
          do a count(*) with the query
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
protected  PersistenceBroker getBroker()
          Gets the broker.
protected  java.lang.Class getCollectionClass()
          Gets the collectionClass.
protected  java.util.Collection getData()
          Gets the data, load it if not already done.
protected  Query getQuery()
          Gets the query.
 boolean isEmpty()
           
protected  boolean isLoaded()
           
 java.util.Iterator iterator()
           
protected  void load()
          loads the data from the database, if count(*) returned > 0
 void ojbAdd(java.lang.Object anObject)
          add a single Object to the Collection.
 void ojbAddAll(ManageableCollection otherCollection)
          adds a Collection to this collection.
 java.util.Iterator ojbIterator()
          returns an Iterator over all elements in the collection.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
protected  void setBroker(PersistenceBroker broker)
          Sets the broker.
protected  void setCollectionClass(java.lang.Class collectionClass)
          Sets the collectionClass.
protected  void setData(java.util.Collection data)
          Sets the data.
protected  void setQuery(Query query)
          Sets the query.
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

CollectionProxy

public CollectionProxy(PersistenceBroker aBroker,
                       Query aQuery)

CollectionProxy

public CollectionProxy(java.lang.Class aCollClass,
                       PersistenceBroker aBroker,
                       Query aQuery)
Method Detail

isLoaded

protected boolean isLoaded()

calculateSize

protected void calculateSize()
do a count(*) with the query


load

protected void load()
             throws PersistenceBrokerException
loads the data from the database, if count(*) returned > 0

PersistenceBrokerException

size

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

isEmpty

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

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection

iterator

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

toArray

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

toArray

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

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection

containsAll

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

addAll

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

removeAll

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

retainAll

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

clear

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

getQuery

protected Query getQuery()
Gets the query.

Returns:
Returns a Query

setQuery

protected void setQuery(Query query)
Sets the query.

Parameters:
query - The query to set

getBroker

protected PersistenceBroker getBroker()
Gets the broker.

Returns:
Returns a PersistenceBroker

setBroker

protected void setBroker(PersistenceBroker broker)
Sets the broker.

Parameters:
broker - The broker to set

getData

protected java.util.Collection getData()
Gets the data, load it if not already done.

Returns:
Returns a Collection

setData

protected void setData(java.util.Collection data)
Sets the data.

Parameters:
data - The data to set

getCollectionClass

protected java.lang.Class getCollectionClass()
Gets the collectionClass.

Returns:
Returns a Class

setCollectionClass

protected void setCollectionClass(java.lang.Class collectionClass)
Sets the collectionClass.

Parameters:
collectionClass - The collectionClass to set

ojbAdd

public void ojbAdd(java.lang.Object anObject)
Description copied from interface: ManageableCollection
add a single Object to the Collection. This method is used during reading Collection elements from the database. Thus it is is save to cast anObject to the underlying element type of the collection.

Specified by:
ojbAdd in interface ManageableCollection

ojbAddAll

public void ojbAddAll(ManageableCollection otherCollection)
Description copied from interface: ManageableCollection
adds a Collection to this collection. Used in reading Extents from the Database. Thus it is save to cast otherCollection to this.getClass().

Specified by:
ojbAddAll in interface ManageableCollection

ojbIterator

public java.util.Iterator ojbIterator()
Description copied from interface: ManageableCollection
returns an Iterator over all elements in the collection. Used during store and delete Operations. If the implementor does not return an iterator over ALL elements, OJB cannot store and delete all elements properly.

Specified by:
ojbIterator in interface ManageableCollection


Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04