Esempio n. 1
0
 public StorageDevice getDeviceById(final Integer datacenterId, final Integer deviceId) {
   Criteria criteria =
       createCriteria(Restrictions.eq("datacenter.id", datacenterId))
           .add(Restrictions.eq("id", deviceId));
   Object obj = criteria.uniqueResult();
   return (StorageDevice) obj;
 }
Esempio n. 2
0
 public static Group findByOrgAndName(Organisation org, String name, Session session) {
   Criteria crit = session.createCriteria(Group.class);
   crit.setCacheable(true);
   crit.add(Restrictions.eq("organisation", org));
   crit.add(Restrictions.eq("name", name));
   return (Group) crit.uniqueResult();
 }
Esempio n. 3
0
  /**
   * Tìm kiếm nhanh
   *
   * @param c Tiêu chí tìm kiếm
   * @return Danh sách các điện thoại thỏa tiêu chí tìm kiếm
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(QuickSearchCriteria c) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (c.getIdHangDienThoai() > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", c.getIdHangDienThoai());
      criteria.add(manufacture);
    }

    if (c.getTenDienThoai() != null) {
      Criterion name = Restrictions.like("ten", "%" + c.getTenDienThoai() + "%");
      criteria.add(name);
    }

    if (c.getGiaTu() >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", c.getGiaTu());
      criteria.add(minPrice);
    }

    if (c.getGiaDen() >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", c.getGiaDen());
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
Esempio n. 4
0
  @SuppressWarnings("unchecked")
  public static java.util.List<Object> getListData(
      Class<?> classBean, String strKey1, Object value1, String strKey2, Object value2) {
    java.util.List<Object> result = new java.util.ArrayList<Object>();
    Session session = null;
    try {
      session = sessionFactory.openSession();
      Transaction tx = session.beginTransaction();

      Criteria criteria = session.createCriteria(classBean);
      if (strKey1 != null) {
        criteria.add(Restrictions.like(strKey1, value1));
      }
      if (strKey2 != null) {
        criteria.add(Restrictions.like(strKey2, value2));
      }

      result = criteria.list();

      tx.commit();

    } finally {
      if (session != null) {
        session.close();
      }
    }
    return result;
  }
 @Override
 @SuppressWarnings("unchecked")
 public List<ProgramInstance> get(TrackedEntityInstance entityInstance, Program program) {
   return getCriteria(
           Restrictions.eq("entityInstance", entityInstance), Restrictions.eq("program", program))
       .list();
 }
Esempio n. 6
0
 @Override
 public List<Participation> getMarkersAvailableParticipations(Group group) {
   if (group.getTutors().size() > 0) {
     Integer[] ids = new Integer[group.getTutors().size()];
     int i = 0;
     for (Participation participation : group.getTutors()) {
       ids[i++] = participation.getId();
     }
     return getSession()
         .createCriteria(Participation.class)
         .add(Restrictions.eq("lecture", group.getLecture()))
         .add(
             Restrictions.or(
                 Restrictions.eq("role", ParticipationRole.TUTOR.toString()),
                 Restrictions.eq("role", ParticipationRole.ADVISOR.toString())))
         .add(Restrictions.not(Restrictions.in("id", ids)))
         .createCriteria("user")
         .addOrder(Order.asc("lastName"))
         .addOrder(Order.asc("firstName"))
         .list();
   } else {
     return getSession()
         .createCriteria(Participation.class)
         .add(Restrictions.eq("lecture", group.getLecture()))
         .add(
             Restrictions.or(
                 Restrictions.eq("role", ParticipationRole.TUTOR.toString()),
                 Restrictions.eq("role", ParticipationRole.ADVISOR.toString())))
         .createCriteria("user")
         .addOrder(Order.asc("lastName"))
         .addOrder(Order.asc("firstName"))
         .list();
   }
 }
  @SuppressWarnings("unchecked")
  public List<DeliveryOrder> getUnexportDeliveryOrderByPlant(Plant plant) {
    DetachedCriteria criteria = DetachedCriteria.forClass(DeliveryOrder.class);
    criteria.createAlias("plantSupplier", "ps");

    criteria.add(Restrictions.eq("ps.plant", plant));
    criteria.add(Restrictions.eq("isPrint", true));
    criteria.add(Restrictions.eq("isExport", false));
    criteria.add(Restrictions.eq("status", "Confirm"));
    criteria.add(Restrictions.eq("ps.needExportDo", true));
    criteria.addOrder(Order.asc("createDate"));

    List<DeliveryOrder> deliveryOrderList = this.findByCriteria(criteria);

    if (deliveryOrderList != null && deliveryOrderList.size() > 0) {
      for (int i = 0; i < deliveryOrderList.size(); i++) {
        DeliveryOrder deliveryOrder = deliveryOrderList.get(i);

        if (deliveryOrder.getDeliveryOrderDetailList() != null
            && deliveryOrder.getDeliveryOrderDetailList().size() > 0) {}
      }
    }

    return deliveryOrderList;
  }
Esempio n. 8
0
  public static void readAll(SessionFactory factory) {

    Session session = factory.openSession();

    Transaction transaction = session.beginTransaction();

    Criterion criterion1 = Restrictions.gt("salary", 40000);
    Criterion criterion2 = Restrictions.eq("dept", "GM");
    Criterion criterionOr = Restrictions.or(criterion1, criterion2);

    Criteria criteria = session.createCriteria(Employee.class);
    criteria.add(criterionOr);

    List<Employee> list = criteria.list();

    for (Employee e : list) {
      System.out.println(e.getId());
      System.out.println(e.getName());
      System.out.println(e.getSalary());
      System.out.println(e.getDesig());
      System.out.println(e.getDept());
      System.out.println("==============");
    }

    transaction.commit();

    session.close();
  }
Esempio n. 9
0
 @SuppressWarnings("unchecked")
 @Override
 public List<Sales> getPendingSalesBetween(Date startDate, Date endDate) throws Exception {
   Session session = HibernateUtil.startSession();
   Criteria criteria = session.createCriteria(Sales.class);
   criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
   List<Sales> sales = new ArrayList<Sales>();
   try {
     Date lowerBound = DateTool.getTomorrowDate(DateTool.getDateWithoutTime(startDate));
     Date upperBound = DateTool.getDateWithoutTime(endDate);
     sales =
         criteria
             .add(Restrictions.ge("date", lowerBound))
             .add(Restrictions.lt("date", upperBound))
             .add(Restrictions.eq("valid", true))
             .add(Restrictions.isNull("inventorySheetData"))
             .addOrder(Order.desc("date"))
             .list();
   } catch (HibernateException ex) {
     ex.printStackTrace();
   } finally {
     session.close();
   }
   return sales;
 }
Esempio n. 10
0
  public ArrayList<Candidate> getNumOfCandidateConstituency(Long constituency, String elecid) {
    Session session = null;
    ArrayList<String> numcon = new ArrayList<String>();
    ArrayList<Candidate> numcan = new ArrayList<Candidate>();
    Criteria ctr;
    try {
      session = getSessionFactory().openSession();
      ctr = session.createCriteria(Locations.class);
      ctr.add(Restrictions.eq("elecid", elecid));
      ctr.add(Restrictions.eq("constituency", constituency));
      if (ctr.list().size() > 0) {
        ctr = session.createCriteria(Candidate.class);
        ctr.add(Restrictions.eq("constituency", constituency));
        ctr.add(Restrictions.eq("validity", Candidate.ACCEPTED));
        for (int i = 0; ctr.list().size() > 0 && i < ctr.list().size(); i++)
          numcan.add((Candidate) ctr.list().get(i));
      }

    } catch (HibernateException e) {
      System.err.println("Error: file: LocationsDAO method: getNumOfCOnsti()");
    } finally {
      if (session != null) session.close();
    }

    return numcan;
  }
Esempio n. 11
0
  /**
   * Search Value2 by detached criteria Test
   *
   * @throws ApplicationException
   */
  @SuppressWarnings("unchecked")
  public void testIvlRealValue3ByDetachedCriteria() throws ApplicationException {
    DetachedCriteria criteria = DetachedCriteria.forClass(IvlRealDataType.class);
    LogicalExpression exp1 =
        Restrictions.or(
            Property.forName("value3.high.value").isNotNull(),
            Property.forName("value3.low.value").isNotNull());
    LogicalExpression exp2 =
        Restrictions.or(
            Property.forName("value3.width.value").isNotNull(),
            Property.forName("value3.width.nullFlavor").isNotNull());
    LogicalExpression exp3 = Restrictions.or(exp1, exp2);
    criteria.add(Restrictions.or(Property.forName("value3.nullFlavor").isNotNull(), exp3));

    criteria.addOrder(Order.asc("id"));

    Collection<IvlRealDataType> result =
        search(criteria, "gov.nih.nci.cacoresdk.domain.other.datatype.IvlRealDataType");
    assertEquals(10, result.size());
    List index = new ArrayList();
    index.add("13");
    index.add("14");
    index.add("15");
    index.add("16");
    index.add("17");
    index.add("18");
    index.add("19");
    index.add("20");
    index.add("21");
    index.add("22");
    assertValue3(result, index);
  }
