org.objectweb.jorm.mapper.rdb.genclass
Class RdbGenClassMapping

java.lang.Object
  extended byorg.objectweb.jorm.genclass.lib.GenClassMapping
      extended byorg.objectweb.jorm.mapper.rdb.genclass.RdbGenClassMapping
All Implemented Interfaces:
GenClassProp, Loggable, PClassMapping, PClassMappingCtrl, RdbGenClassProp

public class RdbGenClassMapping
extends GenClassMapping
implements RdbGenClassProp

This class provides the implementation of PClassMapping for RDBMS.

Author:
P. Dechamboux, S.Chassande-Barrioz

Nested Class Summary
 
Nested classes inherited from class org.objectweb.jorm.api.PClassMapping
PClassMapping.ReferenceConfigurator
 
Field Summary
protected  boolean colocated
           
protected  boolean colocatedMaster
           
protected  java.lang.String[] extCols
           
protected  java.lang.String[] mainCols
           
protected  int nbPrefetchCol
           
protected  boolean prefetchActivated
           
protected  RdbPrefetchablePCM prefetchedPCM
           
protected  boolean readOnly
           
protected  java.lang.String refExtTableName
           
protected  java.lang.String tableName
          The name of the table into which to store generic class object elements.
protected  RdbAdapter typeConverter
          This is the type converter defined for a particular kind of RDB.
protected  boolean useBatch
           
 
Fields inherited from class org.objectweb.jorm.genclass.lib.GenClassMapping
binder, classPNC, elemClassMapping, elemFields, elemNameCoder, genClassMetaInfo, genClassPType, identifierFields, indexFields, jormClassName, logger, loggerFactory, mapper, projectName
 
Fields inherited from interface org.objectweb.jorm.api.PClassMapping
CLEANUP_DONOTHING, CLEANUP_REMOVEALL, CLEANUP_REMOVEDATA, CREATE_STRUCTURE_IF_NEEDED
 
Constructor Summary
RdbGenClassMapping()
           
 
Method Summary
 void addAssociation(PClassMapping targetClass, int[] indexes)
          Adds an association [pclassmapping-> table of indexes] to the association table.
 void classDefined(PMappingStructuresManager pmsm)
          Register the class in the cluster.
 PBinding createPBinding()
          It creates a new PBinding.
 void defineJoinColumns(java.lang.String[] maincols, java.lang.String[] extcols)
          Defines the two sets of columns that are used to join the main table with the extension table.
 boolean exist(PBinding pb, java.lang.Object conn)
          It verifies if the DSI attached to a binding exists within the DS.
 java.util.HashMap getAssociationTable()
          Returns the map storing association between a pclassmapping on which is done a query and a table of int representing the fields numbers to select in the tuple to fill in the field of an instance of the class.
 PName getDecodedPName(TupleCollection tc, PName pname, boolean b)
          It returns the PName valid in the "good" binder according to the tuple collection.
 int[] getIndexesTable(PClassMapping targetClass)
          Returns the indexes table associated to the pclassmapping targetClass, null if not contained in the map.
 PNameIterator getPNameIterator(java.lang.Object conn, boolean withSubType, boolean prefetching, java.lang.Object txctx)
          It returns an iterator over all pname of persitent objects availlable in this class.
 PClassMapping[] getSubPCMs()
          Returns null in case of genclass.
 void init(PMappingCallback mapper, MetaObject metaclass)
          It intialises the class mapping.
 void init(PMappingStructuresManager pmsm)
          Register the mapping structures and the dependencies.
 boolean isConform(java.lang.String mappername)
          It specifies if the given kind of PMapper is supported by this PClassMapping.
 boolean match(java.lang.Object obj, boolean b)
          Returns true if the object obj matches (exactly) this class, else it returns false.
 void read(PBinding pb, java.lang.Object conn, PAccessor pa)
          It reads the data store instance designated by the PName of a binding and transfers each attribute value to the accessor object.
 void read(PBinding pb, java.lang.Object conn, PAccessor pa, java.lang.Object txctx)
          It reads the data store instance designated by the PName of a binding and transfers each attribute value to the accessor object.
 void read(PBinding pb, java.lang.Object conn, PAccessor pa, java.lang.Object txctx, boolean forUpudate)
           
 PName resolve(java.lang.Object conn, PName pname)
          It returns the PName valid in the "good" binder.
 void setColocated(boolean colocated)
          Indicates if the table of the genclass is colocated
 void setColocatedMaster(boolean cm)
          Indicates if the table of the genclass is colocated
 void setPrefetchActivated(boolean prefetch)
           
 void setPrefetchElementPCM(RdbPrefetchablePCM pcm)
          Specify the PClassMapping of the persistent class which must be prefetched
 void setReadOnly(boolean readonly)
          Indicates if the table must be only read.
 void setRefExtTableName(java.lang.String retn)
          Defines the table name property of a generic class instance mapped to a RDB for a table that owns extension fields of a reference element.
 void setTableName(java.lang.String tn)
          Defines the table name property of a generic class instance mapped to a RDB.
 void setTypeConverter(RdbAdapter tc)
          Defines the type converter property of a generic class instance mapped to a RDB.
 void write(PBinding pb, java.lang.Object conn, PAccessor pa)
          It transfers each attribute value taken from the PAccessor object to the data store instance designated by the PName associated with a binding.
 
