Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  protected List<Object[]> getSavedSearchDetails(Long savedSearchQueryID, String type) {
    SavedSearchRetriever.AlertType alertType = SavedSearchRetriever.AlertType.valueOf(type);

    DetachedCriteria criteria =
        DetachedCriteria.forClass(UserProfile.class)
            .setProjection(
                Projections.distinct(
                    Projections.projectionList()
                        .add(Projections.property("ss.ID"))
                        .add(Projections.property("email"))
                        .add(Projections.property("ss.searchName"))))
            .createAlias("savedSearches", "ss")
            .createAlias("ss.searchQuery", "q")
            .add(Restrictions.eq("q.ID", savedSearchQueryID));

    if (alertType == SavedSearchRetriever.AlertType.WEEKLY) {
      criteria.add(Restrictions.eq("ss.weekly", true));
    }

    if (alertType == SavedSearchRetriever.AlertType.MONTHLY) {
      criteria.add(Restrictions.eq("ss.monthly", true));
    }

    return (List<Object[]>) hibernateTemplate.findByCriteria(criteria);
  }
  public void prepareDateRange() throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(ConfirmationRecord.class);
    ProjectionList pjl = Projections.projectionList();
    pjl.add(Projections.property("cycleFrom"));
    pjl.add(Projections.property("cycleTo"));
    criteria.setProjection(Projections.distinct(pjl));

    List<?> list = confirmationRecordService.findByCriteria(criteria);
    if (list.size() > 0) {
      Object[] objs = list.toArray();
      selectionCycleFrom = new ArrayList<>();
      selectionCycleFrom.add(new SelectItem(null, "Please Select"));
      cycleTos = new ArrayList<>();

      for (Object obj : objs) {
        if (obj instanceof Object[]) {
          Object[] innerObjs = (Object[]) obj;
          if (innerObjs.length == 2) {
            Date dFrom = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[0].toString());
            Date dTo = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[1].toString());
            selectionCycleFrom.add(
                new SelectItem(
                    DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dFrom),
                    DateUtil.convDateToString(DISPLAY_DATE_PATTERN, dFrom)));
            cycleTos.add(DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dTo));
          } else {
            System.err.println("ERR: obj[] length not eq to 2");
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
 @SuppressWarnings("unchecked")
 public List<String> listStringByFields(String field) {
   Criteria criteria = getCurrentSession().createCriteria(Titem.class);
   criteria.setProjection(Projections.distinct(Projections.property(field)));
   criteria.addOrder(Order.asc(field));
   List<String> list = criteria.list();
   return list;
 }
Ejemplo n.º 4
0
  @Override
  public int getFormsCount(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.countDistinct("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
 public List<String> getSharedListUserNames() {
   DetachedCriteria criteria = DetachedCriteria.forClass(CustomSeriesList.class);
   ProjectionList projectionList = Projections.projectionList();
   projectionList.add(Projections.property("userName"));
   criteria.setProjection(Projections.distinct(projectionList));
   List<String> results = new ArrayList<String>();
   results = getHibernateTemplate().findByCriteria(criteria);
   return results;
 }
Ejemplo n.º 6
0
 @SuppressWarnings("unchecked")
 @Override
 public ResultList getUnique(String key, String query) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PersonName.class);
   criteria.add(Restrictions.ilike(key, query + "%"));
   criteria.setProjection(Projections.distinct(Projections.property(key)));
   criteria.setMaxResults(20);
   return new ResultList(criteria.list());
 }
Ejemplo n.º 7
0
  @Override
  @SuppressWarnings("unchecked")
  public List<String> getFormNames(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.property("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return getHibernateTemplate().findByCriteria(criteria);
  }
Ejemplo n.º 8
0
  private <P> Criteria buildProjectionCriteria(
      Class<P> projectClass, Criteria criteria, Projection projections, boolean distinctResult) {
    if (distinctResult) {
      criteria.setProjection(Projections.distinct(projections));
    } else {
      criteria.setProjection(projections);
    }

    return criteria.setResultTransformer(Transformers.aliasToBean(projectClass));
  }
Ejemplo n.º 9
0
 @SuppressWarnings("unchecked")
 public List<String> getAllHomeDepartments(ObjectStatus status) {
   Criteria criteria = createCriteria();
   if (status != null) criteria.add(Restrictions.eq("objectStatus", status));
   criteria.add(Restrictions.isNotNull("departmentName"));
   criteria.setProjection(
       Projections.projectionList()
           .add(Projections.distinct(Projections.property("departmentName"))));
   return ((List<String>) criteria.list());
 }
  @SuppressWarnings("unchecked")
  @Override
  public List<Oficina> listarOficinas(Integer idInscricaoCurso) {
    Criteria criteria = getSession().createCriteria(Oficina.class);
    DetachedCriteria subCriteria = DetachedCriteria.forClass(SelecaoOficina.class);
    subCriteria.add(Property.forName("inscricaoCurso.id").eq(idInscricaoCurso));
    subCriteria.setProjection(Projections.distinct(Projections.property("oficina.id")));

    criteria.add(Property.forName("id").in(subCriteria));
    return criteria.list();
  }
 @SuppressWarnings("unchecked")
 @Override
 public List<Integer> recuperarIdsOficinasDisponiveis(Integer idCursoSelecionado) {
   Criteria criteria = getSession().createCriteria(Oficina.class);
   if (idCursoSelecionado != null && !idCursoSelecionado.equals(0)) {
     criteria.createAlias("curso", "curso");
     criteria.add(Restrictions.eq("curso.id", idCursoSelecionado));
     criteria.setProjection(Projections.distinct(Projections.property("id")));
   }
   return criteria.list();
 }
Ejemplo n.º 12
0
  public List<DmAccount> getListOwnerByPermittedAccount(
      String accountId, Integer permissionLevelStart) {
    DmAccount permittedAccount = null;
    if (accountId != null) {
      permittedAccount = new DmAccount();
      permittedAccount.setId(accountId);
    }

    List<DmAccount> ownerList = null;
    if (permittedAccount != null) {
      Criteria crit = getSession().createCriteria(DmFolder.class);
      crit.setProjection(Projections.distinct(Projections.property("owner")));
      crit.add(Restrictions.ne("owner", permittedAccount));
      //            crit.setProjection(Projections.property("owner"));

      //            crit.add(Restrictions.eq("owner", accountOwner));
      //            crit.add(Restrictions.isNull("parent"));
      //            crit.addOrder(Order.asc("name"));
      //            if (permissionLevelStart != null) {
      //                crit.createCriteria("permissionList").add(Restrictions.ge("permissionType",
      // permissionLevelStart));
      //            }
      //            Criterion permissionCrit = null;

      Conjunction conjunction = Restrictions.conjunction();
      if (permissionLevelStart != null) {
        conjunction.add(Restrictions.ge("permissionType", permissionLevelStart));
      }
      conjunction.add(Restrictions.eq("account", permittedAccount));

      crit.createCriteria("permissionList").add(conjunction);

      ownerList = crit.list();

      //            if (ownerList != null) {
      //                for (DmAccount owner : ownerList) {
      //                    System.out.println("name = " + owner.getName());
      //                }
      //            }
      // start - get children for each child (trigger lazy fetch)
      //            for (DmFolder folderTmp : folderList) {
      //                if (folderTmp.getChildList() != null) {
      //                    folderTmp.getChildList().size();
      //                }
      //            }
      // end - get children for each child (trigger lazy fetch)
    }

    return ownerList;
    //        return null;
  }
  @SuppressWarnings("unchecked")
  @Override
  public List<Oficina> recuperarOficina(Integer idCurso, Integer idPacote) {
    Criteria criteria = getSession().createCriteria(Oficina.class);

    DetachedCriteria subCriteria = DetachedCriteria.forClass(PacoteOficina.class);
    subCriteria.createAlias("pacote", "p");
    subCriteria.add(Property.forName("p.id").eq(idPacote));
    subCriteria.createAlias("p.curso", "c");
    subCriteria.add(Property.forName("c.id").eq(idCurso));
    subCriteria.setProjection(Projections.distinct(Projections.property("oficina.id")));

    criteria.add(Property.forName("id").in(subCriteria));
    return criteria.list();
  }
    @Override
    protected Set<String> loadInitialShardNames(Properties properties, BuildContext buildContext) {
      ServiceManager serviceManager = buildContext.getServiceManager();
      SessionFactory sessionFactory =
          serviceManager.requestService(HibernateSessionFactoryService.class).getSessionFactory();
      Session session = sessionFactory.openSession();
      try {
        Criteria initialShardsCriteria = session.createCriteria(Animal.class);
        initialShardsCriteria.setProjection(Projections.distinct(Property.forName("type")));

        @SuppressWarnings("unchecked")
        List<String> initialTypes = initialShardsCriteria.list();
        return new HashSet<String>(initialTypes);
      } finally {
        session.close();
      }
    }
  public Collection<String> findAllQuantificationNames() throws DataAccessException {

    DetachedCriteria criteria = DetachedCriteria.forClass(AimQuantification.class, "q");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("name"));

    criteria.setProjection(Projections.distinct(projectionList));

    Collection<String> names = new ArrayList<String>();

    Collection<String> results = getHibernateTemplate().findByCriteria(criteria);
    for (String result : results) {
      names.add(result);
    }
    return names;
  }
Ejemplo n.º 16
0
  @Override
  public List<String> fetchDistinctCampaignIds() {
    Session session = null;
    List<String> list = null;
    try {
      session = sessionFactory.openSession();
      Criteria criteria = session.createCriteria(CampaignInfo.class);
      ProjectionList projList = Projections.projectionList();
      projList.add(Projections.property("campaignId"));
      criteria.setProjection(Projections.distinct(projList));
      list = criteria.list();

    } catch (HibernateException e) {
      LOGGER.error("HibernateException while Geeting Campaign ID >>" + e.getMessage());
    } finally {
      session.clear();
    }
    return list;
  }
  private List<Object[]> getSharedListResult(List<String> seriesUids) {
    List<Object[]> results = new ArrayList<Object[]>();

    if (seriesUids != null && seriesUids.size() != 0) {
      DetachedCriteria criteria = DetachedCriteria.forClass(CustomSeriesListAttribute.class);
      ProjectionList projectionList = Projections.projectionList();

      projectionList.add(Projections.property("csl.userName"));
      projectionList.add(Projections.property("csl.name"));
      projectionList.add(Projections.property("seriesInstanceUid"));

      criteria.setProjection(Projections.distinct(projectionList));

      criteria.createAlias("parent", "csl");

      criteria.add(Restrictions.in("seriesInstanceUid", seriesUids));

      results = getHibernateTemplate().findByCriteria(criteria);
    }

    return results;
  }
 public List<String> findBallTypes() {
   return getSession()
       .createCriteria(GameEntity.class)
       .setProjection(Projections.distinct(Projections.property("ballType")))
       .list();
 }
Ejemplo n.º 19
0
  @Override
  public List<OnmsAssetRecord> getDistinctProperties() {
    DetachedCriteria criteria = DetachedCriteria.forClass(OnmsAssetRecord.class);
    ProjectionList projList = Projections.projectionList();

    projList.add(
        Projections.alias(Projections.property("additionalhardware"), "additionalhardware"));
    projList.add(Projections.alias(Projections.property("address1"), "address1"));
    projList.add(Projections.alias(Projections.property("address2"), "address2"));
    projList.add(Projections.alias(Projections.property("admin"), "admin"));
    projList.add(Projections.alias(Projections.property("assetNumber"), "assetNumber"));
    projList.add(Projections.alias(Projections.property("autoenable"), "autoenable"));
    projList.add(Projections.alias(Projections.property("building"), "building"));
    projList.add(Projections.alias(Projections.property("category"), "category"));
    projList.add(Projections.alias(Projections.property("circuitId"), "circuitId"));
    projList.add(Projections.alias(Projections.property("city"), "city"));
    projList.add(Projections.alias(Projections.property("comment"), "comment"));
    projList.add(Projections.alias(Projections.property("connection"), "connection"));
    projList.add(Projections.alias(Projections.property("cpu"), "cpu"));
    projList.add(Projections.alias(Projections.property("department"), "department"));
    projList.add(Projections.alias(Projections.property("description"), "description"));
    projList.add(Projections.alias(Projections.property("displayCategory"), "displayCategory"));
    projList.add(Projections.alias(Projections.property("division"), "division"));
    projList.add(Projections.alias(Projections.property("enable"), "enable"));
    projList.add(Projections.alias(Projections.property("floor"), "floor"));
    projList.add(Projections.alias(Projections.property("hdd1"), "hdd1"));
    projList.add(Projections.alias(Projections.property("hdd2"), "hdd2"));
    projList.add(Projections.alias(Projections.property("hdd3"), "hdd3"));
    projList.add(Projections.alias(Projections.property("hdd4"), "hdd4"));
    projList.add(Projections.alias(Projections.property("hdd5"), "hdd5"));
    projList.add(Projections.alias(Projections.property("hdd6"), "hdd6"));
    projList.add(Projections.alias(Projections.property("inputpower"), "inputpower"));
    projList.add(Projections.alias(Projections.property("lease"), "lease"));
    projList.add(Projections.alias(Projections.property("maintcontract"), "maintcontract"));
    projList.add(Projections.alias(Projections.property("manufacturer"), "manufacturer"));
    projList.add(Projections.alias(Projections.property("modelNumber"), "modelNumber"));
    projList.add(Projections.alias(Projections.property("notifyCategory"), "notifyCategory"));
    projList.add(Projections.alias(Projections.property("numpowersupplies"), "numpowersupplies"));
    projList.add(Projections.alias(Projections.property("operatingSystem"), "operatingSystem"));
    projList.add(Projections.alias(Projections.property("pollerCategory"), "pollerCategory"));
    projList.add(Projections.alias(Projections.property("port"), "port"));
    projList.add(Projections.alias(Projections.property("rack"), "rack"));
    projList.add(Projections.alias(Projections.property("ram"), "ram"));
    projList.add(Projections.alias(Projections.property("region"), "region"));
    projList.add(Projections.alias(Projections.property("room"), "room"));
    projList.add(Projections.alias(Projections.property("serialNumber"), "serialNumber"));
    projList.add(Projections.alias(Projections.property("slot"), "slot"));
    projList.add(Projections.alias(Projections.property("snmpcommunity"), "snmpcommunity"));
    projList.add(Projections.alias(Projections.property("state"), "state"));
    projList.add(Projections.alias(Projections.property("storagectrl"), "storagectrl"));
    projList.add(Projections.alias(Projections.property("supportPhone"), "supportPhone"));
    projList.add(Projections.alias(Projections.property("thresholdCategory"), "thresholdCategory"));
    projList.add(Projections.alias(Projections.property("username"), "username"));
    projList.add(Projections.alias(Projections.property("vendor"), "vendor"));
    projList.add(Projections.alias(Projections.property("vendorAssetNumber"), "vendorAssetNumber"));
    projList.add(Projections.alias(Projections.property("vendorFax"), "vendorFax"));
    projList.add(Projections.alias(Projections.property("vendorPhone"), "vendorPhone"));
    projList.add(Projections.alias(Projections.property("zip"), "zip"));

    criteria.setProjection(Projections.distinct(projList));
    criteria.setResultTransformer(Transformers.aliasToBean(OnmsAssetRecord.class));

    @SuppressWarnings("unchecked")
    List<OnmsAssetRecord> result = getHibernateTemplate().findByCriteria(criteria);
    return result;
  }