@Override protected void buildQuery(Session session) throws HibernateException, SQLException { // TODO copied from PojosGetImagesQueryDefinition. Should be merged. QueryBuilder qb = new QueryBuilder(); qb.select("img"); qb.from("Image", "img"); qb.join("img.details.creationEvent", "ce", true, true); qb.join("img.details.updateEvent", "ue", true, true); qb.join("img.pixels", "pix", true, true); qb.join("pix.pixelsType", "pt", true, true); qb.join("img.annotationLinksCountPerOwner", "i_c_ann", true, true); // qb.join("img.datasetLinksCountPerOwner", "i_c_ds", true, true); if (params.isAcquisitionData()) { qb.join("img.stageLabel", "position", true, true); qb.join("img.imagingEnvironment", "condition", true, true); qb.join("img.objectiveSettings", "os", true, true); qb.join("os.medium", "me", true, true); qb.join("os.objective", "objective", true, true); qb.join("objective.immersion", "im", true, true); qb.join("objective.correction", "co", true, true); } qb.where(); // if PojoOptions sets START_TIME and/or END_TIME if (params.getStartTime() != null) { qb.and("img.details.creationEvent.time > :starttime"); qb.param("starttime", params.getStartTime()); } if (params.getEndTime() != null) { qb.and("img.details.creationEvent.time < :endtime"); qb.param("endtime", params.getEndTime()); } setQuery(qb.query(session)); }
@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { String[] link = new String[annotation.length]; String[] ann = new String[annotation.length]; QueryBuilder qb = new QueryBuilder(); qb.select("this"); qb.from(cls.getName(), "this"); // Joins for (int i = 0; i < ann.length; i++) { if (value[i] != null) { 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]); } } // fetch annotations for (int i = 0; i < fetchAnnotationsCopy.size(); 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()); } ids(qb, "this."); ownerOrGroup(cls, qb, "this."); createdOrModified(cls, qb, "this."); for (int j = 0; j < annotation.length; j++) { // Main criteria if (useNamespace) { notNullOrLikeOrEqual( qb, ann + ".ns", type[j], annotation[j].getNs(), useLike, values.caseSensitive); } // If the value of the annotation is null, we assume that we are not // actually searching for null annotations (whose nullability is // actually a by-product of polymorphism), instead we assume the // null acts like a wildcard, in which case this search has been // added to the fetchAnnotationsCopy collection above. if (value[j] != null) { notNullOrLikeOrEqual( qb, ann[j] + "." + path[j], type[j], value[j], useLike, values.caseSensitive); } annotatedBetween(qb, ann[j] + "."); annotatedBy(qb, ann[j] + "."); } // orderBy for (String orderBy : values.orderBy) { String orderByPath = orderByPath(orderBy); boolean ascending = orderByAscending(orderBy); qb.order("this." + orderByPath, ascending); } log.debug(qb.toString()); return qb.query(session).list(); }