org.intermine.objectstore.query.Query类的使用及代码示例

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

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

Query介绍

[英]This class provides an implementation-independent abstract representation of a query
[中]这个类提供了一个独立于实现的查询抽象表示

代码示例

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

private Query internalGetQuery() {
  Query q = new Query();
  QueryClass qc1 = new QueryClass(clazz);
  q.addFrom(qc1);
  q.addToSelect(qc1);
  q.setConstraint(new ContainsConstraint(new QueryCollectionReference(o, fieldName),
          ConstraintOp.CONTAINS, qc1));
  q.setDistinct(false);
  return q;
}

代码示例来源: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

/**
 * Processes an AST node that describes a GROUP BY clause.
 *
 * @param ast an AST node to process
 * @param modelPackage the package for unqualified class names
 * @param iterator an iterator through the list of parameters of the IqlQuery
 */
private static void processGroupClause(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  do {
    q.addToGroupBy(processNewQueryNode(ast, q, modelPackage, iterator));
    ast = ast.getNextSibling();
  } while (ast != null);
}

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

/**
 * Returns a list of aliases, where each alias corresponds to each element of the SELECT list
 * of the Query object. This is effectively a list of column headings for the results object.
 * @param query the Query object
 * @return a List of Strings, each of which is the alias of the column
 */
public static List<String> getColumnAliases(Query query) {
  List<String> columnAliases = new ArrayList<String>();
  for (QuerySelectable node : query.getSelect()) {
    String alias = query.getAliases().get(node);
    columnAliases.add(alias);
  }
  return columnAliases;
}

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

public final void setUp() throws Exception {
  query = new Query();
  assertNotNull("Problem creating Query instance", query);
  // set up three queries for testing .equals() and .hashCode()
  QueryClass qc1 = new QueryClass(Company.class);
  QueryField qf1 = new QueryField(qc1, "name");
  QueryField qf2 = new QueryField(qc1, "vatNumber");
  QueryFunction f1 = new QueryFunction();  // count(*)
  QueryValue qv1 = new QueryValue("CompanyA");
  SimpleConstraint sc1 = new SimpleConstraint(qf1, ConstraintOp.NOT_EQUALS, qv1);
  clearQuery = new Query();
  clearQuery.addToSelect(qc1);
  clearQuery.addToSelect(f1);
  clearQuery.setConstraint(sc1);
  clearQuery.addToGroupBy(qc1);
  clearQuery.addToOrderBy(qf1);
}

代码示例来源: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: org.intermine/intermine-objectstore

/**
 * Constructor for a SingletonResults object
 *
 * @param q the Query that produces this Results
 * @param os the ObjectStore that can be used to get results rows from
 * @param sequence an object representing the state of the ObjectStore, which should be quoted
 * back to the ObjectStore when requests are made
 * @throws IllegalArgumentException if q does not return a single column
 */
public SingletonResults(Query q, ObjectStore os, Map<Object, Integer> sequence) {
  super(q, os, sequence);
  // Test that this Query returns a single column of type QueryClass
  if (q.getSelect().size() != 1) {
    throw new IllegalArgumentException("Query must return a single column");
  }
}

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

public void testClearSelect() {
  clearQuery.clearSelect();
  assertEquals(0, clearQuery.getSelect().size());
}

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

/**
 * Constructor for a SingletonResults object
 *
 * @param q the Query that produces this Results
 * @param os the ObjectStore that can be used to get results rows from
 * @param sequence an object representing the state of the ObjectStore, which should be quoted
 * back to the ObjectStore when requests are made
 * @throws IllegalArgumentException if q does not return a single column
 */
public SingletonResults(Query q, ObjectStore os, Map<Object, Integer> sequence) {
  super(q, os, sequence);
  // Test that this Query returns a single column of type QueryClass
  if (q.getSelect().size() != 1) {
    throw new IllegalArgumentException("Query must return a single column");
  }
}

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

/**
 * Returns a list of aliases, where each alias corresponds to each element of the SELECT list
 * of the Query object. This is effectively a list of column headings for the results object.
 * @param query the Query object
 * @return a List of Strings, each of which is the alias of the column
 */
public static List<String> getColumnAliases(Query query) {
  List<String> columnAliases = new ArrayList<String>();
  for (QuerySelectable node : query.getSelect()) {
    String alias = query.getAliases().get(node);
    columnAliases.add(alias);
  }
  return columnAliases;
}

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

private Results getFieldSummary(ClassDescriptor cld, String fieldName, ObjectStore os) {
  Query q = new Query();
  q.setDistinct(true);
  QueryClass qc = new QueryClass(cld.getType());
  q.addToSelect(new QueryField(qc, fieldName));
  q.addFrom(qc);
  Results results = os.execute(q);
  return results;
}

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

/**
 * Converts a SELECT list from a normal query into a representation of the columns returned
 * in this converted list.
 *
 * @return a List of QuerySelectables corresponding to the columns returned in this list
 */
public List<QuerySelectable> getFlatSelect() {
  ArrayList<QuerySelectable> retval = new ArrayList<QuerySelectable>();
  addFlatSelect(retval, query.getSelect(), null, null);
  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-objectstore

/**
 * Processes an AST node that describes a GROUP BY clause.
 *
 * @param ast an AST node to process
 * @param modelPackage the package for unqualified class names
 * @param iterator an iterator through the list of parameters of the IqlQuery
 */
private static void processGroupClause(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  do {
    q.addToGroupBy(processNewQueryNode(ast, q, modelPackage, iterator));
    ast = ast.getNextSibling();
  } while (ast != null);
}

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

public static Query notSubqueryExistsConstraint() throws Exception {
  Query q1 = new Query();
  q1.addToSelect(new QueryValue("hello"));
  Query q2 = new Query();
  QueryClass qc = new QueryClass(Company.class);
  q2.addFrom(qc);
  q2.addToSelect(qc);
  q2.setDistinct(false);
  q1.setConstraint(new SubqueryExistsConstraint(ConstraintOp.DOES_NOT_EXIST, q2));
  q1.setDistinct(false);
  return q1;
}

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

/**
 * Converts a SELECT list from a normal query into a representation of the columns returned
 * in this converted list.
 *
 * @return a List of QuerySelectables corresponding to the columns returned in this list
 */
public List<QuerySelectable> getFlatSelect() {
  ArrayList<QuerySelectable> retval = new ArrayList<QuerySelectable>();
  addFlatSelect(retval, query.getSelect(), null, null);
  return retval;
}

代码示例来源: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 static Query subqueryExistsConstraintNeg() throws Exception {
  Query q1 = new Query();
  q1.addToSelect(new QueryValue("hello"));
  Query q2 = new Query();
  QueryClass qc = new QueryClass(Bank.class);
  q2.addFrom(qc);
  q2.addToSelect(qc);
  q2.setDistinct(false);
  q1.setConstraint(new SubqueryExistsConstraint(ConstraintOp.EXISTS, q2));
  q1.setDistinct(false);
  return q1;
}

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

/**
   * Returns a list of Class objects, where each object corresponds to the type of each element
   * of the SELECT list of the Query object. This is effectively a list of column types for the
   * results object.
   * @param query the Query object
   * @return a List of Class objects
   */
  public static List<Class<?>> getColumnTypes(Query query) {
    List<Class<?>> columnTypes = new ArrayList<Class<?>>();
    for (QuerySelectable node : query.getSelect()) {
      Class<?> type = node.getType();
      columnTypes.add(type);
    }
    return columnTypes;
  }
}

相关文章