Example usage for org.hibernate.criterion Restrictions or

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

Introduction

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

Prototype

public static LogicalExpression or(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the disjuction of two expressions

Usage

From source file:com.ut.tekir.stock.StockSuggestionBean.java

License:LGPL

public void selectProductList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();

    Criteria crit = session.createCriteria(Product.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("this.code", getCode() + "%"));
    }/*  w  ww. j a va  2 s  .c o  m*/

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("this.name", getName() + "%"));
    }

    if (getBarcode() != null && getBarcode().length() > 0) {
        SimpleExpression barcodeCrit1 = Restrictions.like("this.barcode1", getBarcode() + "%");
        SimpleExpression barcodeCrit2 = Restrictions.like("this.barcode2", getBarcode() + "%");
        SimpleExpression barcodeCrit3 = Restrictions.like("this.barcode3", getBarcode() + "%");

        crit.add(Restrictions.or(Restrictions.or(barcodeCrit1, barcodeCrit2), barcodeCrit3));
    }

    if (getProductType() != ProductType.Unknown) {
        crit.add(Restrictions.eq("this.productType", getProductType()));
    }

    if (getCategory() != null) {
        crit.add(Restrictions.eq("this.category", getCategory()));
    }

    if (getGroup() != null) {
        crit.add(Restrictions.eq("this.group", getGroup()));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("name"), "name").add(Projections.property("productType"), "productType")
            .add(Projections.property("barcode1"), "barcode1").add(Projections.property("category"), "category")
            .add(Projections.property("group"), "group"));

    crit.add(Restrictions.eq("this.active", true));

    crit.setMaxResults(30);
    //        crit.setCacheable(true);
    //TODO: Map niye almyor kine?
    //crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    productList = crit.list();

}

From source file:com.ut.tekir.stock.StockSuggestionBean.java

License:LGPL

public void selectExpenseAndDiscountList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();
    Criteria crit = session.createCriteria(Product.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("this.code", getCode() + "%"));
    }//from  ww  w .j  a va2  s.co m

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("this.name", getName() + "%"));
    }

    if (getProductType() != null && getProductType() == ProductType.Unknown) {
        crit.add(Restrictions.or(Restrictions.eq("this.productType", ProductType.Expense),
                Restrictions.eq("this.productType", ProductType.Discount)));
    } else {
        crit.add(Restrictions.eq("this.productType", getProductType()));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("name"), "name").add(Projections.property("productType"), "productType"));

    crit.add(Restrictions.eq("active", true));

    crit.setMaxResults(30);
    crit.setCacheable(true);
    //TODO: Map niye almyor kine?
    //crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    expenseAndDiscountList = crit.list();

}

From source file:com.uva.jobportal.dao.JobDAOImpl.java

@Override
public List<Job> searchJobByAll(String text, String training, String experience, String languages) {
    try {/*from   w  w  w. j  av a2 s .  co  m*/
        List<Job> jobs;
        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session s = sf.openSession();
        s.beginTransaction();

        Criterion criterionTitle = Restrictions.like("title", "%" + text + "%");
        Criterion criterionDescription = Restrictions.like("description", "%" + text + "%");
        Criterion criterionTitleOrDescription = Restrictions.or(criterionTitle, criterionDescription);
        Criterion criterionTraining = Restrictions.like("training", "%" + training + "%");
        Criterion criterionExperience = Restrictions.like("experience", "%" + experience + "%");
        Criterion criterionLanguages = Restrictions.like("languages", "%" + languages + "%");
        Criteria criteria = s.createCriteria(Job.class).add(Restrictions.and(criterionTitleOrDescription,
                criterionTraining, criterionExperience, criterionLanguages));
        jobs = (List<Job>) criteria.list();
        s.getTransaction().commit();
        s.close();
        sf.close();
        return jobs;
    } catch (HibernateException e) {
        return null;
    }
}

From source file:com.vektorel.hrapp.service.taner.KullaniciService.java

@Override
public List<Kullanici> getAll(String query) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria criteria = session.createCriteria(Kullanici.class);
    if (query != null) {
        //            select * from kullanici where ad_soyad like '%KARA%' or username like '%KARA%'
        criteria.add(Restrictions.or(Restrictions.ilike("username", query, MatchMode.ANYWHERE),
                Restrictions.ilike("adSoyad", query, MatchMode.ANYWHERE)));
    }/*  w  ww .java 2s . c om*/
    criteria.addOrder(Order.asc("id"));
    return criteria.list();
}

From source file:com.vmware.bdd.entity.TaskEntity.java

License:Open Source License

public static List<TaskEntity> findAllByStatus(final Status[] anyStatus, final String exceptCookie) {
    return DAL.autoTransactionDo(new Saveable<List<TaskEntity>>() {
        @Override//from   w w w  . java  2s .c  o  m
        public List<TaskEntity> body() throws Exception {
            Criterion crit = null;
            for (Status s : anyStatus) {
                if (crit == null) {
                    crit = Restrictions.eq("status", s);
                } else {
                    crit = Restrictions.or(crit, Restrictions.eq("status", s));
                }
            }

            AuAssert.check(crit != null);

            if (exceptCookie != null) {
                crit = Restrictions.and(crit, Restrictions.ne("cookie", exceptCookie));
            }

            return DAL.findByCriteria(TaskEntity.class, crit);
        }
    });
}

From source file:com.webbfontaine.valuewebb.action.pricedb.mp.PRDConsult.java

License:Open Source License

