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

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

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

Query.getSelect介绍

[英]Gets the SELECT list
[中]获取选择列表

代码示例

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

/**
 * 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: 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 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: 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

/**
 * 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-api

/**
 * Constructor for this object.
 *
 * @param orig the List&lt;ResultsRow&gt; to encapsulate
 * @param query the Query that generated the results, in order to get the collection layout
 */
public ResultsFlatOuterJoinsImpl(List<ResultsRow> orig, Query query) {
  this.orig = orig;
  this.query = query;
  columnWidth = new int[query.getSelect().size()];
  for (int i = 0; i < columnWidth.length; i++) {
    QuerySelectable qs = query.getSelect().get(i);
    if (qs instanceof QueryCollectionPathExpression) {
      columnWidth[i] = ((QueryCollectionPathExpression) qs).getSelect().size();
      columnWidth[i] = (columnWidth[i] == 0 ? 1 : columnWidth[i]);
    } else {
      columnWidth[i] = 1;
    }
  }
  columnTypes = convertColumnTypes(query.getSelect());
}

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

/**
 * Constructor for this object.
 *
 * @param orig the List&lt;ResultsRow&gt; to encapsulate
 * @param query the Query that generated the results, in order to get the collection layout
 */
public ResultsFlatOuterJoinsImpl(List<ResultsRow> orig, Query query) {
  this.orig = orig;
  this.query = query;
  columnWidth = new int[query.getSelect().size()];
  for (int i = 0; i < columnWidth.length; i++) {
    QuerySelectable qs = query.getSelect().get(i);
    if (qs instanceof QueryCollectionPathExpression) {
      columnWidth[i] = ((QueryCollectionPathExpression) qs).getSelect().size();
      columnWidth[i] = (columnWidth[i] == 0 ? 1 : columnWidth[i]);
    } else {
      columnWidth[i] = 1;
    }
  }
  columnTypes = convertColumnTypes(query.getSelect());
}

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

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

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

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

private void init(PathQuery pq, Map<String, QuerySelectable> pathToQueryNode) {
  osIter = ((List) results).iterator();
  List<List<ResultElement>> empty = Collections.emptyList();
  subIter = empty.iterator();
  for (String pathString : pq.getView()) {
    Path path;
    try {
      path = pq.makePath(pathString);
      paths.add(path);
    } catch (PathException e) {
      throw new RuntimeException("Path " + pathString
          + " in view of PathQuery is invalid", e);
    }
  }
  columns = convertColumnTypes(query.getSelect(), pq, pathToQueryNode);
  columnCount = pq.getView().size();
}

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

private void init(PathQuery pq, Map<String, QuerySelectable> pathToQueryNode) {
  osIter = ((List) results).iterator();
  List<List<ResultElement>> empty = Collections.emptyList();
  subIter = empty.iterator();
  for (String pathString : pq.getView()) {
    Path path;
    try {
      path = pq.makePath(pathString);
      paths.add(path);
    } catch (PathException e) {
      throw new RuntimeException("Path " + pathString
          + " in view of PathQuery is invalid", e);
    }
  }
  columns = convertColumnTypes(query.getSelect(), pq, pathToQueryNode);
  columnCount = pq.getView().size();
}

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

/**
 * Processes an AST node that describes a ORDER 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 processOrderClause(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  do {
    QueryOrderable qo = (QueryOrderable) processNewQueryNodeOrReference(ast, q, false,
        modelPackage, iterator);
    for (QuerySelectable qs : q.getSelect()) {
      if (qo.equals(qs)) {
        qo = (QueryOrderable) qs;
        break;
      }
    }
    q.addToOrderBy(qo);
    ast = ast.getNextSibling();
  } while (ast != null);
}

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

/**
 * Processes an AST node that describes a ORDER 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 processOrderClause(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  do {
    QueryOrderable qo = (QueryOrderable) processNewQueryNodeOrReference(ast, q, false,
        modelPackage, iterator);
    for (QuerySelectable qs : q.getSelect()) {
      if (qo.equals(qs)) {
        qo = (QueryOrderable) qs;
        break;
      }
    }
    q.addToOrderBy(qo);
    ast = ast.getNextSibling();
  } while (ast != null);
}

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

/**
 * {@inheritDoc}
 */
