Example usage for org.hibernate.criterion Restrictions ilike

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

Introduction

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

Prototype

public static Criterion ilike(String propertyName, Object value) 

Source Link

Document

A case-insensitive "like" (similar to Postgres ilike operator)

Usage

From source file:com.ut.tekir.finance.ForeignExchangeBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(ForeignExchange.class);

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("serial", filterModel.getSerial() + "%"));
    }//from w w  w .  j av  a 2  s  .  co  m

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("reference", filterModel.getReference() + "%"));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("code", filterModel.getCode() + "%"));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("date", filterModel.getEndDate()));
    }

    if (filterModel.getBank() != null) {
        crit.add(Restrictions.eq("bank", filterModel.getBank()));
    }

    if (filterModel.getBankBranch() != null) {
        crit.add(Restrictions.eq("bankBranch", filterModel.getBankBranch()));
    }

    if (filterModel.getFromBankAccount() != null) {
        crit.add(Restrictions.eq("fromBankAccount", filterModel.getFromBankAccount()));
    }

    if (filterModel.getToBankAccount() != null) {
        crit.add(Restrictions.eq("toBankAccount", filterModel.getToBankAccount()));
    }

    crit.addOrder(Order.desc("this.date"));
    return crit;
}

From source file:com.ut.tekir.finance.PromissoryChangeStatusBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(PromissoryNote.class);

    crit.createAlias("this.history", "history");
    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.groupProperty("this.id"), "id")
            .add(Projections.groupProperty("this.maturityDate"), "maturityDate")
            .add(Projections.groupProperty("this.referenceNo"), "referenceNo")
            .add(Projections.groupProperty("this.promissorynoteOwner"), "promissorynoteOwner")
            .add(Projections.groupProperty("contact.id"), "contactId")
            .add(Projections.groupProperty("contact.name"), "contactName")
            .add(Projections.groupProperty("this.lastStatus"), "lastStatus")
            .add(Projections.groupProperty("this.previousStatus"), "previousStatus")
            .add(Projections.groupProperty("this.info"), "info")
            .add(Projections.groupProperty("money.currency"), "moneyCurrency")
            .add(Projections.groupProperty("money.value"), "moneyValue")
            .add(Projections.groupProperty("this.serialNo"), "serialNo"));

    crit.setResultTransformer(Transformers.aliasToBean(PromissorySumModel.class));

    if (isNotEmpty(filterModel.getReferenceNo())) {
        crit.add(Restrictions.eq("this.referenceNo", filterModel.getReferenceNo()));
    }//from  w  w w.j  a va  2s.  c o  m

    if (filterModel.getContact() != null) {
        crit.add(Restrictions.eq("this.contact", filterModel.getContact()));
    }

    if (isNotEmpty(filterModel.getPromissorynoteOwner())) {
        crit.add(Restrictions.ilike("this.promissorynoteOwner", filterModel.getPromissorynoteOwner() + "%"));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("history.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("history.date", filterModel.getEndDate()));
    }

    if (filterModel.getLastStatus() != null) {
        crit.add(Restrictions.eq("this.lastStatus", filterModel.getLastStatus()));
    }
    if (getIsClientPromissory() != null) {
        crit.add(Restrictions.eq("this.clientPromissoryNote", getIsClientPromissory()));
    }
    return crit;
}

From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java

License:Apache License

