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, String value, MatchMode matchMode) 

Source Link

Document

A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode

Usage

From source file:com.simple.cms.dao.ArticleDaoImpl.java

@Override
public List<Article> findArticleByNumber(int number) {
    List<Article> Articles;
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }/*ww  w .  ja v a2s.  c o  m*/
    try {
        dbSession.beginTransaction();
        Articles = dbSession.createCriteria(Article.class)
                .add(Restrictions.ilike("number", number + "", MatchMode.ANYWHERE)).list();
        dbSession.getTransaction().commit();
        dbSession.flush();

        return Articles;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }

}

From source file:com.simple.cms.dao.ArticleDaoImpl.java

@Override
public List<Article> findArticleByName(String name) {
    List<Article> Articles;
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }//from   www. j  ava 2s  .co  m
    try {
        dbSession.beginTransaction();
        Articles = dbSession.createCriteria(Article.class)
                .add(Restrictions.ilike("name", name, MatchMode.ANYWHERE)).list();
        dbSession.getTransaction().commit();
        dbSession.flush();

        return Articles;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }
}

From source file:com.simple.cms.dao.UserDaoImpl.java

@Override
public List<User> findUsersByName(String name) {
    List<User> users;/*w ww  .j  av a  2 s.c  o m*/
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }
    try {
        dbSession.beginTransaction();

        users = dbSession.createCriteria(User.class).add(Restrictions.ilike("name", name, MatchMode.ANYWHERE))
                .list();
        dbSession.getTransaction().commit();

        return users;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }

}

From source file:com.socialsite.dao.hibernate.AbstractDaoImpl.java

License:Open Source License

/**
 * helper method to find the count of item that match the filter
 * /*w  w w.  j  a va  2  s.co  m*/
 * @param filter
 *            filter text
 * @param clazz
 *            class of the item
 * @param field
 *            field that will be matched with the criteria
 * @return
 */
@SuppressWarnings("unchecked")
protected int count(String filter, final Class clazz, final String field) {
    // Avoids NPE
    filter = filter == null ? "" : filter;

    final Criteria criteria = getSession().createCriteria(clazz);
    criteria.add(Restrictions.ilike(field, filter, MatchMode.ANYWHERE));
    criteria.setProjection(Projections.rowCount());
    return (Integer) criteria.uniqueResult();
}

From source file:com.socialsite.dao.hibernate.AbstractDaoImpl.java

License:Open Source License

/**
 * a helper method to find the list of item matching the filter
 * /*from  w  w  w  .j  ava  2 s.  c  o  m*/
 * @param filter
 *            filter text
 * @param first
 *            first index of the resul
 * @param count
 *            count
 * @param sortParam
 *            sorting is done based on this property
 * @param clazz
 *            class of the item
 * @param field
 *            field that will be matched with the criteria
 * @return list of item matching the filter text
 */
@SuppressWarnings("unchecked")
protected List find(String filter, final int first, final int count, final SortParam sortParam,
        final Class clazz, final String field) {
    // avoids the NPE
    filter = filter == null ? "" : filter;

    // order
    final Order order = sortParam.isAscending() ? Order.asc(sortParam.getProperty())
            : Order.desc(sortParam.getProperty());
    final Criteria criteria = getSession().createCriteria(clazz);
    criteria.setFirstResult(first);
    criteria.setMaxResults(count);
    criteria.add(Restrictions.ilike(field, filter, MatchMode.ANYWHERE));
    criteria.addOrder(order);
    return criteria.list();
}

From source file:com.tm.main.SystemUI.java

