Example usage for org.hibernate.criterion Restrictions between

List of usage examples for org.hibernate.criterion Restrictions between

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions between.

Prototype

public static Criterion between(String propertyName, Object low, Object high) 

Source Link

Document

Apply a "between" constraint to the named property

Usage

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * An API to fetch count of the batch instances for a given status list and batch priority and isCurrUsrNotReq is used for adding
 * the batch instance access by the current user. This API will return the batch instance having access by the user roles on the
 * basis of ephesoft user./*  w w  w .j a va  2 s.  c o  m*/
 * 
 * @param batchInstStatusList List<{@link BatchInstanceStatus}>
 * @param batchPriorities the priority list of the batches
 * @param isNotCurrentUserCheckReq true if the current user can be anyone. False if current user cannot be null.
 * @param currentUserName {@link String}
 * @param userRoles Set<{@link String}>
 * @param ephesoftUser {@link EphesoftUser}
 * @param searchString the searchString on which batch instances have to be fetched
 * @return int, the count satisfying the above requirements
 */
@Override
public int getCount(final List<BatchInstanceStatus> batchInstStatusList,
        final List<BatchPriority> batchPriorities, final boolean isNotCurrentUserCheckReq,
        final Set<String> userRoles, final String currentUserName, EphesoftUser ephesoftUser,
        final String searchString) {
    DetachedCriteria criteria = criteria();

    if (null != batchInstStatusList) {
        criteria.add(Restrictions.in(STATUS, batchInstStatusList));
    }

    if (null != searchString && !searchString.isEmpty()) {
        String searchStringLocal = searchString.replaceAll(DataAccessConstant.PERCENTAGE, REPLACEMENT_STRING);
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME,
                DataAccessConstant.PERCENTAGE + searchStringLocal + DataAccessConstant.PERCENTAGE);
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER,
                DataAccessConstant.PERCENTAGE + searchStringLocal + DataAccessConstant.PERCENTAGE);

        LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
        criteria.add(searchCriteria);
    }

    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteria.add(disjunction);
    }
    int count = 0;

    Set<String> batchClassIdentifiers = null;
    Set<String> batchInstanceIdentifiers = null;

    if (ephesoftUser.equals(EphesoftUser.ADMIN_USER)) {
        batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        batchInstanceIdentifiers = batchInstanceGroupsDao.getBatchInstanceIdentifierForUserRoles(userRoles);
        if ((null != batchClassIdentifiers && batchClassIdentifiers.size() > 0)
                || (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0)) {
            if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0
                    && null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0) {
                final Disjunction disjunction = Restrictions.disjunction();
                if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
                    criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                    disjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
                }
                if (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0) {
                    disjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
                }
                criteria.add(disjunction);
            } else if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
                criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
            } else if (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0) {
                criteria.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
            }
            // Add check for null current users only.
            // Now we will count only for those current users those are null.
            if (!isNotCurrentUserCheckReq && null != currentUserName) {
                criteria.add(Restrictions.or(Restrictions.isNull(CURRENT_USER),
                        Restrictions.eq(CURRENT_USER, currentUserName)));
            }
            count = count(criteria);
        }
    } else {
        batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        batchInstanceIdentifiers = batchInstanceGroupsDao.getBatchInstanceIdentifierForUserRoles(userRoles);

        if ((null != batchClassIdentifiers && batchClassIdentifiers.size() > 0)
                || (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0)) {
            Set<String> batchInstanceIdentifierSet = batchInstanceGroupsDao
                    .getBatchInstanceIdentifiersExceptUserRoles(userRoles);
            if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0
                    && null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0
                    && null != batchInstanceIdentifierSet && batchInstanceIdentifierSet.size() > 0) {
                final Conjunction conjunction = Restrictions.conjunction();
                final Disjunction disjunction = Restrictions.disjunction();
                criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                disjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
                disjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
                conjunction.add(Restrictions
                        .not(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifierSet)));
                conjunction.add(disjunction);
                criteria.add(conjunction);
            } else if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0
                    && null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0) {
                final Disjunction disjunction = Restrictions.disjunction();
                criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                disjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
                disjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
                criteria.add(disjunction);
            } else if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0
                    && null != batchInstanceIdentifierSet && batchInstanceIdentifierSet.size() > 0) {
                final Conjunction conjunction = Restrictions.conjunction();
                criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                conjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
                conjunction.add(Restrictions
                        .not(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifierSet)));
                criteria.add(conjunction);
            } else if (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0
                    && null != batchInstanceIdentifierSet && batchInstanceIdentifierSet.size() > 0) {
                final Conjunction conjunction = Restrictions.conjunction();
                conjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
                conjunction.add(Restrictions
                        .not(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifierSet)));
                criteria.add(conjunction);
            } else if (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0) {
                criteria.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIdentifiers));
            } else if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
                criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
                criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
            }
            if (!isNotCurrentUserCheckReq && null != currentUserName) {
                criteria.add(Restrictions.or(Restrictions.isNull(CURRENT_USER),
                        Restrictions.eq(CURRENT_USER, currentUserName)));
            }
            count = count(criteria);
        }
    }
    return count;
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * An API to fetch all the batch instance by BatchPriority.
 * /*from w  ww . j  av a2s.  com*/
 * @param batchPriority BatchPriority this will add the where clause to the criteria query based on the priority column.
 * @return List<BatchInstance> return the batch instance list.
 */