Esempio n. 12
0
  public ArrayList<Election> getElectionByConstituency(Long constituency) {
    Session session = null;

    ArrayList<Election> eleclist = new ArrayList<Election>();
    Criteria ctr, tempctr;
    try {
      session = getSessionFactory().openSession();
      ctr = session.createCriteria(Locations.class);
      ctr.add(Restrictions.eq("constituency", constituency));
      for (int i = 0; ctr.list().size() > 0 && i < ctr.list().size(); i++) {
        tempctr = session.createCriteria(Election.class);
        tempctr.add(Restrictions.eq("validity", Election.NOTDONE));
        tempctr.add(Restrictions.idEq(((Locations) ctr.list().get(i)).getElecid()));
        tempctr.add(Restrictions.le("start", new Timestamp(new Date().getTime())));
        tempctr.add(Restrictions.ge("end", new Timestamp(new Date().getTime())));
        if (tempctr.list().size() > 0) eleclist.add((Election) tempctr.list().get(0));
      }

    } catch (HibernateException e) {
      System.err.println("Error: file: LocationsDAO method: getNumOfCOnsti()");
    } finally {
      if (session != null) session.close();
    }

    return eleclist;
  }
  @Override
  public String input() throws Exception {
    this.sysUser = service.getUser(userid);
    set("sysUser", sysUser);

    // 也显示全国律协的以及系统层级的

    System.out.println("===================" + sysUser.getCityid());
    this.datavisible.setProvinceid(sysUser.getProvinceid());
    this.datavisible.setCityid(sysUser.getCityid());
    this.datavisible.setOfficeid(sysUser.getOfficeid());

    this.datavisible.getVisibleDatas(this.getLoginUser(), true);

    SysRole sysrole = this.getLoginUser().getSysRole();
    if (sysrole != null) {
      BasicService bs = (BasicService) this.getBean("basicService");
      DetachedCriteria dc = DetachedCriteria.forClass(SysRole.class);
      Criterion c1 = null;
      if (sysrole.getCansamegrade()) c1 = Restrictions.ge("gradeid", sysrole.getGradeid());
      else c1 = Restrictions.gt("gradeid", sysrole.getGradeid());
      Criterion c2 = Restrictions.eq("roleid", sysrole.getRoleid());
      dc.add(Restrictions.or(c1, c2));
      allroles = bs.findAllByCriteria(dc);

    } else { // 没角色的话,显示所有的角色
      SysRoleService roleService = (SysRoleService) this.getBean("sysRoleService");
      allroles = roleService.getRoles();
    }

    return INPUT;
  }
