| | import com.whitemagicsoftware.rxm.tree.xml.SelectClauseTree; |
| | import com.whitemagicsoftware.rxm.tree.xml.JoinClauseList; |
| | +import com.whitemagicsoftware.rxm.tree.xml.WhereClauseList; |
| | |
| | import org.antlr.v4.runtime.ANTLRInputStream; |
 |
| | /** List of inner and outer joins (tree used as flat hierarchy). */ |
| | private Tree<Payload> joinClauseList; |
| | + |
| | + /** List of where clause expressions (tree used as flat hierarchy). */ |
| | + private Tree<Payload> whereClauseList; |
| | |
| | /** |
 |
| | public synchronized void enterOuterMap( QueryParser.OuterMapContext ctx ) { |
| | addJoinClause( ctx ); |
| | + } |
| | + |
| | + public synchronized void enterWhere( QueryParser.WhereContext ctx ) { |
| | + addWhereClause( ctx ); |
| | } |
| | |
 |
| | |
| | /** |
| | - * TODO: implement |
| | + * Returns the tables SQL WHERE clause expressions. |
| | + * |
| | + * @return The WHERE portion of a SQL statement. |
| | */ |
| | private String getWhereClause() { |
| | - return ""; |
| | + return getWhereClauseList().toString(); |
| | } |
| | - |
| | + |
| | + /** |
| | + * Adds a new leaf, representing a JOIN clause, to the from clause list. |
| | + * |
| | + * @param ctx The INNER/OUTER JOIN expression to add to the list. |
| | + */ |
| | + private void addWhereClause( ParserRuleContext ctx ) { |
| | + getWhereClauseList().addLeaf( createWhereClauseList( ctx ) ); |
| | + } |
| | + |
| | /** |
| | * Adds the given parser rule context to the current context tree. |
 |
| | private Tree<Payload> createJoinClauseList( ParserRuleContext ctx ) { |
| | return new JoinClauseList<Payload>( new Payload( ctx ) ); |
| | + } |
| | + |
| | + /** |
| | + * Changes where the next mapped items will be attached. |
| | + */ |
| | + private void setWhereClauseList( Tree<Payload> whereClauseList ) { |
| | + this.whereClauseList = whereClauseList; |
| | + } |
| | + |
| | + /** |
| | + * Lazily-initializes the from clause list. |
| | + * |
| | + * @return The list that will contain the query's FROM clause. |
| | + */ |
| | + private Tree<Payload> getWhereClauseList() { |
| | + Tree<Payload> list = this.whereClauseList; |
| | + |
| | + if( list == null ) { |
| | + setWhereClauseList( list = createWhereClauseList( null ) ); |
| | + } |
| | + |
| | + return list; |
| | + } |
| | + |
| | + /** |
| | + * Creates a new WhereClauseList instance containing the given parser |
| | + * rule context. The resulting tree should only have leaves added |
| | + * to the root, never branching beyond a flat hierarchy (one-level deep). |
| | + * |
| | + * @return A new WhereClauseList instance, never null, containing a payload |
| | + * with the parser rule context. |
| | + */ |
| | + private Tree<Payload> createWhereClauseList( ParserRuleContext ctx ) { |
| | + return new WhereClauseList<Payload>( new Payload( ctx ) ); |
| | } |
| | } |