org.garret.perst
Interface Link<T extends IPersistent>

All Superinterfaces:
java.util.Collection, ITable, java.lang.Iterable
All Known Implementing Classes:
Relation

public interface Link<T extends IPersistent>
extends ITable<T>

Interface for one-to-many relation. There are two types of relations: embedded (when references to the relarted obejcts are stored in relation owner obejct itself) and stanalone (when relation is separate object, which contains the reference to the relation owner and relation members). Both kinds of relations implements Link interface. Embedded relation is created by Storage.createLink method and standalone relation is represented by Relation persistent class created by Storage.createRelation method.


Method Summary
 boolean add(T obj)
          Add new object to the relation
 boolean addAll(Link<T> link)
          Add all object members of the other relation to this relation
 void addAll(T[] arr)
          Add all elements of the array to the relation
 void addAll(T[] arr, int from, int length)
          Add specified elements of the array to the relation
 void clear()
          Remove all members from the relation
 boolean contains(java.lang.Object obj)
          Check if there is linked object which is equal to the specified object.
 boolean containsElement(int i, T obj)
          Check if i-th element of Link is the same as specified obj
 boolean containsObject(T obj)
          Checks if relation contains specified object instance
 T get(int i)
          Get related object by index
 IPersistent getRaw(int i)
          Get related object by index without loading it.
 int indexOf(java.lang.Object obj)
          Get index of the specified object in the relation
 void insert(int i, T obj)
          Insert new object in the relation
 boolean isEmpty()
          Returns true if there are no related object
 java.util.Iterator<T> iterator()
          Get iterator through link members This iterator supports remove() method.
 void pin()
          Replace references to elements with direct references.
 void remove(int i)
          Remove object with specified index from the relation
 boolean remove(java.lang.Object o)
          Remove object from the relation
 void set(int i, T obj)
          Replace i-th element of the relation
 void setSize(int newSize)
          Set number of the linked objects
 int size()
          Get number of the linked objects
<T> T[]
toArray(T[] arr)
          Get all relation members as array.
 IPersistent[] toPersistentArray()
          Get relation members as array of object
 IPersistent[] toRawArray()
          Return array with relation members.
 void unpin()
          Replace all direct references to linked objects with stubs.
 
Methods inherited from interface org.garret.perst.ITable
select
 
Methods inherited from interface java.util.Collection
add, addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray
 

Method Detail

add

boolean add(T obj)
Add new object to the relation

Parameters:
obj - object inserted in the relation

addAll

boolean addAll(Link<T> link)
Add all object members of the other relation to this relation

Parameters:
link - another relation

addAll

void addAll(T[] arr)
Add all elements of the array to the relation

Parameters:
arr - array of obects which should be added to the relation

addAll

void addAll(T[] arr,
            int from,
            int length)
Add specified elements of the array to the relation

Parameters:
arr - array of obects which should be added to the relation
from - index of the first element in the array to be added to the relation
length - number of elements in the array to be added in the relation

clear

void clear()
Remove all members from the relation

Specified by:
clear in interface java.util.Collection

contains

boolean contains(java.lang.Object obj)
Check if there is linked object which is equal to the specified object. More formally, returns true if and only if this collection contains at least one element e such that (obj==null ? e==null : obj.equals(e)).

Specified by:
contains in interface java.util.Collection
Parameters:
obj - object to be searched in the index. Object should contain indexed field.
Returns:
true if collection contains object equals to the specified

containsElement

boolean containsElement(int i,
                        T obj)
Check if i-th element of Link is the same as specified obj

Parameters:
i - element index
obj - object to compare with
Returns:
true if i-th element of Link reference the same object as "obj"

containsObject

boolean containsObject(T obj)
Checks if relation contains specified object instance

Parameters:
obj - specified object
Returns:
true if object is present in the collection, false otherwise

get

T get(int i)
Get related object by index

Parameters:
i - index of the object in the relation
Returns:
referenced object

getRaw

IPersistent getRaw(int i)
Get related object by index without loading it. Returned object can be used only to get it OID or to compare with other objects using equals method

Parameters:
i - index of the object in the relation
Returns:
stub representing referenced object

indexOf

int indexOf(java.lang.Object obj)
Get index of the specified object in the relation

Parameters:
obj - specified object
Returns:
zero based index of the object or -1 if object is not in the relation

insert

void insert(int i,
            T obj)
Insert new object in the relation

Parameters:
i - insert poistion, should be in [0,size()]
obj - object inserted in the relation

isEmpty

boolean isEmpty()
Returns true if there are no related object

Specified by:
isEmpty in interface java.util.Collection
Returns:
true if there are no related object

iterator

java.util.Iterator<T> iterator()
Get iterator through link members This iterator supports remove() method.

Specified by:
iterator in interface java.util.Collection
Returns:
iterator through linked objects

pin

void pin()
Replace references to elements with direct references. It will impove spped of manipulations with links, but it can cause recursive loading in memory large number of objects and as a result - memory overflow, because garbage collector will not be able to collect them


remove

void remove(int i)
Remove object with specified index from the relation

Parameters:
i - index in the relartion

remove

boolean remove(java.lang.Object o)
Remove object from the relation

Specified by:
remove in interface java.util.Collection
Parameters:
o - removed object
Returns:
true if relation is changed as the result of this operation

set

void set(int i,
         T obj)
Replace i-th element of the relation

Parameters:
i - index in the relartion
obj - object to be included in the relation

setSize

void setSize(int newSize)
Set number of the linked objects

Parameters:
newSize - new number of linked objects (if it is greater than original number, than extra elements will be set to null)

size

int size()
Get number of the linked objects

Specified by:
size in interface java.util.Collection
Returns:
the number of related objects

toArray

<T> T[] toArray(T[] arr)
Get all relation members as array. The runtime type of the returned array is that of the specified array. If the index fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this index.

If this index fits in the specified array with room to spare (i.e., the array has more elements than this index), the element in the array immediately following the end of the index is set to null. This is useful in determining the length of this index only if the caller knows that this index does not contain any null elements.)

Specified by:
toArray in interface java.util.Collection
Returns:
array of object with relation members

toPersistentArray

IPersistent[] toPersistentArray()
Get relation members as array of object

Returns:
array of object with relation members

toRawArray

IPersistent[] toRawArray()
Return array with relation members. Members are not loaded and size of the array can be greater than actual number of members.

Returns:
array of object with relation members used in implementation of Link class

unpin

void unpin()
Replace all direct references to linked objects with stubs. This method is needed tyo avoid memory exhaustion in case when there is a large numebr of objectys in databasse, mutually refefencing each other (each object can directly or indirectly be accessed from other objects).