org.ow2.jonas.lib.ejb21.jorm
Class GenClassImpl

java.lang.Object
  extended by org.ow2.jonas.lib.ejb21.jorm.GenClassImpl
All Implemented Interfaces:
org.objectweb.jorm.api.PAccessor, org.objectweb.jorm.api.PGenClassAccessor, org.objectweb.jorm.api.PIndexedElemFactory
Direct Known Subclasses:
Collection, Set

public abstract class GenClassImpl
extends Object
implements org.objectweb.jorm.api.PGenClassAccessor

This class is a basic implementation of the PGenClassAccessor interface usefull for the multivalued relation.

Author:
S.Chassande-Barrioz

Nested Class Summary
protected  class GenClassImpl.ElementIterator
          this class is an implementation of the Iterator interface which return only the existing objects.
 
Field Summary
protected  int[] deletedLength
          This array represents the distance between two deleted elements in the pIndexedElems arraylist.
protected  JEntityContext ectx
           
protected  org.objectweb.jorm.api.PClassMapping gcm
          This field references the PClassMapping which manages the persistency of this GenClass.
protected  boolean isModified
          true when GenClass has been modified and must be written
protected  GenClassListener listener
          All the actions are send to this listener.
protected  org.objectweb.jorm.api.PBinding pb
          This fields is the PBinding associated to this instance.
protected  ArrayList pIndexedElems
          All elements of the gen class (unmodified, modified, created, deleted) This ArrayList contains GenClassElem objects
protected  boolean selectForUpdate
          true when we want use select ..
protected  int size
          This is the size of the relation.
 
Constructor Summary
GenClassImpl()
          A GenClassImpl object is created for each Multi-Valued CMR field See JEntityCmp2.vm It starts with an empty list.
 
Method Summary
 org.objectweb.jorm.api.PIndexedElem createPIndexedElem()
          The default implementation of the PIndexedElem is GenClassElement.
protected  void gcAdd(PObject element, boolean callListener)
          This method add a new element in the collection.
 void gcClear(boolean delete)
          Clear the GenClass.
protected  boolean gcContains(PObject element, Object connection)
           
protected  PObject gcDeref(org.objectweb.jorm.naming.api.PName pn)
           
protected  PObject gcGetElement(GenClassElement gce, Object connection)
          It dereferences an element if needed
 org.objectweb.jorm.api.PBinding gcGetPBinding()
          Get the PBinding used for this GenClass Used by JEntityCmp2.vm
protected  int gcGetRealIndex(int idx)
          This method calculates the real index of an element.
 int gcGetSize()
           
 boolean gcIsModified()
           
protected  Iterator gcIterator()
           
protected  Iterator gcIterator(Object connection)
           
protected  org.objectweb.jorm.naming.api.PName gcObject2ref(PObject value)
          This method permits to find the PName of an object.
protected  Object gcRemove(Object element, boolean callListener)
          It removes the first occurence of an element from the relation.
 GenClassListener getListener()
           
 Object getMemoryInstance()
          In most of cases this class is extented to personalize to a collection type.
 void paAdd(org.objectweb.jorm.api.PIndexedElem elem, Object conn)
          It adds the elements in the list.
 boolean paDeltaSupported()
          This implementation is able to isolate the modification by element of the gen class.
 int paGetNbElem()
          This method is used by the PBinding to allocated data structure during a write operation.
 Iterator paIterator()
          This method is used by the PBinding to fetch all PIndexedElem.
 void paSetNbElem(int nbelem)
          This method is call in first during a read operation in order to indicate the size of the gen class.
 void printState()
           
 void read(org.objectweb.jorm.naming.api.PName pn, Object connection, Object tx)
          It loads the data of the gen class.
 void reset()
          reset the GenClass to its initial state.
 void setEntityContext(JEntityContext ectx)
          Set the EntityContext needed for setDirty calls
 void setListener(GenClassListener gcl)
           
 void setPBinding(org.objectweb.jorm.api.PBinding pb)
          Set the PBinding that will be used for this GenClass Used by JEntityCmp2.vm
 void setPClassMapping(org.objectweb.jorm.api.PClassMapping gcm)
          Set the PClassMapping for this GenClass.
 void write(org.objectweb.jorm.naming.api.PName pn, Object connection)
          It writes the data of the gen class if it was modified (see the field isModified).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pIndexedElems

