/** * Creates a constraint for a path to be not equal to a value. * * @param path the path to apply the constraint to * @param value the value to constrain to * @return a new PathConstraint object */ public static PathConstraintAttribute neq(String path, String value) { return new PathConstraintAttribute(path, ConstraintOp.NOT_EQUALS, value); }
query.addView("CEOTest.sal"); query.setDescription("CEOTest.name", "CEO name"); query.addConstraint(new PathConstraintAttribute("CEOTest.name", ConstraintOp.CONTAINS, "ploy")); query.addConstraint(new PathConstraintAttribute("CEOTest.company.name", ConstraintOp.CONTAINS, "pany")); query.addConstraint(new PathConstraintLookup( PathConstraintAttribute constraint1 = (PathConstraintAttribute) queryUpdated .getConstraintsForPath("CEO.name").get(0); assertEquals("ploy", constraint1.getValue()); assertEquals(ConstraintOp.CONTAINS, constraint1.getOp().CONTAINS); assertEquals(1, queryUpdated.getConstraintsForPath("CEO.company.name").size()); PathConstraintAttribute constraint2 = (PathConstraintAttribute) queryUpdated .getConstraintsForPath("CEO.company.name").get(0); assertEquals("pany", constraint2.getValue()); assertEquals(ConstraintOp.CONTAINS, constraint2.getOp().CONTAINS); PathConstraintLookup constraint3 = (PathConstraintLookup) queryUpdated .getConstraintsForPath("CEO.company.CEO.department.company.CEO").get(0);
Date dateValue = (Date) TypeUtil.stringToObject(Date.class, c.getValue()); QueryValue endOfDayQV = new QueryValue(endOfDay.getTime()); if (ConstraintOp.EXACT_MATCH.equals(c.getOp()) || ConstraintOp.EQUALS.equals(c.getOp())) { ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.LESS_THAN, endOfDayQV)); return cs; } else if (ConstraintOp.NOT_EQUALS.equals(c.getOp())) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.LESS_THAN, startOfDayQV)); endOfDayQV)); return cs; } else if (ConstraintOp.LESS_THAN_EQUALS.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.LESS_THAN, endOfDayQV); } else if (ConstraintOp.LESS_THAN.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.LESS_THAN, startOfDayQV); } else if (ConstraintOp.GREATER_THAN.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, endOfDayQV); } else if (ConstraintOp.GREATER_THAN_EQUALS.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, startOfDayQV); } else {
q.addViews("Employee.age"); assertEquals(Collections.EMPTY_MAP, q.getConstraints()); PathConstraintAttribute c = new PathConstraintAttribute("Employee.name", ConstraintOp.EQUALS, "Fred"); String code = q.addConstraint(c); assertEquals(Collections.singletonMap(c, code), q.getConstraints()); assertEquals("Employee.name", c.getPath()); assertEquals(ConstraintOp.EQUALS, c.getOp()); assertEquals("Fred", c.getValue()); try { new PathConstraintAttribute(null, ConstraintOp.EQUALS, "Fred"); fail("Expected NullPointerException"); } catch (NullPointerException e) { new PathConstraintAttribute("Employee.name", null, "Fred"); fail("Expected NullPointerException"); } catch (NullPointerException e) { new PathConstraintAttribute("Employee.name", ConstraintOp.EQUALS, null); fail("Expected NullPointerException"); } catch (NullPointerException e) { new PathConstraintAttribute("Employee.name", ConstraintOp.AND, "Fred"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { PathConstraintAttribute c2 = new PathConstraintAttribute("Employee.age", ConstraintOp.LESS_THAN, "50"); String code2 = q.addConstraint(c2); assertFalse("Codes are the same: " + code + " and " + code2 + ", constraints: " + q.getConstraints(), code.equals(code2));
if (constraint.getKey() instanceof PathConstraintAttribute) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); String outputValue = ((PathConstraintAttribute) constraint.getKey()).getValue(); writer.writeAttribute("value", "" + outputValue); } else if (constraint.getKey() instanceof PathConstraintNull) {
ConstraintOp op = pathConstraint.getOp(); if (pathConstraint instanceof PathConstraintAttribute) { newPathConstraint = new PathConstraintAttribute(newPath, op, ((PathConstraintAttribute) pathConstraint).getValue()); } else if (pathConstraint instanceof PathConstraintBag) { newPathConstraint = new PathConstraintBag(newPath, op,
Date dateValue = (Date) TypeUtil.stringToObject(Date.class, c.getValue()); QueryValue endOfDayQV = new QueryValue(endOfDay.getTime()); if (ConstraintOp.EXACT_MATCH.equals(c.getOp()) || ConstraintOp.EQUALS.equals(c.getOp())) { ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.LESS_THAN, endOfDayQV)); return cs; } else if (ConstraintOp.NOT_EQUALS.equals(c.getOp())) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); cs.addConstraint(new SimpleConstraint(qf, ConstraintOp.LESS_THAN, startOfDayQV)); endOfDayQV)); return cs; } else if (ConstraintOp.LESS_THAN_EQUALS.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.LESS_THAN, endOfDayQV); } else if (ConstraintOp.LESS_THAN.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.LESS_THAN, startOfDayQV); } else if (ConstraintOp.GREATER_THAN.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, endOfDayQV); } else if (ConstraintOp.GREATER_THAN_EQUALS.equals(c.getOp())) { return new SimpleConstraint(qf, ConstraintOp.GREATER_THAN_EQUALS, startOfDayQV); } else {
String value = ((PathConstraintAttribute) pc).getValue(); return start + "{\"op\": \"" + op + "\", \"value\": \"" + value + "\"}";
ConstraintOp op = pathConstraint.getOp(); if (pathConstraint instanceof PathConstraintAttribute) { newPathConstraint = new PathConstraintAttribute(newPath, op, ((PathConstraintAttribute) pathConstraint).getValue()); } else if (pathConstraint instanceof PathConstraintBag) { newPathConstraint = new PathConstraintBag(newPath, op,
/** * Creates a constraint for a path to be LIKE a value. * * @param path the path to apply the constraint to * @param value the value to constrain to * @return a new PathConstraint object */ public static PathConstraintAttribute like(String path, String value) { return new PathConstraintAttribute(path, ConstraintOp.MATCHES, value); }
if (constraint.getKey() instanceof PathConstraintAttribute) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); String outputValue = ((PathConstraintAttribute) constraint.getKey()).getValue(); writer.writeAttribute("value", "" + outputValue); } else if (constraint.getKey() instanceof PathConstraintNull) {
/** * Creates a constraint for a path to be NOT LIKE a value. * * @param path the path to apply the constraint to * @param value the value to constrain to * @return a new PathConstraint object */ public static PathConstraintAttribute notLike(String path, String value) { return new PathConstraintAttribute(path, ConstraintOp.DOES_NOT_MATCH, value); }
sb.append("\"" + op.toString() + "\""); } else if ("PathConstraintAttribute".equals(className)) { String value = ((PathConstraintAttribute) pc).getValue(); sb.append("\"" + op.toString() + "\""); sb.append(", \"" + value + "\"");
/** * Creates a constraint for a path to not contain a value. * * @param path the path that the constraint is attached to * @param contained the value this path's field should not contain. * @return a new PathConstraint object */ public static PathConstraintAttribute doesNotContain(String path, String contained) { return new PathConstraintAttribute(path, ConstraintOp.DOES_NOT_CONTAIN, contained); } }
} else { ConstraintOp simpleOp = ConstraintOp.EXACT_MATCH == pca.getOp() ? ConstraintOp.EQUALS : ConstraintOp.STRICT_NOT_EQUALS == pca.getOp() ? ConstraintOp.NOT_EQUALS : pca.getOp(); codeToConstraint.put(code, new SimpleConstraint((QueryField) field, simpleOp, new QueryValue(TypeUtil.stringToObject( fieldType, pca.getValue()))));
String value = ((PathConstraintAttribute) pc).getValue(); return start + "{\"op\": \"" + op + "\", \"value\": \"" + value + "\"}";
/** * Creates a constraint for a path to be greater than a value. * * @param path the path to apply the constraint to * @param value the value to constrain to * @return a new PathConstraint object */ public static PathConstraintAttribute greaterThan(String path, String value) { return new PathConstraintAttribute(path, ConstraintOp.GREATER_THAN, value); }
} else { ConstraintOp simpleOp = ConstraintOp.EXACT_MATCH == pca.getOp() ? ConstraintOp.EQUALS : ConstraintOp.STRICT_NOT_EQUALS == pca.getOp() ? ConstraintOp.NOT_EQUALS : pca.getOp(); codeToConstraint.put(code, new SimpleConstraint((QueryField) field, simpleOp, new QueryValue(TypeUtil.stringToObject( fieldType, pca.getValue()))));