/** * Compare this SubQuery to another AbstractTable, ignoring alias. * * @param obj an AbstractTable to compare to * @return true if the object is of the same class, and with an equal query */ @Override public boolean equalsIgnoreAlias(AbstractTable obj) { if (obj instanceof SubQuery) { return query.equals(((SubQuery) obj).query); } return false; } }
/** * Compare this SubQuery to another AbstractTable, ignoring alias. * * @param obj an AbstractTable to compare to * @return true if the object is of the same class, and with an equal query */ @Override public boolean equalsIgnoreAlias(AbstractTable obj) { if (obj instanceof SubQuery) { return query.equals(((SubQuery) obj).query); } return false; } }
/** * Overrides Object.equals(). * * @param obj an Object to compare to * @return true if the object is equal */ @Override public boolean equals(Object obj) { if (obj instanceof PrecomputedTable) { PrecomputedTable objTable = (PrecomputedTable) obj; return q.equals(objTable.q) && name.equals(objTable.name); } return false; }
/** * Overrides Object.equals(). * * @param obj an Object to compare to * @return true if the object is of the same class, and with an equal query and alias */ @Override public boolean equals(Object obj) { if (obj instanceof SubQuery) { SubQuery objSubQuery = (SubQuery) obj; return query.equals(objSubQuery.query) && alias.equals(objSubQuery.alias); } return false; }
/** * Overrides Object.equals(). * * @param obj an Object to compare to * @return true if the object is of the same class, and with an equal query and alias */ @Override public boolean equals(Object obj) { if (obj instanceof SubQuery) { SubQuery objSubQuery = (SubQuery) obj; return query.equals(objSubQuery.query) && alias.equals(objSubQuery.alias); } return false; }
/** * Overrides Object.equals(). * * @param obj an Object to compare to * @return true if the object is equal */ @Override public boolean equals(Object obj) { if (obj instanceof PrecomputedTable) { PrecomputedTable objTable = (PrecomputedTable) obj; return q.equals(objTable.q) && name.equals(objTable.name); } return false; }
/** * Compare this SubQueryConstraint with another AbstractConstraint, ignoring aliases in member * fields and tables. * * {@inheritDoc} */ @Override public int compare(AbstractConstraint obj, Map<AbstractTable, AbstractTable> tableMap, Map<AbstractTable, AbstractTable> reverseTableMap) { if (obj instanceof SubQueryConstraint) { SubQueryConstraint objC = (SubQueryConstraint) obj; return (left.valueEquals(objC.left, tableMap, reverseTableMap) && right.equals(objC.right) ? EQUAL : INDEPENDENT); // TODO: Implement this a bit better maybe? Two unequal queries may actually have the // same set of results. Also, a Query with less Constraints should result in a // SubQueryConstraint that is less restrictive. Complicated. } else if (obj instanceof NotConstraint) { NotConstraint objNC = (NotConstraint) obj; return alterComparisonNotObj(compare(objNC.con, tableMap, reverseTableMap)); } return INDEPENDENT; }
/** * Compare this SubQueryConstraint with another AbstractConstraint, ignoring aliases in member * fields and tables. * * {@inheritDoc} */ @Override public int compare(AbstractConstraint obj, Map<AbstractTable, AbstractTable> tableMap, Map<AbstractTable, AbstractTable> reverseTableMap) { if (obj instanceof SubQueryConstraint) { SubQueryConstraint objC = (SubQueryConstraint) obj; return (left.valueEquals(objC.left, tableMap, reverseTableMap) && right.equals(objC.right) ? EQUAL : INDEPENDENT); // TODO: Implement this a bit better maybe? Two unequal queries may actually have the // same set of results. Also, a Query with less Constraints should result in a // SubQueryConstraint that is less restrictive. Complicated. } else if (obj instanceof NotConstraint) { NotConstraint objNC = (NotConstraint) obj; return alterComparisonNotObj(compare(objNC.con, tableMap, reverseTableMap)); } return INDEPENDENT; }
public void testEquals() throws Exception { assertEquals(q1, q1); assertEquals(q1, q2); assertTrue("Expected q1 to not equal q3", !q1.equals(q3)); }
public void testTreeParserRulesForConstraint() throws Exception { // (aleft != aleft) becomes NOT (aleft = aright) Query lq1 = new Query("select t.a from t where t.a != t.b"); Query lq2 = new Query("select t.a from t where not t.a = t.b"); assertEquals(lq1, lq2); Query lq3 = new Query("select t.a from t where t.a = t.b"); assertTrue("Expected lq1 to not equal lq3", !lq1.equals(lq3)); // (bleft >= bright) becomes NOT (bleft < bright) lq1 = new Query("select t.a from t where t.a >= t.b"); lq2 = new Query("select t.a from t where not t.a < t.b"); assertEquals(lq1, lq2); // (cleft <= cright) becomes NOT (cright < cleft) lq1 = new Query("select t.a from t where t.a <= t.b"); lq2 = new Query("select t.a from t where not t.a > t.b"); assertEquals(lq1, lq2); // (dleft > dright) becomes (dright < dleft) lq1 = new Query("select t.a from t where t.a < t.b"); lq2 = new Query("select t.a from t where t.b > t.a"); assertEquals(lq1, lq2); }
public void testUnion() throws Exception { q1 = new Query("select table.field from table union select table2.field2 from table2"); q2 = new Query(); q3 = new Query(); Table t1 = new Table("table"); Table t2 = new Table("table2"); Field f1 = new Field("field", t1); Field f2 = new Field("field2", t2); q2.addSelect(new SelectValue(f1, null)); q2.addFrom(t1); q3.addSelect(new SelectValue(f2, null)); q3.addFrom(t2); q2.addToUnion(q3); Query q4 = new Query("select table2.field2 from table2 union select table.field from table"); Query q5 = new Query("select table.field from table union select table.field from table"); Query q6 = new Query("select table.field from table"); Query q7 = new Query("select table.field from table union select table.field from table union select table2.field2 from table2"); assertEquals(q2, q1); assertEquals(q2.hashCode(), q1.hashCode()); assertEquals("SELECT table.field FROM table UNION SELECT table2.field2 FROM table2", q1.getSQLString()); assertEquals(q1, q4); assertEquals(q1.hashCode(), q4.hashCode()); assertTrue("Expected q1 and q5 to be not equal.", !q1.equals(q5)); assertTrue("Expected q1.hashCode to not equal q5.hashCode.", q1.hashCode() != q5.hashCode()); assertTrue("Expected q1 and q6 to be not equal.", !q1.equals(q6)); assertTrue("Expected q1.hashCode to not equal q6.hashCode.", q1.hashCode() != q6.hashCode()); assertTrue("Expected q1 and q7 to be not equal.", !q1.equals(q7)); assertTrue("Expected q1.hashCode to not equal q7.hashCode.", q1.hashCode() != q7.hashCode()); }