Search in sources :

Example 1 with SimpleConstraint

use of org.intermine.objectstore.query.SimpleConstraint in project intermine by intermine.

the class SetupDataTestCase method queryClassBagNotViaNand.

/*
     * SELECT a1_.id, a2_ FROM ?::Department AS a1_, Employee AS a2_ WHERE NOT (a1_.employees CONTAINS a2_ AND 1 = 1)
     */
public static Query queryClassBagNotViaNand() throws Exception {
    Query q = new Query();
    QueryClassBag qcb = new QueryClassBag(Department.class, Arrays.asList(new Object[] { data.get("DepartmentA1"), data.get("DepartmentB1") }));
    QueryClass qc = new QueryClass(Employee.class);
    q.addFrom(qcb);
    q.addFrom(qc);
    q.addToSelect(new QueryField(qcb));
    q.addToSelect(qc);
    ConstraintSet cs = new ConstraintSet(ConstraintOp.NAND);
    cs.addConstraint(new ContainsConstraint(new QueryCollectionReference(qcb, "employees"), ConstraintOp.CONTAINS, qc));
    cs.addConstraint(new SimpleConstraint(new QueryValue(new Integer(1)), ConstraintOp.EQUALS, new QueryValue(new Integer(1))));
    q.setConstraint(cs);
    q.setDistinct(false);
    return q;
}
Also used : Query(org.intermine.objectstore.query.Query) QueryClassBag(org.intermine.objectstore.query.QueryClassBag) QueryField(org.intermine.objectstore.query.QueryField) InterMineObject(org.intermine.model.InterMineObject) ConstraintSet(org.intermine.objectstore.query.ConstraintSet) ContainsConstraint(org.intermine.objectstore.query.ContainsConstraint) QueryClass(org.intermine.objectstore.query.QueryClass) QueryValue(org.intermine.objectstore.query.QueryValue) QueryCollectionReference(org.intermine.objectstore.query.QueryCollectionReference) SimpleConstraint(org.intermine.objectstore.query.SimpleConstraint)

Example 2 with SimpleConstraint

use of org.intermine.objectstore.query.SimpleConstraint in project intermine by intermine.

the class SetupDataTestCase method queryClassBagNotViaNor.

/*
     * SELECT a1_.id, a2_ FROM ?::Department AS a1_, Employee AS a2_ WHERE NOT (a1_.employees CONTAINS a2_ OR 1 = 1)
     */
public static Query queryClassBagNotViaNor() throws Exception {
    Query q = new Query();
    QueryClassBag qcb = new QueryClassBag(Department.class, Arrays.asList(new Object[] { data.get("DepartmentA1"), data.get("DepartmentB1") }));
    QueryClass qc = new QueryClass(Employee.class);
    q.addFrom(qcb);
    q.addFrom(qc);
    q.addToSelect(new QueryField(qcb));
    q.addToSelect(qc);
    ConstraintSet cs = new ConstraintSet(ConstraintOp.NOR);
    cs.addConstraint(new ContainsConstraint(new QueryCollectionReference(qcb, "employees"), ConstraintOp.CONTAINS, qc));
    cs.addConstraint(new SimpleConstraint(new QueryValue(new Integer(1)), ConstraintOp.EQUALS, new QueryValue(new Integer(1))));
    q.setConstraint(cs);
    q.setDistinct(false);
    return q;
}
Also used : Query(org.intermine.objectstore.query.Query) QueryClassBag(org.intermine.objectstore.query.QueryClassBag) QueryField(org.intermine.objectstore.query.QueryField) InterMineObject(org.intermine.model.InterMineObject) ConstraintSet(org.intermine.objectstore.query.ConstraintSet) ContainsConstraint(org.intermine.objectstore.query.ContainsConstraint) QueryClass(org.intermine.objectstore.query.QueryClass) QueryValue(org.intermine.objectstore.query.QueryValue) QueryCollectionReference(org.intermine.objectstore.query.QueryCollectionReference) SimpleConstraint(org.intermine.objectstore.query.SimpleConstraint)

Example 3 with SimpleConstraint

use of org.intermine.objectstore.query.SimpleConstraint in project intermine by intermine.

the class SqlGeneratorTest method testQueryValueUnderscoreInEquals.

/**
 * Expect underscores to be unescaped in other queries *
 */
