Example usage for org.hibernate.criterion Restrictions like

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

Introduction

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

Prototype

public static SimpleExpression like(String propertyName, Object value) 

Source Link

Document

Apply a "like" constraint to the named property

Usage

From source file:com.bean.DirectoryAdminBean.java

public List<Directory> getAllDirectory() {
    Dao dao = new Dao();
    List<Directory> list = null;
    if (searchkey == null || searchkey.equals(null) || searchkey.equals("")) {
        list = dao.getByCondition(Directory.class, Order.desc("dirId"));
    } else {//from  w  w  w.j a  v  a2  s. c om
        Criterion name = Restrictions.like("dirName", "%" + searchkey + "%");
        Criterion address = Restrictions.like("dirAddress", "%" + searchkey + "%");
        Criterion web = Restrictions.like("dirWebsite", "%" + searchkey + "%");
        Criterion desc = Restrictions.like("dirDescription", "%" + searchkey + "%");
        Criterion phone = Restrictions.like("dirPhone", "%" + searchkey + "%");
        Disjunction orExp = Restrictions.or(new Criterion[] { name, address, web, desc, phone });
        list = dao.getByCondition(Directory.class, orExp, Order.desc("dirId"));
    }
    return list;
}

From source file:com.bean.DirectoryTypeBean.java

public List<DirectoryType> getAllDirectoryType() {
    Dao dao = new Dao();
    List<DirectoryType> list = null;
    if (searchkey == null || searchkey.equals(null) || searchkey.equals("")) {
        list = dao.getByCondition(DirectoryType.class, Order.desc("dirtId"));
    } else {/*from w w  w .  j ava 2s .c  o m*/
        Criterion name = Restrictions.like("dirtName", "%" + searchkey + "%");
        Criterion desc = Restrictions.like("dirtDescription", "%" + searchkey + "%");
        LogicalExpression orExp = Restrictions.or(desc, name);
        list = dao.getByCondition(DirectoryType.class, orExp, Order.desc("dirtId"));
    }
    return list;
}

From source file:com.bean.DistrictBean.java

public List<District> getAllDistrict() {
    Dao dao = new Dao();
    //them dng ny v ch no select ln
    HibernateUtil.getInstance().clear();
    list = null;/*from   w w  w .j  av a 2  s .  c o  m*/
    if (disSearch == null || disSearch.equals(null) || disSearch.equals("")) {
        list = dao.getByCondition(District.class, Order.desc("distId"));
    } else {
        Criterion name = Restrictions.like("distName", "%" + disSearch + "%");
        Criterion desc = Restrictions.like("distDescription", "%" + disSearch + "%");
        LogicalExpression orExp = Restrictions.or(desc, name);
        list = dao.getByCondition(District.class, orExp, Order.desc("distId"));
    }
    return list;
}

From source file:com.bean.FAQsBean.java

public List<Faqs> getAllFAQs() {
    Dao dao = new Dao();
    List<Faqs> list = null;
    if (faqsSearch == null || faqsSearch.equals("")) {
        list = dao.getByCondition(Faqs.class, Order.desc("faqId"));
    } else {// w  w  w .ja va 2 s .c  o m
        Criterion name = Restrictions.like("faqQuestion", "%" + faqsSearch + "%");
        Criterion desc = Restrictions.like("faqQuestion", "%" + faqsSearch + "%");
        LogicalExpression orExp = Restrictions.or(desc, name);
        list = dao.getByCondition(Faqs.class, orExp, Order.desc("faqId"));
    }
    return list;
}

From source file:com.bean.FeedbackBean.java

public List<Feedback> getAllFeedback() {
    Dao dao = new Dao();
    List<Feedback> list = null;
    if (searchkey == null || searchkey.equals(null) || searchkey.equals("")) {
        Order o = Order.desc("feedDate");
        list = dao.getByCondition(Feedback.class, o);
    } else {// ww w.  j  ava  2  s. c o  m
        Criterion name = Restrictions.like("feedCustomerName", "%" + searchkey + "%");
        Criterion mail = Restrictions.like("feedEmail", "%" + searchkey + "%");
        Criterion phone = Restrictions.like("feedPhone", "%" + searchkey + "%");
        Criterion msg = Restrictions.like("feedMessage", "%" + searchkey + "%");
        Order o = Order.desc("feedDate");
        Disjunction orExp = Restrictions.or(new Criterion[] { name, mail, phone, msg });
        list = dao.getByCondition(Feedback.class, orExp, o);
    }
    return list;
}

From source file:com.bean.NewFavoritePropertyBean.java

public List<NewFavoritePropertyBean> getAllProvince() {
    Dao dao = new Dao();
    List<NewFavoritePropertyBean> list = null;
    if (getFpsearch() == null || getFpsearch().equals(null) || getFpsearch().equals("")) {
        list = dao.getAll(NewFavoritePropertyBean.class);
    } else {/*from w w w.ja v a  2 s. co  m*/
        Criterion name = Restrictions.like("favId", "%" + getFpsearch() + "%");
        Criterion desc = Restrictions.like("property", "" + getFpsearch() + "%");
        LogicalExpression orExp = Restrictions.or(desc, name);
        list = dao.getByCondition(NewFavoritePropertyBean.class, orExp);
    }
    return list;
}