@Override
public Criterion apply(FilterPredicate filterPredicate) {
    List<FilterPredicate.PathElement> path = filterPredicate.getPath();

    /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */
    String alias;/* w ww.  j  a  v a2s  .  c  o  m*/
    if (path.size() > 1) {
        alias = getAlias(path);
        alias = alias + "." + path.get(path.size() - 1).getFieldName();
        /* If the predicate refers to the root entity, the restriction should be 'fieldName' */
    } else {
        alias = path.get(0).getFieldName();
    }

    switch (filterPredicate.getOperator()) {
    case IN:
        if (filterPredicate.getValues().isEmpty()) {
            return Restrictions.sqlRestriction("(false)");
        }
        return Restrictions.in(alias, filterPredicate.getValues());
    case NOT:
        if (filterPredicate.getValues().isEmpty()) {
            return Restrictions.sqlRestriction("(true)");
        }
        return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues()));
    case PREFIX:
        return Restrictions.like(alias,
                filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case PREFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias,
                filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case POSTFIX:
        return Restrictions.like(alias, MATCHALL_CHARACTER
                + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER));
    case POSTFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias, MATCHALL_CHARACTER
                + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER));
    case INFIX:
        return Restrictions.like(alias,
                MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case INFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias,
                MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case ISNULL:
        return Restrictions.isNull(alias);
    case NOTNULL:
        return Restrictions.isNotNull(alias);
    case LT:
        return Restrictions.lt(alias, filterPredicate.getValues().get(0));
    case LE:
        return Restrictions.le(alias, filterPredicate.getValues().get(0));
    case GT:
        return Restrictions.gt(alias, filterPredicate.getValues().get(0));
    case GE:
        return Restrictions.ge(alias, filterPredicate.getValues().get(0));
    case TRUE:
        return Restrictions.sqlRestriction("(true)");
    case FALSE:
        return Restrictions.sqlRestriction("(false)");
    default:
        throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator());
    }
}

From source file:com.zdtx.ifms.specific.service.analy.PhenomenonManager.java

public Page<Phenomenon> getPage(Page<Phenomenon> page, PhenomenonVO pheVo) {
    List<Order> orderList = new ArrayList<Order>();
    Criteria criteria = baseDao.getSession().createCriteria(Phenomenon.class);
    criteria.add(Restrictions.eq("isdelete", "F"));
    if (!Utils.isEmpty(pheVo.getDrivername())) {
        criteria.add(Restrictions.ilike("drivername", "%" + pheVo.getDrivername().trim() + "%"));
    }/*from   ww  w  .  ja  va2  s .c o m*/
    if (!Utils.isEmpty(pheVo.getVehiclename())) {
        criteria.add(Restrictions.ilike("licenseplate", "%" + pheVo.getVehiclename().trim() + "%"));
    }
    if (!Utils.isEmpty(pheVo.getIsremove()) && !"-1".equals(pheVo.getIsremove())) {
        criteria.add(Restrictions.eq("isremove", pheVo.getIsremove()));
    }
    orderList.add(Order.asc("isremove"));
    orderList.add(Order.asc("licenseplate"));
    return baseDao.getBatch(page, criteria, orderList);
}

From source file:com.zdtx.ifms.specific.service.monitor.IpCamManager.java

public Page<Camera> getBatch(Page<Camera> page, IpCamVO vo) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Camera.class);
    criteria.createAlias("modelID", "modelID");
    criteria.add(Restrictions.eq("isDelete", "F"));

    criteria.add(Restrictions.in("deptid", (Long[]) Struts2Util.getSession().getAttribute("userDepartment")));
    if (null != vo.getDepartmentid() && -1L != vo.getDepartmentid()) {
        criteria.add(Restrictions.eq("deptid", vo.getDepartmentid()));
    }// w  w  w . j a va2s. c  om

    if (!Utils.isEmpty(vo.getModelID()) && vo.getModelID() != -1L) {
        criteria.add(Restrictions.eq("modelID.modelID", vo.getModelID()));
    }
    if (!Utils.isEmpty(vo.getCamName())) {
        criteria.add(Restrictions.ilike("cameraName", "%" + vo.getCamName() + "%"));
    }
    if (!Utils.isEmpty(vo.getCamCode())) {
        criteria.add(Restrictions.ilike("cameraCode", "%" + vo.getCamCode() + "%"));
    }
    if (!Utils.isEmpty(vo.getCamIP())) {
        criteria.add(Restrictions.ilike("ipAddress", "%" + vo.getCamIP() + "%"));
    }
    List<Order> orderList = new ArrayList<Order>();
    orderList.add(Order.asc("cameraName"));
    //      orders.add(Order.asc("modelID.modelID"));
    Page<Camera> pageResult = dao.getBatch(page, criteria.getExecutableCriteria(dao.getSession()), orderList);

    if (1 == pageResult.getCurrentPage()) {
        Utils.getSession().setAttribute("criteria_export", criteria);
        Utils.getSession().setAttribute("page_export", page);
        Utils.getSession().setAttribute("orderList_export", orderList);
    }
    return pageResult;
}

