Package org.teiid.query.sql.lang

Examples of org.teiid.query.sql.lang.JoinPredicate


  }

    public void testJoinPredicate5() {
        ArrayList<Criteria> crits = new ArrayList<Criteria>();
        crits.add(new NotCriteria(new CompareCriteria(new ElementSymbol("m.g2.e1"), CompareCriteria.EQ, new ElementSymbol("m.g3.e1")))); //$NON-NLS-1$ //$NON-NLS-2$
        JoinPredicate jp = new JoinPredicate(
            new UnaryFromClause(new GroupSymbol("m.g2")), //$NON-NLS-1$
            new UnaryFromClause(new GroupSymbol("m.g3")), //$NON-NLS-1$
            JoinType.JOIN_INNER,
            crits );
                       
View Full Code Here


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

    GroupSymbol g1 = new GroupSymbol("m.g1"); //$NON-NLS-1$
    GroupSymbol g2 = new GroupSymbol("m.g2"); //$NON-NLS-1$
    FromClause lc = new UnaryFromClause(g1);
    FromClause rc = new UnaryFromClause(g2);

    Expression le = new ElementSymbol("m.g1." + joinOnElement); //$NON-NLS-1$
    Expression re = new ElementSymbol("m.g2." + joinOnElement); //$NON-NLS-1$
    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;       
  }   
View Full Code Here

   *                         side criteria of the right hand expression of AND
   *                         criteria of the ON expression of the join 
   * @return a join predicate object
   */
  public static JoinPredicate example(JoinType joinType, String joinOnElement, String andJoinOnElement) {
    JoinPredicate jp = example(joinType, joinOnElement);
    List<Criteria> joinCrits = jp.getJoinCriteria();
    List<Object> newJoinCrits = new ArrayList<Object>(1);

    Expression le = new ElementSymbol("m.g1." + andJoinOnElement); //$NON-NLS-1$
    Expression re = new ElementSymbol("m.g2." + andJoinOnElement); //$NON-NLS-1$
    Criteria c1 = new CompareCriteria(le, CompareCriteria.EQ, re);
   
    Iterator<Criteria> ci = joinCrits.iterator();

    if (!ci.hasNext()) {
      newJoinCrits.add(c1);
    }
   
    while (ci.hasNext()) {
      Criteria crit = ci.next();
      if ( ci.hasNext() ) newJoinCrits.add(crit);
      else {
        Criteria compundCrit = new CompoundCriteria(CompoundCriteria.AND, crit, c1);
        newJoinCrits.add(compundCrit);
      }
    }

    jp.setJoinCriteria(newJoinCrits);
   
    return jp;
  }   
View Full Code Here

   * <p>
   * For example:
   * ... m.g1 LEFT OUTER JOIN m.g2 ON m.g1.e1 = m.g2.e1
   */
  public void testEquals1() {   
    JoinPredicate jp1 = example(JoinType.JOIN_LEFT_OUTER, "e1"); //$NON-NLS-1$
    JoinPredicate jp2 = example(JoinType.JOIN_LEFT_OUTER, "e1"); //$NON-NLS-1$
    assertTrue("Equivalent join predicate don't compare as equal: " + jp1 + ", " + jp2, jp1.equals(jp2)); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here

   * <p>
   * For example:
   * ... m.g1 LEFT OUTER JOIN m.g2 ON ((m.g1.e1 = m.g2.e1) AND (m.g1.e2 = m.g2.e2))
   */
  public void testEquals2() {   
    JoinPredicate jp1 = example(JoinType.JOIN_LEFT_OUTER, "e1", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
        JoinPredicate jp2 = example(JoinType.JOIN_LEFT_OUTER, "e1", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue("Equivalent join predicate don't compare as equal: " + jp1 + ", " + jp2, jp1.equals(jp2)); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here

   * For example:
   * ... m.g1 LEFT OUTER JOIN m.g2 ON ((m.g1.e1 = m.g2.e1) AND (m.g1.e2 = m.g2.e2))
   * ... m.g1 RIGHT OUTER JOIN m.g2 ON ((m.g1.e1 = m.g2.e1) AND (m.g1.e2 = m.g2.e2))
   */
  public void testEquals3() {   
    JoinPredicate jp1 = example(JoinType.JOIN_LEFT_OUTER, "e1", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
        JoinPredicate jp2 = example(JoinType.JOIN_RIGHT_OUTER, "e1", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue("Different join predicate compare as equal: " + jp1 + ", " + jp2, !jp1.equals(jp2)); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here

   * For example:
   * ... m.g1 INNER JOIN m.g2 ON m.g1.e1 = m.g2.e1
   * ... m.g1 INNER JOIN m.g2 ON m.g1.e2 = m.g2.e2
   */
  public void testEquals4() {   
    JoinPredicate jp1 = example(JoinType.JOIN_INNER, "e1"); //$NON-NLS-1$
        JoinPredicate jp2 = example(JoinType.JOIN_INNER, "e2"); //$NON-NLS-1$
    assertTrue("Different join predicate compare as equal: " + jp1 + ", " + jp2, !jp1.equals(jp2)); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here

   * For example:
   * ... m.g1 CROSS JOIN m.g2 ON ((m.g1.e1 = m.g2.e1) AND (m.g1.e2 = m.g2.e2))
   * ... m.g1 CROSS JOIN m.g2 ON ((m.g1.e2 = m.g2.e2) AND (m.g1.e2 = m.g2.e2))
   */
  public void testEquals5() {   
    JoinPredicate jp1 = example(JoinType.JOIN_CROSS, "e1", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
        JoinPredicate jp2 = example(JoinType.JOIN_CROSS, "e2", "e2"); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue("Different join predicate compare as equal: " + jp1 + ", " + jp2, !jp1.equals(jp2)); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here

   * <p>
   * For example:
   * ... m.g1 FULL OUTER JOIN m.g2 ON m.g1.e1 = m.g2.e1
   */
  public void testSelfEquivalence(){
    JoinPredicate jp1 = example(JoinType.JOIN_FULL_OUTER, "e1"); //$NON-NLS-1$
    int equals = 0;
    UnitTestUtil.helpTestEquivalence(equals, jp1, jp1);
  }
View Full Code Here

   * For example:
   * ... m.g1 FULL OUTER JOIN m.g2 ON m.g1.e1 = m.g2.e1
   * ... m.g1 FULL OUTER JOIN m.g2 ON m.g1.e1 = m.g2.e1
   */
  public void testEquivalence(){
    JoinPredicate jp1 = example(JoinType.JOIN_FULL_OUTER, "e1"); //$NON-NLS-1$
    JoinPredicate jp2 = example(JoinType.JOIN_FULL_OUTER, "e1"); //$NON-NLS-1$
    int equals = 0;
    UnitTestUtil.helpTestEquivalence(equals, jp1, jp2);
  }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.JoinPredicate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.