@Override
public void addToBagFromQuery(ObjectStoreBag osb, Query query) throws ObjectStoreException {
  List<QuerySelectable> select = query.getSelect();
  if (select.size() != 1) {
    throw new IllegalArgumentException("Query has incorrect number of SELECT elements.");
  }
  Class<?> type = select.get(0).getType();
  if (!(Integer.class.equals(type) || InterMineObject.class.isAssignableFrom(type))) {
    throw new IllegalArgumentException("The type of the result colum (" + type.getName()
        + ") is not an Integer or InterMineObject");
  }
  try {
    Connection c = null;
    try {
      c = getConnection();
      Set<String> readTables = SqlGenerator.findTableNames(query, getSchema());
      readTables.add(INT_BAG_TABLE_NAME);
      batch.flush(c, readTables);
      addToBagFromQueryWithConnection(c, osb, query);
    } finally {
      releaseConnection(c);
    }
  } catch (SQLException e) {
    throw new ObjectStoreException("Could not get connection to database", e);
  }
}

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

/**
 * {@inheritDoc}
 */
@Override
public void addToBagFromQuery(ObjectStoreBag osb, Query query) throws ObjectStoreException {
  List<QuerySelectable> select = query.getSelect();
  if (select.size() != 1) {
    throw new IllegalArgumentException("Query has incorrect number of SELECT elements.");
  }
  Class<?> type = select.get(0).getType();
  if (!(Integer.class.equals(type) || InterMineObject.class.isAssignableFrom(type))) {
    throw new IllegalArgumentException("The type of the result colum (" + type.getName()
        + ") is not an Integer or InterMineObject");
  }
  try {
    Connection c = null;
    try {
      c = getConnection();
      Set<String> readTables = SqlGenerator.findTableNames(query, getSchema());
      readTables.add(INT_BAG_TABLE_NAME);
      batch.flush(c, readTables);
      addToBagFromQueryWithConnection(c, osb, query);
    } finally {
      releaseConnection(c);
    }
  } catch (SQLException e) {
    throw new ObjectStoreException("Could not get connection to database", e);
  }
}

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

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

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

/**
 * Processes an IQL_STATEMENT AST node produced by antlr.
 *
 * @param ast an AST node to process
 * @param q the Query to build
 * @param modelPackage the package for unqualified class names
 * @param iterator an iterator through the list of parameters of the IqlQuery
 */
private static void processIqlStatementAST(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  if (ast.getType() != IqlTokenTypes.IQL_STATEMENT) {
    throw new IllegalArgumentException("Expected: an IQL SELECT statement");
  }
  processAST(ast.getFirstChild(), q, modelPackage, iterator);
  for (QuerySelectable qs : q.getSelect()) {
    if (qs instanceof QueryValue) {
      QueryValue qv = (QueryValue) qs;
      if (UnknownTypeValue.class.equals(qv.getType())) {
        if (((UnknownTypeValue) qv.getValue()).getApproximateType()
            == UnknownTypeValue.TYPE_STRING) {
          qv.youAreType(String.class);
        }
      }
    }
  }
}

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

/**
 * Processes an IQL_STATEMENT AST node produced by antlr.
 *
 * @param ast an AST node to process
 * @param q the Query to build
 * @param modelPackage the package for unqualified class names
 * @param iterator an iterator through the list of parameters of the IqlQuery
 */
private static void processIqlStatementAST(AST ast, Query q, String modelPackage,
    Iterator<?> iterator) {
  if (ast.getType() != IqlTokenTypes.IQL_STATEMENT) {
    throw new IllegalArgumentException("Expected: an IQL SELECT statement");
  }
  processAST(ast.getFirstChild(), q, modelPackage, iterator);
  for (QuerySelectable qs : q.getSelect()) {
    if (qs instanceof QueryValue) {
      QueryValue qv = (QueryValue) qs;
      if (UnknownTypeValue.class.equals(qv.getType())) {
        if (((UnknownTypeValue) qv.getValue()).getApproximateType()
            == UnknownTypeValue.TYPE_STRING) {
          qv.youAreType(String.class);
        }
      }
    }
  }
}

代码示例来源: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");
  }
}

相关文章