public static Query fieldPathExpression2() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); q.addFrom(qc); q.addToSelect(qc); QueryObjectPathExpression qope1 = new QueryObjectPathExpression(qc, "department"); QueryObjectPathExpression qope2 = new QueryObjectPathExpression(qope1.getDefaultClass(), "company"); QueryObjectPathExpression qope3 = new QueryObjectPathExpression(qope2.getDefaultClass(), "address"); qope3.addToSelect(new QueryField(qope3.getDefaultClass(), "address")); qope2.addToSelect(qope3); qope1.addToSelect(qope2); q.addToSelect(qope1); q.setDistinct(false); return q; }
QueryObjectPathExpression ref) { StringBuffer retval = new StringBuffer(); retval.append(q.getAliases().get(ref.getQueryClass())) .append(".") .append(ref.getFieldName()); if (ref.getSubclass() != null) { Class<?> subclass = ref.getSubclass(); Collection<Class<?>> subclasses = Util.decomposeClass(subclass); if (subclasses.size() == 1) { if ((!ref.getSelect().isEmpty()) || (ref.getConstraint() != null)) { Set<Integer> empty = Collections.emptySet(); Query subQ = ref.getQuery(empty, true); retval.append("("); boolean needSpace = false; Set<QueryObjectPathExpression> subPathList = new HashSet<QueryObjectPathExpression>(); if (!ref.getSelect().isEmpty()) { retval.append("SELECT "); boolean needComma = false; for (QuerySelectable selectable : ref.getSelect()) { if (needComma) { retval.append(", "); if (ref.getConstraint() != null) { if (needSpace) { retval.append(" "); .append(constraintToString(subQ, ref.getConstraint(), parameters));
private static void copySelectList(Queryable q, List<QuerySelectable> select) { // Copy select list into query: QueryClass defaultClass = null; if (q instanceof QueryObjectPathExpression) { defaultClass = ((QueryObjectPathExpression) q).getDefaultClass(); } if ((select.size() == 1) && select.get(0).equals(defaultClass)) { // Don't add anything to the SELECT list - default is fine } else { for (QuerySelectable qs : select) { if (qs instanceof QueryObjectPathExpression) { QueryObjectPathExpression qope = (QueryObjectPathExpression) qs; if (qope.getSelect().size() > 1) { for (int i = 0; i < qope.getSelect().size(); i++) { q.addToSelect(new PathExpressionField(qope, i)); } } else { q.addToSelect(qope); } } else { q.addToSelect(qs); } } } }
} else if (orig instanceof QueryObjectPathExpression) { QueryObjectPathExpression origC = (QueryObjectPathExpression) orig; QueryObjectPathExpression retval = new QueryObjectPathExpression((QueryClass) fromElementMap.get(origC.getQueryClass()), origC.getFieldName()); Map<FromElement, FromElement> subFromElementMap = new HashMap<FromElement, FromElement>(); subFromElementMap.put(origC.getDefaultClass(), retval.getDefaultClass()); for (QuerySelectable selectable : origC.getSelect()) { retval.addToSelect((QuerySelectable) cloneThing(selectable, subFromElementMap, qopeMap)); retval.setConstraint((Constraint) cloneThing(origC.getConstraint(), subFromElementMap, qopeMap)); return retval;
QueryClass lastQc = qope.getDefaultClass(); qf = new QueryField(lastQc, fieldName); subQ.addFrom(lastQc); subQ.addToSelect(lastQc); QueryClass rootQc = qope.getQueryClass(); QueryHelper.addAndConstraint(subQ, new ContainsConstraint( new QueryObjectReference(rootQc, qope.getFieldName()), ConstraintOp.CONTAINS, lastQc)); if (qope.getConstraint() != null) { QueryHelper.addAndConstraint(subQ, qope.getConstraint()); QueryObjectPathExpression qope = ((PathExpressionField) qs).getQope(); Query tempSubQ = QueryCloner.cloneQuery(subQ); QueryClass lastQc = qope.getDefaultClass(); tempSubQ.addFrom(lastQc); tempSubQ.addToSelect(lastQc); QueryClass rootQc = qope.getQueryClass(); QueryHelper.addAndConstraint(tempSubQ, new ContainsConstraint( new QueryObjectReference(rootQc, qope.getFieldName()), ConstraintOp.CONTAINS, lastQc)); if (qope.getConstraint() != null) { QueryHelper.addAndConstraint(tempSubQ, qope.getConstraint()); new HashSet<QuerySelectable>(qope.getSelect()), pathToQueryNode, occurancesOnly); } else if (qs instanceof QueryCollectionPathExpression) {
if (isSelect) { try { obj = new QueryObjectPathExpression((QueryClass) obj, unescape( ast.getText())); } catch (IllegalArgumentException e2) { if ("id".equals(ast.getText())) { obj = new QueryForeignKey(((QueryObjectPathExpression) obj) .getQueryClass(), ((QueryObjectPathExpression) obj) .getFieldName()); } else { QueryObjectPathExpression ref = (QueryObjectPathExpression) obj; break; case IqlTokenTypes.WHERE_CLAUSE: ref.setConstraint(processConstraint(ast.getFirstChild(), ref.getQuery(empty, false), modelPackage, iterator)); break; } else { Collection<Integer> empty = Collections.emptySet(); colQuery = ((QueryObjectPathExpression) col).getQuery(empty, false);
expected.addToSelect(qc); QueryObjectPathExpression comOuter = new QueryObjectPathExpression(qc, "company"); comOuter.addToSelect(comOuter.getDefaultClass()); QueryCollectionReference col = new QueryCollectionReference(comOuter.getDefaultClass(), "contractors"); ContainsConstraint cc = new ContainsConstraint(col, ConstraintOp.IS_NOT_NULL); comOuter.setConstraint(cc); expected.addToSelect(comOuter);
if (parentNode instanceof QueryObjectPathExpression) { QueryObjectPathExpression qope = (QueryObjectPathExpression) parentNode; if (qope.getSelect().isEmpty()) { qope.addToSelect(qope.getDefaultClass()); qope.addToSelect(pathToQueryNode.get(path)); break; } else if (parentNode instanceof QueryCollectionPathExpression) {
int startingPoint; Set<Integer> idsToFetch = new HashSet<Integer>(); QueryClass qc = qope.getQueryClass(); FastPathObject o = (FastPathObject) row.get(startingPoint); try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { idsToFetch.add(ref.getId()); Query qopeQuery = qope.getQuery(idsToFetch, os.getSchema().isMissingNotXml()); long startTime = System.currentTimeMillis(); List<ResultsRow<Object>> res = os.executeWithConnection(c, qopeQuery, 0, Integer refId = null; try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { refId = ref.getId(); + o + " field: " + qope.getFieldName());
queryBits.put(root, ((QueryObjectPathExpression) q).getDefaultClass()); } else if (q instanceof QueryCollectionPathExpression) { queryBits.put(root, ((QueryCollectionPathExpression) q).getDefaultClass()); } else { QueryObjectPathExpression qn = new QueryObjectPathExpression(parentQc, path.getLastElement(), path.getEndType()); makeQuery(qn, stringPath, pathQuery, savedBags, pathToQueryNode,
public static Query objectPathExpression() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); q.addFrom(qc); q.addToSelect(qc); q.addToSelect(new QueryObjectPathExpression(qc, "department")); q.setDistinct(false); return q; }
/** * {@inheritDoc} */ public Class<?> getType() { return qope.getSelect().get(fieldNumber).getType(); }
Collection<Integer> empty = Collections.singleton(new Integer(1)); findTableNames(tablenames, ((QueryObjectPathExpression) selectable) .getQuery(empty, schema.isMissingNotXml()), schema, addInterMineObject, individualOsbs); } else if (selectable instanceof PathExpressionField) { Collection<Integer> empty = Collections.singleton(new Integer(1)); findTableNames(tablenames, ((PathExpressionField) selectable).getQope() .getQuery(empty, schema.isMissingNotXml()), schema, addInterMineObject, individualOsbs); } else {
} else if (orig instanceof QueryObjectPathExpression) { QueryObjectPathExpression origC = (QueryObjectPathExpression) orig; QueryObjectPathExpression retval = new QueryObjectPathExpression((QueryClass) fromElementMap.get(origC.getQueryClass()), origC.getFieldName()); Map<FromElement, FromElement> subFromElementMap = new HashMap<FromElement, FromElement>(); subFromElementMap.put(origC.getDefaultClass(), retval.getDefaultClass()); for (QuerySelectable selectable : origC.getSelect()) { retval.addToSelect((QuerySelectable) cloneThing(selectable, subFromElementMap, qopeMap)); retval.setConstraint((Constraint) cloneThing(origC.getConstraint(), subFromElementMap, qopeMap)); return retval;
QueryClass lastQc = qope.getDefaultClass(); qf = new QueryField(lastQc, fieldName); subQ.addFrom(lastQc); subQ.addToSelect(lastQc); QueryClass rootQc = qope.getQueryClass(); QueryHelper.addAndConstraint(subQ, new ContainsConstraint( new QueryObjectReference(rootQc, qope.getFieldName()), ConstraintOp.CONTAINS, lastQc)); if (qope.getConstraint() != null) { QueryHelper.addAndConstraint(subQ, qope.getConstraint()); QueryObjectPathExpression qope = ((PathExpressionField) qs).getQope(); Query tempSubQ = QueryCloner.cloneQuery(subQ); QueryClass lastQc = qope.getDefaultClass(); tempSubQ.addFrom(lastQc); tempSubQ.addToSelect(lastQc); QueryClass rootQc = qope.getQueryClass(); QueryHelper.addAndConstraint(tempSubQ, new ContainsConstraint( new QueryObjectReference(rootQc, qope.getFieldName()), ConstraintOp.CONTAINS, lastQc)); if (qope.getConstraint() != null) { QueryHelper.addAndConstraint(tempSubQ, qope.getConstraint()); new HashSet<QuerySelectable>(qope.getSelect()), pathToQueryNode, occurancesOnly); } else if (qs instanceof QueryCollectionPathExpression) {
if (isSelect) { try { obj = new QueryObjectPathExpression((QueryClass) obj, unescape( ast.getText())); } catch (IllegalArgumentException e2) { if ("id".equals(ast.getText())) { obj = new QueryForeignKey(((QueryObjectPathExpression) obj) .getQueryClass(), ((QueryObjectPathExpression) obj) .getFieldName()); } else { QueryObjectPathExpression ref = (QueryObjectPathExpression) obj; break; case IqlTokenTypes.WHERE_CLAUSE: ref.setConstraint(processConstraint(ast.getFirstChild(), ref.getQuery(empty, false), modelPackage, iterator)); break; } else { Collection<Integer> empty = Collections.emptySet(); colQuery = ((QueryObjectPathExpression) col).getQuery(empty, false);
private static void copySelectList(Queryable q, List<QuerySelectable> select) { // Copy select list into query: QueryClass defaultClass = null; if (q instanceof QueryObjectPathExpression) { defaultClass = ((QueryObjectPathExpression) q).getDefaultClass(); } if ((select.size() == 1) && select.get(0).equals(defaultClass)) { // Don't add anything to the SELECT list - default is fine } else { for (QuerySelectable qs : select) { if (qs instanceof QueryObjectPathExpression) { QueryObjectPathExpression qope = (QueryObjectPathExpression) qs; if (qope.getSelect().size() > 1) { for (int i = 0; i < qope.getSelect().size(); i++) { q.addToSelect(new PathExpressionField(qope, i)); } } else { q.addToSelect(qope); } } else { q.addToSelect(qs); } } } }
if (parentNode instanceof QueryObjectPathExpression) { QueryObjectPathExpression qope = (QueryObjectPathExpression) parentNode; if (qope.getSelect().isEmpty()) { qope.addToSelect(qope.getDefaultClass()); qope.addToSelect(pathToQueryNode.get(path)); break; } else if (parentNode instanceof QueryCollectionPathExpression) {
int startingPoint; Set<Integer> idsToFetch = new HashSet<Integer>(); QueryClass qc = qope.getQueryClass(); FastPathObject o = (FastPathObject) row.get(startingPoint); try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { idsToFetch.add(ref.getId()); Query qopeQuery = qope.getQuery(idsToFetch, os.getSchema().isMissingNotXml()); long startTime = System.currentTimeMillis(); List<ResultsRow<Object>> res = os.executeWithConnection(c, qopeQuery, 0, Integer refId = null; try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { refId = ref.getId(); + o + " field: " + qope.getFieldName());
queryBits.put(root, ((QueryObjectPathExpression) q).getDefaultClass()); } else if (q instanceof QueryCollectionPathExpression) { queryBits.put(root, ((QueryCollectionPathExpression) q).getDefaultClass()); } else { QueryObjectPathExpression qn = new QueryObjectPathExpression(parentQc, path.getLastElement(), path.getEndType()); makeQuery(qn, stringPath, pathQuery, savedBags, pathToQueryNode,