Methods inherited from class org.objectweb.jorm.genclass.lib.GenClassMapping
configureRefFields, getClassName, getClassPNameCoder, getElemFields, getGenClassMapping, getGenClassMapping, getIdentifierFields, getIndexFields, getLogger, getLoggerFactory, getMetaInfo, getPBinder, getPMapper, getPNameCoder, getPNameCoder, getPNameIterator, getProjectName, getPType, setClassPNameCoder, setElemDesc, setGenClassMapping, setGenClassMapping, setIdentifierDesc, setIndexDesc, setLogger, setLoggerFactory, setPBinder, setPNameCoder, setPNameCoder, setProjectName, setPType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.jorm.genclass.api.GenClassProp
setElemDesc, setIdentifierDesc, setIndexDesc, setPType
 

Field Detail

tableName

protected java.lang.String tableName
The name of the table into which to store generic class object elements. It should be null in case of "legacy" mapping.


refExtTableName

protected java.lang.String refExtTableName

mainCols

protected java.lang.String[] mainCols

extCols

protected java.lang.String[] extCols

prefetchedPCM

protected RdbPrefetchablePCM prefetchedPCM

nbPrefetchCol

protected int nbPrefetchCol

prefetchActivated

protected boolean prefetchActivated

typeConverter

protected RdbAdapter typeConverter
This is the type converter defined for a particular kind of RDB.


useBatch

protected boolean useBatch

colocated

protected boolean colocated

colocatedMaster

protected boolean colocatedMaster

readOnly

protected boolean readOnly
Constructor Detail

RdbGenClassMapping

public RdbGenClassMapping()
Method Detail

setPrefetchActivated

public void setPrefetchActivated(boolean prefetch)

createPBinding

public PBinding createPBinding()
                        throws PException
It creates a new PBinding.

Specified by:
createPBinding in interface PClassMapping
Returns:
The new PBinding with lifecycle state set to LIFECYCLE_NOTBOUND.
Throws:
PException

getPNameIterator

public PNameIterator getPNameIterator(java.lang.Object conn,
                                      boolean withSubType,
                                      boolean prefetching,
                                      java.lang.Object txctx)
                               throws PException
It returns an iterator over all pname of persitent objects availlable in this class. When you use the returned iterator you must leave the connection opened.

Specified by:
getPNameIterator in interface PClassMapping
Parameters:
conn - is the connection which permits to access to the support
withSubType - indicates if the subclass instances must be included into the iterator
prefetching - indicates if prefething must be activated during the query on the persistent support.
txctx - The transaction context that can be used in case of prefetching.
Returns:
the iterator over PName objects
Throws:
PException

getSubPCMs

public PClassMapping[] getSubPCMs()
                           throws PException
Returns null in case of genclass.

