List of usage examples for org.hibernate.criterion Restrictions between
public static Criterion between(String propertyName, Object low, Object high)
From source file:com.scopix.periscope.extractionmanagement.dao.EvidenceFileDAO.java
License:Open Source License
public EvidenceFile findEvidenceFileByEERAndDate(Integer evidenceExtractionRequestId, Date date) throws ScopixException { EvidenceFile evidenceFile = null;/*w w w .j a v a 2 s. c o m*/ SimpleDateFormat sdfParse = new SimpleDateFormat("dd-MM-yyyy HH:mm"); SimpleDateFormat sdfFormat = new SimpleDateFormat("dd-MM-yyyy"); Criteria criteria = this.getSession().createCriteria(EvidenceFile.class); criteria.add(Restrictions.eq("evidenceExtractionRequest.id", evidenceExtractionRequestId)); try { criteria.add(Restrictions.between("evidenceDate", sdfParse.parse(sdfFormat.format(date) + " 00:00"), sdfParse.parse(sdfFormat.format(date) + " 23:59"))); } catch (ParseException ex) { log.error(ex, ex); throw new ScopixException("Error obteniendo evidenceFile: ", ex); } List<EvidenceFile> evidenceFiles = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); if (evidenceFiles != null && !evidenceFiles.isEmpty()) { evidenceFile = evidenceFiles.get(0); } return evidenceFile; }
From source file:com.selfsoft.baseinformation.service.impl.TbCarInfoServiceImpl.java
public List<TbCarInfo> findByTbCarInfo(TbCarInfo tbCarInfo) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCarInfo.class); if (null != tbCarInfo) { if (null != tbCarInfo.getId()) { detachedCriteria.add(Restrictions.eq("id", tbCarInfo.getId())); }//from w ww. j av a2s. com if (null != tbCarInfo.getLicenseCode() && !"".equals(tbCarInfo.getLicenseCode())) { //? detachedCriteria.add(Restrictions.like("licenseCode", "%" + tbCarInfo.getLicenseCode() + "%")); } if (null != tbCarInfo.getInsureCardCode() && !"".equals(tbCarInfo.getInsureCardCode())) { detachedCriteria .add(Restrictions.like("insureCardCode", "%" + tbCarInfo.getInsureCardCode() + "%")); } if (null != tbCarInfo.getTmCarModelType()) { detachedCriteria.createAlias("tmCarModelType", "tmCarModelType"); if (null != tbCarInfo.getTmCarModelType().getId()) { detachedCriteria .add(Restrictions.eq("tmCarModelType.id", tbCarInfo.getTmCarModelType().getId())); } } if (null != tbCarInfo.getTbCustomer()) { detachedCriteria.createAlias("tbCustomer", "tbCustomer"); if (null != tbCarInfo.getTbCustomer().getId()) { detachedCriteria.add(Restrictions.eq("tbCustomer.id", tbCarInfo.getTbCustomer().getId())); } if (null != tbCarInfo.getTbCustomer().getCustomerCode()) { detachedCriteria.add(Restrictions.like("tbCustomer.customerCode", "%" + tbCarInfo.getTbCustomer().getCustomerCode() + "%")); } if (null != tbCarInfo.getTbCustomer().getCustomerName()) { detachedCriteria.add(Restrictions.like("tbCustomer.customerName", "%" + tbCarInfo.getTbCustomer().getCustomerName() + "%")); } if (null != tbCarInfo.getTbCustomer().getTelephone()) { detachedCriteria.add(Restrictions.like("tbCustomer.telephone", "%" + tbCarInfo.getTbCustomer().getTelephone() + "%")); } } if (StringUtils.isNotBlank(tbCarInfo.getBeginLicenseDate())) { detachedCriteria.add(Restrictions.ge("licenseDate", Date.valueOf(tbCarInfo.getBeginLicenseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getEndLicenseDate())) { detachedCriteria.add(Restrictions.le("licenseDate", Date.valueOf(tbCarInfo.getEndLicenseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getBeginPurchaseDate())) { detachedCriteria .add(Restrictions.ge("purchaseDate", Date.valueOf(tbCarInfo.getBeginPurchaseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getEndPurchaseDate())) { detachedCriteria.add(Restrictions.le("purchaseDate", Date.valueOf(tbCarInfo.getEndPurchaseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getChassisCode())) { detachedCriteria.add(Restrictions.like("chassisCode", "%" + tbCarInfo.getChassisCode() + "%")); } if (tbCarInfo.getCarProperty() != null) { detachedCriteria.add(Restrictions.eq("carProperty", tbCarInfo.getCarProperty())); } if (StringUtils.isNotBlank(tbCarInfo.getLicenseMonth())) { detachedCriteria .add(Restrictions.sqlRestriction("month(LICENSE_DATE)=" + tbCarInfo.getLicenseMonth())); } if (tbCarInfo.getMaxKilo() != null && tbCarInfo.getMinKilo() != null) { detachedCriteria.add(Restrictions.between("kilo", tbCarInfo.getMinKilo(), tbCarInfo.getMaxKilo())); } } return tbCarInfoDao.findByCriteria(detachedCriteria, tbCarInfo); }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private void loadModificationsForPMR(List<PipelineMaterialRevision> pmrs) { List<Criterion> criterions = new ArrayList<>(); for (PipelineMaterialRevision pmr : pmrs) { if (goCache.get(pmrModificationsKey(pmr)) != null) { continue; }/*from ww w. ja va2s. com*/ final Criterion modificationClause = Restrictions.between("id", pmr.getFromModification().getId(), pmr.getToModification().getId()); final SimpleExpression idClause = Restrictions.eq("materialInstance", pmr.getMaterialInstance()); criterions.add(Restrictions.and(idClause, modificationClause)); } List<Modification> modifications = (List<Modification>) getHibernateTemplate() .findByCriteria(buildModificationDetachedQuery(criterions)); sortPersistentObjectsById(modifications, false); for (Modification modification : modifications) { List<String> cacheKeys = pmrModificationsKey(modification, pmrs); for (String cacheKey : cacheKeys) { List<Modification> modificationList = (List<Modification>) goCache.get(cacheKey); if (modificationList == null) { modificationList = new ArrayList<>(); goCache.put(cacheKey, modificationList); } modificationList.add(modification); } } }
From source file:com.tm.main.SystemUI.java
public void addSearchCriteria() { mLogger.info("addSearchCriteria--Starts"); mSearchCriteria.clear();//from ww w. j ava2 s . c o m this.getRootPane().setDefaultButton(btnListData); if (sptxtRecordId.getText() != null && sptxtRecordId.getText().length() > 0) { mSearchCriteria.add(Restrictions.eq("taskId", new BigDecimal(sptxtRecordId.getText()))); } if (sptxtReferenceNo.getText() != null && sptxtReferenceNo.getText().length() > 0) { mSearchCriteria.add(Restrictions.eq("taskReference", sptxtReferenceNo.getText())); } if (spcmbAssignee.getSelectedIndex() > 0) { mSearchCriteria.add(Restrictions.eq("assignee", ((CellDTO) spcmbAssignee.getSelectedItem()).getKey())); } if (spcmbStatus.getSelectedIndex() > 0) { mSearchCriteria.add(Restrictions.eq("status", ((CellDTO) spcmbStatus.getSelectedItem()).getKey())); } if (spcmbProject.getSelectedIndex() > 0) { mSearchCriteria .add(Restrictions.eq("projectName", ((CellDTO) spcmbProject.getSelectedItem()).getKey())); } if (spcmbPriority.getSelectedIndex() > 0) { mSearchCriteria.add(Restrictions.eq("priority", ((CellDTO) spcmbPriority.getSelectedItem()).getKey())); } /* Date Criteria */ if (spdtAssignDateFrom.getDate() != null && spdtAssignDateTo.getDate() == null) { mSearchCriteria.add(Restrictions.eq("createDate", spdtAssignDateFrom.getDate())); } if (spdtAssignDateFrom.getDate() != null && spdtAssignDateTo.getDate() != null) { mSearchCriteria.add( Restrictions.between("createDate", spdtAssignDateFrom.getDate(), spdtAssignDateTo.getDate())); } if (spdtDeliveryDateFrom.getDate() != null && spdtDeliveryDateTo.getDate() == null) { mSearchCriteria.add(Restrictions.eq("eta", spdtDeliveryDateFrom.getDate())); } if (spdtDeliveryDateFrom.getDate() != null && spdtDeliveryDateTo.getDate() != null) { mSearchCriteria .add(Restrictions.between("eta", spdtDeliveryDateFrom.getDate(), spdtDeliveryDateTo.getDate())); } /* Date Criteria Ends */ if (sptxtTitle.getText() != null && sptxtTitle.getText().length() > 0) { mSearchCriteria.add(Restrictions.ilike("title", sptxtTitle.getText(), MatchMode.ANYWHERE)); } if (sptxtComment.getText() != null && sptxtComment.getText().length() > 0) { mSearchCriteria.add(Restrictions.ilike("commentText", sptxtComment.getText(), MatchMode.ANYWHERE)); } if (sptxtModuleName.getText() != null && sptxtModuleName.getText().length() > 0) { mSearchCriteria.add(Restrictions.ilike("moduleName", sptxtModuleName.getText(), MatchMode.ANYWHERE)); } if (spcmbTaskType.getSelectedIndex() > 0) { mSearchCriteria.add(Restrictions.eq("taskType", ((CellDTO) spcmbTaskType.getSelectedItem()).getKey())); } if (rdoPlanningStatus.isSelected()) { mSearchCriteria.add(Restrictions.isNull("eta")); mSearchCriteria.add(Restrictions.isNull("assignee")); } mLogger.info("addSearchCriteria--Ends"); }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.EventDAOImpl.java
License:Open Source License
@Override protected Criteria createCriteria(SearchFilter<Event> filter) { Criteria criteria = getSession().createCriteria(Event.class); if (filter instanceof EventFilter) { EventFilter eventFilter = (EventFilter) filter; if (eventFilter.getDate() != null) { Date from = DateUtil.getMidnightDate(eventFilter.getDate()); Calendar toc = DateUtil.getCalendarInstance(); toc.setTime(from);/*w w w . j av a2 s . c om*/ toc.add(Calendar.DAY_OF_YEAR, 1); toc.add(Calendar.SECOND, 1); Date to = toc.getTime(); criteria.add(Restrictions.between("date", from, to)); } } return criteria; }
From source file:com.uniminuto.ejercicio2.dao.EmployeeDaoImpl.java
public List<Employee> buscarSalarioRango(int menor, int mayor) { List<Employee> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession();//from w ww .jav a2 s.c o m Criteria cr = session.createCriteria(Employee.class); //Trae entre 1 a 8 como maximo de registros cr.setFirstResult(1); cr.setMaxResults(8); cr.add(Restrictions.between("salario", menor, mayor)); return results = cr.list(); }
From source file:com.valco.dao.AbonosCuentasXCobrarDAO.java
public List<NotasDeVenta> getNotasDeVenta(Date fechaInicial, Date fechaFinal, Clientes cliente, Integer numeroNota, String estatus) throws Exception { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx = null;// ww w . j a va 2 s. c o m List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>(); try { tx = session.beginTransaction(); Criteria criteria = session.createCriteria(NotasDeVenta.class); if (fechaInicial != null && fechaFinal != null) { criteria.add(Restrictions.between("fechaDeVenta", fechaInicial, fechaFinal)); } else if (fechaInicial != null) { criteria.add(Restrictions.eq("fechaDeVenta", fechaInicial)); } else if (fechaFinal != null) { criteria.add(Restrictions.eq("fechaDeVenta", fechaFinal)); } if (cliente != null) { criteria.add(Restrictions.eq("clientes", cliente)); } if (numeroNota != null) { criteria.add(Restrictions.eq("folio", numeroNota)); } if (estatus != null) { criteria.add(Restrictions.eq("estatus", estatus)); } notas = (List<NotasDeVenta>) criteria.list(); for (NotasDeVenta nota : notas) { Hibernate.initialize(nota.getCuentaXCobrar()); if (nota.getCuentaXCobrar() != null) { Hibernate.initialize(nota.getCuentaXCobrar().getAbonosCuentasXCobrars()); } } return notas; } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los abonos."); } finally { try { if (session.isOpen()) { session.close(); } } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los abonos."); } } }
From source file:com.valco.dao.NotasVentaDAO.java
public List<NotasDeVenta> getNotasDeVenta(Repartidores repartidor, Date fechaInicial, Date fechaFinal, String estatus) throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;//from www. j ava2s. co m List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>(); try { tx = session.beginTransaction(); Criteria criteria = session.createCriteria(NotasDeVenta.class) .add(Restrictions.eq("repartidores", repartidor)); if (fechaInicial != null && fechaFinal != null) { criteria.add(Restrictions.between("fechaDeVenta", fechaInicial, fechaFinal)); } else if (fechaInicial != null) { criteria.add(Restrictions.eq("fechaDeVenta", fechaInicial)); } else if (fechaFinal != null) { criteria.add(Restrictions.eq("fechaDeVenta", fechaFinal)); } if (estatus != null) { criteria.add(Restrictions.eq("estatus", estatus)); } notas = (List<NotasDeVenta>) criteria.list(); for (NotasDeVenta nota : notas) { for (CuentasXCobrar cuenta : nota.getCuentasXCobrars()) { Hibernate.initialize(cuenta); } } return notas; } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar las notas."); } finally { try { if (session.isOpen()) { session.close(); } } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar las notas."); } } }
From source file:Controlador.ControladorLecturas.java
public ControladorLecturas(Date desde, Date hasta) { SessionFactory sesion = NewHibernateUtil.getSessionFactory(); Session session = sesion.openSession(); Transaction tx = session.beginTransaction(); Criteria c = session.createCriteria(Lecturas.class); c.add(Restrictions.between("fecha", desde, hasta)); lista = c.list();/*w ww . jav a 2 s . c om*/ tx.commit(); session.close(); }
From source file:Dao.MovieDAO.java
public List<Movie> getMoviesOpeningThisWeek() { Session session = this.sessionFactory.getCurrentSession(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 7);//from w w w.j a v a 2 s.c o m Date date = cal.getTime(); Timestamp today = new Timestamp(System.currentTimeMillis()); Timestamp nextWeek = new Timestamp(date.getTime()); System.out.println("TODAY: " + today); System.out.println("NextWeeK: " + nextWeek); List movies = session.createCriteria(Movie.class).add(Restrictions.between("releaseDate", today, nextWeek)) .list(); if (movies.isEmpty()) { return null; } logger.info("Opening This Week loaded successfully, Movie details=" + movies); return movies; }