org.objectweb.medor.query.rdb.lib

Class BasicRdbExpQueryLeaf

Implemented Interfaces:
Cloneable, Cloneable, FilteredQueryTree, QueryLeaf, QueryTree, RdbExpQueryLeaf, RdbQueryLeaf, TupleStructure

public class BasicRdbExpQueryLeaf
extends BasicRdbQueryLeaf
implements RdbExpQueryLeaf

This class represents a QueryLeaf that maps onto a relational database store. It implements the case where the relational query is provided as a set of QualifiedTables and an Expression representing the filter.

Field Summary

Fields inherited from class org.objectweb.medor.query.rdb.lib.BasicRdbQueryLeaf

ds, isSubquery, query, sqlFilter

Fields inherited from class org.objectweb.medor.query.lib.BasicQueryTree

distinct, indexes, name, orderfields

Fields inherited from class org.objectweb.medor.lib.BasicTupleStructure

fields, logger, name2field

Constructor Summary

BasicRdbExpQueryLeaf()
BasicRdbExpQueryLeaf(DataStore ds, String nodeName)
BasicRdbExpQueryLeaf(DataStore ds, QualifiedTable[] from, String nodeName)
Constructs a BasicRdbExpQueryLeaf from an Expression and a set of QualifiedTables.

Method Summary

void
addQualifiedTable(QualifiedTable qt)
RdbExpField
addRdbField(String name, PType type, String colName, QualifiedTable table)
Adds a Field to the RdbExpQueryLeaf
RdbExpField
addRdbField(RdbExpField rdbField)
Adds an RdbExpField to the RdbExpQueryLeaf
Object
clone(Object clone, Map obj2clone)
boolean
containsQualifiedTable(QualifiedTable qt)
protected String
getFromList()
Builds the FROM clause of the query (without "FROM").
RdbExpField
getGroupByField()
protected static String
getQualifiedFieldName(RdbExpField field)
Builds the qualified name of a RdbExpField.
QualifiedTable[]
getQualifiedTables()
Returns the associated QualifiedTables.
Expression
getQueryFilter()
Retrieves the filter associated to the RbdQueryLeaf.
RdbAdapter
getRdbAdapter()
String
getRdbAdapterName()
String
getSelectList(String selectList, ArrayList selectFields, boolean qualified)
Builds the SELECT clause of the query (without "SELECT ").
String
getSqlRequest(ParameterOperand[] pos, ArrayList selectFields, int rangeStartAt, int rangeSize)
Returns the associated SQL queryn giving the list of SELECT fields as an input parameter.
String
getSqlRequest(ParameterOperand[] pos, int rangeStartAt, int rangeSize)
Returns the associated SQL query.
void
removeQualifiedTable(QualifiedTable qt)
void
removeRdbField(RdbExpField rdbField)
void
resetSqlRequest()
void
setGroupBy(RdbExpField groupBy)
void
setQueryFilter(Expression exp)
Sets the filter associated to the RbdQueryLeaf.
void
setRdbAdapter(RdbAdapter adapter)
void
setRdbAdapterName(String an)
void
setRootJoinedTables(List rootjts)

Methods inherited from class org.objectweb.medor.query.rdb.lib.BasicRdbQueryLeaf

clone, getDataStore, isSubquery, setDataStore, setIsSubquery

Methods inherited from class org.objectweb.medor.query.lib.BasicQueryTree

clone, getDistinct, getName, getOrderBy, getTupleStructure, setDistinct, setOrderBy

Methods inherited from class org.objectweb.medor.lib.BasicTupleStructure

clone, contains, contains, getField, getField, getFieldRank, getFields, getSize

Constructor Details

BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf()


BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf(DataStore ds,
                            String nodeName)


BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf(DataStore ds,
                            QualifiedTable[] from,
                            String nodeName)
            throws QueryLeafException
Constructs a BasicRdbExpQueryLeaf from an Expression and a set of QualifiedTables.

The SQL request (string) will be calculated.

Parameters:
ds - is the DataStore associated to the QueryLeaf to be created
from - is the array of QualifiedTables associated to the QueryLeaf to be created

Throws:
QueryLeafException - if the QualifiedTables have all the same names, and in this case also the same aliases.

Method Details

addQualifiedTable

public void addQualifiedTable(QualifiedTable qt)
Specified by:
addQualifiedTable in interface RdbExpQueryLeaf


addRdbField

public RdbExpField addRdbField(String name,
                               PType type,
                               String colName,
                               QualifiedTable table)
            throws QueryLeafException
Adds a Field to the RdbExpQueryLeaf
Specified by:
addRdbField in interface RdbExpQueryLeaf

Parameters:
name - is the name of the Field to be added.
type - is the PTyme of the Field to be added.
colName - is the name of the column in the associated QualifiedTable.
table - is the QualifiedTable from which the Field is to be created.

Returns:
the created RdbExpField.


addRdbField

public RdbExpField addRdbField(RdbExpField rdbField)
            throws QueryLeafException
Adds an RdbExpField to the RdbExpQueryLeaf
Specified by:
addRdbField in interface RdbExpQueryLeaf

Parameters:
rdbField - is the RdbField to be added.


clone