public void testQueryValueUnderscoreInEquals() throws Exception {
    QueryValue right = new QueryValue("Hello_World");
    QueryValue left = new QueryValue("HelloXWorld");
    SimpleConstraint con = new SimpleConstraint(left, ConstraintOp.EQUALS, right);
    SqlGenerator.State state = new SqlGenerator.State();
    StringBuffer buffer = state.getWhereBuffer();
    SqlGenerator.simpleConstraintToString(state, buffer, con, null);
    assertEquals("'HelloXWorld' = 'Hello_World'", buffer.toString());
}
Also used : QueryValue(org.intermine.objectstore.query.QueryValue) SimpleConstraint(org.intermine.objectstore.query.SimpleConstraint)

Example 4 with SimpleConstraint

use of org.intermine.objectstore.query.SimpleConstraint in project intermine by intermine.

the class SqlGeneratorTest method testQueryValueUnderscoreInMatch.

/**
 * Expect Underscores to not be escaped in LIKE queries *
 */
public void testQueryValueUnderscoreInMatch() throws Exception {
    QueryValue right = new QueryValue("%Hello_World");
    QueryValue left = new QueryValue("Hello-World");
    SimpleConstraint con = new SimpleConstraint(left, ConstraintOp.MATCHES, right);
    SqlGenerator.State state = new SqlGenerator.State();
    StringBuffer buffer = state.getWhereBuffer();
    SqlGenerator.simpleConstraintToString(state, buffer, con, null);
    assertEquals("'Hello-World' LIKE '%Hello_World'", buffer.toString());
}
Also used : QueryValue(org.intermine.objectstore.query.QueryValue) SimpleConstraint(org.intermine.objectstore.query.SimpleConstraint)

Example 5 with SimpleConstraint

use of org.intermine.objectstore.query.SimpleConstraint in project intermine by intermine.

the class SqlGeneratorTest method testQueryValueEscapedOpsInMatch.

/**
 * Expect Underscores to not be escaped in LIKE queries *
 */
public void testQueryValueEscapedOpsInMatch() throws Exception {
    QueryValue right = new QueryValue("\\%Hello_Under\\_Score%");
    QueryValue left = new QueryValue("%Hello-Under_Score!");
    SimpleConstraint con = new SimpleConstraint(left, ConstraintOp.MATCHES, right);
    SqlGenerator.State state = new SqlGenerator.State();
    StringBuffer buffer = state.getWhereBuffer();
    SqlGenerator.simpleConstraintToString(state, buffer, con, null);
    String expected = "'%Hello-Under_Score!' LIKE E'\\\\%Hello_Under\\\\_Score%'";
    assertEquals(expected, buffer.toString());
}
Also used : QueryValue(org.intermine.objectstore.query.QueryValue) SimpleConstraint(org.intermine.objectstore.query.SimpleConstraint)

Aggregations

SimpleConstraint (org.intermine.objectstore.query.SimpleConstraint)121 QueryField (org.intermine.objectstore.query.QueryField)104 QueryClass (org.intermine.objectstore.query.QueryClass)102 QueryValue (org.intermine.objectstore.query.QueryValue)99 Query (org.intermine.objectstore.query.Query)95 ConstraintSet (org.intermine.objectstore.query.ConstraintSet)78 ContainsConstraint (org.intermine.objectstore.query.ContainsConstraint)49 QueryObjectReference (org.intermine.objectstore.query.QueryObjectReference)31 BagConstraint (org.intermine.objectstore.query.BagConstraint)23 Constraint (org.intermine.objectstore.query.Constraint)23 SubqueryConstraint (org.intermine.objectstore.query.SubqueryConstraint)18 PathQuery (org.intermine.pathquery.PathQuery)18 QueryCollectionReference (org.intermine.objectstore.query.QueryCollectionReference)17 SingletonResults (org.intermine.objectstore.query.SingletonResults)17 QueryReference (org.intermine.objectstore.query.QueryReference)16 InterMineObject (org.intermine.model.InterMineObject)14 ClassConstraint (org.intermine.objectstore.query.ClassConstraint)12 MultipleInBagConstraint (org.intermine.objectstore.query.MultipleInBagConstraint)12 SubqueryExistsConstraint (org.intermine.objectstore.query.SubqueryExistsConstraint)12 OverlapConstraint (org.intermine.objectstore.query.OverlapConstraint)11