List of usage examples for org.hibernate.criterion Restrictions le
public static SimpleExpression le(String propertyName, Object value)
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
public double getHoursResourceInDates(Project project, Employee member, Date since, Date until, Integer idResourcePool, Operation operation, Projectactivity activity) { Criteria crit = getSession().createCriteria(getPersistentClass()); Criteria employeeCrit = null;// w w w . ja va2s . c om if (member != null || idResourcePool != null) { employeeCrit = crit.createCriteria(Timesheet.EMPLOYEE); } if (idResourcePool != null) { employeeCrit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } if (member != null) { employeeCrit.add(Restrictions.idEq(member.getIdEmployee())); } if (since != null && until != null) { crit.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 (project != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); Criteria activitiesCrit = crit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, project)); // Select only timesheet whose activity is control account Criteria wbsnodeCrit = activitiesCrit.createCriteria(Projectactivity.WBSNODE) .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)); } else if (operation != null) { crit.add(Restrictions.or(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2), Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.OPERATION, operation)); } else if (activity != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.eq(Timesheet.PROJECTACTIVITY, activity)); } return calcHours(crit.list(), since, until); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * /* w w w . j av a 2s . c o m*/ * @param employee * @param initDate * @param endDate * @param joins * @return */ @SuppressWarnings("unchecked") public List<Timesheet> findByProject(Employee employee, Project project, Date initDate, Date endDate, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.ge(Timesheet.INITDATE, initDate)).add(Restrictions.le(Timesheet.ENDDATE, endDate)) .addOrder(Order.asc(Timesheet.INITDATE)); crit.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)) .addOrder(Order.asc(Projectactivity.PROJECT)); if (joins != null) { addJoins(crit, joins); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find time sheet affected for update date out * /*from w ww .ja v a 2 s . c o m*/ * @param teammember * @param newDateOut * @return */ @SuppressWarnings("unchecked") public List<Timesheet> timeSheetsForUpdateOut(Teammember teammember, Date newDateOut) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Timesheet.PROJECTACTIVITY, teammember.getProjectactivity())) .add(Restrictions.eq(Timesheet.EMPLOYEE, teammember.getEmployee())) .add(Restrictions.conjunction() .add(Restrictions.le(Timesheet.INITDATE, DateUtil.getFirstWeekDay(teammember.getDateOut()))) .add(Restrictions.ge(Timesheet.ENDDATE, DateUtil.getLastWeekDay(newDateOut)))); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find time sheet affected for update date in * // ww w . jav a 2s . c o m * @param teammember * @param newDateOut * @return */ @SuppressWarnings("unchecked") public List<Timesheet> timeSheetsForUpdateIn(Teammember teammember, Date newDateIn) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Timesheet.PROJECTACTIVITY, teammember.getProjectactivity())) .add(Restrictions.eq(Timesheet.EMPLOYEE, teammember.getEmployee())) .add(Restrictions.conjunction() .add(Restrictions.ge(Timesheet.INITDATE, DateUtil.getFirstWeekDay(teammember.getDateIn()))) .add(Restrictions.le(Timesheet.ENDDATE, DateUtil.getLastWeekDay(newDateIn)))); return crit.list(); }
From source file:es.tid.fiware.rss.dao.impl.DbeTransactionDaoImpl.java
License:Open Source License
private Criteria getCriteriaTxBySvcRefcPrdtUserDate(String transactionId, Long nuServiceId, String refCode, Long nuProductId, Long nuMopId, String enduserid, Date fromDate, Date untilDate, String applicationId, String[] txTypes, String operationNature, String originalTxId, String gUserId, Long paymentMethodType) { Criteria criteria = this.getSession().createCriteria(DbeTransaction.class); if (null != transactionId) { criteria.add(Restrictions.eq("txTransactionId", transactionId)); }//from w ww . j a v a2 s. co m if (null != nuServiceId) { criteria.add(Restrictions.eq("bmService.nuServiceId", nuServiceId)); } if (null != refCode) { criteria.add(Restrictions.eq("txReferenceCode", refCode)); } if (null != nuProductId) { criteria.add(Restrictions.eq("bmProduct.nuProductId", nuProductId)); } if (null != nuMopId) { criteria.add(Restrictions.eq("bmObMop.id.nuMopId", nuMopId)); } if (null != enduserid) { criteria.add(Restrictions.eq("txEndUserId", enduserid)); } if (null != applicationId) { criteria.add(Restrictions.eq("txApplicationId", applicationId)); } if (null != fromDate) { criteria.add(Restrictions.ge("tsClientDate", fromDate)); } if (null != untilDate) { criteria.add(Restrictions.le("tsClientDate", untilDate)); } if ((null != txTypes) && (txTypes.length > 0)) { Criterion crTxTypes = Restrictions.eq("tcTransactionType", txTypes[0]); for (int i = 1; i < txTypes.length; i++) { crTxTypes = Restrictions.or(crTxTypes, Restrictions.eq("tcTransactionType", txTypes[i])); } criteria.add(crTxTypes); } if (null != operationNature) { criteria.add(Restrictions.eq("txOperationNature", operationNature)); } if (null != originalTxId) { criteria.add(Restrictions.eq("txOrgTransactionId", originalTxId)); } if (null != gUserId) { criteria.add(Restrictions.eq("txGlobalUserId", gUserId)); } if (null != paymentMethodType) { criteria.add(Restrictions.eq("bmObMop.id.nuMopId", paymentMethodType)); } return criteria; }
From source file:es.urjc.mctwp.service.commands.researchCmds.FindTasks.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public ResultCommand<List<Task>> runCommand() { Session sesion = sf.getCurrentSession(); Criteria criteria = sesion.createCriteria(Task.class); if (startDate != null) criteria.add(Restrictions.ge("endDate", startDate)); if (endDate != null) criteria.add(Restrictions.le("endDate", endDate)); if (owner != null) criteria.createCriteria("owner").add(Restrictions.eq("code", owner)); if (process != null) criteria.createCriteria("process").add(Restrictions.eq("code", process)); if (taskState != null) criteria.add(Restrictions.eq("status", taskState)); this.setResult(criteria.list()); return this; }
From source file:eu.interedition.text.query.RangeFitsWithinCriterion.java
License:Apache License
@Override Criterion restrict() { return Restrictions.and(Restrictions.ge("target.start", range.getStart()), Restrictions.le("target.end", range.getEnd())); }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Reservation.java
License:Open Source License
/** * load all reservations from DB which lie in a given time-period. *//*from w ww. j av a 2s . com*/ @SuppressWarnings("unchecked") public static final Set<Reservation> loadAllInPeriod(Date startTime, Date endTime) throws DatabaseException { return (Set<Reservation>) (new TransactionManager(new Tuple<Date, Date>(startTime, endTime)) { @Override protected void dbOperation() { Set<Reservation> result = new HashSet<Reservation>(); Tuple<Date, Date> times = (Tuple<Date, Date>) this.arg; // select all reservation-IDs from ReservationPeriod-view, which // lie in the given time-period DetachedCriteria ids = DetachedCriteria.forClass(VIEW_ReservationPeriod.class) .setProjection(Property.forName("reservationId")) .add(Restrictions.disjunction() .add(Restrictions.between("startTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.between("endTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.and(Restrictions.le("startTime", times.getFirstElement()), Restrictions.ge("endTime", times.getSecondElement())))); // select all reservations from DB accoring to the IDs from step // one final List<Reservation> tmpReservation = this.session.createCriteria(Reservation.class) .add(Subqueries.propertyIn("reservationId", ids)) // use join-select, because all infos will be // needed later .setFetchMode("Reservation", FetchMode.JOIN).list(); for (Reservation r : tmpReservation) { result.add(r); } this.result = result; } }).getResult(); }
From source file:eu.jangos.manager.utils.Utils.java
License:Apache License
/** * Generic method to apply a date filter on an Hibernate query. * * @param query The query object in its actual state. * @param param The name of the parameter in Hibernate configuration. * @param filter The filter type for the date. * @param from The starting date./*from www.ja v a2s.co m*/ * @param to The second date filter. * @return The updated query object with the corresponding filter. */ public static Criteria applyDateFilter(Criteria query, String param, DateType filter, Date from, Date to) { // We first exchange dates if they are invalid. if (from != null && to != null && from.after(to)) { Date temp = from; from = to; to = temp; } switch (filter) { case BEFORE: query.add(Restrictions.le(param, from)); break; case AFTER: query.add(Restrictions.ge(param, from)); break; case BETWEEN: query.add(Restrictions.gt(param, from)).add(Restrictions.lt(param, to)); break; } return query; }
From source file:financeiro.dao.hibernate.LancamentoDAOHibernate.java
License:Creative Commons License
@SuppressWarnings("unchecked") @Override// w ww .j ava2s . c o m public List<Lancamento> listar(Conta conta, Date dataInicio, Date dataFim) { Criteria criteria = this.session.createCriteria(Lancamento.class); if (dataInicio != null && dataFim != null) { criteria.add(Restrictions.between("data", dataInicio, dataFim)); } else if (dataInicio != null) { criteria.add(Restrictions.ge("data", dataInicio)); } else if (dataFim != null) { criteria.add(Restrictions.le("data", dataFim)); } criteria.add(Restrictions.eq("conta", conta)); criteria.addOrder(Order.asc("data")); return criteria.list(); }