public Object clone(Object clone,
                    Map obj2clone)
            throws CloneNotSupportedException
Overrides:
clone in interface BasicRdbQueryLeaf


containsQualifiedTable

public boolean containsQualifiedTable(QualifiedTable qt)
Specified by:
containsQualifiedTable in interface RdbExpQueryLeaf


getFromList

protected String getFromList()
Builds the FROM clause of the query (without "FROM").

Returns:
the list of qualified table names for the FROM clause tables is appended.


getGroupByField

public RdbExpField getGroupByField()
Specified by:
getGroupByField in interface RdbExpQueryLeaf


getQualifiedFieldName

protected static String getQualifiedFieldName(RdbExpField field)
Builds the qualified name of a RdbExpField.

Parameters:
field - is the RdbExpField for which the qualified name is built.

Returns:
the qualified name of an RdbExpField.


getQualifiedTables

public QualifiedTable[] getQualifiedTables()
Returns the associated QualifiedTables.
Specified by:
getQualifiedTables in interface RdbExpQueryLeaf

Returns:
the array of associated QualifiedTables.


getQueryFilter

public Expression getQueryFilter()
Retrieves the filter associated to the RbdQueryLeaf.
Specified by:
getQueryFilter in interface FilteredQueryTree

Returns:
the Medor Expression representing the filter to be applied to the relational source tables.


getRdbAdapter

public RdbAdapter getRdbAdapter()
Specified by:
getRdbAdapter in interface RdbExpQueryLeaf


getRdbAdapterName

public String getRdbAdapterName()
Specified by:
getRdbAdapterName in interface RdbExpQueryLeaf


getSelectList

public String getSelectList(String selectList,
                            ArrayList selectFields,
                            boolean qualified)
Builds the SELECT clause of the query (without "SELECT ").
Specified by:
getSelectList in interface RdbQueryLeaf

Parameters:
selectList - is the start of the SELECT clause to which the list of qualified columns is appended.
selectFields - is the fields for the SELECT clause. Such fields can either be plain fields, or can be aggregate fields
qualified - indicates whether the field names should be qualified with the table name or not.

Returns:
the list of qualified columns for the SELECT clause


getSqlRequest

public String getSqlRequest(ParameterOperand[] pos,
                            ArrayList selectFields,
                            int rangeStartAt,
                            int rangeSize)
            throws MedorException,
                   ExpressionException
Returns the associated SQL queryn giving the list of SELECT fields as an input parameter.

In the case of an RdbExpQueryLeaf, the query is computed.

Specified by:
getSqlRequest in interface RdbQueryLeaf

Parameters:
pos - is an array of ParameterOperand
selectFields - is the input Array of fields for constructing the SELECT clause.
rangeStartAt - is the offset of the first row to be returned in the case of a range query, starting at 0.
rangeSize - is the number of rows to be returned in the case of a range query.

Returns:
the SQL query associated to the RdbQueryLeaf, as a String.

Throws:
MedorException - in the case of RdbExpQueryLeaves if the SQL request cannot be computed from the associated Expression


getSqlRequest

public String getSqlRequest(ParameterOperand[] pos,
                            int rangeStartAt,
                            int rangeSize)
            throws MedorException,
                   ExpressionException
Returns the associated SQL query.

In the case of an RdbExpQueryLeaf, the query is computed.

Specified by:
getSqlRequest in interface RdbQueryLeaf

Parameters:
pos - is an array of ParameterOperand
rangeStartAt - is the offset of the first row to be returned in the case of a range query, starting at 0.
rangeSize - is the number of rows to be returned in the case of a range query.

Returns:
the SQL query associated to the RdbQueryLeaf, as a String.

Throws:
MedorException - in the case of RdbExpQueryLeaves if the SQL request cannot be computed from the associated Expression


removeQualifiedTable

public void removeQualifiedTable(QualifiedTable qt)
            throws MedorException
Specified by:
removeQualifiedTable in interface RdbExpQueryLeaf


removeRdbField

public void removeRdbField(RdbExpField rdbField)
            throws QueryLeafException
Specified by:
removeRdbField in interface RdbExpQueryLeaf


resetSqlRequest

public void resetSqlRequest()
Specified by:
resetSqlRequest in interface RdbExpQueryLeaf


setGroupBy

public void setGroupBy(RdbExpField groupBy)
            throws QueryLeafException
Specified by:
setGroupBy in interface RdbExpQueryLeaf


setQueryFilter

public void setQueryFilter(Expression exp)
Sets the filter associated to the RbdQueryLeaf.

This filter is represented by an Expression. Unlike the filter of a QueryNode, is applies to its own Fields, instead of the Fields of its children.

Specified by:
setQueryFilter in interface FilteredQueryTree

Parameters:
exp - is the Medor Expression representing the filter to be applied to the relational source tables.


setRdbAdapter

public void setRdbAdapter(RdbAdapter adapter)
Specified by:
setRdbAdapter in interface RdbExpQueryLeaf


setRdbAdapterName

public void setRdbAdapterName(String an)
Specified by:
setRdbAdapterName in interface RdbExpQueryLeaf


setRootJoinedTables

public void setRootJoinedTables(List rootjts)
Specified by:
setRootJoinedTables in interface RdbExpQueryLeaf