From source file:com.Bean.PostinfoHelper.java

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

    List<Post> postList = new ArrayList<Post>();
    try {/*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.PropertyBean.java

public List<Property> getGenerateList() {
    Dao dao = new Dao();
    HibernateUtil.getInstance().clear();
    if (searchkey == null) {
        searchkey = "";
    }/*from   www.  ja  v a  2  s.  c  o  m*/
    long idP = 0;
    try {
        idP = Long.parseLong(searchkey);
    } catch (Exception ex) {

    }
    Criterion cTitle = Restrictions.like("proTitle", "%" + searchkey + "%");
    Criterion cUser = Restrictions.eq("users", new Users(searchkey));
    LogicalExpression logic = Restrictions.or(cTitle, cUser);
    if (idP != 0) {
        Criterion cid = Restrictions.eq("proId", idP);
        logic = Restrictions.or(logic, cid);
    }

    Criterion cType = null;
    if (searchtype != null && !searchtype.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchtype);
            cType = Restrictions.eq("exchangeType", new ExchangeType(id));
        } catch (Exception ex) {
            cType = Restrictions.isNotNull("exchangeType");
        }
    } else {
        cType = Restrictions.isNotNull("exchangeType");
    }
    logic = Restrictions.and(cType, logic);

    Criterion cCat = null;
    if (searchcat != null && !searchcat.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchcat);
            cCat = Restrictions.eq("propertyType", new PropertyType(id));
            logic = Restrictions.and(logic, cCat);
        } catch (Exception ex) {

        }
    }
    Criterion cPub = null;
    if (searchpub != null && !searchpub.equals("")) {
        boolean id = false;
        try {
            id = Boolean.parseBoolean(searchpub);
            cPub = Restrictions.eq("proPublish", id);
            logic = Restrictions.and(logic, cPub);
        } catch (Exception ex) {
        }
    }
    Criterion cStt = null;
    if (searchStt != null && !searchStt.equals("")) {
        int id;
        try {
            id = Integer.parseInt(searchpub);
            cStt = Restrictions.eq("proStatus", id);
            logic = Restrictions.and(logic, cStt);
        } catch (Exception ex) {
        }
    }
    Order o = Order.desc("proPublishDate");
    listProperty = dao.getByCondition(Property.class, logic, o);
    return listProperty;
}

From source file:com.bean.PropertyOfUserBean.java

public List<Property> getGenerateList() {
    Dao dao = new Dao();
    HibernateUtil.getInstance().clear();
    Users u = (Users) dao.getById(Users.class, user);
    Criterion cUser = Restrictions.eq("users", u);
    if (searchkey == null) {
        searchkey = "";
    }//  ww w.j  a va 2 s .c  om
    Criterion cTitle = Restrictions.like("proTitle", "%" + searchkey + "%");
    LogicalExpression logic;

    Criterion cType = null;
    if (searchtype != null && !searchtype.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchtype);
            cType = Restrictions.eq("exchangeType", new ExchangeType(id));
        } catch (Exception ex) {
            cType = Restrictions.isNotNull("exchangeType");
        }
    } else {
        cType = Restrictions.isNotNull("exchangeType");
    }
    logic = Restrictions.and(cType, cTitle);

    Criterion cCat = null;
    if (searchcat != null && !searchcat.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchcat);
            cCat = Restrictions.eq("propertyType", new PropertyType(id));
            logic = Restrictions.and(logic, cCat);
        } catch (Exception ex) {

        }
    }
    Criterion cPub = null;
    if (searchpub != null && !searchpub.equals("")) {
        boolean id = false;
        try {
            id = Boolean.parseBoolean(searchpub);
            cPub = Restrictions.eq("proPublish", id);
            logic = Restrictions.and(logic, cPub);
        } catch (Exception ex) {
        }
    }
    Criterion cStt = null;
    if (searchStt != null && !searchStt.equals("")) {
        int id;
        try {
            id = Integer.parseInt(searchpub);
            cStt = Restrictions.eq("proStatus", id);
            logic = Restrictions.and(logic, cStt);
        } catch (Exception ex) {
        }
    }
    logic = Restrictions.and(logic, cUser);
    Order o = Order.desc("proPublishDate");
    listProperty = dao.getByCondition(Property.class, logic, o);
    return listProperty;
}

From source file:com.bean.PropertyTypeBean.java

public List<PropertyType> getPropertyType() {
    Dao dao = new Dao();
    HibernateUtil.getInstance().clear();
    List<PropertyType> list = null;
    if (getPropertytypeSearch() == null || getPropertytypeSearch().equals(null)
            || getPropertytypeSearch().equals("")) {
        list = dao.getByCondition(PropertyType.class, Order.desc("protId"));
    } else {/*  w  w w  .j a v  a 2  s  .  co  m*/
        Criterion name = Restrictions.like("protName", "%" + getPropertytypeSearch() + "%");
        Criterion desc = Restrictions.like("protDescription", "%" + getPropertytypeSearch() + "%");
        LogicalExpression orExp = Restrictions.or(desc, name);
        list = dao.getByCondition(PropertyType.class, orExp, Order.desc("protId"));
    }
    return list;
}