Example usage for org.hibernate.criterion Restrictions ge

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

Introduction

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

Prototype

public static SimpleExpression ge(String propertyName, Object value) 

Source Link

Document

Apply a "greater than or equal" constraint to the named property

Usage

From source file:com.mycompany.rosterms.dao.impl.ResearchPublicationDAOIMPL.java

@Override
public ResearchPublication getByResearchPublicationId(int rpId) {
    Criteria c = sessionFactory.getCurrentSession().createCriteria(ResearchPublication.class);
    c.add(Restrictions.ge("rpId", rpId));
    return (ResearchPublication) c.uniqueResult();
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:com.mycompany.rosterms.dao.impl.UserDAOImpl.java

@Override
public User getByUserId(int userId) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
    criteria.add(Restrictions.ge("userId", userId));
    return (User) criteria.uniqueResult();
}

From source file:com.mycompany.rosterms.dao.impl.WorkingExperienceDAOIMPL.java

@Override
public WorkingExperience getByWorkingExperienceId(int weId) {
    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    Criteria c = sessionFactory.getCurrentSession().createCriteria(WorkingExperience.class);
    c.add(Restrictions.ge("weId", weId));
    return (WorkingExperience) c.uniqueResult();
}

From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*ww w .ja v  a2  s  .  co  m*/
public Map<String, BudgetPerformance> findByOrgCodeAndStartMonthEndMonthAndKmkCodeJs(String orgCode,
        String startMonth, String endMonth, String... kmkCodeJs) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException(
                "Organization code or current month in acton must not be null or empty");
    }
    if (StringUtils.isEmpty(startMonth)) {
        throw new IllegalArgumentException("Start month must not be null or empty");
    }
    if (StringUtils.isEmpty(endMonth)) {
        throw new IllegalArgumentException("End month month must not be null or empty");
    }
    if (ArrayUtils.isEmpty(kmkCodeJs)) {
        throw new IllegalArgumentException("KmkCodeJs must not be null");
    }

    // 
    logger.info("Find by organization code:" + orgCode + " startMonth " + startMonth + " endMonth " + endMonth
            + "kmkcodej " + StringUtils.join(kmkCodeJs, ","));
    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Map<String, BudgetPerformance> mapBudgetPerformances = new HashMap<String, BudgetPerformance>();

    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("pk.organization.strCode", orgCode),
                Restrictions.and(Restrictions.ge("pk.getSudo", startMonth),
                        Restrictions.and(Restrictions.le("pk.getSudo", endMonth),
                                Restrictions.and(Restrictions.in("pk.kmkCodeJ", kmkCodeJs),
                                        Restrictions.eq("delKbn", Constants.STATUS_ACTIVE)))));
        Criteria crit = session.createCriteria(BudgetPerformance.class);
        crit.add(criterion);

        List<BudgetPerformance> budgetPerformances = repository.findByCriteria(crit);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(budgetPerformances)) {
            throw new ObjectNotFoundException("There is no the budget performance object");
        }

        mapBudgetPerformances = new HashMap<String, BudgetPerformance>();
        for (BudgetPerformance budgetPerformance : budgetPerformances) {
            mapBudgetPerformances.put(
                    budgetPerformance.getPk().getGetSudo() + budgetPerformance.getPk().getKmkCodeJ(),
                    budgetPerformance);
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while get budget performance data by organization code " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return mapBudgetPerformances;
}

From source file:com.onecheckoutV1.sa.TransactionSandboxReportBean.java

public String getTransaction(int merchantCode, Date day) {

    Criteria criteria = getSession().createCriteria(Transactions.class);
    criteria.createCriteria("merchantPaymentChannel", "mpc", Criteria.INNER_JOIN);
    criteria.createCriteria("mpc.paymentChannel", "pc", Criteria.INNER_JOIN);

    criteria.add(Restrictions.eq("incMallid", merchantCode));
    criteria.add(Restrictions.ge("transactionsDatetime", day));

    List<Transactions> list = (List<Transactions>) criteria.list();
    List<HashMap> listhashmap = new ArrayList<HashMap>();
    System.out.println(list.size());

    for (Transactions transactions : list) {
        HashMap<String, String> obj = new HashMap<String, String>();
        obj.put("invoice", transactions.getIncTransidmerchant());
        obj.put("amount", transactions.getIncAmount().toString());
        obj.put("trans_date", transactions.getTransactionsDatetime().toString());
        obj.put("status", transactions.getTransactionsStatus().toString());
        obj.put("payment_channel",
                transactions.getMerchantPaymentChannel().getPaymentChannel().getPaymentChannelId());

        listhashmap.add(obj);//from  w  ww  .  j a  va 2s  .com
    }

    Gson gson = new Gson();
    return gson.toJson(listhashmap);
}

From source file:com.pontorural.pedidovenda.repository.Pedidos.java

