Dave Jarvis' Repositories

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

Pushed up common methods into superclass.

AuthorDave Jarvis <email>
Date2015-03-12 23:05:03 GMT-0700
Commitcc3c77089b5d51b01e263f8900fd544e8a183668
Parent5a50cd0
source/grammar/Query.g
/* Map lines affect the tree depth differently.
*/
-map : tableMap | columnMap | attributeMap | innerMap | outerMap;
+map : tableMap | columnMap | attributeMap | innerMap | outerMap ;
tableMap : table T_MAP path ;
columnMap : column T_MAP path ;
TAttr. Attribute ::= "@" Identifier ;
TParam. Parameter ::= "$" Identifier ;
-
-WCompEq. ComparatorOperatorEquality ::= "=" ;
-WCompNeq. ComparatorOperatorEquality ::= "<>" ;
-
-WCompLt. ComparatorOperator ::= "<" ;
-WCompGt. ComparatorOperator ::= ">" ;
-WCompLte. ComparatorOperator ::= "<=" ;
-WCompGte. ComparatorOperator ::= ">=" ;
-
-WAnd. LogicalOp ::= "&&" ;
-WOr. LogicalOp ::= "||" ;
-
-WEmpty. Where ::= Where ;
-WEq. Where ::= TableColumn ComparatorOperatorEquality AllValues ;
-WComp. Where ::= TableColumn ComparatorOperator Value ;
-WLogic. Where ::= Where LogicalOp Where ;
-WParen. Where ::= "(" Where ")" ;
VValue. AllValues ::= Value ;
source/java/com/whitemagicsoftware/rxm/tree/xml/AttributeMapContext.java
}
- private String getColumnName() {
- return column().getChild(1).getText();
- }
-
private String getAttributeName() {
return attribute().getChild(1).getText();
- }
-
- private String getTableName() {
- return table().getText();
}
/**
* Returns the attribute (node) name.
*/
private QueryParser.AttributeContext attribute() {
- return getContext().attribute();
- }
-
- /**
- * Returns the column name.
- */
- private QueryParser.ColumnContext column() {
- return getContext().column();
+ return getAttributeMapContext().attribute();
}
/**
* Returns the attribute map context that this class wraps.
*/
- private QueryParser.AttributeMapContext getContext() {
+ private QueryParser.AttributeMapContext getAttributeMapContext() {
return (QueryParser.AttributeMapContext)getParserRuleContext();
}
- /**
- * Returns the table instance for the table map context.
- */
- private QueryParser.TableContext table() {
- return getTableMapContext().table();
+ @Override
+ protected QueryParser.ColumnContext column() {
+ return getAttributeMapContext().column();
}
/**
- * Returns the nearest table context to this attribute.
+ * Formats the start of the XMLATTRIBUTES call.
+ *
+ * @param table The table name assigned to the attribute.
+ * @param column The column name assigned to the attribute.
+ * @param node The document node name assigned to the attribute.
+ *
+ * @return The text used for SQL/XML XMLATTRIBUTES calls.
*/
- private QueryParser.TableMapContext getTableMapContext() {
- return (QueryParser.TableMapContext)getTreePayload().getParserRuleContext();
+ private String firstAttribute( String table, String column, String node ) {
+ return "XMLATTRIBUTES( " + nextAttribute( table, column, node );
}
/**
- * Returns the tree instance associated with this attribute map.
+ * Formats the next attribute of the XMLATTRIBUTES call. This is only
+ * called when there are contiguous attributes listed in the <b>rxm</b>.
+ *
+ * @param table The table name assigned to the attribute.
+ * @param column The column name assigned to the attribute.
+ * @param node The document node name assigned to the attribute.
+ *
+ * @return The text used for SQL/XML XMLATTRIBUTES calls.
*/
- private Payload getTreePayload() {
- return getTree().getPayload();
+ private String nextAttribute( String table, String column, String node ) {
+ String result = "%s.%s%s";
+
+ // If the column name and attribute name are the same, then the
+ // "AS" clause is superfluous.
+ if( column.equals( node ) ) {
+ result = String.format( result, table, column, "" );
+ }
+ else {
+ node = String.format( " AS \"%s\"", node );
+ result = String.format( result, table, column, node );
+ }
+
+ return result;
}
}
source/java/com/whitemagicsoftware/rxm/tree/xml/PayloadParserRuleContext.java
/**
- * Formats the start of the XMLELEMENT call.
- *
- * @param name The name assigned to the element.
+ * Answers whether the current payload has an antecedent sibling.
*
- * @return The text used for SQL/XML XMLELEMENT calls.
+ * @return true This payload has a preceding sibling.
*/
- protected String startElement( String name ) {
- return String.format( "XMLELEMENT( NAME \"%s\"", name );
+ public boolean hasPrecedingPayload() {
+ return getTree().hasPrecedingPayload( getInitPayload() );
}
/**
- * Formats the start of the XMLATTRIBUTES call.
- *
- * @param table The table name assigned to the attribute.
- * @param column The column name assigned to the attribute.
- * @param node The document node name assigned to the attribute.
+ * Answers whether the current payload has an antecedent sibling.
*
- * @return The text used for SQL/XML XMLATTRIBUTES calls.
+ * @return true This payload has a following sibling.
*/
- protected String firstAttribute( String table, String column, String node ) {
- return "XMLATTRIBUTES( " + nextAttribute( table, column, node );
+ public boolean hasFollowingPayload() {
+ return getTree().hasFollowingPayload( getInitPayload() );
}
/**
- * Formats the next attribute of the XMLATTRIBUTES call. This is only
- * called when there are contiguous attributes listed in the <b>rxm</b>.
- *
- * @param table The table name assigned to the attribute.
- * @param column The column name assigned to the attribute.
- * @param node The document node name assigned to the attribute.
- *
- * @return The text used for SQL/XML XMLATTRIBUTES calls.
+ * Returns column name without the preceding period.
+ *
+ * @return The column name.
*/
- protected String nextAttribute( String table, String column, String node ) {
- String result = "%s.%s%s";
+ protected String getColumnName() {
+ return column().getChild(1).getText();
+ }
- // If the column name and attribute name are the same, then the
- // "AS" clause is superfluous.
- if( column.equals( node ) ) {
- result = String.format( result, table, column, "" );
- }
- else {
- node = String.format( " AS \"%s\"", node );
- result = String.format( result, table, column, node );
- }
+ /**
+ * Returns nearest, contextual table name.
+ *
+ * @return The table name that precedes the column name.
+ */
+ protected String getTableName() {
+ return table().getText();
+ }
- return result;
+ /**
+ * Returns the table instance for the table map context.
+ */
+ protected QueryParser.TableContext table() {
+ return getTableMapContext().table();
+ }
+
+ /**
+ * Implemented by subclasses to return the column context.
+ * An alternative is to revise the grammar to have a common
+ * BNF definition that defines both a table map and a column
+ * map.
+ *
+ * @return null by default.
+ */
+ protected QueryParser.ColumnContext column() {
+ return null;
+ }
+
+ /**
+ * Formats the start of the XMLELEMENT call.
+ *
+ * @param name The name assigned to the element.
+ *
+ * @return The text used for SQL/XML XMLELEMENT calls.
+ */
+ protected String startElement( String name ) {
+ return String.format( "XMLELEMENT( NAME \"%s\"", name );
}
protected ParserRuleContext getParserRuleContext() {
return getInitPayload().getParserRuleContext();
+ }
+
+ /**
+ * Returns the nearest table context to this parser rule context.
+ */
+ protected QueryParser.TableMapContext getTableMapContext() {
+ return (QueryParser.TableMapContext)getTreePayload().getParserRuleContext();
}
protected Tree<Payload> getTree() {
return getInitPayload().getTree();
+ }
+
+ /**
+ * Returns the tree instance associated with this attribute map.
+ */
+ protected Payload getTreePayload() {
+ return getTree().getPayload();
}
private Payload getInitPayload() {
return this.initPayload;
- }
-
- /**
- * Answers whether the current payload has an antecedent sibling.
- *
- * @return true This payload has a preceding sibling.
- */
- public boolean hasPrecedingPayload() {
- return getTree().hasPrecedingPayload( getInitPayload() );
- }
-
- /**
- * Answers whether the current payload has an antecedent sibling.
- *
- * @return true This payload has a following sibling.
- */
- public boolean hasFollowingPayload() {
- return getTree().hasFollowingPayload( getInitPayload() );
}
}
Delta101 lines added, 98 lines removed, 3-line increase