@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { QueryBuilder qb = new QueryBuilder(); qb.select("distinct fa"); qb.from("Image", "i"); qb.append(", Roi roi "); qb.join("roi.annotationLinks", "rlinks", false, false); qb.join("rlinks.child", "rfa", false, false); qb.join("i.wellSamples", "ws", false, false); qb.join("ws.well", "well", false, false); qb.join("well.plate", "plate", false, false); qb.join("plate.annotationLinks", "links", false, false); qb.join("links.child", "fa", false, false); qb.where(); qb.and("fa.ns = '" + NSMEASUREMENT.value + "'"); qb.and("rfa.id = fa.id"); qb.and("i.id = :id"); qb.and("i.id = roi.image"); qb.param("id", imageId); qb.filter("fa", filter(opts)); return qb.query(session).list(); } }));
@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { final Filter f = filter(opts); final QueryBuilder qb = new QueryBuilder(); qb.select("distinct r").from("Roi", "r"); qb.join("r.image", "i", false, false); qb.join("r.shapes", "shapes", false, true); // fetch qb.join("r.folderLinks", "folderLinks", true, true); // fetch qb.join("folderLinks.parent", "folder", true, true); // fetch qb.where(); qb.and("i.id = :id"); qb.filter("r", f); qb.filterNow(); qb.order("r.id", true); // ascending qb.param("id", imageId); return qb.queryWithoutFilter(session).list(); } }));
private void ids(Criteria criteria, QueryBuilder qb, String path) { if (values.onlyIds != null) { if (criteria != null) { criteria.add(Restrictions.in("id", values.onlyIds)); } if (qb != null) { String unique = qb.unique_alias("ids"); qb.and(String.format("%sid in (:%s) ", path, unique)); qb.paramList(unique, values.onlyIds); } } }
void on(QueryBuilder qb, boolean equals) { check(); String op = equals ? "=" : "!="; String unique = qb.unique_alias("owner"); qb.and(path); qb.append(" "); qb.append(op); qb.append(" :"); qb.append(unique); qb.appendSpace(); qb.param(unique, id); } }
QueryBuilder qb = new QueryBuilder(); qb.select("link"); qb.from(_parentType + "AnnotationLink", "link"); qb.join("link.parent", "parent", false, false); qb.join("link.child", "child", false, true); qb.join("link.details.creationEvent", "creation", false, true); qb.join("link.details.updateEvent", "update", false, true); qb.where(); qb.and("TRUE = TRUE "); if (childTypes != null && childTypes.size() > 0) { try { Class kls = mapper.omeroClass(_childType, true); qb.and("child.class = " + kls.getName()); } catch (Exception e) { throw new ValidationException("Error mapping: " qb.and(" ( "); String param = qb.unique_alias("ns"); qb.append("child.ns like :" + param); qb.param(param, namespaces.get(0)); for (int i = 1; i < namespaces.size(); i++) { qb.append(" OR "); String param2 = qb.unique_alias("ns"); qb.append("child.ns like :" + param2); qb.param(param2, namespaces.get(i)); qb.append(" ) ");
String[] ann = new String[annotation.length]; QueryBuilder qb = new QueryBuilder(); qb.select("this"); qb.from(cls.getName(), "this"); link[i] = qb.unique_alias("link"); ann[i] = link[i] + "_child"; qb.join("this.annotationLinks", link[i], false, fetch[i]); qb.join(link[i] + ".child", ann[i], false, fetch[i]); qb.join("this.annotationLinks", "fetchannlink" + i, false, true); qb.join("fetchannlink" + i + ".child", "fetchannchild" + i, false, true); qb.where(); for (int i = 0; i < fetchAnnotationsCopy.size(); i++) { qb.and("fetchannchild" + i + ".class = " + fetchAnnotationsCopy.get(i).getSimpleName()); String orderByPath = orderByPath(orderBy); boolean ascending = orderByAscending(orderBy); qb.order("this." + orderByPath, ascending); log.debug(qb.toString()); return qb.query(session).list();
/** * Build a query string based on the current {@link #excludes} {@link List}. * The query expects a single :id parameter to be set on execution. The * {@link #excludes} list is used to filter out unwanted {@link EventLog} * instances. */ private void initQueryString() { List<String> copy = excludes; // Instead of synchronizing QueryBuilder qb = new QueryBuilder(); qb.select("el"); qb.from("EventLog", "el"); qb.where(); qb.and("el.id > :id"); if (copy != null) { for (String exclude : copy) { qb.and("el.entityType != '" + exclude + "'"); } } qb.order("id", true); query = qb.queryString(); }
QueryBuilder qb = new QueryBuilder(256); if (count) { qb.select("count(obj)"); qb.skipFrom(); qb.append(qString.replaceAll("@FETCH@", "")); } else { qb.select("obj"); qb.skipFrom(); qb.append(qString.replaceAll("@FETCH@", "fetch")); qb.skipWhere(); qb.and(""); qb.and("e.experimenter.id = :owner_id"); qb.param("owner_id", parameters.theFilter.ownerId .getValue()); qb.and("e.experimenterGroup.id = :group_id"); qb.param("group_id", parameters.theFilter.groupId .getValue()); qb.append(")"); } else { throw new InternalException("No ownership info for: " String orderBy = ORDERBY.get(type); if (orderBy != null) { qb.append(orderBy);
public Map<String, Long> countLocks(final Session session, final Long id, String[][] checks, String clause) { final QueryBuilder qb = new QueryBuilder(); qb.select("count(x.id)"); qb.from("%s", "x"); qb.join("x.%s", "y", false, false); qb.where(); qb.and("%s.id = :id"); qb.where(); qb.and(clause); qb.appendSpace(); final String queryString = qb.queryString(); final Map<String, Long> counts = new HashMap<String, Long>(); long total = 0L;
public Object call() throws Exception { final QueryBuilder qb = new QueryBuilder(); qb.select("o").from("OriginalFile", "o"); if (!parseAcceptsList(qb, acceptsList)) { long gid = factory.sessionManager .getEventContext(factory.principal) .getCurrentGroupId(); qb.and("o.details.group.id = " + gid); } List<Long> officialIds = scripts.idsInDb(); if (officialIds != null && officialIds.size() > 0) { qb.and("o.id not in (:ids) "); qb.paramList("ids", officialIds); } List<OriginalFile> files = (List<OriginalFile>) factory.executor.execute(__current.ctx, factory.principal, new Executor.SimpleWork(this, "getUserScripts") { @Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { return qb.query(session).list(); } }); IceMapper mapper = new IceMapper(); return mapper.map(files); } });
private void annotatedBetween(AnnotationCriteria ann, QueryBuilder qb, String path) { if (values.annotatedStart != null) { if (ann != null) { ann.getCreate().add( Restrictions .gt("anncreate.time", values.annotatedStart)); } if (qb != null) { String astart = qb.unique_alias("astart"); qb.and(path + "details.creationEvent.time > :" + astart); qb.param(astart, values.annotatedStart); } } if (values.annotatedStop != null) { if (ann != null) { ann.getCreate() .add( Restrictions.lt("anncreate.time", values.annotatedStop)); } if (qb != null) { String astop = qb.unique_alias("astop"); qb.and(path + "details.creationEvent.time < :" + astop); qb.param(astop, values.annotatedStop); } } }
/** * If the current user is not an admin, then this methods adds a subclause * to the HQL: * * AND ( share.owner.id = :userId or user.id = :userId ) * * {@link QueryBuilder#where()} should already have been called. */ protected void applyIfShareAccessible(QueryBuilder qb) { EventContext ec = getSecuritySystem().getEventContext(); if ( ! ec.isCurrentUserAdmin()) { qb.param("userId", ec.getCurrentUserId()); qb.and("("); qb.append("share.owner.id = :userId" ); qb.append(" OR "); qb.append("user.id = :userId" ); qb.append(" ) "); } }
private boolean parseAcceptsList(final QueryBuilder qb, final List<IObject> acceptsList) { qb.where(); scripts.buildQuery(qb); if (acceptsList != null && acceptsList.size() > 0) { for (IObject object : acceptsList) { if (object instanceof Experimenter) { qb.and("o.details.owner.id = :oid"); qb.param("oid", object.getId().getValue()); } else if (object instanceof ExperimenterGroup) { qb.and("o.details.group.id = :gid"); qb.param("gid", object.getId().getValue()); } else { throw new ome.conditions.ValidationException( "Unsupported accept-type: " + object); } } return true; } return false; }
@RolesAllowed("user") public Long aggByQuery(String agg, String field, String query, Parameters params) { if (!AGGS.matcher(agg).matches()) { throw new ValidationException(agg + " does not match " + AGGS); } if (!FIELD.matcher(field).matches()) { throw new ValidationException(field + " does not match " + FIELD); } final QueryBuilder qb = new QueryBuilder(); qb.select(agg + "("+field+")").append(query); qb.params(params); return (Long) getHibernateTemplate().execute( new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return qb.query(session).uniqueResult(); } }); }
/** * Adds a single clause of the form "AND (A OR B ...)" where each * {@link ScriptFileType} A, B, etc. is given a chance to define * its own clause. */ public void buildQuery(QueryBuilder qb) { boolean first = true; qb.and(" ("); // will prepend "AND" if not first clause. for (String mimetype : mimetypes) { if (first) { first = false; } else { qb.append(" OR "); } qb.append("o.mimetype = '" + mimetype + "'"); } qb.append(") "); }
private void applyOwnerGroup(final Parameters p, QueryBuilder qb, String ownerPath, String groupPath) { if (p != null && p.theFilter != null) { Filter f = p.theFilter; if (f.ownerId != null) { qb.and(ownerPath + " = :owner_id "); qb.param("owner_id", f.ownerId.getValue()); } if (f.groupId != null) { qb.and(groupPath + " = :group_id "); qb.param("group_id", f.groupId.getValue()); } } }
public Object doInHibernate(Session session) throws HibernateException, SQLException { return qb.query(session).list(); } });
public Object call() throws Exception { final QueryBuilder qb = new QueryBuilder(); qb.select("o").from("OriginalFile", "o");
private Query __query(Session session, boolean usefilter) { filterNow(); final String s = queryString(); if (sqlQuery) { q = session.createSQLQuery(queryString()); } else { q = session.createQuery(queryString()); log.warn("Failed query: " + queryString(), rt); throw rt;