@Override
public List<BatchInstance> getBatchInstance(BatchPriority batchPriority) {
    DetachedCriteria criteria = criteria();
    Integer lowValue = batchPriority.getLowerLimit();
    Integer upperValue = batchPriority.getUpperLimit();
    criteria.add(Restrictions.between(PRIORITY, lowValue, upperValue));
    return find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * An API to fetch all the batch instances only remotely executing batches by status list. Parameter firstResult set a limit upon
 * the number of objects to be retrieved. Parameter maxResults set the first result to be retrieved. Parameter orderList set the
 * sort property and order of that property. If orderList parameter is null or empty then this parameter is avoided.
 * //  w w w  .ja va  2s.  c  om
 * @param statusList List<BatchInstanceStatus> status list of batch instance status.
 * @param firstResult the first result to retrieve, numbered from <tt>0</tt>
 * @param maxResults maxResults the maximum number of results
 * @param orderList List<Order> orderList set the sort property and order of that property. If orderList parameter is null or empty
 *            then this parameter is avoided.
 * @param filterClauseList List<BatchInstanceFilter> this will add the where clause to the criteria query based on the property
 *            name and value. If filterClauseList parameter is null or empty then this parameter is avoided.
 * @param batchPriorities List<BatchPriority> this will add the where clause to the criteria query based on the priority list
 *            selected. If batchPriorities parameter is null or empty then this parameter is avoided.
 * @param userName Current user name.
 * @param userRoles Set<String>
 * @return List<BatchInstance> return the batch instance list.
 */
@Override
public List<BatchInstance> getRemoteBatchInstances(List<BatchInstanceStatus> statusList, final int firstResult,
        final int maxResults, final List<Order> orderList, final List<BatchInstanceFilter> filterClauseList,
        final List<BatchPriority> batchPriorities, String userName, final Set<String> userRoles) {
    EphesoftCriteria criteria = criteria();

    if (null != statusList) {
        criteria.add(Restrictions.in(STATUS, statusList));
        criteria.add(
                Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));
        criteria.add(Restrictions.eq(IS_REMOTE, true));
    }

    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteria.add(disjunction);

    }

    List<BatchInstance> batchInstances = new ArrayList<BatchInstance>();

    Set<String> batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);

    if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
        BatchInstanceFilter[] filters = null;
        if (filterClauseList != null) {
            filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
        }
        Order[] orders = null;
        if (orderList != null) {
            orders = orderList.toArray(new Order[orderList.size()]);
        }

        criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
        criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
        batchInstances = find(criteria, firstResult, maxResults, filters, orders);
    }

    return batchInstances;
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * An API to fetch all the batch instances by status list. Parameter firstResult set a limit upon the number of objects to be
 * retrieved. Parameter maxResults set the first result to be retrieved. Parameter orderList set the sort property and order of
 * that property. If orderList parameter is null or empty then this parameter is avoided.
 * // w  w w.j  a v  a 2 s.  com
 * @param statusList List<BatchInstanceStatus> status list of batch instance status.
 * @param firstResult the first result to retrieve, numbered from <tt>0</tt>
 * @param maxResults maxResults the maximum number of results
 * @param orderList List<Order> orderList set the sort property and order of that property. If orderList parameter is null or empty
 *            then this parameter is avoided.
 * @param filterClauseList List<BatchInstanceFilter> this will add the where clause to the criteria query based on the property
 *            name and value. If filterClauseList parameter is null or empty then this parameter is avoided.
 * @param batchPriorities List<BatchPriority> this will add the where clause to the criteria query based on the priority list
 *            selected. If batchPriorities parameter is null or empty then this parameter is avoided.
 * @param userName Current user name.
 * @param userRoles currentUserRoles
 * @param EphesoftUser current ephesoft-user
 * @param criteria EphesoftCriteria
 * @param searchString the searchString on which batch instances have to be fetched
 * @return List<BatchInstance> return the batch instance list.
 */