public void addSearchCriteria() {
    mLogger.info("addSearchCriteria--Starts");
    mSearchCriteria.clear();/*from w w w  . java2s  .  c  om*/

    this.getRootPane().setDefaultButton(btnListData);

    if (sptxtRecordId.getText() != null && sptxtRecordId.getText().length() > 0) {
        mSearchCriteria.add(Restrictions.eq("taskId", new BigDecimal(sptxtRecordId.getText())));
    }

    if (sptxtReferenceNo.getText() != null && sptxtReferenceNo.getText().length() > 0) {
        mSearchCriteria.add(Restrictions.eq("taskReference", sptxtReferenceNo.getText()));
    }

    if (spcmbAssignee.getSelectedIndex() > 0) {
        mSearchCriteria.add(Restrictions.eq("assignee", ((CellDTO) spcmbAssignee.getSelectedItem()).getKey()));
    }

    if (spcmbStatus.getSelectedIndex() > 0) {
        mSearchCriteria.add(Restrictions.eq("status", ((CellDTO) spcmbStatus.getSelectedItem()).getKey()));
    }

    if (spcmbProject.getSelectedIndex() > 0) {
        mSearchCriteria
                .add(Restrictions.eq("projectName", ((CellDTO) spcmbProject.getSelectedItem()).getKey()));
    }

    if (spcmbPriority.getSelectedIndex() > 0) {
        mSearchCriteria.add(Restrictions.eq("priority", ((CellDTO) spcmbPriority.getSelectedItem()).getKey()));
    }

    /* Date Criteria */
    if (spdtAssignDateFrom.getDate() != null && spdtAssignDateTo.getDate() == null) {
        mSearchCriteria.add(Restrictions.eq("createDate", spdtAssignDateFrom.getDate()));
    }

    if (spdtAssignDateFrom.getDate() != null && spdtAssignDateTo.getDate() != null) {
        mSearchCriteria.add(
                Restrictions.between("createDate", spdtAssignDateFrom.getDate(), spdtAssignDateTo.getDate()));
    }

    if (spdtDeliveryDateFrom.getDate() != null && spdtDeliveryDateTo.getDate() == null) {
        mSearchCriteria.add(Restrictions.eq("eta", spdtDeliveryDateFrom.getDate()));
    }

    if (spdtDeliveryDateFrom.getDate() != null && spdtDeliveryDateTo.getDate() != null) {
        mSearchCriteria
                .add(Restrictions.between("eta", spdtDeliveryDateFrom.getDate(), spdtDeliveryDateTo.getDate()));
    }

    /* Date Criteria Ends */
    if (sptxtTitle.getText() != null && sptxtTitle.getText().length() > 0) {
        mSearchCriteria.add(Restrictions.ilike("title", sptxtTitle.getText(), MatchMode.ANYWHERE));
    }

    if (sptxtComment.getText() != null && sptxtComment.getText().length() > 0) {
        mSearchCriteria.add(Restrictions.ilike("commentText", sptxtComment.getText(), MatchMode.ANYWHERE));
    }

    if (sptxtModuleName.getText() != null && sptxtModuleName.getText().length() > 0) {
        mSearchCriteria.add(Restrictions.ilike("moduleName", sptxtModuleName.getText(), MatchMode.ANYWHERE));
    }

    if (spcmbTaskType.getSelectedIndex() > 0) {
        mSearchCriteria.add(Restrictions.eq("taskType", ((CellDTO) spcmbTaskType.getSelectedItem()).getKey()));
    }

    if (rdoPlanningStatus.isSelected()) {
        mSearchCriteria.add(Restrictions.isNull("eta"));
        mSearchCriteria.add(Restrictions.isNull("assignee"));
    }

    mLogger.info("addSearchCriteria--Ends");
}

From source file:com.ub.hrappub.service.KullaniciService.java

@Override
public List<Kullanici> getAll(String query) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria criteria = session.createCriteria(Kullanici.class);
    if (query != null) {
        criteria.add(Restrictions.or(Restrictions.ilike("uname", query, MatchMode.ANYWHERE),
                Restrictions.ilike("isim", query, MatchMode.ANYWHERE)));
    }//from   ww  w.  j a v a2s . c om
    criteria.addOrder(Order.asc("id"));
    return criteria.list();
}

From source file:com.ub.hrappub.service.PersonelService.java

@Override
public List<Personel> getAll(String query) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria criteria = session.createCriteria(Personel.class);
    if (query != null) {
        criteria.add(Restrictions.or(Restrictions.ilike("isim", query, MatchMode.ANYWHERE)));
    }/* w  w w .  java2s  .  co  m*/
    criteria.addOrder(Order.asc("id"));
    return criteria.list();
}

