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; }
/** * 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; }
/** * 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); }
/** * 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; }
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); }
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()); }
/** * 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"); } }
public void testClearSelect() { clearQuery.clearSelect(); assertEquals(0, clearQuery.getSelect().size()); }
/** * 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"); } }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
/** * 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); }
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; }
/** * 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; }
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 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; }
/** * 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; } }