public List<BatchInstance> getBatchInstances(List<BatchInstanceStatus> statusList, final int firstResult,
        final int maxResults, final List<Order> orderList, final List<BatchInstanceFilter> filterClauseList,
        final List<BatchPriority> batchPriorities, String userName, final Set<String> userRoles,
        EphesoftUser ephesoftUser, final EphesoftCriteria criteria, final String searchString) {
    EphesoftCriteria criteriaLocal = null;
    if (criteria == null) {
        criteriaLocal = criteria();
    } else {
        criteriaLocal = criteria;
    }

    // For adding identifier as an criteria for result
    if (null != searchString && !searchString.isEmpty()) {
        String searchStringLocal = searchString.replaceAll("%", "\\\\%");
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, "%" + searchStringLocal + "%");
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, "%" + searchStringLocal + "%");

        LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
        criteriaLocal.add(searchCriteria);
    }

    if (null != statusList) {
        criteriaLocal.add(Restrictions.in(STATUS, statusList));
        // criteria.add(Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));
    }

    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteriaLocal.add(disjunction);

    }

    List<BatchInstance> batchInstaceList = new ArrayList<BatchInstance>();
    BatchInstanceFilter[] filters = null;
    Order[] orders = null;
    switch (ephesoftUser) {
    default:
        Set<String> batchClassIndentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        Set<String> batchInstanceIndentifiers = batchInstanceGroupsDao
                .getBatchInstanceIdentifierForUserRoles(userRoles);
        if ((null != batchClassIndentifiers && batchClassIndentifiers.size() > 0)
                || (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0)) {
            if (filterClauseList != null) {
                filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
            }
            if (orderList != null) {
                orders = orderList.toArray(new Order[orderList.size()]);
            }
            if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0
                    && null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                final Disjunction disjunction = Restrictions.disjunction();
                if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0) {
                    criteriaLocal.createAlias(BATCH_CLASS, BATCH_CLASS);
                    disjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIndentifiers));
                }
                if (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                    disjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIndentifiers));
                }
                criteriaLocal.add(disjunction);
            } else if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0) {
                criteriaLocal.createAlias(BATCH_CLASS, BATCH_CLASS);
                criteriaLocal.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIndentifiers));
            } else if (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                criteriaLocal.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIndentifiers));
            }
            batchInstaceList = find(criteriaLocal, firstResult, maxResults, filters, orders);
        }
        break;
    }
    return batchInstaceList;
}