Specified by:
getSubPCMs in interface PClassMapping
Returns:
the list of sub pcms or null if the class has no child
Throws:
PException

isConform

public boolean isConform(java.lang.String mappername)
It specifies if the given kind of PMapper is supported by this PClassMapping. In this case, all kinds of RDB mappers are supported.

Specified by:
isConform in interface PClassMapping
Parameters:
mappername - The name defining the PMapper kind.
Returns:
true if this kind of mapper is supported.

exist

public boolean exist(PBinding pb,
                     java.lang.Object conn)
              throws PException
Description copied from interface: PClassMapping
It verifies if the DSI attached to a binding exists within the DS.

Specified by:
exist in interface PClassMapping
Parameters:
pb - is the PBinding instance
conn - The connection that can be used to refer to the DS.
Returns:
It returns true if the DSI exists.
Throws:
PException

read

public void read(PBinding pb,
                 java.lang.Object conn,
                 PAccessor pa)
          throws PException
Description copied from interface: PClassMapping
It reads the data store instance designated by the PName of a binding and transfers each attribute value to the accessor object.

Specified by:
read in interface PClassMapping
Parameters:
conn - The connection that can be used to refer to the DS.
pa - The PAccessor used to access memory variables.
Throws:
PException

read

public void read(PBinding pb,
                 java.lang.Object conn,
                 PAccessor pa,
                 java.lang.Object txctx)
          throws PException
Description copied from interface: PClassMapping
It reads the data store instance designated by the PName of a binding and transfers each attribute value to the accessor object. This read method should be used when prefetching is requested.

Specified by:
read in interface PClassMapping
Overrides:
read in class GenClassMapping
Throws:
PException

read

public void read(PBinding pb,
                 java.lang.Object conn,
                 PAccessor pa,
                 java.lang.Object txctx,
                 boolean forUpudate)
          throws PException
Specified by:
read in interface PClassMapping
Overrides:
read in class GenClassMapping
Throws:
PException

write

public void write(PBinding pb,
                  java.lang.Object conn,
                  PAccessor pa)
           throws PException
Description copied from interface: PClassMapping
It transfers each attribute value taken from the PAccessor object to the data store instance designated by the PName associated with a binding.

Specified by:
write in interface PClassMapping
Parameters:
conn - The connection that can be used to refer to the DS.
pa - The PAccessor used to access memory variables.
Throws:
PException

setTableName

public void setTableName(java.lang.String tn)
Description copied from interface: RdbGenClassProp
Defines the table name property of a generic class instance mapped to a RDB.

Specified by:
setTableName in interface RdbGenClassProp
Parameters:
tn - The table name

setRefExtTableName

public void setRefExtTableName(java.lang.String retn)
Description copied from interface: RdbGenClassProp
Defines the table name property of a generic class instance mapped to a RDB for a table that owns extension fields of a reference element.

Specified by:
setRefExtTableName in interface RdbGenClassProp
Parameters:
retn - The table name of the extension fields

setColocated

public void setColocated(boolean colocated)
Description copied from interface: RdbGenClassProp
Indicates if the table of the genclass is colocated

Specified by:
setColocated in interface RdbGenClassProp

setColocatedMaster

public void setColocatedMaster(boolean cm)
Description copied from interface: RdbGenClassProp
Indicates if the table of the genclass is colocated

Specified by:
setColocatedMaster in interface RdbGenClassProp

setReadOnly

public void setReadOnly(boolean readonly)
Description copied from interface: RdbGenClassProp
Indicates if the table must be only read.

Specified by:
setReadOnly in interface RdbGenClassProp
Parameters:
readonly -

setTypeConverter

public void setTypeConverter(RdbAdapter tc)
Description copied from interface: RdbGenClassProp
Defines the type converter property of a generic class instance mapped to a RDB.

Specified by:
setTypeConverter in interface RdbGenClassProp
Parameters:
tc - The associated type.

defineJoinColumns

public void defineJoinColumns(java.lang.String[] maincols,
                              java.lang.String[] extcols)
