List of usage examples for org.hibernate.criterion Restrictions le
public static SimpleExpression le(String propertyName, Object value)
From source file:ee.ria.xroad.proxy.messagelog.LogArchiver.java
License:Open Source License
@SuppressWarnings("unchecked") protected List<TimestampRecord> getNonArchivedTimestampRecords(Session session, int maxRecordsToGet, long maxTimestampId) { Criteria criteria = session.createCriteria(TimestampRecord.class); criteria.add(Restrictions.eq("archived", false)); criteria.add(Restrictions.le("id", maxTimestampId)); criteria.setMaxResults(maxRecordsToGet); criteria.addOrder(Order.asc("id")); return criteria.list(); }
From source file:eionet.webq.task.RemoveExpiredUserFilesTask.java
License:Mozilla Public License
/** * Perform removal task.//from w w w . ja va 2s .c om */ @Scheduled(cron = "0 0 0 * * *") @Transactional public void removeExpiredUserFiles() { Integer hoursAgo = getExpirationHours(); Date allowedDate = DateUtils.addHours(new Date(), -hoursAgo); LOGGER.info("Removing user files last modified before " + allowedDate + "(in storage more than " + hoursAgo + " hours). "); Session currentSession = factory.getCurrentSession(); List rowsAffected = currentSession.createCriteria(UserFile.class) .add(Restrictions.le("updated", new Timestamp(allowedDate.getTime()))).list(); for (Object row : rowsAffected) { currentSession.delete(row); } LOGGER.info("Removal successful. Removed " + rowsAffected + " files."); }
From source file:es.emergya.bbdd.dao.IncidenciaHome.java
License:Open Source License
/** * Devuelve todas las incidencias que estuvieron abiertas en el intervalo * pasado y su posicin coincide con alguna de las zonas indicadas. Si no se * pasan zonas, la posicin no se utilizar como criterio para obtener la * lista de incidencias./*from w w w . j a v a 2 s . c o m*/ * * @param nombreUsuario * el nombre de usuario del usuario que realiza la consulta. * @param fechaInicio * el instante inicial a usar en el filtro. * @param fechaFinal * el instante final a usar en el filtro. * @param zonas * Lista de zonas en las que deben estar las incidencias. * @return La lista de zonas que estuvieron abiertas en algn momento del * periodo en alguna de las zonas pasadas. */ @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Incidencia> getIncidenciasEnPeriodo(String nombreUsuario, Calendar fechaInicio, Calendar fechaFinal) { Date inicio = null; Date fin = null; if (fechaInicio != null) { inicio = fechaInicio.getTime(); } else { return new ArrayList<Incidencia>(0); } if (fechaFinal != null) { fin = fechaFinal.getTime(); } else { return new ArrayList<Incidencia>(0); } Criteria c = getSession().createCriteria(Incidencia.class).addOrder(Order.asc("referenciaHumana")) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .createAlias("street", "st", Criteria.LEFT_JOIN).createAlias("portal", "pt", Criteria.LEFT_JOIN); if (fin != null) { c = c.add(Restrictions.le("fechaCreacion", fin)); } if (inicio != null) { c = c.add(Restrictions.or(Restrictions.ge("fechaCierre", inicio), Property.forName("fechaCierre").isNull())); } log.trace("Criteria final: " + c); return c.list(); }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
/** * Devuelve todos los recursos que tienen posiciones en HistoricoGPS ms * antiguas que lmite.//from www .j a v a 2s .c o m * * @param limite * @return */ @SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public List<Recurso> getTodas(Calendar limite) { List<Recurso> res = new ArrayList<Recurso>(); try { Session currentSession = getSession(); currentSession.clear(); DetachedCriteria dc = DetachedCriteria.forClass(HistoricoGPS.class) .setProjection(Projections.property("recurso")) .add(Restrictions.le("marcaTemporal", limite.getTime())) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); final Criteria query = currentSession.createCriteria(Recurso.class) .add(Subqueries.propertyIn("identificador", dc)).addOrder(Order.asc("identificador")); if (log.isDebugEnabled()) log.debug(query); res = query.list(); // Para evitar LazyInicializationException accedemos a // todas las flotas de los recursos devueltos ya que en // los lugares en los que se usa esta funcin es necerasio // tambin la flota. for (Recurso uniqueResult : res) { if (uniqueResult != null) { if (uniqueResult.getFlotas() != null) { uniqueResult.getFlotas().getId(); } } } } catch (Throwable t) { log.error("Sacando los recursos para generar los gpx", t); } return res; }
From source file:es.sm2.openppm.core.dao.AuditDAO.java
License:Open Source License
private Criterion[] getRestrictions(AuditSearch search) { List<Criterion> restrictions = new ArrayList<Criterion>(); restrictions.add(Restrictions.eq(Audit.IDCOMPANY, search.getCompany().getIdCompany())); restrictions.add(Restrictions.eq(Audit.LOCATION, search.getLocation().name())); if (search.getIdProject() != null) { restrictions.add(Restrictions.eq(Audit.IDPROJECT, search.getIdProject())); }//w w w . j ava 2s . c om if (search.getIdContact() != null) { restrictions.add(Restrictions.eq(Audit.IDCONTACT, search.getIdContact())); } if (ValidateUtil.isNotNull(search.getProjectStatus())) { restrictions.add(Restrictions.eq(Audit.PROJECTSTATUS, search.getProjectStatus())); } if (search.getSince() != null && search.getUntil() != null) { restrictions.add(Restrictions.between(Audit.CREATIONDATE, search.getSince(), search.getUntil())); } else if (search.getSince() != null) { restrictions.add(Restrictions.ge(Audit.CREATIONDATE, search.getSince())); } else if (search.getUntil() != null) { restrictions.add(Restrictions.le(Audit.CREATIONDATE, search.getUntil())); } return restrictions.toArray(new Criterion[restrictions.size()]); }
From source file:es.sm2.openppm.core.dao.CalendarbaseexceptionsDAO.java
License:Open Source License
/** * /*from w w w . ja v a 2 s.c om*/ * @param base * @param idEmployee * @param initDate * @param endDate * @return */ @SuppressWarnings("unchecked") public List<Calendarbaseexceptions> findByCalendarBase(Calendarbase base, Integer idEmployee, Date initDate, Date endDate) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Calendarbaseexceptions.CALENDARBASE, base)) .add(Restrictions.ge(Calendarbaseexceptions.STARTDATE, initDate)) .add(Restrictions.le(Calendarbaseexceptions.FINISHDATE, endDate)) .createCriteria(Calendarbaseexceptions.CALENDARBASE).createCriteria(Calendarbase.EMPLOYEES) .add(Restrictions.idEq(idEmployee)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.DataTableDAO.java
License:Open Source License
private void applyFilters(Criteria crit, List<DatoColumna> filtrosExtras) throws ParseException { SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); for (DatoColumna filtroColumna : filtrosExtras) { if (filtroColumna.getTipo() == Date.class) { // Filtramos si es una fecha Date tempDate = df.parse(filtroColumna.getValor()); crit.add(Restrictions.eq(filtroColumna.getNombre(), tempDate)); } else if (filtroColumna.getTipo() == Integer.class) { // Filtramos si es un numero Integer integer = Integer.parseInt(filtroColumna.getValor()); crit.add(Restrictions.eq(filtroColumna.getNombre(), integer)); } else if (filtroColumna.getTipo() == Boolean.class) { // Filtramos si es un booleano Boolean bool = Boolean.parseBoolean(filtroColumna.getValor()); crit.add(Restrictions.eq(filtroColumna.getNombre(), bool)); } else if (filtroColumna.getTipo() == List.class) { // Since Until if (filtroColumna.getSubTipo() != null && filtroColumna.getSubTipo() == Date.class) { Date sinceDate = (Date) filtroColumna.getObjectList()[0]; Date untilDate = (Date) filtroColumna.getObjectList()[1]; String sinceName = (String) filtroColumna.getNombreList()[0]; String untilName = (String) filtroColumna.getNombreList()[1]; crit.add(Restrictions.disjunction().add(Restrictions.between(sinceName, sinceDate, untilDate)) .add(Restrictions.between(untilName, sinceDate, untilDate)).add(Restrictions.and( Restrictions.le(sinceName, sinceDate), Restrictions.ge(untilName, untilDate)))); } else { // Tiene que estar en la lista crit.add(Restrictions.in(filtroColumna.getNombre(), filtroColumna.getValorList())); }//from w w w . j a v a 2 s. co m } else if (filtroColumna.getTipo() == String.class) { if (filtroColumna.getSubTipo() == List.class) { if (!ValidateUtil.isNull(filtroColumna.getValor())) { String[] value = filtroColumna.getValor().split(","); List<Integer> ids = new ArrayList<Integer>(); for (String id : value) { ids.add(Integer.parseInt(id)); } if (filtroColumna.getCriteria() != null) { Criteria crit2 = crit.createCriteria(filtroColumna.getCriteria()); crit2.add(Restrictions.in(filtroColumna.getNombre(), ids)); } else { crit.add(Restrictions.in(filtroColumna.getNombre(), ids)); } } } else { // Comparando texto crit.add(Restrictions.like(filtroColumna.getNombre(), "%" + filtroColumna.getValor() + "%")); } } else { // Filtrando Objectos crit.add(Restrictions.eq(filtroColumna.getNombre(), filtroColumna.getObject())); } } }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Employees where inputed hours is approval * //from www .j av a 2 s . c o m * @param project * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProject(Project project, Date since, Date until) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Criteria members = crit.createCriteria(Employee.TEAMMEMBERS) .add(Restrictions.or(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED), Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_RELEASED))); if (since != null && until != null) { members.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } members.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); if (since != null && until != null) { sheets.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } sheets.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find imputed in projects// w w w .jav a2 s.c o m * * @param projects * @param since * @param until * @param idResourcePool * @param activities * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProjects(List<Project> projects, Date since, Date until, Integer idResourcePool, List<Projectactivity> activities) { List<Employee> employees = null; if (ValidateUtil.isNotNull(projects) || ValidateUtil.isNotNull(activities)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (idResourcePool != null) { crit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } // Timesheet filter by status app3 and dates and projects // Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); if (since != null && until != null) { sheets.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } if (projects != null) { Criteria activitiesCrit = sheets.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.in(Projectactivity.PROJECT, projects)); // Select employees whose activity is control account Criteria wbsnodeCrit = activitiesCrit.createCriteria(Projectactivity.WBSNODE) .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)); } else if (activities != null) { sheets.add(Restrictions.in(Timesheet.PROJECTACTIVITY, activities)); } crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); employees = crit.list(); } return employees; }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Employee> findInputedInOperations(List<Employee> employees, Date since, Date until, Integer idResourcePool) { List<Employee> returnEmployees = null; if (ValidateUtil.isNotNull(employees)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Integer> ids = new ArrayList<Integer>(); for (Employee item : employees) { ids.add(item.getIdEmployee()); }/*from w w w.j av a2 s .c om*/ crit.add(Restrictions.not(Restrictions.in(Employee.IDEMPLOYEE, ids))); if (idResourcePool != null) { crit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.isNotNull(Timesheet.OPERATION)); if (since != null && until != null) { sheets.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); returnEmployees = crit.list(); } return returnEmployees; }