Esempio n. 14
0
 public StorageDevice findDeviceById(final Integer datacenterId, final String managementIp) {
   Criteria criteria =
       createCriteria(Restrictions.eq("datacenter.id", datacenterId))
           .add(Restrictions.eq("managementIp", managementIp));
   Object obj = criteria.uniqueResult();
   return (StorageDevice) obj;
 }
 private Criteria getHBCriteria(Session session, SearchCriteria criteria) {
   Criteria newCriteria = session.createCriteria(WarrantyInformationType.class);
   if (criteria.getInternalId() != null) {
     newCriteria.add(Restrictions.eq("internalId", criteria.getInternalId()));
   }
   if ((criteria.ascending != null) && (criteria.ascending.contains("internalId")))
     newCriteria.addOrder(Order.asc("internalId"));
   else if ((criteria.descending != null) && (criteria.descending.contains("internalId")))
     newCriteria.addOrder(Order.desc("internalId"));
   if (criteria.getVersion() != null) {
     newCriteria.add(Restrictions.eq("version", criteria.getVersion()));
   }
   if ((criteria.ascending != null) && (criteria.ascending.contains("version")))
     newCriteria.addOrder(Order.asc("version"));
   else if ((criteria.descending != null) && (criteria.descending.contains("version")))
     newCriteria.addOrder(Order.desc("version"));
   if (criteria.getValue() != null) {
     newCriteria.add(Restrictions.eq("value", criteria.getValue()));
   }
   if ((criteria.ascending != null) && (criteria.ascending.contains("value")))
     newCriteria.addOrder(Order.asc("value"));
   else if ((criteria.descending != null) && (criteria.descending.contains("value")))
     newCriteria.addOrder(Order.desc("value"));
   if (criteria.getLanguageID() != null) {
     newCriteria.add(Restrictions.eq("languageID", criteria.getLanguageID()));
   }
   if ((criteria.ascending != null) && (criteria.ascending.contains("languageID")))
     newCriteria.addOrder(Order.asc("languageID"));
   else if ((criteria.descending != null) && (criteria.descending.contains("languageID")))
     newCriteria.addOrder(Order.desc("languageID"));
   return newCriteria;
 }
  @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);
  }