protected ArrayList pIndexedElems
All elements of the gen class (unmodified, modified, created, deleted) This ArrayList contains GenClassElem objects


deletedLength

protected int[] deletedLength
This array represents the distance between two deleted elements in the pIndexedElems arraylist. O means there is no element in the middle. The first element is in fact the quantity of existing element before the first deleted element. The size of this array is also the quantity of deleted elements. Then if the array is empty there is no deleted elements. for example: if this fields is equals to [3, 2] then the elements whith the index 3 and 6 are marked as deleted: [a, b, c, D, d, e, D, ....] This array is useless to convert an index valid inside the user/virtual collection to an index valid inside the 'pIndexedElems' ArrayList.


size

protected int size
This is the size of the relation. This field is equal to the pIndexedElems size minus the quantity of deleted element. The value is always right and is updated during each delete or create action.


isModified

protected boolean isModified
true when GenClass has been modified and must be written


selectForUpdate

protected boolean selectForUpdate
true when we want use select .. for ..update


gcm

protected org.objectweb.jorm.api.PClassMapping gcm
This field references the PClassMapping which manages the persistency of this GenClass. (xxxGCM.java) This is actually a GenClassMapping, returned by the bean Factory (PClassMapping)


ectx

protected JEntityContext ectx

pb

protected org.objectweb.jorm.api.PBinding pb
This fields is the PBinding associated to this instance.


listener

protected GenClassListener listener
All the actions are send to this listener. There is 1 Listener for each GenClass, i.e. for each multi-valued CMR field. (See JEntityCmp2.vm) Used mainly for coherence.

Constructor Detail

GenClassImpl

public GenClassImpl()
A GenClassImpl object is created for each Multi-Valued CMR field See JEntityCmp2.vm It starts with an empty list.

Method Detail

setPClassMapping

public void setPClassMapping(org.objectweb.jorm.api.PClassMapping gcm)
Set the PClassMapping for this GenClass. It's needed to get Connections for read and write operations. Used by JEntityCmp2.vm

Parameters:
gcm - the PClassMapping

setEntityContext

public void setEntityContext(JEntityContext ectx)
Set the EntityContext needed for setDirty calls


reset

public void reset()
reset the GenClass to its initial state.


setPBinding

public void setPBinding(org.objectweb.jorm.api.PBinding pb)
Set the PBinding that will be used for this GenClass Used by JEntityCmp2.vm

Parameters:
pb - The PBinding for this GenClass

gcGetPBinding

public org.objectweb.jorm.api.PBinding gcGetPBinding()
Get the PBinding used for this GenClass Used by JEntityCmp2.vm

Returns:
The PBinding for this GenClass

setListener

public void setListener(GenClassListener gcl)

getListener

public GenClassListener getListener()

gcIsModified

public boolean gcIsModified()

read

public void read(org.objectweb.jorm.naming.api.PName pn,
                 Object connection,
                 Object tx)
          throws org.objectweb.jorm.api.PException
It loads the data of the gen class.

Parameters:
pn - is the PName of the genclass
connection - is a connection to access to the support. If it is null a connection is asked to the mapper and closed after its use.
Throws:
org.objectweb.jorm.api.PException

write

public void write(org.objectweb.jorm.naming.api.PName pn,
                  Object connection)
           throws org.objectweb.jorm.api.PException
It writes the data of the gen class if it was modified (see the field isModified).

Parameters:
pn - is the PName of the genclass
connection - is a connection to access to the support. If it is null a connection is asked to the mapper and closed after its use.
Throws:
org.objectweb.jorm.api.PException

getMemoryInstance

public Object getMemoryInstance()
In most of cases this class is extented to personalize to a collection type. Then an instance of this class is often the real collection.

Specified by:
getMemoryInstance in interface org.objectweb.jorm.api.PAccessor

paAdd

public void paAdd(org.objectweb.jorm.api.PIndexedElem elem,
                  Object conn)
           throws org.objectweb.jorm.api.PException
It adds the elements in the list. This method is used by the PBinding to load the data. The elements is added at the end of the 'pIndexedElems' then 'deletedLength' is not impacted.

