| | |
| | /** |
| | - * 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() ); |
| | } |
| | } |