private static void setConstraints(Queryable q, ConstraintSet andCs) { if (!andCs.getConstraints().isEmpty()) { Constraint c = andCs; while ((c instanceof ConstraintSet) && (((ConstraintSet) c).getConstraints().size() == 1)) { c = ((ConstraintSet) c).getConstraints().iterator().next(); } q.setConstraint(c); } }
private static void setConstraints(Queryable q, ConstraintSet andCs) { if (!andCs.getConstraints().isEmpty()) { Constraint c = andCs; while ((c instanceof ConstraintSet) && (((ConstraintSet) c).getConstraints().size() == 1)) { c = ((ConstraintSet) c).getConstraints().iterator().next(); } q.setConstraint(c); } }
/** * Adds all the constraints present in the argument into the given List. * * @param list a List of Constraints, to which to add more entries * @param constraint a Constraint to pick apart */ public static void addToList(List<Constraint> list, Constraint constraint) { if (constraint != null) { if (constraint instanceof ConstraintSet) { if (((ConstraintSet) constraint).getOp() == ConstraintOp.AND) { Set<Constraint> constraints = ((ConstraintSet) constraint).getConstraints(); for (Constraint con : constraints) { addToList(list, con); } } else { list.add(constraint); } } else { list.add(constraint); } } }
/** * Traverse the given Constraint tree (ie. recursively look for nested constraints if the * argument is a ConstraintSet) and call ConstraintTraverseAction for each Constraint. * @param c the Constraint to traverse - could be a ConstraintSet (possibly with nested * ConstraintSets) * @param ca ConstraintTraverseAction.apply() is called for each Constraint found */ public static void traverseConstraints(Constraint c, ConstraintTraverseAction ca) { ca.apply(c); if (c instanceof ConstraintSet) { for (Constraint childConstraint : ((ConstraintSet) c).getConstraints()) { traverseConstraints(childConstraint, ca); } } }
/** * Traverse the given Constraint tree (ie. recursively look for nested constraints if the * argument is a ConstraintSet) and call ConstraintTraverseAction for each Constraint. * @param c the Constraint to traverse - could be a ConstraintSet (possibly with nested * ConstraintSets) * @param ca ConstraintTraverseAction.apply() is called for each Constraint found */ public static void traverseConstraints(Constraint c, ConstraintTraverseAction ca) { ca.apply(c); if (c instanceof ConstraintSet) { for (Constraint childConstraint : ((ConstraintSet) c).getConstraints()) { traverseConstraints(childConstraint, ca); } } }
/** * Adds all the constraints present in the argument into the given List. * * @param list a List of Constraints, to which to add more entries * @param constraint a Constraint to pick apart */ public static void addToList(List<Constraint> list, Constraint constraint) { if (constraint != null) { if (constraint instanceof ConstraintSet) { if (((ConstraintSet) constraint).getOp() == ConstraintOp.AND) { Set<Constraint> constraints = ((ConstraintSet) constraint).getConstraints(); for (Constraint con : constraints) { addToList(list, con); } } else { list.add(constraint); } } else { list.add(constraint); } } }
/** * {@inheritDoc} */ public List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, Map<Object, Integer> sequence) throws ObjectStoreException { Constraint where = q.getConstraint(); // we know there will be no results if we ORing or NANDing over an empty constraint set if (where instanceof ConstraintSet) { ConstraintSet where2 = (ConstraintSet) where; if (where2.getConstraints().isEmpty() && (ConstraintOp.NAND.equals(where2.getOp()) || ConstraintOp.OR.equals(where2.getOp()))) { return Collections.emptyList(); } } Connection c = null; try { c = getConnection(); return executeWithConnection(c, q, start, limit, optimise, explain, sequence); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ public List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, Map<Object, Integer> sequence) throws ObjectStoreException { Constraint where = q.getConstraint(); // we know there will be no results if we ORing or NANDing over an empty constraint set if (where instanceof ConstraintSet) { ConstraintSet where2 = (ConstraintSet) where; if (where2.getConstraints().isEmpty() && (ConstraintOp.NAND.equals(where2.getOp()) || ConstraintOp.OR.equals(where2.getOp()))) { return Collections.emptyList(); } } Connection c = null; try { c = getConnection(); return executeWithConnection(c, q, start, limit, optimise, explain, sequence); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
if (con instanceof ConstraintSet) { ConstraintSet cs = (ConstraintSet) con; Set<Constraint> constraints = new HashSet<Constraint>(cs.getConstraints()); for (Constraint c : constraints) { if (c instanceof BagConstraint) {
if (con instanceof ConstraintSet) { ConstraintSet cs = (ConstraintSet) con; Set<Constraint> constraints = new HashSet<Constraint>(cs.getConstraints()); for (Constraint c : constraints) { if (c instanceof BagConstraint) {
public void testCreateListAnd() throws Exception { IqlQuery fq = new IqlQuery("select a from Company as a where a.vatNumber = 5 and a.name = 'hello'", "org.intermine.model.testmodel"); q = IqlQueryParser.parse(fq); List expected = new ArrayList(); Iterator conIter = ((ConstraintSet) q.getConstraint()).getConstraints().iterator(); while (conIter.hasNext()) { expected.add((Constraint) conIter.next()); } List got = ConstraintHelper.createList(q); assertEquals(expected, got); }
public void testAddConstrint() { ConstraintSet set = new ConstraintSet(ConstraintOp.AND); set.addConstraint(sc1); set.addConstraint(sc2); LinkedHashSet test = new LinkedHashSet(); test.add(sc1); test.add(sc2); assertEquals(test, set.getConstraints()); }
for (Constraint subC : ((ConstraintSet) constraint).getConstraints()) { ((ConstraintSet) queryConstraint).addConstraint(subC); if (constraint instanceof ConstraintSet && constraint.getOp().equals(ConstraintOp.AND)) { for (Constraint subC : ((ConstraintSet) constraint).getConstraints()) { constraints.addConstraint(subC);
for (Constraint subC : ((ConstraintSet) constraint).getConstraints()) { ((ConstraintSet) queryConstraint).addConstraint(subC); if (constraint instanceof ConstraintSet && constraint.getOp().equals(ConstraintOp.AND)) { for (Constraint subC : ((ConstraintSet) constraint).getConstraints()) { constraints.addConstraint(subC);
public void testRemoveConstrint() { ConstraintSet set = new ConstraintSet(ConstraintOp.AND); set.addConstraint(sc1); set.addConstraint(sc2); set.removeConstraint(sc1); LinkedHashSet test = new LinkedHashSet(); test.add(sc2); assertEquals(test, set.getConstraints()); }
DatabaseSchema schema, boolean individualOsbs) throws ObjectStoreException { if (c instanceof ConstraintSet) { for (Constraint subC : ((ConstraintSet) c).getConstraints()) { findTableNamesInConstraint(tablenames, subC, schema, individualOsbs);
int csSize = cs.getConstraints().size(); if (csSize == 1) { q.setConstraint(cs.getConstraints().iterator().next()); } else if (csSize > 1) { q.setConstraint(cs);
public void testAddReference() throws ClassNotFoundException { Query query = new Query(); ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); query.setConstraint(cs); QueryClass startQc = new QueryClass(Class.forName("org.intermine.model.testmodel.Employee")); query.addFrom(startQc); widgetLdr.addReference(query, startQc, "department", "Employee.department"); ContainsConstraint cc = (ContainsConstraint) (cs.getConstraints().iterator().next()); assertEquals("Department", cc.getQueryClass().getType().getSimpleName()); QueryObjectReference qr = (QueryObjectReference) cc.getReference(); assertEquals("department", qr.getFieldName()); assertEquals("Employee", qr.getQcType().getSimpleName()); }
public void testAddConstraintEmpty() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); SimpleConstraint sc = new SimpleConstraint(new QueryField(qc, "name"), ConstraintOp.EQUALS, new QueryValue("Bob")); q.setConstraint(sc); QueryHelper.addAndConstraint(q, new ConstraintSet(ConstraintOp.AND)); assertEquals(1, ((ConstraintSet) q.getConstraint()).getConstraints().size()); }
public void testAddConstraintToConstraint() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); SimpleConstraint sc1 = new SimpleConstraint(new QueryField(qc, "name"), ConstraintOp.EQUALS, new QueryValue("Bob")); SimpleConstraint sc2 = new SimpleConstraint(new QueryField(qc, "age"), ConstraintOp.EQUALS, new QueryValue(new Integer(54))); ConstraintSet cs2 = new ConstraintSet(ConstraintOp.AND); cs2.addConstraint(sc2); q.setConstraint(sc1); QueryHelper.addAndConstraint(q, cs2); assertTrue(q.getConstraint() instanceof ConstraintSet); assertEquals(2, ((ConstraintSet) q.getConstraint()).getConstraints().size()); ConstraintSet cs3 = new ConstraintSet(ConstraintOp.AND); cs3.addConstraint(sc1); cs3.addConstraint(sc2); assertEquals(cs3, ((ConstraintSet) q.getConstraint())); }