Dave Jarvis' Repositories

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

Join clauses are now properly mapped.

Author Dave Jarvis <email>
Date 2015-03-14 16:04:40 GMT-0700
Commit c54480410b0da30f27fe9179a655b8d467669978
Parent 1086c14
source/java/com/whitemagicsoftware/rxm/tree/xml/InnerMapContext.java
@Override
- protected QueryParser.TableColumnContext tableColumn() {
- return ((QueryParser.InnerMapContext)getParserRuleContext()).tableColumn(0);
+ protected QueryParser.TableColumnContext tableColumn( int i ) {
+ return ((QueryParser.InnerMapContext)getParserRuleContext()).tableColumn(i);
}
}
source/java/com/whitemagicsoftware/rxm/tree/xml/JoinClauseList.java
public String toString() {
StringBuilder sb = new StringBuilder( 2048 );
+ final String NL = getNewline();
+
+ // Separate the JOIN statements from each other.
+ String separateStart = beautify() ? NL + getIndent( getIndentBy() ) : " ";
+ String separateStop = beautify() ? NL : " ";
for( Tree<T> branch : getBranches() ) {
Payload payload = branch.getPayload();
// Payload must be able to find the appropriate subclass to instantiate
// based on its tree instance's package. See the getStart and getStop
// methods in the Payload class for details.
payload.setTree( (Tree<Payload>)this );
-
- sb.append( payload.getStart() );
-
- if( beautify() ) {
- sb.append( getNewline() );
- }
- sb.append( payload.getStop() );
+ sb.append( payload.getStart() ).append( separateStart );
+ sb.append( payload.getStop() ).append( separateStop );
}
source/java/com/whitemagicsoftware/rxm/tree/xml/JoinMapContext.java
@Override
public Token getStart() {
- return new Token( String.format( "%s JOIN %s ON",
+ return new Token( String.format( "%s JOIN %s %s ON",
getJoinType(),
+ getTableName(),
getTableName() )
);
}
/**
* Returns the ending text for an OUTER JOIN clause.
*/
@Override
public Token getStop() {
- String s;
-
- return new Token( "" );
+ return new Token(
+ String.format( "%s = %s",
+ tableColumn( 0 ).getText(),
+ tableColumn( 1 ).getText()
+ )
+ );
}
private String getTableName() {
return table().getText();
- }
-
- private String getColumnName() {
- return column().getText();
}
+ /**
+ * Returns the left-hand-side (LHS) table, used for <code>JOIN * ON</code>.
+ *
+ * @return The <code>*</code> value in the aforementioned JOIN.
+ */
protected QueryParser.TableContext table() {
- return tableColumn().table();
- }
-
- protected QueryParser.ColumnContext column() {
- return tableColumn().column();
+ return tableColumn( 0 ).table();
}
/**
- * Returns the left-hand-side table name, which is the implied JOIN
- * table.
+ * Returns the left-hand-side (LHS) or right-hand-side (RHS) table column
+ * context.
+ *
+ * @param i Pass 0 for the LHS, pass 1 for the RHS.
+ * @return The TableColumnContext for the given index.
*/
- protected abstract QueryParser.TableColumnContext tableColumn();
+ protected abstract QueryParser.TableColumnContext tableColumn( int i );
}
source/java/com/whitemagicsoftware/rxm/tree/xml/OuterMapContext.java
@Override
- protected QueryParser.TableColumnContext tableColumn() {
- return ((QueryParser.OuterMapContext)getParserRuleContext()).tableColumn(0);
+ protected QueryParser.TableColumnContext tableColumn( int i ) {
+ return ((QueryParser.OuterMapContext)getParserRuleContext()).tableColumn(i);
}
}
test/people.rxm
.*,
^,
-company.person_id -> person.id,
+company.id -> person.company_id,
company > company,
.id > @id,
Delta 32 lines added, 28 lines removed, 4-line increase