Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Starting to parse the WHERE expressions.

Author Dave Jarvis <email>
Date 2015-03-15 18:54:25 GMT-0700
Commit 38434d8a7a3cfc82cddda116ac3b0086d080ab2e
Parent 96be566
source/java/com/whitemagicsoftware/rxm/QueryBuilder.java
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 ) );
}
}
source/java/com/whitemagicsoftware/rxm/tree/xml/JoinClauseList.java
* <p>
* Stores a list of Payload instances. This is instantiated by the parser
- * to create a transformation list capable of generating a SQL/XML FROM
- * clause. The superclass dynamically determines the set of wrapper classes
- * by virtue of being in the same package as this class.
+ * to create a transformation list capable of generating SQL/XML JOIN
+ * clauses. The payload dynamically determines the set of wrapper classes
+ * using the package for name of class.
* </p>
* <p>
source/java/com/whitemagicsoftware/rxm/tree/xml/SelectClauseTree.java
* Stores a tree of Payload instances. This is instantiated by
* the parser to create a transformation tree capable of generating a
- * SQL/XML SELECT clause. The superclass dynamically determines the set of
- * wrapper classes by virtue of being in the same package as this class.
+ * SQL/XML SELECT clause. See the Payload class for details on how
+ * the implicit factory is used to create the correct transformer class.
*/
public class SelectClauseTree<T extends Payload> extends TransformationTree<T> {
Delta 61 lines added, 8 lines removed, 53-line increase