From source file:com.fe.daos.DAOFilm.java

/**
 * Busca todas las grabaciones en un rango de length
 * @param init/*  w  ww  .j ava2  s .c  o  m*/
 * @param end
 * @return 
 */
public ArrayList<Film> loadFilmsByRange(int init, int end) {
    ArrayList<Film> tmp = new ArrayList();//Temporal Array to storage the results
    short s_init = (short) init;//TO sconsider the lower number
    short s_end = (short) end;
    try {
        initTransaction();
        Criteria cr = session.createCriteria(Film.class);//Define the type of the class, if you define the class you
        //don't need specify the context class
        cr.add(Restrictions.between("length", s_init, s_end));//Defines a restriction between acording the property
        cr.setMaxResults(100);
        tmp = (ArrayList) cr.list();
        transaction.commit();//does flush the session, but it also ends the unit of work.
    } catch (HibernateException ex1) {
        System.out.println("HibernateEx on loadFilmsByRange()");
        ex1.printStackTrace();
    } finally {
        HibernateUtil.close(session);
    }
    return tmp;
}

From source file:com.fich.wafproject.dao.UserDaoImpl.java

public List<Users> findAll(int pageNumber, String[] targets, String[] names, String[] values,
        boolean pagination) {
    int pageSize = 4;
    Criteria crit = this.createEntityCriteria();
    crit.setProjection(Projections.distinct(Projections.property("id")));
    String dateFrom = "", dateTo = "", targetDate = "";
    if (names != null) {
        for (String alias : names) {
            crit.createAlias(alias, alias);
        }/*w w w  . ja  va2 s.  co  m*/
    }
    int count = 0;
    if (values != null) {
        for (String value : values) {
            if (!value.equals("") && value != null) {
                if (targets[count].contains("date")) {
                    if (dateFrom != "") {
                        dateTo = value;
                    } else {
                        dateFrom = value;
                        targetDate = targets[count];
                    }
                } else {
                    crit.add(Restrictions.like(targets[count], "%" + value + "%"));
                }
            }
            count++;
        }
        if (targetDate != "") {
            if (dateFrom != "" && dateTo == "") {
                dateTo = dateFrom;
            }
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
            try {
                Date dateF = format.parse(dateFrom);
                Date dateT = format.parse(dateTo);
                crit.add(Restrictions.between(targetDate, dateF, dateT));
            } catch (ParseException ex) {
                Logger.getLogger(UserDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    if (pagination) {
        crit.setFirstResult((pageNumber - 1) * pageSize);
        crit.setMaxResults(pageSize);
    }
    List<Users> users = new ArrayList<Users>();
    for (Object idEvent : crit.list()) {
        //            System.out.println(idEvent);
        users.add(this.findById((Long) idEvent));
    }
    return (List<Users>) users;
}

From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java

public List<UsersHistory> filter(String[] values, String[] names, String[] targets, int pageNumber,
        String role) {/*from   w w  w.j  a va  2 s. c o m*/
    int pageSize = 6;
    int count = 0;
    boolean filterByUserProperty = false, filterByUserName = false;
    Criteria crit = this.createEntityCriteria();//.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    crit.setProjection(Projections.distinct(Projections.property("id")));
    String dateFrom = "", dateTo = "", targetDate = "";
    if (names != null) {
        for (String alias : names) {
            crit.createAlias(alias, alias);
            if (alias.equals("user"))
                filterByUserProperty = true;
        }
    }
    if (!filterByUserProperty && !role.equals(""))
        crit.createAlias("user", "user");
    if (values != null) {
        for (String value : values) {
            if (!value.equals("") && value != null) {
                if (targets[count].contains("date")) {
                    if (dateFrom != "") {
                        dateTo = value;
                    } else {
                        dateFrom = value;
                        targetDate = targets[count];
                    }
                } else {
                    if (targets[count].contains("userName"))
                        filterByUserName = true;
                    crit.add(Restrictions.like(targets[count], "%" + value + "%"));
                }
            }
            count++;
        }
        if (targetDate != "") {
            if (dateFrom != "" && dateTo == "") {
                dateTo = dateFrom;
            }
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
            try {
                Date dateF = format.parse(dateFrom);
                Date dateT = format.parse(dateTo);
                crit.add(Restrictions.between(targetDate, dateF, dateT));
            } catch (ParseException ex) {
                Logger.getLogger(UserHistoryDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (!filterByUserName && !role.equals(""))
        crit.add(Restrictions.like("user.userName", role));
    crit.setFirstResult((pageNumber - 1) * pageSize);
    crit.setMaxResults(pageSize);
    List<UsersHistory> events = new ArrayList<UsersHistory>();
    for (Object idEvent : crit.list()) {
        events.add(this.findById((Long) idEvent));
    }
    return (List<UsersHistory>) events;
}

From source file:com.floreantpos.model.dao.PosTransactionDAO.java

License:Open Source License

public List<PosTransaction> findAuthorizedTransactions(User owner) {
    Session session = null;/*  www .j a v  a  2s .c  o  m*/

    try {
        session = getSession();

        Criteria criteria = session.createCriteria(CreditCardTransaction.class);
        criteria.add(Restrictions.eq(PosTransaction.PROP_CAPTURED, Boolean.TRUE));
        criteria.add(Restrictions.or(Restrictions.isNull(PosTransaction.PROP_VOIDED),
                Restrictions.eq(PosTransaction.PROP_VOIDED, Boolean.FALSE)));
        criteria.add(Restrictions.isNotNull(PosTransaction.PROP_TICKET));
        //criteria.add(Restrictions.eq(PosTransaction.PROP_DRAWER_RESETTED, Boolean.FALSE));
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date startOfDay = DateUtil.startOfDay(calendar.getTime());
        Date endOfDay = DateUtil.endOfDay(new Date());
        //show credit card transactions of last 2 days
        criteria.add(Restrictions.between(PosTransaction.PROP_TRANSACTION_TIME, startOfDay, endOfDay));

        return criteria.list();
    } finally {
        closeSession(session);
    }
}

From source file:com.green.modules.sys.service.LogService.java

License:Open Source License

public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = logDao.createDetachedCriteria();

    Long createById = StringUtils.toLong(paramMap.get("createById"));
    if (createById > 0) {
        dc.add(Restrictions.eq("createBy.id", createById));
    }//w ww .ja  v  a2 s  .c  o  m

    String requestUri = ObjectUtils.toString(paramMap.get("requestUri"));
    if (StringUtils.isNotBlank(requestUri)) {
        dc.add(Restrictions.like("requestUri", "%" + requestUri + "%"));
    }

    String exception = ObjectUtils.toString(paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
        dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
        beginDate = DateUtils.setDays(new Date(), 1);
        paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
        endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
        paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("id"));
    return logDao.find(page, dc);
}

From source file:com.heimaide.server.service.sys.SysLogService.java

License:Open Source License

public Page<SysLog> find(Page<SysLog> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = logDao.createDetachedCriteria();

    String createById = (String) paramMap.get("createById");
    if (StringUtils.isNotBlank(createById)) {
        dc.add(Restrictions.eq("createBy.id", createById));
    }/*w w w.j  av  a  2s.  co m*/

    String requestUri = (String) (paramMap.get("requestUri"));
    if (StringUtils.isNotBlank(requestUri)) {
        dc.add(Restrictions.like("requestUri", "%" + requestUri + "%"));
    }

    String exception = (String) (paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
        dc.add(Restrictions.eq("type", SysLog.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
        beginDate = DateUtils.setDays(new Date(), 1);
        paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
        endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
        paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("id"));
    return logDao.find(page, dc);
}