Esempio n. 17
0
  /**
   * 查询一个对象的属性值在数据库中是不是唯一
   *
   * @param entity 实体对象
   * @param propertyNames 属性的名称,可多个 如:"prop1,prop2"
   * @return 针对 编辑 对象保存时 如果和其它 对象 属性名称相同 抛出异常问题 重写此方法
   */
  public boolean isUnique(Object entity, String propertyNames) {
    Class<?> clazz = getTrueClass(entity);
    Criteria criteria = createCriteria(clazz).setProjection(Projections.rowCount());
    String[] nameList = propertyNames.split(",");
    try {
      boolean isQuery = false;
      for (String name : nameList) {
        Object obj = PropertyUtils.getProperty(entity, name);
        if (obj != null) {
          criteria.add(Restrictions.eq(name, obj));
          isQuery = true;
        } else {
          isQuery = false;
        }
      }
      if (!isQuery) {
        return true;
      }

      String idName = getIdName(clazz);
      Serializable id = getId(clazz, entity);
      if (id != null) {
        criteria.add(Restrictions.not(Restrictions.eq(idName, id)));
      }
    } catch (Exception e) {
      ReflectionUtils.handleReflectionException(e);
    }
    this.getSession().evict(entity);
    return (Integer) criteria.uniqueResult() == 0;
  }
