org.objectweb.medor.query.rdb.lib
Class BasicRdbExpQueryLeaf

java.lang.Object
  extended byBasicCloneable
      extended byorg.objectweb.medor.lib.BasicTupleStructure
          extended byorg.objectweb.medor.query.lib.BasicQueryTree
              extended byorg.objectweb.medor.query.rdb.lib.BasicRdbQueryLeaf
                  extended byorg.objectweb.medor.query.rdb.lib.BasicRdbExpQueryLeaf
All Implemented Interfaces:
AnnotationsHolder, Cloneable, java.lang.Cloneable, FilteredQueryTree, QueryLeaf, QueryTree, RdbExpQueryLeaf, RdbQueryLeaf, java.io.Serializable, 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.

See Also:
Serialized Form

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
annotations, distinct, indexes, name, orderfields
 
Fields inherited from class org.objectweb.medor.lib.BasicTupleStructure
fields, logger, name2field
 
Constructor Summary
BasicRdbExpQueryLeaf()
           
BasicRdbExpQueryLeaf(DataStore ds, QualifiedTable[] from, java.lang.String nodeName)
          Constructs a BasicRdbExpQueryLeaf from an Expression and a set of QualifiedTables.
BasicRdbExpQueryLeaf(DataStore ds, java.lang.String nodeName)
           
 
Method Summary
 void addGroupBy(RdbExpField groupBy)
          Adds a groupBy Field.
 void addQualifiedTable(QualifiedTable qt)
          Adds a QualifiedTable to the QueryLeaf
 RdbExpField addRdbField(RdbExpField rdbField)
          Adds an RdbExpField to the RdbExpQueryLeaf
 RdbExpField addRdbField(java.lang.String name, PType type, java.lang.String colName, QualifiedTable table)
          Adds a Field to the RdbExpQueryLeaf
 java.lang.Object clone(java.lang.Object clone, java.util.Map obj2clone)
           
 boolean containsQualifiedTable(QualifiedTable qt)
          Checks if a QualifiedTable is in the list of QualifiedTables of this QueryLeaf
protected  java.lang.String getFromList()
          Builds the FROM clause of the query (without "FROM").
 java.lang.String getGroupBy()
          Returns the GROUP BY clause of the query leaf.
 RdbExpField[] getGroupByFields()
          Gets the RdbExpFields of the GroupBy Clause.
static java.lang.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()
          It retrieves the rdb adapter.
 java.lang.String getRdbAdapterName()
          It retrieves the rdb adapter name.
 java.lang.String getSelectList(java.lang.String selectList, java.util.ArrayList selectFields, boolean qualified)
          Builds the SELECT clause of the query (without "SELECT ").
 java.lang.String getSqlRequest(ParameterOperand[] pos, java.util.ArrayList selectFields, boolean rangeStart, boolean rangeSize)
          Returns the associated SQL queryn giving the list of SELECT fields as an input parameter.
 java.lang.String getSqlRequest(ParameterOperand[] pos, boolean rangeStartAt, boolean rangeSize)
          Returns the associated SQL query.
 void removeQualifiedTable(QualifiedTable qt)
          Adds a QualifiedTable to the QueryLeaf
 void removeRdbField(RdbExpField rdbField)
          Adds an RdbExpField to the RdbExpQueryLeaf.
 void resetSqlRequest()
          In case the SQL query was already computed, resets it to null.
 void setNoGroupBy(boolean noGB)
          Requires that the GROUP BY clause not be output by the getSqlRequest method.
 void setQueryFilter(Expression exp)
          Sets the filter associated to the RbdQueryLeaf.
 void setRdbAdapter(RdbAdapter adapter)
          It assigns the rdb adapter.
 void setRdbAdapterName(java.lang.String an)
          It assignes the rdb adapter name.
 void setRootJoinedTables(java.util.List rootjts)
           
 
