org.apache.ojb.broker.core.proxy
Class CollectionProxyDefaultImpl

java.lang.Object
  extended by org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, CollectionProxy, ManageableCollection
Direct Known Subclasses:
ListProxyDefaultImpl, SetProxyDefaultImpl

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

A place holder for a whole collection to support deferred loading of relationships. The complete collection is loaded on access to the data.

Version:
$Id: CollectionProxyDefaultImpl.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
Jakob Braeuchi
See Also:
Serialized Form

Constructor Summary
CollectionProxyDefaultImpl(PBKey brokerKey, java.lang.Class collClass, Query query)
          Creates a new collection proxy that uses the given collection type.
CollectionProxyDefaultImpl(PBKey brokerKey, Query query)
          Creates a new collection proxy (uses RemovalAwareCollection as the collection class).
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 void addListener(CollectionProxyListener listener)
          Adds a listener to this collection.
 void afterStore(PersistenceBroker broker)
          A callback method to implement 'removal-aware' (track removed objects and delete them by its own) collection implementations.
 void clear()
          Clears the proxy.
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 PBKey getBrokerKey()
          Returns the key of the persistence broker used by this collection.
 java.lang.Class getCollectionClass()
          Returns the collection type.
 java.util.Collection getData()
          Returns the collection data, load it if not already done so.
 Query getQuery()
          Returns the defining query.
 boolean isEmpty()
           
 boolean isLoaded()
          Determines whether the collection data already has been loaded from the database.
 java.util.Iterator iterator()
           
 void ojbAdd(java.lang.Object anObject)
          Adds a single object to the Collection.
 void ojbAddAll(ManageableCollection otherCollection)
          Adds another 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)
           
 void removeListener(CollectionProxyListener listener)
          Removes the given listener from this collecton.
 boolean retainAll(java.util.Collection c)
           
 void setData(java.util.Collection data)
          Sets the collection data.
 void setProfileKey(java.lang.Object profileKey)
          Sets the metadata profile key used when creating this proxy.
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

CollectionProxyDefaultImpl

public CollectionProxyDefaultImpl(PBKey brokerKey,
                                  Query query)
Creates a new collection proxy (uses RemovalAwareCollection as the collection class).

Parameters:
brokerKey - The key of the persistence broker
query - The defining query

CollectionProxyDefaultImpl

public CollectionProxyDefaultImpl(PBKey brokerKey,
                                  java.lang.Class collClass,
                                  Query query)
Creates a new collection proxy that uses the given collection type.

Parameters:
brokerKey - The key of the persistence broker
collClass - The collection type
query - The defining query
Method Detail

isLoaded

public boolean isLoaded()
Determines whether the collection data already has been loaded from the database.

Specified by:
isLoaded in interface CollectionProxy
Returns:
true if the data is already loaded

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.lang.Iterable
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()
Clears the proxy. A cleared proxy is defined as loaded

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

getQuery

public Query getQuery()
Returns the defining query.

Returns:
The query

getData

public java.util.Collection getData()
Returns the collection data, load it if not already done so.

Returns:
The data

setData

public void setData(java.util.Collection data)
Sets the collection data.

Parameters:
data - The data

getCollectionClass

public java.lang.Class getCollectionClass()
Returns the collection type.

Returns:
The collection type

ojbAdd

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

Specified by:
ojbAdd in interface ManageableCollection
Parameters:
anObject - The object to add
See Also:
ManageableCollection.ojbAdd(Object)

ojbAddAll

public void ojbAddAll(ManageableCollection otherCollection)
Description copied from interface: ManageableCollection
Adds another collection to this collection. Used in reading extents from the database. Thus it is safe to cast the given collection to this class.

Specified by:
ojbAddAll in interface ManageableCollection
Parameters:
otherCollection - The added collection
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
Returns:
The iterator
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
Parameters:
broker - The persistence broker
Throws:
PersistenceBrokerException
See Also:
ManageableCollection.afterStore(PersistenceBroker broker)

getBrokerKey

public PBKey getBrokerKey()
Returns the key of the persistence broker used by this collection.

Returns:
The broker key

setProfileKey

public void setProfileKey(java.lang.Object profileKey)
Sets the metadata profile key used when creating this proxy.

Parameters:
profileKey - the metadata profile key

addListener

public void addListener(CollectionProxyListener listener)
Adds a listener to this collection.

Specified by:
addListener in interface CollectionProxy
Parameters:
listener - The listener to add

removeListener

public void removeListener(CollectionProxyListener listener)
Removes the given listener from this collecton.

Specified by:
removeListener in interface CollectionProxy
Parameters:
listener - The listener to remove


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30