Esempio n. 18
0
  @SuppressWarnings("unchecked")
  @Override
  public Object tryAndFindLookupValue(
      final String systemName,
      final String tableName,
      final String columnName,
      final String lookupValue)
      throws ClassNotFoundException {

    final List<PhysicalToPhysicalLookupView> physicalLookups =
        getSession()
            .createCriteria(PhysicalToPhysicalLookupView.class)
            .add(Restrictions.eq("id.systemName", systemName))
            .add(Restrictions.eq("id.tableName", tableName))
            .add(Restrictions.eq("id.columnNume", columnName))
            .list();

    if (physicalLookups == null || physicalLookups.size() != 2) {
      // do nothing - return a warning if > 2
      return null;
    }

    String lookupSystem = "";
    String lookupTable = "";
    String lookupColumn = "";
    String projection = "";

    for (final PhysicalToPhysicalLookupView lookup : physicalLookups) {
      if (lookup.getId().getNameRuleType().equals(LOOKUP_KEY)) {
        lookupSystem = lookup.getId().getSystemName();
        lookupTable = lookup.getId().getLookupTable();
        lookupColumn = lookup.getId().getLookupColumn();
      }
      if (lookup.getId().getNameRuleType().equals(LOOKUP_VALUE)) {
        projection = lookup.getId().getLookupColumn();
      }
    }

    if (lookupSystem == null || lookupTable == null || lookupColumn == null || projection == null) {
      throw new RuntimeException(
          "Unable to create a lookup map for system name: "
              + systemName
              + " on table "
              + tableName
              + " with column "
              + columnName);
    }

    final Class<?> clazz = null; // explorer.getClass(lookupTable,
    // systemName.toLowerCase(),"com.equityopschange.systems");

    final Object lookedUpValue =
        getSession()
            .createCriteria(clazz)
            .add(Restrictions.eq(lookupColumn, lookupValue))
            .setProjection(Projections.property(projection))
            .uniqueResult();

    return lookedUpValue;
  }
Esempio n. 19
0
 private void filtroPorStatus(Emprestimo filtro, Criteria criteria) {
   if (filtro.getOpFiltro() == 2) {
     criteria.add(Restrictions.isNull("c.dataDevolucao"));
   } else if (filtro.getOpFiltro() == 3) {
     criteria.add(Restrictions.isNotNull("c.dataDevolucao"));
   }
 }
Esempio n. 20
0
 public Sample getSample(Long projectId, String sampleName, Session session) throws DAOException {
   Sample retVal = null;
   try {
     Criteria crit = session.createCriteria(Sample.class);
     crit.add(
         Restrictions.and(
             Restrictions.eq("sampleName", sampleName), Restrictions.eq("projectId", projectId)));
     List results = crit.list();
     if (results != null) {
       if (results.size() == 1) {
         retVal = (Sample) results.get(0);
       } else if (results.size() > 1) {
         throw new DAOException(
             "Found "
                 + results.size()
                 + " samples for sample name "
                 + sampleName
                 + " but expected only 1.");
       }
     }
   } catch (Exception ex) {
     throw new DAOException(ex);
   }
   return retVal;
 }
 public PagingWrapper<ChallengeChallengeReferral> getAllforChallengeReferralAndChallenge(
     final UUID challengeReferralId, final UUID challengeId, final SortingAndPaging sAndP) {
   final Criteria query = createCriteria();
   query.add(Restrictions.eq("challengeReferral.id", challengeReferralId));
   query.add(Restrictions.eq("challenge.id", challengeId));
   return processCriteriaWithStatusSortingAndPaging(query, sAndP);
 }
Esempio n. 22
0
 public List getChildPersons(String userId, boolean withSelfUser) {
   Criteria objCriteria = null;
   Session objSession = null;
   List objList = null;
   try {
     logger.info("GETTING ALL USERS");
     objSession = HibernateUtil.getSession();
     objCriteria =
         objSession.createCriteria(UsersVO.class).add(Restrictions.eq("valid", new Boolean(true)));
     if (withSelfUser)
       objCriteria.add(
           Restrictions.or(
               Restrictions.eq("userId", userId), Restrictions.eq("parentUser.userId", userId)));
     else objCriteria.add(Restrictions.eq("parentUser.userId", userId));
     objCriteria.addOrder(Order.asc("userId"));
     objList = objCriteria.list();
     logger.info("GET ALL USERS ENDS");
   } catch (HibernateException e) {
     logger.error("HIBERNATE EXCEPTION DURING GET ALL USERS", e);
     e.printStackTrace();
   } finally {
     if (objSession != null) {
       objSession.close();
     }
   }
   return objList;
 }
