in empire-db/src/main/java/org/apache/empire/db/DBCommand.java [1825:1895]
protected void addFrom(DBSQLBuilder sql)
{
int originalLength = sql.length();
sql.append("\r\nFROM ");
// Join
boolean sep = false;
// int whichParams = 0;
List<DBRowSet> tables = getRowSetList();
if (joins!=null && joins.size()>0)
{ // Join
List<DBRowSet> joinTables = new ArrayList<DBRowSet>();
for (int i=0; i<joins.size(); i++)
{ // append join
long context;
DBJoinExpr join = joins.get(i);
if (i<1)
{ // Add Join Tables
joinTables.add(join.getLeftTable());
joinTables.add(join.getRightTable());
// Remove from List
tables.remove(join.getLeftTable());
tables.remove(join.getRightTable());
// Context
context = CTX_NAME|CTX_VALUE;
// whichParams = 0;
}
else
{ // Extend the join
if (joinTables.contains(join.getRightTable()))
join.reverse();
// Add Right Table
joinTables.add(join.getRightTable());
tables .remove(join.getRightTable());
// Context
context = CTX_VALUE;
sql.append( "\t" );
// whichParams = 1;
}
// check
join.addSQL(sql, context);
// cmdParams.addJoin(sql, join, context, whichParams);
// add CRLF
if( i!=joins.size()-1 )
sql.append("\r\n");
}
sep = true;
}
for (int i=0; i<tables.size(); i++)
{
DBRowSet t = tables.get(i);
// check whether it's a parent table
if (this.parentTables!=null && this.parentTables.contains(t))
continue; // yes, ignore
// append
if (sep) sql.append(", ");
t.addSQL(sql, CTX_DEFAULT|CTX_ALIAS);
sep = true;
}
if (sep==false)
{ // add pseudo table or omitt from
String pseudoTable = getDatabase().getDbms().getSQLPhrase(DBSqlPhrase.SQL_PSEUDO_TABLE);
if (StringUtils.isNotEmpty(pseudoTable))
{ // add pseudo table
sql.append(pseudoTable);
}
else
{ // remove from
sql.reset(originalLength);
}
}
}