@SuppressWarnings("unchecked")
public List<Pedido> filtrados(PedidoFilter filtro) {
    Session session = this.manager.unwrap(Session.class);

    Criteria criteria = session.createCriteria(Pedido.class);

    if (filtro.getNumeroDe() != null) {
        // id deve ser maior ou igual (ge = greater or equals) a filtro.numeroDe
        criteria.add(Restrictions.ge("codigo", filtro.getNumeroDe()));
    }//  w  ww.  j  a va2s . c  o m

    if (filtro.getNumeroAte() != null) {
        // id deve ser menor ou igual (le = lower or equal) a filtro.numeroDe
        criteria.add(Restrictions.le("codigo", filtro.getNumeroAte()));
    }

    if (filtro.getEmissaoDe() != null) {
        criteria.add(Restrictions.ge("emissao", filtro.getEmissaoDe()));
    }

    if (filtro.getEmissaoAte() != null) {
        criteria.add(Restrictions.le("emissao", filtro.getEmissaoAte()));
    }

    return criteria.addOrder(Order.asc("codigo")).list();

}

From source file:com.ponysdk.hibernate.query.decorator.AbstractCriteriaDecorator.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override//from   w  w w.j  a  v a2 s  . com
public void render(final CriteriaContext context) {
    final Criterion field = context.getCriterion();
    Criteria criteria = context.getOrderingCriteria();

    final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT));
    final Iterator<String> iter = propertyNamePath.iterator();
    String key = null;
    String associationPath = null;
    if (propertyNamePath.size() == 1) {
        associationPath = iter.next();
    } else
        while (iter.hasNext()) {
            key = iter.next();
            if (associationPath == null) {
                associationPath = new String(key);
            } else {
                associationPath += "." + key;
            }
            if (iter.hasNext()) {
                criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.INNER_JOIN);
                associationPath = new String(key);
            }
        }

    final T value = getObjectValue(field);
    ComparatorType comparator = field.getComparator();

    if (value != null) {
        if (value.toString().contains("%")) {
            comparator = ComparatorType.LIKE;
        }
    }

    if (field.getValue() != null || field.getComparator() == ComparatorType.IS_NULL
            || field.getComparator() == ComparatorType.IS_NOT_NULL) {

        switch (comparator) {
        case EQ:
            criteria.add(Restrictions.eq(associationPath, value));
            break;
        case GE:
            criteria.add(Restrictions.ge(associationPath, value));
            break;
        case GT:
            criteria.add(Restrictions.gt(associationPath, value));
            break;
        case LE:
            criteria.add(Restrictions.le(associationPath, value));
            break;
        case LT:
            criteria.add(Restrictions.lt(associationPath, value));
            break;
        case NE:
            criteria.add(Restrictions.ne(associationPath, value));
            break;
        case LIKE:
            criteria.add(Restrictions.ilike(associationPath, value));
            break;
        case IS_NULL:
            criteria.add(Restrictions.isNull(associationPath));
            break;
        case IS_NOT_NULL:
            criteria.add(Restrictions.isNotNull(associationPath));
            break;
        case IN:
            if (value instanceof Collection) {
                criteria.add(Restrictions.in(associationPath, (Collection) value));
            } else if (value instanceof Object[]) {
                criteria.add(Restrictions.in(associationPath, (Object[]) value));
            } else {
                log.warn("Type not allowed for IN clause: " + value.getClass() + ", value: " + value);
            }
            break;

        default:
            log.warn("Restriction not supported: " + comparator);
            break;
        }
    }

    switch (field.getSortingType()) {
    case ASCENDING:
        criteria.addOrder(Order.asc(associationPath));
        break;
    case DESCENDING:
        criteria.addOrder(Order.desc(associationPath));
        break;
    case NONE:
        break;
    }

}

From source file:com.qcadoo.model.api.search.SearchRestrictions.java

License:Open Source License

/**
 * Creates criterion which checks if field is greater than or equal to given value.
 * /*from   ww w. jav  a  2  s  .c  o m*/
 * @param field
 *            field
 * @param value
 *            value
 * @return criterion
 */
public static SearchCriterion ge(final String field, final Object value) {
    return new SearchCriterionImpl(Restrictions.ge(field, value));
}

From source file:com.qcadoo.model.internal.PriorityServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
private void changePriority(final InternalDataDefinition dataDefinition, final FieldDefinition fieldDefinition,
        final Object databaseEntity, final int fromPriority, final int toPriority, final int diff) {
    Criteria criteria = getCriteria(dataDefinition, fieldDefinition, databaseEntity)
            .add(Restrictions.ge(fieldDefinition.getName(), fromPriority))
            .add(Restrictions.le(fieldDefinition.getName(), toPriority));

    List<Object> entitiesToDecrement = criteria.list();

    for (Object entity : entitiesToDecrement) {
        int priority = (Integer) entityService.getField(entity, fieldDefinition);
        entityService.setField(entity, fieldDefinition, priority + diff);
        hibernateService.getCurrentSession().update(entity);
    }//from w  w w  .j a va 2s.c  om
}

From source file:com.quakearts.webapp.hibernate.HibernateBean.java

License:Open Source License

private Criterion createCriterion(String key, Serializable value, QueryContext context) {
    key = handleKey(key, context);/*from   w  w w . j  av a2s . c o m*/
    if (value instanceof Range) {
        Range range = (Range) value;
        if (range.getFrom() != null && range.getTo() == null)
            return Restrictions.ge(key, ((Range) value).getFrom());
        else if (range.getFrom() == null && range.getTo() != null)
            return Restrictions.le(key, ((Range) value).getTo());

        return Restrictions.between(key, range.getFrom(), range.getTo());
    } else if (value instanceof VariableString) {
        return Restrictions.ilike(key, ((VariableString) value).getValue());
    } else {
        return Restrictions.eq(key, value);
    }
}