From source file:com.ut.tekir.contact.ContactBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {
    DetachedCriteria crit = DetachedCriteria.forClass(Contact.class);

    crit.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("code"), "code").add(Projections.property("name"), "name")
            .add(Projections.property("fullname"), "fullname").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("taxNumber"), "taxNumber")
            .add(Projections.property("taxOffice"), "taxOffice").add(Projections.property("title"), "title")
            .add(Projections.property("representative"), "representative")
            .add(Projections.property("info"), "info").add(Projections.property("exCode1"), "exCode1")
            .add(Projections.property("exCode2"), "exCode2").add(Projections.property("allType"), "allType")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("bankType"), "bankType")
            .add(Projections.property("relatedType"), "relatedType")
            .add(Projections.property("foundationType"), "foundationType")));

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

    if (filterModel.getCode() != null && filterModel.getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }//from w  ww  .j  a v a2 s  .c  om

    if (filterModel.getFullname() != null && filterModel.getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", filterModel.getFullname(), MatchMode.ANYWHERE));
    }

    if (filterModel.getCompany() != null && filterModel.getCompany().length() > 0) {
        crit.add(Restrictions.ilike("this.company", filterModel.getCompany(), MatchMode.START));
    }

    if (filterModel.getSsn() != null && filterModel.getSsn().length() > 0) {
        crit.add(Restrictions.ilike("this.ssn", filterModel.getSsn(), MatchMode.START));
    }

    if (filterModel.getTaxNumber() != null && filterModel.getTaxNumber().length() > 0) {
        crit.add(Restrictions.ilike("this.taxNumber", filterModel.getTaxNumber(), MatchMode.START));
    }

    if (filterModel.getRepresentative() != null && filterModel.getRepresentative().length() > 0) {
        crit.add(Restrictions.ilike("this.representative", filterModel.getRepresentative(), MatchMode.START));
    }

    if (filterModel.getExCode1() != null && filterModel.getExCode1().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode1", filterModel.getExCode1(), MatchMode.START));
    }

    if (filterModel.getExCode2() != null && filterModel.getExCode2().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode2", filterModel.getExCode2(), MatchMode.START));
    }

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

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

    if (filterModel.getCompanyType() != null && !filterModel.getCompanyType().equals("All")) {
        if (filterModel.getCompanyType().equals("Person")) {
            crit.add(Restrictions.eq("this.person", Boolean.TRUE));
        } else
            crit.add(Restrictions.eq("this.person", Boolean.FALSE));
    }

    if (filterModel.getType() != null && filterModel.getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + filterModel.getType().toString().toLowerCase() + "Type",
                Boolean.TRUE));
    }

    if (filterModel.getCountry() != null) {
        crit.createAlias("this.addressList", "addressList", CriteriaSpecification.INNER_JOIN);
        crit.add(Restrictions.eq("addressList.address.country", filterModel.getCountry()));

        if (filterModel.getCity1() != null) {
            crit.add(Restrictions.eq("addressList.city", filterModel.getCity1()));
        }
    }

    //FIXME: bu kontrol nasl olmal?
    if (hasRegionRestriction()) {
        if (activeUser.getContact() != null && activeUser.getContact().getOrganization() != null
                && activeUser.getContact().getOrganization() != null) {

            crit.add(Restrictions.or(
                    Restrictions.eq("this.organization.id", activeUser.getContact().getOrganization().getId()),
                    Restrictions.eq("this.isPublic", Boolean.TRUE)));
        }
    }
    crit.addOrder(Order.desc("this.code"));

    return crit;
}

From source file:com.ut.tekir.contact.ContactSuggestionBean.java

License:LGPL

public void selectCustomerList() {

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

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

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", getCode(), MatchMode.START));
    }//from w  w w  . jav a  2 s .c o m

    if (getCompany() != null && !getCompany().isEmpty()) {
        crit.add(Restrictions.ilike("this.company", getCompany(), MatchMode.START));
    }

    if (getSsn() != null && !getSsn().isEmpty()) {
        crit.add(Restrictions.ilike("this.ssn", getSsn(), MatchMode.START));
    }

    if (getTaxNumber() != null & !getTaxNumber().isEmpty()) {
        crit.add(Restrictions.ilike("this.taxNumber", getTaxNumber(), MatchMode.START));
    }

    if (getFullname() != null && getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", getFullname(), MatchMode.ANYWHERE));
    }
    if (getType() != null && getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + getType().toString().toLowerCase() + "Type", Boolean.TRUE));
    }
    if (getCategory() != null) {
        crit.add(Restrictions.eq("this.category", getCategory()));
    }
    if (getExCode1() != null & !getExCode1().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode1", getExCode1(), MatchMode.START));
    }
    if (getExCode2() != null & !getExCode2().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode2", getExCode2(), MatchMode.START));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("fullname"), "fullname")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("allType"), "allType").add(Projections.property("id"), "id")
            .add(Projections.property("category"), "category")
            .add(Projections.property("taxNumber"), "taxNumber").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("exCode2"), "exCode2")
            .add(Projections.property("exCode1"), "exCode1"));

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

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

}