/** * Converts a constraint from a query into a List of Constraint objects. * * @param query a Query object to list Constraints for * @return a List of Constraint objects */ public static List<Constraint> createList(Query query) { List<Constraint> retval = new ArrayList<Constraint>(); if (query != null) { addToList(retval, query.getConstraint()); } return retval; }
/** * Converts a constraint from a query into a List of Constraint objects. * * @param query a Query object to list Constraints for * @return a List of Constraint objects */ public static List<Constraint> createList(Query query) { List<Constraint> retval = new ArrayList<Constraint>(); if (query != null) { addToList(retval, query.getConstraint()); } return retval; }
Map<QueryEvaluable, ConstraintSet> nodes = new LinkedHashMap<QueryEvaluable, ConstraintSet>(); if (q.getConstraint() instanceof BagConstraint) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); nodes.put((QueryEvaluable) ((BagConstraint) q.getConstraint()).getQueryNode(), cs); q.setConstraint(cs); } else if (q.getConstraint() instanceof MultipleInBagConstraint) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); MultipleInBagConstraint c = (MultipleInBagConstraint) q.getConstraint(); for (QueryEvaluable qe : c.getEvaluables()) { nodes.put(qe, cs); traverseConstraint(q.getConstraint(), nodes);
Map<QueryEvaluable, ConstraintSet> nodes = new LinkedHashMap<QueryEvaluable, ConstraintSet>(); if (q.getConstraint() instanceof BagConstraint) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); nodes.put((QueryEvaluable) ((BagConstraint) q.getConstraint()).getQueryNode(), cs); q.setConstraint(cs); } else if (q.getConstraint() instanceof MultipleInBagConstraint) { ConstraintSet cs = new ConstraintSet(ConstraintOp.OR); MultipleInBagConstraint c = (MultipleInBagConstraint) q.getConstraint(); for (QueryEvaluable qe : c.getEvaluables()) { nodes.put(qe, cs); traverseConstraint(q.getConstraint(), nodes);
/** * {@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); } }
Query q = TemplatePrecomputeHelper.getPrecomputeQuery(template, indexes, null); if (q.getConstraint() == null) { if (q.getConstraint() instanceof ConstraintSet) { if (((ConstraintSet) q.getConstraint()).getConstraints().size() == 0) {
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 testCreateListSingleConstraint() throws Exception { IqlQuery fq = new IqlQuery("select a from Company as a where a.vatNumber = 5", "org.intermine.model.testmodel"); q = IqlQueryParser.parse(fq); List expected = new ArrayList(); expected.add(q.getConstraint()); List got = ConstraintHelper.createList(q); assertEquals(expected, got); }
public void testCreateListOr() throws Exception { IqlQuery fq = new IqlQuery("select a from Company as a where a.vatNumber = 5 or a.name = 'hello'", "org.intermine.model.testmodel"); q = IqlQueryParser.parse(fq); List expected = new ArrayList(); expected.add(q.getConstraint()); List got = ConstraintHelper.createList(q); assertEquals(expected, got); }
Iterator bagIter = ((BagConstraint) q.getConstraint()).getBag().iterator();
Constraint queryConstraint = q.getConstraint();
Constraint queryConstraint = q.getConstraint();
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())); }
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 testAddConstraintToNull() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); Constraint sc = new SimpleConstraint(new QueryField(qc, "name"), ConstraintOp.EQUALS, new QueryValue("Bob")); ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); cs.addConstraint(sc); QueryHelper.addAndConstraint(q, cs); assertEquals(cs, q.getConstraint()); }
public void testAddConstraintToConstraintSetOrAnd() 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 cs1 = new ConstraintSet(ConstraintOp.OR); cs1.addConstraint(sc1); ConstraintSet cs2 = new ConstraintSet(ConstraintOp.AND); cs2.addConstraint(sc2); q.setConstraint(cs1); QueryHelper.addAndConstraint(q, cs2); ConstraintSet cs3 = new ConstraintSet(ConstraintOp.AND); cs3.addConstraint(cs1); cs3.addConstraint(sc2); assertEquals(cs3, q.getConstraint()); }
public void testAddConstraintToConstraintSet() 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 cs1 = new ConstraintSet(ConstraintOp.AND); cs1.addConstraint(sc1); ConstraintSet cs2 = new ConstraintSet(ConstraintOp.AND); cs2.addConstraint(sc2); q.setConstraint(cs1); QueryHelper.addAndConstraint(q, cs2); ConstraintSet cs3 = new ConstraintSet(ConstraintOp.AND); cs3.addConstraint(sc1); cs3.addConstraint(sc2); assertEquals(cs3, q.getConstraint()); }
public void testAddConstraintToConstraintSetAndOr() 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 cs1 = new ConstraintSet(ConstraintOp.AND); cs1.addConstraint(sc1); ConstraintSet cs2 = new ConstraintSet(ConstraintOp.OR); cs2.addConstraint(sc2); q.setConstraint(cs1); QueryHelper.addAndConstraint(q, cs2); ConstraintSet cs3 = new ConstraintSet(ConstraintOp.AND); cs3.addConstraint(sc1); cs3.addConstraint(cs2); assertEquals(cs3, q.getConstraint()); }
/** * The absence of a proper Query.equals() method means that we * have to do various tests here. This does rely on constructing * the query in the tests in the correct form, ie. we will not * notice that an "OR" ConstraintSet with one SimpleConstraint in * it is the same as a SimpleConstraint. */ public static void assertEquals(String msg, Query q1, Query q2) { if ((q1 != null) && (q2 != null)) { msg += ": expected <" + q1.toString() + "> but was <" + q2.toString() + ">"; //msg += ": q1 = " + q1.toString() + ", q2 = " + q2.toString(); // Are the SELECT lists equal? checkQueryClassLists(msg + ": SELECT lists are not equal", q1.getSelect(), q2.getSelect(), q1, q2); // Are the FROM lists equal? checkQueryClassLists(msg + ": FROM lists are not equal", q1.getFrom(), q2.getFrom(), q1, q2); // Are the constraints equal? checkConstraints(msg + ": CONSTRAINTS not the same", q1.getConstraint(), q2.getConstraint(), q1, q2); // Are the ORDER BY lists equal? checkQueryClassLists(msg + ": ORDER BY lists are not equal", q1.getOrderBy(), q2.getOrderBy(), q1, q2); Assert.assertEquals(msg + ": LIMIT is the not the same", q1.getLimit(), q2.getLimit()); // Do the toString methods return the same thing? checkToString(msg + ": toString does not return the same String", q1, q2); } else if ((q1 == null) && (q2 == null)) { // They are equal - albeit null. } else { Assert.assertNotNull(msg + ": q1 is null, while q2 is not null", q1); Assert.fail(msg + ": q2 is null, while q1 is not null"); } }