Dave Jarvis' Repositories

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

When column name matches the attribute name, only the column name is required.

AuthorDave Jarvis <email>
Date2015-03-09 23:44:44 GMT-0700
Commit68f92187431261f791892097a52984668931ab1f
Parent5d705fc
source/java/com/whitemagicsoftware/rxm/tree/xml/AttributeMapContext.java
@Override
public Token getStart() {
- return new Token( String.format( ",%s\"%s\"",
- startAttributes( getTableName() + getColumnName() ),
- getAttributeName() ) );
+ return new Token(
+ String.format( ",%s",
+ startAttributes(
+ getTableName(),
+ getColumnName(),
+ getAttributeName()
+ )
+ )
+ );
}
private String getColumnName() {
- return column().getText();
+ return column().getChild(1).getText();
}
private String getAttributeName() {
- return attribute().T_ID().getSymbol().getText();
+ return attribute().getChild(1).getText();
}
source/java/com/whitemagicsoftware/rxm/tree/xml/PayloadParserRuleContext.java
* Formats the start of the XMLATTRIBUTES call.
*
- * @param name The name assigned to the attribute.
+ * @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.
*/
- protected String startAttributes( String name ) {
- return String.format( "XMLATTRIBUTES( %s AS ", name );
+ protected String startAttributes( String table, String column, String node ) {
+ String result = "XMLATTRIBUTES( %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;
}
test/people.rxm
root > people,
person > person,
-.age > @age,
+.birthday > @born,
.first_name > first,
.last_name > name/last,
Delta29 lines added, 9 lines removed, 20-line increase