org.garret.perst
Interface Link

All Superinterfaces:
ITable
All Known Implementing Classes:
Relation

public interface Link
extends ITable

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
 void add(IPersistent obj)
          Add new object to the relation
 void addAll(IPersistent[] arr)
          Add all elements of the array to the relation
 void addAll(IPersistent[] arr, int from, int length)
          Add specified elements of the array to the relation
 void addAll(Link link)
          Add all object members of the other relation to this relation
 void clear()
          Remove all members from the relation
 boolean contains(IPersistent obj)
          Check if there is linked object which is equal to the specified object.
 boolean containsElement(int i, IPersistent obj)
          Check if i-th element of Link is the same as specified obj
 boolean containsObject(IPersistent obj)
          Checks if relation contains specified object instance
 IPersistent get(int i)
          Get related object by index
 IPersistent getRaw(int i)
          Get related object by index without loading it.
 int indexOf(IPersistent obj)
          Get index of the specified object in the relation
 void insert(int i, IPersistent obj)
          Insert new object in the relation
 java.util.Iterator iterator()
          Get iterator through link members.
 void pin()
          Replace references to elements with direct references.
 void remove(int i)
          Remove object with specified index from the relation
 void set(int i, IPersistent 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
 IPersistent[] toArray()
          Get relation members as array of object
 IPersistent[] toArray(IPersistent[] arr)
          Get all relation members as array.
 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
 

Method Detail

add

public void add(IPersistent obj)
Add new object to the relation

Parameters:
obj - object inserted in the relation

addAll

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

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

addAll

public void addAll(IPersistent[] 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

addAll

public void addAll(Link link)
Add all object members of the other relation to this relation

Parameters:
link - another relation

clear

public void clear()
Remove all members from the relation


contains

public boolean contains(IPersistent 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)).

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

public boolean containsElement(int i,
                               IPersistent 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

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

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

get

public IPersistent get(int i)
Get related object by index

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

getRaw

public 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

public int indexOf(IPersistent 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

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

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

iterator

public java.util.Iterator iterator()
Get iterator through link members. This iterator supports remove() method.

Specified by:
iterator in interface ITable
Returns:
iterator through linked objects

pin

public 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 garabge collector will not be able to collect them


remove

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

Parameters:
i - index in the relartion

set

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

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

setSize

public 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

public int size()
Get number of the linked objects

Specified by:
size in interface ITable
Returns:
the number of related objects

toArray

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

Returns:
array of object with relation members

toArray

public IPersistent[] toArray(IPersistent[] 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.)

Returns:
array of object with relation members

toRawArray

public 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

public 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).