org.apache.ojb.broker.accesslayer
Class CollectionProxy

java.lang.Object
  extended byorg.apache.ojb.broker.accesslayer.CollectionProxy
All Implemented Interfaces:
java.util.Collection, ManageableCollection, java.io.Serializable
Direct Known Subclasses:
ListProxy, SetProxy

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:
$Id: CollectionProxy.java,v 1.25 2004/01/14 00:09:32 olegnitz Exp $
Author:
Jakob Braeuchi
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.ojb.broker.ManageableCollection
serialVersionUID
 
Constructor Summary
CollectionProxy(PBKey aKey, java.lang.Class aCollClass, Query aQuery)
           
CollectionProxy(PBKey aKey, Query aQuery)
           
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 void addListener(CollectionProxyListener l)
           
protected  void afterLoading()
           
 void afterStore(PersistenceBroker broker)
          A callback method to implement 'removal-aware' (track removed objects and delete them by its own) collection implementations.
protected  void beforeLoading()
           
 void clear()
          Clear the proxy.
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
protected  PersistenceBroker getBroker()
          Gets the broker.
protected  PBKey getBrokerKey()
          Returns the brokerKey.
protected  java.lang.Class getCollectionClass()
          Gets the collectionClass.
 java.util.Collection getData()
          Gets the data, load it if not already done.
protected  Query getQuery()
          Gets the query.
 boolean isEmpty()
           
 boolean isLoaded()
           
 java.util.Iterator iterator()
           
protected  java.util.Collection loadData()
          loads the data from the database, if count(*) returned > 0
protected  void loadSize()
          do a count(*) with the query
 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.
protected  void releaseBroker()
          release the PersistenceBroker
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 void removeListener(CollectionProxyListener l)
           
 boolean retainAll(java.util.Collection c)
           
protected  void setBrokerKey(PBKey brokerKey)
          Sets the brokerKey.
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(PBKey aKey,
                       Query aQuery)

CollectionProxy

public CollectionProxy(PBKey aKey,
                       java.lang.Class aCollClass,
                       Query aQuery)
Method Detail

isLoaded

public boolean isLoaded()

loadSize

protected void loadSize()
                 throws PersistenceBrokerException
do a count(*) with the query

Throws:
PersistenceBrokerException

loadData

protected java.util.Collection loadData()
                                 throws PersistenceBrokerException
loads the data from the database, if count(*) returned > 0

Throws:
PersistenceBrokerException

beforeLoading

protected void beforeLoading()

afterLoading

protected void afterLoading()

size

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

isEmpty

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

contains

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

iterator

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

toArray

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

toArray

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

add

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

remove

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

containsAll

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

addAll

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

removeAll

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

retainAll

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

clear

public void clear()
Clear the proxy. A cleared proxy is defined as loaded

Specified by:
clear in interface java.util.Collection
See Also:
Collection.clear()

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

releaseBroker

protected void releaseBroker()
release the PersistenceBroker


getBroker

protected PersistenceBroker getBroker()
                               throws PBFactoryException
Gets the broker. If no PBKey is available a runtime exception will be thrown.

Returns:
a PersistenceBroker
Throws:
PBFactoryException

getData

public 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
See Also:
ManageableCollection.ojbAdd(Object)

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
See Also:
ManageableCollection.ojbAddAll(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
See Also:
ManageableCollection.ojbIterator()

afterStore

public void afterStore(PersistenceBroker broker)
                throws PersistenceBrokerException
Description copied from interface: ManageableCollection
A callback method to implement 'removal-aware' (track removed objects and delete them by its own) collection implementations.

Specified by:
afterStore in interface ManageableCollection
Throws:
PersistenceBrokerException
See Also:
ManageableCollection.afterStore(PersistenceBroker broker)

getBrokerKey

protected PBKey getBrokerKey()
Returns the brokerKey.

Returns:
PBKey

setBrokerKey

protected void setBrokerKey(PBKey brokerKey)
Sets the brokerKey.

Parameters:
brokerKey - The brokerKey to set

addListener

public void addListener(CollectionProxyListener l)

removeListener

public void removeListener(CollectionProxyListener l)


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14