Specified by:
paAdd in interface org.objectweb.jorm.api.PGenClassAccessor
Throws:
org.objectweb.jorm.api.PException

createPIndexedElem

public org.objectweb.jorm.api.PIndexedElem createPIndexedElem()
The default implementation of the PIndexedElem is GenClassElement. This method may be redefined for different GenClass implementations.

Specified by:
createPIndexedElem in interface org.objectweb.jorm.api.PIndexedElemFactory

paDeltaSupported

public boolean paDeltaSupported()
This implementation is able to isolate the modification by element of the gen class.

Specified by:
paDeltaSupported in interface org.objectweb.jorm.api.PGenClassAccessor

paGetNbElem

public int paGetNbElem()
This method is used by the PBinding to allocated data structure during a write operation. The returned size must then contains also the deleted elements.

Specified by:
paGetNbElem in interface org.objectweb.jorm.api.PGenClassAccessor

paIterator

public Iterator paIterator()
This method is used by the PBinding to fetch all PIndexedElem.

Specified by:
paIterator in interface org.objectweb.jorm.api.PGenClassAccessor

paSetNbElem

public void paSetNbElem(int nbelem)
This method is call in first during a read operation in order to indicate the size of the gen class. if the value is equals to -1 then that means the data support is unable to known the size of the relation in advance. Then the previous size is kept. Otherwise the list is initialized to the specified size.

Specified by:
paSetNbElem in interface org.objectweb.jorm.api.PGenClassAccessor

gcGetRealIndex

protected int gcGetRealIndex(int idx)
This method calculates the real index of an element.

Parameters:
idx - the index valid in the colllection
Returns:
an index valid into the 'pIndexedElems' ArrayList.

gcAdd

protected void gcAdd(PObject element,
                     boolean callListener)
This method add a new element in the collection. A PIndexedElem is built via the 'createPIndexedElem' method. Then this instance is initialized with the element and the staus specified by the parameter 'status'. Before added the element, a checking is done. If the element was previously removed in the same transaction then the status of the removed element is changed to ELEM_UNMODIFIED. This optimization avoid two useless I/O.

Parameters:
element - the object to add
callListener - indicates if the gen class listener must be call about this action

gcRemove

protected Object gcRemove(Object element,
                          boolean callListener)
                   throws org.objectweb.jorm.api.PException
It removes the first occurence of an element from the relation.

Parameters:
element - an element which must be removed
callListener - indicates if the gen class listener must be call about this action
Returns:
the remove element
Throws:
org.objectweb.jorm.api.PException

gcGetSize

public int gcGetSize()

gcContains

protected boolean gcContains(PObject element,
                             Object connection)
                      throws org.objectweb.jorm.api.PException
Throws:
org.objectweb.jorm.api.PException

gcIterator

protected Iterator gcIterator()
                       throws org.objectweb.jorm.api.PException
Throws:
org.objectweb.jorm.api.PException

gcIterator

protected Iterator gcIterator(Object connection)
                       throws org.objectweb.jorm.api.PException
Parameters:
connection - the connection to use during the PName resolving (if it has not already dereferenced).
Returns:
an Iterator over the virtual relations (only the existing elements).
Throws:
org.objectweb.jorm.api.PException

gcGetElement

protected PObject gcGetElement(GenClassElement gce,
                               Object connection)
                        throws org.objectweb.jorm.api.PException
It dereferences an element if needed

Parameters:
gce - is the PIndexedElem which must be dereferenced
connection - a connection to use to resolve the PName. If this parameter is null a new connection is allocate via the mapper. This connection is closed just after its use.
Returns:
a reference to the bean (The local interface in fact).
Throws:
org.objectweb.jorm.api.PException

gcClear

public void gcClear(boolean delete)
Clear the GenClass.

Parameters:
delete - true if cascade delete must be checked (ONE - MANY)

gcDeref

protected PObject gcDeref(org.objectweb.jorm.naming.api.PName pn)

gcObject2ref

protected org.objectweb.jorm.naming.api.PName gcObject2ref(PObject value)
                                                    throws org.objectweb.jorm.api.PException
This method permits to find the PName of an object.

Throws:
org.objectweb.jorm.api.PException

printState

public void printState()


Copyright © 2010 OW2 Consortium. All Rights Reserved.