org.objectweb.medor.optim.jorm

Class JormFlatten2Rdb

Implemented Interfaces:
RewriteRule

public class JormFlatten2Rdb
extends JormRule

This rules transforms a QueryTree built on top of JORM Extents into a QueryTree built on top of RdbExpQueryLeaves.

The initial QueryTree can be a JORM Extent, or composed of one QueryNode with one or several JORM Extent. The FlattenQueryTree rewriting rule can produce such a QueryTree.

The resulting QueryTree always has a SelectProject node on top of the RdbExpQueryLeaf, in case of CalculatedFields (for example the PName).

Author:
S. Chassande-Barrioz

Nested Class Summary

class
JormFlatten2Rdb.Join
A join linking two relational tables.
class
JormFlatten2Rdb.JoinColumn
It describes the join between two columns
class
JormFlatten2Rdb.RdbJormExtentMapping
Represents the mapping of a JormExtent over relational tables.

Nested classes/interfaces inherited from class org.objectweb.medor.optim.lib.BasicRule

BasicRule.ModifiedExpression

Field Summary

Fields inherited from class org.objectweb.medor.optim.lib.BasicRule

debug, log

Constructor Summary

JormFlatten2Rdb()

Method Summary

Expression
getDecode(PNameField pnf, BasicRdbExpQueryLeaf leaf, boolean add)
Create an expression to decode a PName.
QueryTreeField
getField(String fieldname, PType type, JormExtent extent, BasicRdbExpQueryLeaf leaf, boolean add)
Adds a field in a leaf if it is not already present.
QueryTreeField
getField(String fieldname, JormExtent extent, BasicRdbExpQueryLeaf leaf, boolean add)
Shortcut to the getField(String, PType, JormExtent, BasicRdbExpQueryLeaf, boolean) method.
QueryTreeField
getField(Field old, BasicRdbExpQueryLeaf leaf, boolean add)
Is a shorcut to the getField(String, PType, JormExtent, BasicRdbExpQueryLeaf, boolean) method.
JormFlatten2Rdb.RdbJormExtentMapping
getMapping(int i)
Retrieves the RdbJormExtentMapping at the position i the packet.
JormFlatten2Rdb.RdbJormExtentMapping
getMapping(JormExtent je)
Retrieves the RdbJormExtentMapping at the position i the packet.
QueryTree
rewrite(QueryTree qt, QueryNode parent)
Expression
updateFieldOfExpression(Expression e, BasicRdbExpQueryLeaf leaf, boolean add)
Replaces the uses of the old fields of extents by fields of a leaf.

Methods inherited from class org.objectweb.medor.optim.jorm.JormRule

getClassMapping, getGenClassMapping, getJORMFieldName, getPEM, getPNCOperand, getPrimitiveElement

Methods inherited from class org.objectweb.medor.optim.lib.BasicRule

replaceUsage, rewrite

Constructor Details

JormFlatten2Rdb

public JormFlatten2Rdb()

Method Details

getDecode

public Expression getDecode(PNameField pnf,
                            BasicRdbExpQueryLeaf leaf,
                            boolean add)
            throws MedorException
Create an expression to decode a PName.

Parameters:
pnf - is the PNameField linked to JormExtent which is the old representation of the PName.
leaf - is the leaf which contains the field of the NameDef. It the fields do not exist then they are created.

Returns:
an expression to decode a PName.

Throws:
MedorException - if the NameDef is not supported or if the a field can not be created in the leaf.


getField

public QueryTreeField getField(String fieldname,
                               PType type,
                               JormExtent extent,
                               BasicRdbExpQueryLeaf leaf,
                               boolean add)
            throws MedorException
Adds a field in a leaf if it is not already present.

Parameters:
fieldname - is the field name of the expected field.
type - is the jorm type of expected field.
extent - is the extent containing the old version of the expected field.
leaf - is the leaf which must contain the expected field after the the method call
add - indicates whether the field should be added to the leaf

Returns:
the expected field

Throws:
MedorException - if no old field is not available on the extent or if no mapping is available for the field.


getField

public QueryTreeField getField(String fieldname,
                               JormExtent extent,
                               BasicRdbExpQueryLeaf leaf,
                               boolean add)
            throws MedorException
Shortcut to the getField(String, PType, JormExtent, BasicRdbExpQueryLeaf, boolean) method.

The field type is calculated looking for the field in the JORM meta information.

Throws:
MedorException - if the field is not found in the JORM meta information or if an error occurs during the real getField call.


getField

public QueryTreeField getField(Field old,
                               BasicRdbExpQueryLeaf leaf,
                               boolean add)
            throws MedorException
Is a shorcut to the getField(String, PType, JormExtent, BasicRdbExpQueryLeaf, boolean) method.

The fieldname, the type and the extent values are calculated from the old Field.

Parameters:
old - the old field

Throws:
MedorException - if an error occurs during the real getField call.


getMapping

public JormFlatten2Rdb.RdbJormExtentMapping getMapping(int i)
Retrieves the RdbJormExtentMapping at the position i the packet.

Parameters:
i - is position of the expected RdbJormExtentMapping

Returns:
a RdbJormExtentMapping (never null).


getMapping

public JormFlatten2Rdb.RdbJormExtentMapping getMapping(JormExtent je)
Retrieves the RdbJormExtentMapping at the position i the packet.

Parameters:
je - is the jorm extent which the mapping is expected

Returns:
a RdbJormExtentMapping (never null).


rewrite

public QueryTree rewrite(QueryTree qt,
                         QueryNode parent)
            throws MedorException
Specified by:
rewrite in interface RewriteRule


updateFieldOfExpression

public Expression updateFieldOfExpression(Expression e,
                                          BasicRdbExpQueryLeaf leaf,
                                          boolean add)
            throws MedorException,
                   ExpressionException
Replaces the uses of the old fields of extents by fields of a leaf. The PNameField uses are replaced by the corresponding equality between fields of the name(single or composite).

Parameters:
e - the expression to update
leaf - is the field containing the new field.
add - indicates whether the Field should be added (it is projected) or not (it is only in the Filter).

Returns:
the updated expression (Never null).

Throws:
MedorException - if it is not possible to fetch a new field in the leaf or if the PName equality are malformed