org.intermine.objectstore.query.Query.getConstraint()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中org.intermine.objectstore.query.Query.getConstraint方法的一些代码示例,展示了Query.getConstraint的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getConstraint方法的具体详情如下:
包路径:org.intermine.objectstore.query.Query
类名称:Query
方法名:getConstraint

Query.getConstraint介绍

[英]Get the current constraint on this Query
[中]获取此查询的当前约束

代码示例

代码示例来源:origin: org.intermine/intermine-objectstore

/**
 * 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;
}

代码示例来源:origin: intermine/intermine

/**
 * 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;
}

代码示例来源:origin: org.intermine/intermine-api

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);

代码示例来源:origin: intermine/intermine

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);

代码示例来源:origin: org.intermine/intermine-objectstore

/**
 * {@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);
  }
}

代码示例来源:origin: intermine/intermine

/**
 * {@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);
  }
}

代码示例来源:origin: org.intermine/intermine-webtasks

Query q = TemplatePrecomputeHelper.getPrecomputeQuery(template, indexes, null);
if (q.getConstraint() == null) {
if (q.getConstraint() instanceof ConstraintSet) {
  if (((ConstraintSet) q.getConstraint()).getConstraints().size() == 0) {

代码示例来源:origin: intermine/intermine

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);
}

代码示例来源:origin: intermine/intermine

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);
}

代码示例来源:origin: intermine/intermine

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);
}

代码示例来源:origin: intermine/intermine

Iterator bagIter = ((BagConstraint) q.getConstraint()).getBag().iterator();

代码示例来源:origin: org.intermine/intermine-objectstore

Constraint queryConstraint = q.getConstraint();

代码示例来源:origin: intermine/intermine

Constraint queryConstraint = q.getConstraint();

代码示例来源:origin: intermine/intermine

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()));
}

代码示例来源:origin: intermine/intermine

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());
}

代码示例来源:origin: intermine/intermine

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());
}

代码示例来源:origin: intermine/intermine

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());
}

代码示例来源:origin: intermine/intermine

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());
}

代码示例来源:origin: intermine/intermine

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());
}

代码示例来源:origin: intermine/intermine

/**
 * 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");
  }
}

相关文章