Esempio n. 23
0
  public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de facturas con params {}", params);
    if (params == null) {
      params = new HashMap<>();
    }

    if (!params.containsKey("max")) {
      params.put("max", 10);
    } else {
      params.put("max", Math.min((Integer) params.get("max"), 100));
    }

    if (params.containsKey("pagina")) {
      Long pagina = (Long) params.get("pagina");
      Long offset = (pagina - 1) * (Integer) params.get("max");
      params.put("offset", offset.intValue());
    }

    if (!params.containsKey("offset")) {
      params.put("offset", 0);
    }
    Criteria criteria = currentSession().createCriteria(FacturaAlmacen.class);
    Criteria countCriteria = currentSession().createCriteria(FacturaAlmacen.class);

    if (params.containsKey("almacen")) {
      criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
      countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
    }

    if (params.containsKey("filtro")) {
      String filtro = (String) params.get("filtro");
      Disjunction propiedades = Restrictions.disjunction();
      propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE));
      criteria.add(propiedades);
      countCriteria.add(propiedades);
    }

    if (params.containsKey("order")) {
      String campo = (String) params.get("order");
      if (params.get("sort").equals("desc")) {
        criteria.addOrder(Order.desc(campo));
      } else {
        criteria.addOrder(Order.asc(campo));
      }
    } else {
      criteria.createCriteria("estatus").addOrder(Order.asc("prioridad"));
    }
    criteria.addOrder(Order.desc("fechaModificacion"));

    if (!params.containsKey("reporte")) {
      criteria.setFirstResult((Integer) params.get("offset"));
      criteria.setMaxResults((Integer) params.get("max"));
    }
    params.put("facturas", criteria.list());

    countCriteria.setProjection(Projections.rowCount());
    params.put("cantidad", (Long) countCriteria.list().get(0));

    return params;
  }
Esempio n. 24
0
  @RequestMapping("/self/message/list")
  public String listMessage(
      String type,
      Integer pageNum,
      Integer pageSize,
      Model model,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    User user = getCurrentUser();
    EntityView ev = new EntityView();
    Boolean sendbox = false;
    if (StringUtils.isNotBlank(type) && type.equals("send")) {
      sendbox = true;
      ev.add(Restrictions.eq("sender", user.getUserId()));
    } else {
      ev.add(Restrictions.eq("receiver", user.getUserId()));
    }

    PageContext<Message> pageCtx = messageMng.queryUsePage(ev, pageNum, 10);
    model.addAttribute("pageCtx", pageCtx);
    model.addAttribute("sendbox", sendbox);
    return "self/message/list";
  }
  @Override
  @SuppressWarnings("unchecked")
  public List<ProgramInstance> getByStatus(
      ProgramStatus status,
      Program program,
      Collection<Integer> orgunitIds,
      Date startDate,
      Date endDate,
      Integer min,
      Integer max) {
    Criteria criteria =
        getCriteria(
                Restrictions.eq("program", program),
                Restrictions.between("enrollmentDate", startDate, endDate))
            .createAlias("entityInstance", "entityInstance")
            .createAlias("entityInstance.organisationUnit", "organisationUnit")
            .add(Restrictions.in("organisationUnit.id", orgunitIds))
            .add(Restrictions.eq("status", status));

    if (min != null) {
      criteria.setFirstResult(min);
    }

    if (max != null) {
      criteria.setMaxResults(max);
    }

    return criteria.list();
  }
  @Override
  public Long countParceirosInscritos(
      Integer idCursoSelecionado, Integer idGradeOficina, List<Integer> idsParceiros) {

    List<Integer> idsStatus = new ArrayList<Integer>();
    idsStatus.add(Status.CANCELADO);
    idsStatus.add(Status.AGUARDANDO_VAGA_PRIORIDADE);
    idsStatus.add(Status.AGUARDANDO_VAGA);

    Criteria criteria = getSession().createCriteria(InscricaoGrade.class);
    criteria.createAlias("inscricaoCurso", "ic");
    criteria.createAlias("ic.curso", "c");
    criteria.add(Restrictions.eq("c.id", idCursoSelecionado));
    criteria.createAlias("ic.ultimoStatus", "us");
    criteria.createAlias("us.status", "s");
    criteria.add(Restrictions.not(Restrictions.in("s.id", idsStatus)));
    criteria.createAlias("gradeOficina", "go");
    criteria.add(Restrictions.eq("go.id", idGradeOficina));
    if (idsParceiros != null && !idsParceiros.isEmpty()) {
      criteria.createAlias("ic.candidato", "cand");
      criteria.add(Restrictions.in("cand.id", idsParceiros));
    }
    criteria.setProjection(Projections.rowCount());
    Long result = (Long) criteria.list().get(0);
    return result;
  }
