Exemple #1
0
  /**
   * Method to get the original file of the script with id. This method will not throw an exception,
   * but instead will return null.
   *
   * @param name See above.
   * @return original file or null if script does not exist or more than one script with name
   *     exists.
   */
  @SuppressWarnings("unchecked")
  private OriginalFile getOriginalFileOrNull(long id, final Ice.Current current) {

    try {
      final QueryBuilder qb = new QueryBuilder();
      qb.select("o").from("OriginalFile", "o");
      qb.where();
      scripts.buildQuery(qb);
      qb.and("o.id = :id");
      qb.param("id", id);

      OriginalFile file =
          (OriginalFile)
              factory.executor.execute(
                  current.ctx,
                  factory.principal,
                  new Executor.SimpleWork(this, "getOriginalFileOrNull", id) {

                    @Transactional(readOnly = true)
                    public Object doWork(Session session, ServiceFactory sf) {
                      return qb.query(session).uniqueResult();
                    }
                  });
      return file;
    } catch (RuntimeException re) {
      return null;
    }
  }
Exemple #2
0
  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;
  }
  @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();
  }