From source file:control.dao.StaffDAO.java

public List<Object> getStaffList(String key, int type, int page) {
    int firstResult = (page - 1) * 20;
    int totalSize;
    Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    List<Object> resultSet = new ArrayList<>();
    boolean searchByFirstName = true;
    try {/*from   w w w  .  ja  v a2  s  . c  om*/
        session.beginTransaction();
        //            Query qr =session.createQuery("from "
        //                    +Staff.class.getName() 
        //                    + " s left join fetch s.roleCollection");
        //            session.createQuery(")
        Criteria crit = session.createCriteria(Staff.class);
        crit.setFetchMode("roleCollection", FetchMode.SELECT);
        crit.addOrder(Order.asc("id"));
        crit.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("userName")).add(Projections.property("firstName"))
                .add(Projections.property("lastName")).add(Projections.property("phone"))
                .add(Projections.property("email")).add(Projections.property("status")));

        switch (type) {
        case 0:
            break;

        case 1:
            crit.add(Restrictions.ilike("userName", "%" + key + "%"));
            break;

        case 2:
            while (true) {
                if (searchByFirstName) {
                    crit.add(Restrictions.ilike("firstName", "%" + key + "%"));
                    searchByFirstName = crit.list().isEmpty();
                    if (searchByFirstName) {
                        break;
                    }
                } else {
                    crit.add(Restrictions.ilike("lastName", "%" + key + "%"));
                    break;
                }
            }
            break;

        case 3:
            crit.add(Restrictions.ilike("phone", "%" + key + "%"));
            break;

        case 4:
            crit.add(Restrictions.ilike("email", "%" + key + "%"));
            break;

        case 5:
            crit.add(Restrictions.ilike("adress", "%" + key + "%"));
            break;
        }

        totalSize = crit.list().size();
        crit.setFirstResult(firstResult);
        crit.setMaxResults(20);
        resultSet = crit.list();
        resultSet.add(totalSize);
        return resultSet == null ? new ArrayList<>() : resultSet;
    } catch (Exception e) {
        e.printStackTrace();
        return new ArrayList<>();
    } finally {
        if (session.getTransaction().isActive()) {
            session.getTransaction().commit();
        }
    }
}

From source file:control.dao.SupplierDAO.java

public List<SupplierBean> getSupplier(String key, int type) {
    List<Supplier> res = null;
    Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    try {//from   w ww.jav a  2  s  . c om
        session.beginTransaction();
        Criteria crit = session.createCriteria(Supplier.class);
        switch (type) {
        case 0:
            break;

        case 1:
            crit.add(Restrictions.ilike("name", "%" + key + "%"));
            break;

        case 2:
            res = new ArrayList<Supplier>();
            List<Product> plist = null;
            Criteria pcrit = session.createCriteria(Product.class);
            pcrit.add(Restrictions.eq("barcode", key));
            plist = pcrit.list();
            if (plist == null || plist.isEmpty()) {
                return null;
            } else {
                session.getTransaction().commit();
                for (Product product : plist) {
                    res.add(product.getSId());
                    System.out.println(res.size());
                    return res.isEmpty() ? null : dco.toSupplierBeanCollect(res);
                }
            }
            break;
        case 3:
            crit.add(Restrictions.ilike("code", "%" + key + "%"));
            break;

        case 4:
            crit.add(Restrictions.ilike("email", "%" + key + "%"));
            break;

        case 5:
            crit.add(Restrictions.ilike("adress", "%" + key + "%"));
            break;

        case 6:
            crit.add(Restrictions.ilike("fax", "%" + key + "%"));
            break;

        case 7:
            crit.add(Restrictions.ilike("phone", "%" + key + "%"));
            break;

        }
        res = crit.list();
        return res == null ? null : dco.toSupplierBeanCollect(res);
    } catch (Exception e) {
        System.out.println("Error at" + this.getClass());
        return null;
    } finally {
        if (session.getTransaction().isActive()) {
            session.getTransaction().commit();
        }
    }
}

