Example usage for org.hibernate.criterion Restrictions in

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

Introduction

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

Prototype

public static Criterion in(String propertyName, Collection values) 

Source Link

Document

Apply an "in" constraint to the named property.

Usage

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@SuppressWarnings("unchecked")
@Override//from   ww  w .  jav  a 2  s  .  c o m
public List<Factura> getAll() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Factura> list = criteria.list();
    return list;
}

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@Override
public List<Factura> getDiary() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.asc("idFactura"));
    criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.addOrder(Order.desc("idFactura"));
    List<Factura> list = criteria.list();
    return list;//  ww  w.j ava 2  s  . c  om
}

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@Override
public List<Factura> getMonth() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    Calendar calendar = Calendar.getInstance();
    Date toDate = calendar.getTime();
    calendar.add(Calendar.MONTH, -1);
    Date fromDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.addOrder(Order.desc("idFactura"));
    List<Factura> list = criteria.list();
    return list;/* ww w.j a  v  a2s  .com*/
}

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@Override
public List<Factura> getDiaryReserva() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.desc("idFactura"));
    criteria.add(Restrictions/*from www .  j a  v  a2 s.c o  m*/
            .not(Restrictions.in("estado", new String[] { "INICIADO", "CONFIRMADO", "CANCELADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Factura> list = criteria.list();
    return list;
}

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@Override
public List<Factura> getMonthReserva() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    Calendar calendar = Calendar.getInstance();
    Date toDate = calendar.getTime();
    calendar.add(Calendar.MONTH, -1);
    Date fromDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.add(Restrictions//w ww .j  a  va2s .co m
            .not(Restrictions.in("estado", new String[] { "INICIADO", "CONFIRMADO", "CANCELADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.addOrder(Order.desc("idFactura"));
    List<Factura> list = criteria.list();
    return list;
}

From source file:com.Bean.PostinfoHelper.java

public List<Post> searchByCriteria(PostSearcher postSearcher, int page) {

    List<Post> postList = new ArrayList<Post>();
    try {/*from   w  w w .  j a v a 2  s  .co  m*/
        Criteria c = session.createCriteria(Post.class);
        if (postSearcher.getTitle() != null) {
            c.add(Restrictions.like("title", "%" + postSearcher.getTitle() + "%"));
        }
        if ((postSearcher.getMinPrice() >= 0) && (postSearcher.getMaxPrice() >= 0)) {
            c.add(Restrictions.between("price", postSearcher.getMinPrice(), postSearcher.getMaxPrice()));
        } else if (postSearcher.getMinPrice() >= 0) {
            c.add(Restrictions.ge("price", postSearcher.getMinPrice()));
        } else if (postSearcher.getMaxPrice() >= 0) {
            c.add(Restrictions.le("price", postSearcher.getMaxPrice()));
        }
        if (postSearcher.getTypes() != null) {
            c.add(Restrictions.in("type", postSearcher.getTypes()));
        }
        maxPage = c.list().size() / itemsPerPage;
        c.setFirstResult(page * itemsPerPage);
        c.setMaxResults(itemsPerPage);
        postList = (List<Post>) c.list();
        return postList;
    } catch (HibernateException e) {
        System.err.println(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.bean.SearchBean.java

public void init() {
    Dao dao = new Dao();

    long pMin = 0, pMax = 0, aMin = 0, aMax = 0;
    try {//from w ww  .  j a v  a 2s .c  o m
        pMin = Long.parseLong(this.priceMin);
    } catch (Exception ex) {

    }
    try {
        pMax = Long.parseLong(this.priceMax);
    } catch (Exception ex) {

    }
    try {
        aMin = Long.parseLong(this.areaMin);
    } catch (Exception ex) {

    }
    try {
        aMax = Long.parseLong(this.areaMax);
    } catch (Exception ex) {

    }

    LogicalExpression logic;
    Criterion district = null;
    Criterion province;
    Criterion propertyType = null;
    Criterion exchange = null;
    Criterion priceMin;
    Criterion priceMax;
    Criterion areaMin;
    Criterion areaMax;

    if (this.propertyType != 0) {
        PropertyType p = new PropertyType(this.propertyType);
        propertyType = Restrictions.eq("propertyType", p);
    } else {
        propertyType = Restrictions.isNotNull("propertyType");
    }

    if (this.exchangeType != 0) {
        ExchangeType e = new ExchangeType(this.exchangeType);
        exchange = Restrictions.eq("exchangeType", e);
    } else {
        exchange = Restrictions.isNotNull("exchangeType");
    }

    if (districtId != 0) {
        District d = new District(districtId);
        district = Restrictions.eq("district", d);
    } else {
        if (provinceId != 0) {
            Province p = (Province) dao.getById1(Province.class, provinceId);
            //Set<District> list = p.getDistricts();
            if (p != null && p.getDistricts().size() > 0) {
                district = Restrictions.in("district", p.getDistricts());
            } else {
                district = Restrictions.isNull("district");
            }
        }
    }
    Criterion cpub = Restrictions.eq("proPublish", true);
    Criterion stt = Restrictions.eq("proStatus", 0);
    logic = Restrictions.and(propertyType, exchange);
    logic = Restrictions.and(logic, stt);
    logic = Restrictions.and(logic, cpub);
    if (district != null) {
        logic = Restrictions.and(logic, district);
    }

    if (pMax > 0) {
        priceMax = Restrictions.between("proPrice", pMin, pMax);
        logic = Restrictions.and(logic, priceMax);
    } else {
        priceMin = Restrictions.gt("proPrice", pMin);
        logic = Restrictions.and(logic, priceMin);
    }

    if (aMax > 0) {
        areaMax = Restrictions.between("proArea", aMin, aMax);
        logic = Restrictions.and(logic, areaMax);
    } else {
        areaMin = Restrictions.gt("proArea", aMin);
        logic = Restrictions.and(logic, areaMin);
    }

    Order o = Order.desc("proPublishDate");

    listSearch = dao.getByCondition(Property.class, logic, o);

}

From source file:com.bean.SuggestedBean.java

public void init(long id) {
    Dao dao = new Dao();
    Property p = (Property) dao.getById(Property.class, id);
    Province prov = (Province) dao.getById(Province.class, p.getDistrict().getProvince().getProvId());
    Criterion d = Restrictions.in("district", prov.getDistricts());
    Criterion cat = Restrictions.eq("propertyType", p.getPropertyType());
    Criterion type = Restrictions.eq("exchangeType", p.getExchangeType());
    Criterion status = Restrictions.eq("proStatus", 0);
    Order o = Order.desc("proCreateDate");
    Conjunction logic = Restrictions.and(new Criterion[] { d, cat, type, status });
    listSuggested = dao.getByCondition(Property.class, logic, o, 0, 6);
}

From source file:com.benfante.minimark.blo.QuestionBo.java

License:Apache License

/**
 * Search questions by example./*from   ww  w.  j a v  a  2 s. c o m*/
 * 
 * @param questionBean The values for searching questions.
 * @return The list of questions matching the questionBean values.
 */
public List<Question> search(QuestionBean questionBean) {
    DetachedCriteria crit = null;
    if (StringUtils.isBlank(questionBean.getType())) {
        crit = DetachedCriteria.forClass(Question.class);
    } else {
        if ("open".equals(questionBean.getType())) {
            crit = DetachedCriteria.forClass(OpenQuestion.class);
            if (StringUtils.isNotBlank(questionBean.getVisualization())) {
                crit.add(Restrictions.eq("visualization", questionBean.getVisualization()));
            }
        } else if ("closed".equals(questionBean.getType())) {
            crit = DetachedCriteria.forClass(ClosedQuestion.class);
        } else {
            throw new IllegalArgumentException("Unknown question type (" + questionBean.getType() + ")");
        }
    }
    if (StringUtils.isNotBlank(questionBean.getTitle())) {
        crit.add(Restrictions.ilike("title", questionBean.getTitle(), MatchMode.ANYWHERE));
    }
    if (questionBean.getWeight() != null) {
        crit.add(Restrictions.eq("weight", questionBean.getWeight()));
    }
    if (questionBean.getCourse() != null && questionBean.getCourse().getId() != null) {
        crit.add(Restrictions.eq("course.id", questionBean.getCourse().getId()));
    }
    crit.addOrder(Order.asc("title"));
    crit.addOrder(Order.asc("content"));
    if (StringUtils.isNotBlank(questionBean.getTags())) {
        crit.createAlias("tags", "tags");
        crit.createAlias("tags.tag", "tag");
        crit.add(Restrictions.in("tag.name", questionBean.getTagList()));
    }
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return questionDao.searchByCriteria(crit);
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

/**
 * @param variables// ww  w .  ja va2  s .  c o  m
 * @return
 */
private Disjunction createProcessIdCriteria(Criteria variables) {
    // retrieve list of processes matching specified variables
    List<?> processList = variables.list();
    Object[] processIds = getProcessIds(processList);

    // ALF-5841 fix
    int batch = 0;
    List<Object> buf = new ArrayList<Object>(1000);

    Disjunction ids = Restrictions.disjunction();
    for (Object id : processIds) {
        if (batch < 1000) {
            batch++;
            buf.add(id);
        } else {
            ids.add(Restrictions.in("id", buf));
            batch = 0;
            buf.clear();
        }
    }

    if (!buf.isEmpty()) {
        ids.add(Restrictions.in("id", buf));
    }
    return ids;
}