Methods inherited from class org.objectweb.medor.query.rdb.lib.BasicRdbQueryLeaf
getDataStore, isSubquery, setDataStore, setIsSubquery
 
Methods inherited from class org.objectweb.medor.query.lib.BasicQueryTree
getAnnotations, getDistinct, getName, getOrderBy, getTupleStructure, setDistinct, setOrderBy
 
Methods inherited from class org.objectweb.medor.lib.BasicTupleStructure
contains, contains, getField, getField, getFieldRank, getFields, getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.medor.query.rdb.api.RdbQueryLeaf
isSubquery, setIsSubquery
 
Methods inherited from interface org.objectweb.medor.query.api.QueryLeaf
getDataStore
 
Methods inherited from interface org.objectweb.medor.query.api.QueryTree
getDistinct, getName, getOrderBy, getTupleStructure, setDistinct, setOrderBy
 
Methods inherited from interface org.objectweb.medor.query.api.AnnotationsHolder
getAnnotations
 
Methods inherited from interface org.objectweb.medor.api.Cloneable
clone
 

Constructor Detail

BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf()

BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf(DataStore ds,
                            java.lang.String nodeName)

BasicRdbExpQueryLeaf

public BasicRdbExpQueryLeaf(DataStore ds,
                            QualifiedTable[] from,
                            java.lang.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 Detail

clone

public java.lang.Object clone(java.lang.Object clone,
                              java.util.Map obj2clone)
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class BasicRdbQueryLeaf
Throws:
java.lang.CloneNotSupportedException

setRdbAdapterName

public void setRdbAdapterName(java.lang.String an)
Description copied from interface: RdbExpQueryLeaf
It assignes the rdb adapter name. The RdbAdapter is used to adapte the sql queries to a relational database

Specified by:
setRdbAdapterName in interface RdbExpQueryLeaf

getRdbAdapterName

public java.lang.String getRdbAdapterName()
Description copied from interface: RdbExpQueryLeaf
It retrieves the rdb adapter name. The RdbAdapter is used to adapte the sql queries to a relational database

Specified by:
getRdbAdapterName in interface RdbExpQueryLeaf

setRdbAdapter

public void setRdbAdapter(RdbAdapter adapter)
Description copied from interface: RdbExpQueryLeaf
It assigns the rdb adapter. The RdbAdapter is used to adapt sql queries to a relational database

Specified by:
setRdbAdapter in interface RdbExpQueryLeaf

getRdbAdapter

public RdbAdapter getRdbAdapter()
Description copied from interface: RdbExpQueryLeaf
It retrieves the rdb adapter. The RdbAdapter is used to adapt sql queries to a relational database

Specified by:
getRdbAdapter in interface RdbExpQueryLeaf

setRootJoinedTables

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

addRdbField

public RdbExpField addRdbField(java.lang.String name,
                               PType type,
                               java.lang.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.
Throws:
QueryLeafException - if the QualifiedTable is not in the set of QualifiedTables associatged with the current RdbExpQueryLeaf.

addQualifiedTable

public void addQualifiedTable(QualifiedTable qt)
Description copied from interface: RdbExpQueryLeaf
Adds a QualifiedTable to the QueryLeaf

Specified by:
addQualifiedTable in interface RdbExpQueryLeaf
Parameters:
qt - the QualifiedTable to be added

removeQualifiedTable

public void removeQualifiedTable(QualifiedTable qt)
                          throws MedorException
Description copied from interface: RdbExpQueryLeaf
Adds a QualifiedTable to the QueryLeaf

Specified by:
removeQualifiedTable in interface RdbExpQueryLeaf
Parameters:
qt - the QualifiedTable to be added
Throws:
MedorException - if the QualifiedTable in not in the current leaf.

containsQualifiedTable

public boolean containsQualifiedTable(QualifiedTable qt)
Description copied from interface: RdbExpQueryLeaf
Checks if a QualifiedTable is in the list of QualifiedTables of this QueryLeaf

Specified by:
containsQualifiedTable in interface RdbExpQueryLeaf
Parameters:
qt - the QualifiedTable to be tested
Returns:
true if qt is in the list of QualifiedTables for this QueryLeaf

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.
Throws:
QueryLeafException

removeRdbField

public void removeRdbField(RdbExpField rdbField)
                    throws QueryLeafException
Description copied from interface: RdbExpQueryLeaf
Adds an RdbExpField to the RdbExpQueryLeaf. The QueryLeaf associated to the RdbExpField becomes the current RdbExpQueryLeaf.

Specified by:
removeRdbField in interface RdbExpQueryLeaf
Parameters:
rdbField - is the RdbField to be added.
Throws:
QueryLeafException

resetSqlRequest

public void resetSqlRequest()
Description copied from interface: RdbExpQueryLeaf
In case the SQL query was already computed, resets it to null.

Specified by:
resetSqlRequest in interface RdbExpQueryLeaf

getSqlRequest

public java.lang.String getSqlRequest(ParameterOperand[] pos,
                                      boolean rangeStartAt,
                                      boolean rangeSize)
                               throws MedorException,
                                      ExpressionException
Description copied from interface: RdbQueryLeaf
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 true for range queries where the first row to be returned in the case of a range query is greater than 0.
rangeSize - is true for range queries where the number of rows to be returned in the case of a range query is less than Integer.MAXVALUE
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
ExpressionException

getSqlRequest

public java.lang.String getSqlRequest(ParameterOperand[] pos,
                                      java.util.ArrayList selectFields,
                                      boolean rangeStart,
                                      boolean rangeSize)
                               throws MedorException,
                                      ExpressionException
Description copied from interface: RdbQueryLeaf
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.
rangeStart - is true for range queries where the first row to be returned in the case of a range query is greater than 0.
rangeSize - is true for range queries where the number of rows to be returned in the case of a range query is less than Integer.MAXVALUE
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
ExpressionException

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.
See Also:
Expression

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.
See Also:
Expression

getQualifiedTables

public QualifiedTable[] getQualifiedTables()
Returns the associated QualifiedTables.

Specified by:
getQualifiedTables in interface RdbExpQueryLeaf
Returns:
the array of associated QualifiedTables.

addGroupBy

public void addGroupBy(RdbExpField groupBy)
                throws QueryLeafException
Description copied from interface: RdbExpQueryLeaf
Adds a groupBy Field. This RdbExpField must be in The TupleStructure of this QueryLeaf Object.

Specified by:
addGroupBy in interface RdbExpQueryLeaf
Parameters:
groupBy - : RdbExpField
Throws:
QueryLeafException - if this RdbExpField doesn't appears in the list of the fields which will be projected in Select clause

getGroupByFields

public RdbExpField[] getGroupByFields()
Description copied from interface: RdbExpQueryLeaf
Gets the RdbExpFields of the GroupBy Clause. It returns null if there is no Result Grouping

Specified by:
getGroupByFields in interface RdbExpQueryLeaf
Returns:
an array of RdbExpField

setNoGroupBy

public void setNoGroupBy(boolean noGB)
Description copied from interface: RdbExpQueryLeaf
Requires that the GROUP BY clause not be output by the getSqlRequest method.

Specified by:
setNoGroupBy in interface RdbExpQueryLeaf
Parameters:
noGB - is true if no GROUP BY clause should be output (false by default).

getGroupBy

public java.lang.String getGroupBy()
Description copied from interface: RdbExpQueryLeaf
Returns the GROUP BY clause of the query leaf.

Specified by:
getGroupBy in interface RdbExpQueryLeaf
Returns:
the GROUP BY clause of the query leaf.

getSelectList

public java.lang.String getSelectList(java.lang.String selectList,
                                      java.util.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

getQualifiedFieldName

public static java.lang.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.

getFromList

protected java.lang.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.