From source file:controllers.WniosekController.java

public List<Wniosek> mojeWnioski() {

        Session session = ConnectionFactory.getSessionFactory().openSession();
        String login_zalogowanego = UserController.getUserName();
        Criteria cr = session.createCriteria(Users.class);
        cr.add(Restrictions.ilike("login", login_zalogowanego));
        List<Users> result = cr.list();
        String query = "FROM Wniosek WHERE Osoba_wnioskodawcaID=" + result.get(0).getUser_id()
                + "OR Kierownik_dzialu_naukID=" + result.get(0).getUser_id() + "OR Kierownik_BRPM_BWM_ID="
                + result.get(0).getUser_id() + "OR Kwestor_ID=" + result.get(0).getUser_id() + "OR Szef_pionuID="
                + result.get(0).getUser_id() + "OR Osoba_przyjmujaca_wniosek_ID=" + result.get(0).getUser_id()
                + "OR Kierownik_dzialu_zam_pub_ID=" + result.get(0).getUser_id() + "OR Pelnomocnik_rektora_ID="
                + result.get(0).getUser_id();

        wnioski = session.createQuery(query).list();
        session.close();//  w  w w  .  j a v a2  s. c o  m

        return wnioski;

    }

From source file:controllers.WniosekController.java

public String zobacz(Wniosek w) {
        Session session = ConnectionFactory.getSessionFactory().openSession();

        String login_zalogowanego = UserController.getUserName();
        Criteria cr = session.createCriteria(Users.class);
        cr.add(Restrictions.ilike("login", login_zalogowanego));
        List<Users> result = cr.list();

        String query1 = "FROM Przedmiot_zamowienia WHERE Wniosek_ID=" + w.getWniosek_ID();
        String query = "FROM Przedmiot_zamowienia_item WHERE Przedmiot_zamowienia_ID IN (SELECT Przedmiot_zamowienia_id FROM Przedmiot_zamowienia WHERE Wniosek_ID="
                + w.getWniosek_ID() + ")";
        listaPrzedmiotowZamowienia = session.createQuery(query).list();
        przedmiot_zamowienia = (Przedmiot_zamowienia) session.createQuery(query1).list().get(0);

        NawigacjaZatwierdzanieWnioskow nawigacja = new NawigacjaZatwierdzanieWnioskow();

        session.close();//  w w  w . j  av  a  2 s . c om
        this.wniosekView = w;
        return nawigacja.getNawigacjaFromRole(result.get(0).getRola());
    }

From source file:controllers.WniosekController.java

public String wnioskiDoAkceptacji() {
        Session session = ConnectionFactory.getSessionFactory().openSession();

        String login_zalogowanego = UserController.getUserName();
        Criteria cr = session.createCriteria(Users.class);
        cr.add(Restrictions.ilike("login", login_zalogowanego));
        List<Users> result = cr.list();

        MaszynaStanow ms = new MaszynaStanow();
        String stan = ms.getStanFromRole(result.get(0).getRola());
        System.out.println(stan);
        if (stan != null)
            wnioski = session.createQuery("FROM Wniosek WHERE Stan='" + stan + "'").list(); //jak stan===null to znaczy e to jest jaki wnioskodawca czy jakas osoba ktora nie moze akceptowac wnioskow
        else {/* w w w  .j a  v  a2 s  .  co m*/
            wnioski = null;
            return "brakWnioskowDoAkceptacji";
        }

        session.close();

        if (wnioski.isEmpty())
            return "brakWnioskowDoAkceptacji";
        return "wnioskiDoAkceptacji";
    }