Esempio n. 27
0
  /**
   * Tìm kiếm nhanh
   *
   * @param idHangDienThoai id của HangDienThoai.
   * @param ten tên DienThoai.
   * @param giaTu giá chặn dưới.
   * @param giaDen giá chặn trên.
   * @return Danh sách DienThoai thỏa tiêu chí tìm kiếm.
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(int idHangDienThoai, String ten, double giaTu, double giaDen) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (idHangDienThoai > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", idHangDienThoai);
      criteria.add(manufacture);
    }

    if (ten != null) {
      Criterion name = Restrictions.like("ten", "%" + ten + "%");
      criteria.add(name);
    }

    if (giaTu >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", giaTu);
      criteria.add(minPrice);
    }

    if (giaDen >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", giaDen);
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
 @Override
 public boolean duplicatecheck(String idProperty, Object id, Map<String, Object> map) {
   Criteria criteria = createCriteria();
   if (map != null) {
     for (Iterator<String> i = map.keySet().iterator(); i.hasNext(); ) {
       String name = i.next();
       if (filterProperty(name)) {
         criteria.add(Restrictions.eq(name, map.get(name)));
       } else {
         log.error("Could not resolve property:" + name);
       }
     }
   }
   if (null == id) {
     List<?> list = criteria.list();
     if (list != null && list.size() > 0) {
       return true;
     }
   } else {
     List<?> list = criteria.add(Restrictions.ne(idProperty, id)).list();
     if (list != null && list.size() > 0) {
       return true;
     }
   }
   return false;
 }
Esempio n. 29
0
 @Override
 public VerifyPO get(long uid, int type) {
   Criteria c = createCriteria();
   c.add(Restrictions.eq("uid", uid));
   c.add(Restrictions.eq("type", type));
   return (VerifyPO) c.uniqueResult();
 }
Esempio n. 30
0
  private DetachedCriteria createActivityCriteria(Activity activity, String matchType) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Activity.class);
    if (activity.getActivityName() != null) {
      if (matchType.equalsIgnoreCase("exact")) {
        criteria.add(
            Restrictions.eq("activityName", "" + activity.getActivityName() + "").ignoreCase());
      } else {
        criteria.add(
            Restrictions.like("activityName", "%" + activity.getActivityName() + "%").ignoreCase());
      }
    }
    if (activity.getActivityDescription() != null) {
      criteria.add(
          Restrictions.like("activityDescription", "%" + activity.getActivityDescription() + "%")
              .ignoreCase());
    }
    if (activity.getIsActive() != null) {
      /*criteria.add(Restrictions.like("isActive",
      "%" + activity.getIsActive() + "%").ignoreCase());*/
      criteria.add(Restrictions.eq("isActive", "" + activity.getIsActive() + ""));
    }
    if (activity.getOrganization() != null) {
      criteria.add(Restrictions.eq("organization", activity.getOrganization()));
    }

    return criteria;
  }