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

java.lang.Object
  extended byorg.objectweb.medor.lib.BasicTupleStructure
      extended byorg.objectweb.medor.query.lib.BasicQueryTree
          extended byorg.objectweb.medor.query.rdb.lib.BasicRdbExpQueryLeaf
All Implemented Interfaces:
Cloneable, java.lang.Cloneable, FilteredQueryTree, QueryLeaf, QueryTree, RdbExpQueryLeaf, RdbQueryLeaf, TupleStructure

public class BasicRdbExpQueryLeaf
extends BasicQueryTree
implements RdbExpQueryLeaf, TupleStructure

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
protected  boolean debug
           
protected  Logger log
           
 
Fields inherited from class org.objectweb.medor.query.lib.BasicQueryTree
indexes, name, orderfields
 
Fields inherited from class org.objectweb.medor.lib.BasicTupleStructure
fields, name2field
 
Constructor Summary
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 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
 boolean containsQualifiedTable(QualifiedTable qt)
          Checks if a QualifiedTable is in the list of QualifiedTables of this QueryLeaf
 DataStore getDataStore()
           
 boolean getDistinct()
          Tests whether the results should be distinct or not.
protected  java.lang.String getFromList()
          Builds the FROM clause of the query (without "FROM").
 RdbExpField getGroupByField()
          Gets the RdbExpField of the GroupBy Clause.
 java.lang.String getName()
          It returns the name of the query tree.
protected  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)
          Returns the associated SQL query.
 java.lang.String getSqlRequest(ParameterOperand[] pos, java.util.ArrayList selectFields)
          Builds and returns the SQL query as a String corresponding to the current RdbExpQueryLeaf.
 TupleStructure getTupleStructure()
          Returns the TupleStructure associated to the QueryTree.
 boolean isSubquery()
          Is the current query leaf a subquery (in particular for the case of aggregates).
 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 setDistinct(boolean d)
          Indicates whether evaluating the QueryTree should return unique results (duplicate elimination) or not.
 void setGroupBy(RdbExpField groupBy)
          Sets the groupBy Field.
 void setIsSubquery(boolean subquery)
          Indicates whether the current RdbExpQueryLeaf is a subquery of another Rdb query leaf (in particular in the case of subqueries).
 void setQueryFilter(Expression exp)
          Sets the filter associated to the RbdQueryLeaf.
 void setRdbAdapter(RdbAdapter 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.lib.BasicQueryTree
clone, getOrderBy, setOrderBy
 
Methods inherited from class org.objectweb.medor.lib.BasicTupleStructure
contains, contains, getField, getField, getFieldRank, getFields, getSize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.medor.query.rdb.api.RdbExpQueryLeaf
setRdbAdapter
 
Methods inherited from interface org.objectweb.medor.query.api.QueryTree
getOrderBy, setOrderBy
 
Methods inherited from interface org.objectweb.medor.api.TupleStructure
contains, contains, getField, getField, getFieldRank, getFields, getSize
 
Methods inherited from interface org.objectweb.medor.api.Cloneable
clone
 

Field Detail

log

protected Logger log

debug

protected boolean debug
Constructor Detail

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.

BasicRdbExpQueryLeaf

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

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)

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

getName

public java.lang.String getName()
Description copied from interface: QueryTree
It returns the name of the query tree.

Specified by:
getName in interface QueryTree
Overrides:
getName in class BasicQueryTree

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

getSqlRequest

public java.lang.String getSqlRequest(ParameterOperand[] pos)
                               throws MedorException
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
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

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,
                                      java.util.ArrayList selectFields)
                               throws MedorException
Builds and returns the SQL query as a String corresponding to the current RdbExpQueryLeaf.

The SQL query is computed from the provided RdbExpFields (SELECT clause), QualifiedTables (FROM clause) and Expression (WHERE clause).

Specified by:
getSqlRequest in interface RdbQueryLeaf
Returns:
the SQL query as a String.
Throws:
MedorException - in the case of RdbExpQueryLeaves if the SQL request cannot be computed from the associated Expression

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.

getDataStore

public DataStore getDataStore()
Specified by:
getDataStore in interface QueryLeaf

getTupleStructure

public TupleStructure getTupleStructure()
Description copied from interface: QueryTree
Returns the TupleStructure associated to the QueryTree. Note that the Fields cannot be added by manipulating the TupleStructure, but by using either constructors in the case of a QueryLeaf, or by using the addXXXFields methods in the case of QueryNodes.

Specified by:
getTupleStructure in interface QueryTree
Overrides:
getTupleStructure in class BasicQueryTree

getDistinct

public boolean getDistinct()
Description copied from interface: QueryTree
Tests whether the results should be distinct or not.

Specified by:
getDistinct in interface QueryTree
Overrides:
getDistinct in class BasicQueryTree

setDistinct

public void setDistinct(boolean d)
Description copied from interface: QueryTree
Indicates whether evaluating the QueryTree should return unique results (duplicate elimination) or not.

The default should be that duplicates are not eliminated (distinct is false).

Specified by:
setDistinct in interface QueryTree
Overrides:
setDistinct in class BasicQueryTree

setGroupBy

public void setGroupBy(RdbExpField groupBy)
                throws QueryLeafException
Description copied from interface: RdbExpQueryLeaf
Sets the groupBy Field. This RdbExpField must be in The TupleStructure of this QuaryLeaf Object.

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

getGroupByField

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

Specified by:
getGroupByField in interface RdbExpQueryLeaf
Returns:
an RdbExpField

setIsSubquery

public void setIsSubquery(boolean subquery)
Description copied from interface: RdbQueryLeaf
Indicates whether the current RdbExpQueryLeaf is a subquery of another Rdb query leaf (in particular in the case of subqueries).

The default value is false.

Specified by:
setIsSubquery in interface RdbQueryLeaf
Parameters:
subquery - is true when the current RdbExpQueryLeaf is a subquery of another Rdb query leaf/node, false otherwise.

isSubquery

public boolean isSubquery()
Description copied from interface: RdbQueryLeaf
Is the current query leaf a subquery (in particular for the case of aggregates).

Specified by:
isSubquery in interface RdbQueryLeaf
Returns:
true if the current RdbExpQueryLeaf is a subquery

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

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