Description copied from interface: RdbGenClassProp
Defines the two sets of columns that are used to join the main table with the extension table.

Specified by:
defineJoinColumns in interface RdbGenClassProp
Parameters:
maincols - Names of columns within the main table.
extcols - Names of columns within the extension table.

setPrefetchElementPCM

public void setPrefetchElementPCM(RdbPrefetchablePCM pcm)
Description copied from interface: RdbGenClassProp
Specify the PClassMapping of the persistent class which must be prefetched

Specified by:
setPrefetchElementPCM in interface RdbGenClassProp

init

public void init(PMappingCallback mapper,
                 MetaObject metaclass)
          throws PException
It intialises the class mapping. It especially assigns a mapper as well as a meta-object describing either a class or a generic class.

Specified by:
init in interface PClassMapping
Overrides:
init in class GenClassMapping
Parameters:
mapper - The mapper to be assigned to this class mapping.
metaclass - The meta-object describing the associated class. It may be null.
Throws:
PException

getAssociationTable

public java.util.HashMap getAssociationTable()
Description copied from interface: PClassMapping
Returns the map storing association between a pclassmapping on which is done a query and a table of int representing the fields numbers to select in the tuple to fill in the field of an instance of the class. Example: Let's say we are instanciating D objects A(pk1, pk2, f1), B(f2), C(f3, f4), D(f5) _________A_______ B C____ D The prefetch query on A will be: Select pk1, pk2, f1, f2, f3, f4, f5 For D, the index table will be [1,2,3,5,6,7] because we need only pk1, pk2, f1, f3, f4, f5 to instanciate D objects The prefetch query on C will be: Select pk1, pk2, f1, f3, f4, f5 For D, the index table will be [1,2,3,4,5,6] because we need all the fields to instanciate D objects Then, the map returned for D will be: [ pclassmapping of A, [1,2,3,5,6,7]] [ pclassmapping of C, [1,2,3,4,5,6]]

Specified by:
getAssociationTable in interface PClassMapping

addAssociation

public void addAssociation(PClassMapping targetClass,
                           int[] indexes)
Description copied from interface: PClassMapping
Adds an association [pclassmapping-> table of indexes] to the association table. If the map already has an entry corresponding to the pclassmapping, this entry is replaced by the new one.

Specified by:
addAssociation in interface PClassMapping
Parameters:
targetClass - the PClassMapping on which is done the query
indexes - a table of int composed of the indexes of fields required

getIndexesTable

public int[] getIndexesTable(PClassMapping targetClass)
Description copied from interface: PClassMapping
Returns the indexes table associated to the pclassmapping targetClass, null if not contained in the map.

Specified by:
getIndexesTable in interface PClassMapping

resolve

public PName resolve(java.lang.Object conn,
                     PName pname)
              throws PException
Description copied from interface: PClassMapping
It returns the PName valid in the "good" binder.

Specified by:
resolve in interface PClassMapping
Parameters:
conn - The connection that can be used to refer to the DS.
Throws:
PException

match

public boolean match(java.lang.Object obj,
                     boolean b)
              throws PException
Description copied from interface: PClassMapping
Returns true if the object obj matches (exactly) this class, else it returns false.

Specified by:
match in interface PClassMapping
Throws:
PException

getDecodedPName

public PName getDecodedPName(TupleCollection tc,
                             PName pname,
                             boolean b)
                      throws PException
Description copied from interface: PClassMapping
It returns the PName valid in the "good" binder according to the tuple collection.

Specified by:
getDecodedPName in interface PClassMapping
Throws:
PException

init

public void init(PMappingStructuresManager pmsm)
          throws PException
Description copied from interface: PClassMapping
Register the mapping structures and the dependencies.

Specified by:
init in interface PClassMapping
Parameters:
pmsm - The PMappingStructuresManager in which mapping structures are registered.
Throws:
PException

classDefined

public void classDefined(PMappingStructuresManager pmsm)
                  throws PException
Description copied from interface: PClassMapping
Register the class in the cluster.

Specified by:
classDefined in interface PClassMapping
Parameters:
pmsm -
Throws:
PException