private Criteria getSimpliedCriteria(Criteria crit, Expression a, boolean outcome, boolean nullPossible) { if (nullPossible) { if (outcome) { if (processing) { return crit; } IsNullCriteria inc = new IsNullCriteria(a); inc.setNegated(true); return inc; } } else if (outcome) { return TRUE_CRITERIA; } return FALSE_CRITERIA; }
public static IsNullCriteria example(String element, boolean negated) { IsNullCriteria crit = new IsNullCriteria(); crit.setNegated(negated); crit.setExpression(new ElementSymbol(element)); return crit; }
/** * Comparees this criteria to another object for equality * @param obj Other object * @return True if objects are equal */ public boolean equals(Object obj) { if(this == obj) { return true; } if(! (obj instanceof IsNullCriteria)) { return false; } IsNullCriteria other = (IsNullCriteria) obj; if (isNegated() ^ other.isNegated()) { return false; } return EquivalenceUtil.areEqual(getExpression(), other.getExpression()); }
/** * Deep copy of object * @return Deep copy of object */ public Object clone() { Expression copy = null; if(getExpression() != null) { copy = (Expression) getExpression().clone(); } IsNullCriteria criteriaCopy = new IsNullCriteria(copy); criteriaCopy.setNegated(isNegated()); return criteriaCopy; }
/** * @see org.teiid.query.sql.LanguageVisitor#visit(IsNullCriteria) */ public void visit(IsNullCriteria obj) { obj.setExpression( replaceExpression(obj.getExpression()) ); }
@Test public void testIsNullCriteria3() { IsNullCriteria inc = new IsNullCriteria(); helpTest(inc, "<undefined> IS NULL"); //$NON-NLS-1$ }
@Test public void testIsNullCriteria2() { IsNullCriteria inc = new IsNullCriteria(); inc.setExpression(new ElementSymbol("m.g.e1")); //$NON-NLS-1$ helpTest(inc, "m.g.e1 IS NULL"); //$NON-NLS-1$ }
/** * Get hash code. WARNING: The hash code is based on data in the criteria. * If data values are changed, the hash code will change - don't hash this * object and change values. * @return Hash code for object */ public int hashCode() { return (getExpression() == null) ? 0 : getExpression().hashCode(); }
public void visit(IsNullCriteria obj) { // Check if compares are allowed if (willBecomeConstant(obj)) { return; } if(! this.caps.supportsCapability(Capability.CRITERIA_ISNULL)) { markInvalid(obj, "IsNull not supported by source"); //$NON-NLS-1$ return; } if (obj.isNegated() && !this.caps.supportsCapability(Capability.CRITERIA_NOT)) { markInvalid(obj, "Negation is not supported by source"); //$NON-NLS-1$ return; } }
@Test public void testOpen_Defect16059() throws Exception { Query query = (Query)TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5 AND ? IS NULL", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ IsNullCriteria nullCrit = (IsNullCriteria)((CompoundCriteria)query.getCriteria()).getCriteria(1); nullCrit.setExpression(new Constant(null)); helpTestOpen(query, "SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5", true); //$NON-NLS-1$ }
public void testCloneEquivalence(){ IsNullCriteria c1 = example("abc", false); //$NON-NLS-1$ IsNullCriteria c2 = (IsNullCriteria)c1.clone(); int equals = 0; UnitTestUtil.helpTestEquivalence(equals, c1, c2); }
public void testEquals1() { IsNullCriteria c1 = example("abc", true); //$NON-NLS-1$ IsNullCriteria c2 = example("abc", true); //$NON-NLS-1$ assertTrue("Equivalent is null criteria don't compare as equal: " + c1 + ", " + c2, c1.equals(c2)); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Deep copy of object * @return Deep copy of object */ public Object clone() { Expression copy = null; if(getExpression() != null) { copy = (Expression) getExpression().clone(); } IsNullCriteria criteriaCopy = new IsNullCriteria(copy); criteriaCopy.setNegated(isNegated()); return criteriaCopy; }
Criteria crit; if (compareString == null) { crit = new IsNullCriteria((Expression) exprs[0].clone()); } else { crit = new CompareCriteria((Expression) exprs[0].clone(), CompareCriteria.EQ, new Constant(compareString));
/** * @see org.teiid.query.sql.LanguageVisitor#visit(IsNullCriteria) */ public void visit(IsNullCriteria obj) { obj.setExpression( replaceExpression(obj.getExpression()) ); }
@Test public void testIsNullCriteria1() { IsNullCriteria inc = new IsNullCriteria(); inc.setExpression(new Constant("abc")); //$NON-NLS-1$ helpTest(inc, "'abc' IS NULL"); //$NON-NLS-1$ }
/** * Get hash code. WARNING: The hash code is based on data in the criteria. * If data values are changed, the hash code will change - don't hash this * object and change values. * @return Hash code for object */ public int hashCode() { return (getExpression() == null) ? 0 : getExpression().hashCode(); }
public void visit(IsNullCriteria obj) { // Check if compares are allowed if(! this.caps.supportsCapability(Capability.CRITERIA_ISNULL)) { if (willBecomeConstant(obj)) { return; } markInvalid(obj, "IsNull not supported by source"); //$NON-NLS-1$ return; } if (obj.isNegated() && !this.caps.supportsCapability(Capability.CRITERIA_NOT)) { if (willBecomeConstant(obj)) { return; } markInvalid(obj, "Negation is not supported by source"); //$NON-NLS-1$ return; } }
@Test public void testOpen_Defect16059_2() throws Exception { Query query = (Query)TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5 AND ? IS NOT NULL", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ IsNullCriteria nullCrit = (IsNullCriteria)((CompoundCriteria)query.getCriteria()).getCriteria(1); nullCrit.setExpression(new Constant(null)); helpTestOpen(query, null, false); }