private void fillPDs(Pd pd) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MONTH, -3);
    Date dateOfTodayMinus3Months = calendar.getTime();

    Criteria criteria = PersistenceUtil.getSession(entityManager).createCriteria(Pd.class)
            .setMaxResults(Constants.MAX_RECORDS_IN_FINDER_RESULT).addOrder(Order.desc("id"));
    if (pd.getHsCodeF() != null) {
        criteria.add(Restrictions.like("hsCodeF", pd.getHsCodeF(), MatchMode.START));
    }/*from   w  ww  .j  a va 2 s  . c o  m*/
    if (pd.getProductDscF() != null) {
        criteria.add(Restrictions.ilike("productDscF", pd.getProductDscF(), MatchMode.ANYWHERE));
    }
    if (!StringUtils.isEmpty(pd.getValMethod())) {
        criteria.add(Restrictions.ilike("valMethod", pd.getValMethod(), MatchMode.ANYWHERE));
    }

    if (ApplicationProperties.getAppCountry().equals(Constants.CI)) {
        // according to ELL-1186, hardcoded restriction added to qlClassLine, qlValLine
        criteria.add(Restrictions.and(
                Restrictions.or(Restrictions.eq("qlValLine", "1"), Restrictions.isNull("qlValLine")),
                Restrictions.or(Restrictions.eq("qlClassLine", "1"), Restrictions.isNull("qlClassLine"))));
    }

    Criteria ttCrit = criteria.createCriteria("ttGen");
    ttCrit.add(Restrictions.ge("date", dateOfTodayMinus3Months));

    pdDB.addAll(criteria.list());
}

From source file:com.wonders.bud.freshmommy.service.content.dao.impl.ContentDaoImpl.java

License:Open Source License

@Override
public Page<ContentPO> findByPageCustom(Page<ContentPO> page, String orQuery) {
    Criteria c = createCriteria();//from ww  w. j av  a2s. c  om
    if (page.getParam() != null) {
        c = page.getParam().andCriteria(c);
    }
    if (orQuery != null) {
        Criterion cTitle = Restrictions.like("title", "%" + orQuery + "%");
        Criterion cShortTitle = Restrictions.like("shortTitle", "%" + orQuery + "%");
        LogicalExpression orExp1 = Restrictions.or(cTitle, cShortTitle);
        Criterion cTxt = Restrictions.like("txt", "%" + orQuery + "%");
        LogicalExpression orExp = Restrictions.or(orExp1, cTxt);
        c.add(orExp);
    }

    c.setProjection(null);

    // ??
    int totalCount = ((Long) c.setProjection(Projections.rowCount()).uniqueResult()).intValue();

    c.setProjection(null);
    c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);

    // page
    if (page.getStart() > -1) {
        c.setFirstResult(page.getStart());
    }
    if (page.getPagesize() > -1) {
        c.setMaxResults(page.getPagesize());
    }
    List<ContentPO> result = c.list();
    getSession().clear();
    page.setResult(result);
    page.setTotal(totalCount);
    return page;
}

From source file:com.zanvork.guildhub.model.Realm.java

public static Realm getRealm(String realmName, String regionName) {
    Realm realm = null;/* ww  w.  j  a  v  a2s.  c  om*/
    List<Realm> list;
    Region region = Region.valueOf(regionName);

    SessionFactory sessionFactory = HibernateMySQLDAO.getSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();

    list = session.createCriteria(Realm.class).add(Restrictions.eq("region", region))
            .add(Restrictions.or(Restrictions.eq("slug", realmName), Restrictions.eq("realm_name", realmName)))
            .list();
    session.getTransaction().commit();

    if (!list.isEmpty()) {
        realm = list.get(0);
    }
    return realm;
}

From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object readInnerProperty(String type, String paramId, String calType) {
    String average = null;/*from w  w  w.ja  v  a 2s.  com*/
    List<Reply> list = null;
    switch (type) {
    case "rating":
        session = getSessionFactory().openSession();

        Criteria criteria = session.createCriteria(Reply.class, "reply");
        criteria.createAlias("reply.client", "client");
        criteria.setReadOnly(true);
        Calendar cal = Calendar.getInstance();
        String date0 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date1 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date2 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date3 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date4 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date5 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date6 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());

        criteria.add(Restrictions.or(Restrictions.eq("client.date", date0),
                Restrictions.or(Restrictions.eq("client.date", date1),
                        Restrictions.or(Restrictions.eq("client.date", date2),
                                Restrictions.or(Restrictions.eq("client.date", date3),
                                        Restrictions.or(Restrictions.eq("client.date", date4), Restrictions.or(
                                                Restrictions.eq("client.date", date5),
                                                Restrictions.or(Restrictions.eq("client.date", date6)))))))));
        criteria.add(Restrictions.eq("reply.question", paramId));
        criteria.add(Restrictions.eq("reply.type", type));
        criteria.add(Restrictions.ne("reply.answer", "0"));
        criteria.setResultTransformer(criteria.DISTINCT_ROOT_ENTITY);
        list = (List<Reply>) criteria.list();

        Float value = 0.0f;
        for (Reply val : list) {
            if (val.getAnswer() != null && !val.getAnswer().equals("")) {
                value += Float.parseFloat(val.getAnswer());
            }
        }
        value /= list.size();
        average = value.toString();

    case "descriptive":
    case "options":
    case "binary":
    default:
    }
    return average;
}

From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Long getProm() {
    Long val = null;

    session = getSessionFactory().getCurrentSession();

    Criteria criteria = session.createCriteria(Reply.class, "reply");
    criteria.setReadOnly(true);//  w  w w.  j  a  va  2  s . c  o m
    criteria.add(Restrictions.like("reply.type", "rating"));
    criteria.add(Restrictions.ne("reply.answer", "0"));

    criteria.add(Restrictions.or(Restrictions.like("reply.answer", "4", MatchMode.START),
            Restrictions.like("reply.answer", "5", MatchMode.START)));
    criteria.setProjection(Projections.rowCount());
    val = (Long) criteria.uniqueResult();

    return val;
}