|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.hydrateframework.ObjectCollection<E>
public abstract class ObjectCollection<E extends HydrateObject>
This class is used to represent a collection of hydrate objects.
The class implements the Collection
interface for
objects of class HydrateObject
. The class is abstract
and each '-to-many' reference defined in the class definition
which is represented by a collection in the generated code will
have its own concrete implementation of this class to support it.
The implementation of this collection is always a set, and it
uses two strategies for guaranteeing uniqueness. For small lists
with a number of attributes less than or equal to a threshold value (=16), the
set is held as a dynamically resizing array which doubles in size
each time the limit is hit. This is an efficient way of storing
the data in the set, but requires the array to be scanned each time
a new element is added to ensure it is not in the set already.
Beyond this size, the set automatically reconfigures itself into
a HashSet, which is more expensive to create, and uses more memory,
but avoids the scan when adding new elements.
Nested Class Summary | |
---|---|
class |
ObjectCollection.Iter
This nested class implements an iterator that can be used to scan a business object collection. |
class |
ObjectCollection.IterHs
This nested class implements an iterator that can be used to scan an object collection. |
Field Summary | |
---|---|
protected java.lang.Class |
m_cls
The type of object held by this collection |
protected java.lang.Object |
m_list
The array or hashset holding the list of business objects. |
protected static org.apache.commons.logging.Log |
m_log
|
protected java.lang.String |
m_nm
The name of the collection. |
protected static int |
SIZETHRESH
The threshold above which a hash map is used to store this collection. |
Constructor Summary | |
---|---|
protected |
ObjectCollection(java.lang.Class cls,
java.lang.String nm)
The constructor is called by derived versions of this abstract class |
Method Summary | ||
---|---|---|
boolean |
addAll(java.util.Collection<? extends E> c)
This implements the addAll method of the Collection interface. |
|
boolean |
addInit(E o)
This call adds an object to this collection without worrying about reverse links etc. |
|
boolean |
addMTM(E o,
boolean reverse)
Add an object to this collection that is part of a many-to-many relationship. |
|
void |
clear()
This implements the clear method of the Collection interface. |
|
boolean |
contains(java.lang.Object o)
This implements the contains method of the Collection interface. |
|
boolean |
containsAll(java.util.Collection<?> c)
This implements the containsAll method of the Collection interface. |
|
boolean |
equals(java.lang.Object o)
This implements the equals method of the Collection interface. |
|
protected java.util.Set<ObjectRelationshipFactory.RelationshipMap> |
getMTM(ObjectContext ctx)
Return the list of changes to the many-to-many relationship table. |
|
java.lang.String |
getName()
|
|
protected abstract E |
getOwner()
Collections are owned by the object in which they exist. |
|
boolean |
isEmpty()
|
|
java.util.Iterator<E> |
iterator()
|
|
boolean |
remove(java.lang.Object o)
This implements the remove method of the Collection interface. |
|
boolean |
removeAll(java.util.Collection<?> c)
This implements the removeAll method of the Collection interface. |
|
java.lang.Object |
removeInit(java.lang.Object o)
Remove a business object from this collection. |
|
boolean |
removeMTM(HydrateObject o,
boolean reverse)
Remove an object from the collection which forms part of a many to many relationship. |
|
protected abstract void |
removeRefs(E o)
The implementation of the removeRefs method will fix up any reverse
references that may exist for this object. |
|
boolean |
retainAll(java.util.Collection<?> c)
This implements the retainAll method of the Collection interface. |
|
void |
save(SaveContext sc)
|
|
int |
size()
This implements the size method of the Collection interface |
|
java.lang.Object[] |
toArray()
This implements the toArray method of the Collection interface. |
|
|
toArray(T[] a)
This implements the toArray(Object[]) method of the Collection interface |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
add, hashCode |
Field Detail |
---|
protected static final org.apache.commons.logging.Log m_log
protected static final int SIZETHRESH
protected java.lang.Object m_list
protected java.lang.String m_nm
protected java.lang.Class m_cls
Constructor Detail |
---|
protected ObjectCollection(java.lang.Class cls, java.lang.String nm)
cls
- the interface representing the business object that
the collection will hold.nm
- the name of the collection is usually a short version
of the name of the business object relationship that requires it.Method Detail |
---|
protected abstract void removeRefs(E o)
removeRefs
method will fix up any reverse
references that may exist for this object. For example if an employee
is in one department, and a department has many employees, the department
will have a getEmployeeColl member that will return an ObjectCollection
and the employee will have an initDepartment method that takes a
Department object. When an employee is removed from the department, this
method is called on the collection returned by getEmployeeColl and it
must also call initDepartment(null) on the employee being added In the
case of many-to-many relationships, the implementation
code must also worry about calling removeMTM to ensure that the many-to-many
relationship table is kept up-to-date.
o
- the object to be removed from the collection.protected abstract E getOwner()
protected java.util.Set<ObjectRelationshipFactory.RelationshipMap> getMTM(ObjectContext ctx)
public boolean addMTM(E o, boolean reverse)
addInit(E)
except
that it also adds a request to add a row to the many-to-many relationship
table. This request will be executed when this collection is saved in the
database.
o
- the object that is being added to this collectionreverse
- true if the relationship is being populated 'right to left'
or false if it is being populated 'left to right'
public boolean removeMTM(HydrateObject o, boolean reverse)
removeInit(java.lang.Object)
except
that it also adds a requires to remove a row to the many-to-many
relationship table. It also checks the current list of requests to
see if the remove request cancels an unexecuted add request.
outstanding requests will be executed when this collection is saved in
the database.
o
- the object to be removed.reverse
- true if the relationship is being populated 'right to left'
or false if it is being populated 'left to right'
public boolean addInit(E o)
o
- the object to be added
public java.lang.String getName()
public void save(SaveContext sc) throws SaveException
SaveException
public java.lang.Object removeInit(java.lang.Object o)
remove
call, this does not attempt to maintain the integrity of any reverse
links. It is used internally for managing indexes, and is called by the
remove
call which does maintain integrity.
o
- the business object to be removed (or an object with a matching key)
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E extends HydrateObject>
addAll
in interface java.util.Set<E extends HydrateObject>
c
- the collection of objects to add which must all be
BusObject objects.
public void clear()
clear
in interface java.util.Collection<E extends HydrateObject>
clear
in interface java.util.Set<E extends HydrateObject>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E extends HydrateObject>
contains
in interface java.util.Set<E extends HydrateObject>
o
- the object to search for
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E extends HydrateObject>
containsAll
in interface java.util.Set<E extends HydrateObject>
c
- the collection containing objects to search for
public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<E extends HydrateObject>
equals
in interface java.util.Set<E extends HydrateObject>
equals
in class java.lang.Object
o
- A collection against which equlity is tested.
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E extends HydrateObject>
isEmpty
in interface java.util.Set<E extends HydrateObject>
public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E extends HydrateObject>
iterator
in interface java.util.Collection<E extends HydrateObject>
iterator
in interface java.util.Set<E extends HydrateObject>
Iterator
that can be used to scan the
objects in this collection.public boolean remove(java.lang.Object o)
removeRefs(E)
remove
in interface java.util.Collection<E extends HydrateObject>
remove
in interface java.util.Set<E extends HydrateObject>
o
- the object to remove
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E extends HydrateObject>
removeAll
in interface java.util.Set<E extends HydrateObject>
c
- the list of objects to remove
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E extends HydrateObject>
retainAll
in interface java.util.Set<E extends HydrateObject>
c
- the list of objects to retain
public int size()
size
in interface java.util.Collection<E extends HydrateObject>
size
in interface java.util.Set<E extends HydrateObject>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E extends HydrateObject>
toArray
in interface java.util.Set<E extends HydrateObject>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E extends HydrateObject>
toArray
in interface java.util.Set<E extends HydrateObject>
a
- a template for the type of array to return (which is used as
the return value if there is enough space in it).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |