Search in sources :

Example 1 with FromClause

use of org.teiid.query.sql.lang.FromClause in project teiid by teiid.

the class TestJoinPredicate method example.

// ################################## TEST HELPERS ################################
/**
 * Constructs an example <code>JoinPredicate</code> object that can be used
 * as join predicate in a query.
 *
 * @param joinType the type of join to be constructed
 * @param joinOnElement the element name to be used in the left and right
 * 						side criteria of the ON expression of the join
 * @return a join predicate object
 */
public static JoinPredicate example(JoinType joinType, String joinOnElement) {
    JoinPredicate jp = new JoinPredicate();
    // $NON-NLS-1$
    GroupSymbol g1 = new GroupSymbol("m.g1");
    // $NON-NLS-1$
    GroupSymbol g2 = new GroupSymbol("m.g2");
    FromClause lc = new UnaryFromClause(g1);
    FromClause rc = new UnaryFromClause(g2);
    // $NON-NLS-1$
    Expression le = new ElementSymbol("m.g1." + joinOnElement);
    // $NON-NLS-1$
    Expression re = new ElementSymbol("m.g2." + joinOnElement);
    Criteria c1 = new CompareCriteria(le, CompareCriteria.EQ, re);
    jp.setLeftClause(lc);
    jp.setRightClause(rc);
    jp.setJoinType(joinType != null ? joinType : JoinType.JOIN_LEFT_OUTER);
    jp.setJoinCriteria(Arrays.asList(new Object[] { c1 }));
    return jp;
}
Also used : FromClause(org.teiid.query.sql.lang.FromClause) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) JoinPredicate(org.teiid.query.sql.lang.JoinPredicate) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Aggregations

CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)1 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)1 Criteria (org.teiid.query.sql.lang.Criteria)1 FromClause (org.teiid.query.sql.lang.FromClause)1 JoinPredicate (org.teiid.query.sql.lang.JoinPredicate)1 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)1