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.wavemaker.runtime.data.task.SearchTask.java

License:Open Source License

private static void addRestriction(Criteria c, String propName, Object value, QueryOptions options) {

    if (value == null && options.getExcludeNone()) {
        return;//from  w  w w  .  j a  v  a  2s. co m
    }

    if (String.class.isAssignableFrom(value.getClass())) {

        MatchMode matchMode = options.getTypedMatchMode();

        if (options.getIgnoreCase()) {
            c.add(Restrictions.ilike(propName, (String) value, matchMode));
        } else {
            c.add(Restrictions.like(propName, (String) value, matchMode));
        }

    } else {
        if (String.valueOf(value).equals("0") && options.getExcludeZeros()) {
            return;
        }
        c.add(Restrictions.eq(propName, value));
    }

}

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));
    }/* w w w.j a  v  a  2s .  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.webbfontaine.valuewebb.action.pricedb.mp.PRDConsult.java

License:Open Source License

private void fillMPs(MarketPrice mp) {

    Criteria criteria = PersistenceUtil.getSession(entityManager).createCriteria(MarketPrice.class);
    criteria.createCriteria("sourceOfPrice", "sourceOfPrice");

    criteria.setMaxResults(Constants.MAX_RECORDS_IN_FINDER_RESULT).addOrder(Order.desc("priceDate"));

    if (mp.getHsCode() != null) {
        criteria.add(Restrictions.like("hsCode", mp.getHsCode(), MatchMode.START));
    }/*from w  w w.  j a  v a2s . co m*/

    if (mp.getDpd() != null) {
        criteria.add(Restrictions.ilike("dpd", mp.getDpd(), MatchMode.ANYWHERE));
    }

    if (!StringUtils.isEmpty(mp.getVmRuleCode())) {
        criteria.add(Restrictions.eq("vmRuleCode", mp.getVmRuleCode()));
    }

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

From source file:cras.service.UsuarioService.java

public List<Usuario> readByCriteria(String nome) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria crit = session.createCriteria(Usuario.class);
    crit.add(Restrictions.ilike("nomeresponsavel", nome, MatchMode.ANYWHERE));
    List<Usuario> usuarioList = crit.list();
    return usuarioList;

}

From source file:dao.LeitorDAO.java

public List<Leitor> buscar(String nome, String cpf) {
    return getSession().createCriteria(Leitor.class).add(Restrictions.ilike("nome", nome, MatchMode.START))
            .add(Restrictions.ilike("cpf", cpf, MatchMode.START)).list();
}

From source file:db.DBConnector.java

public void searchDescObjByName(String name) {
    createDCriteria();//from  w w w.  ja  va  2s  . c  om
    dCriteria.add(Restrictions.ilike("this.name", name, MatchMode.ANYWHERE));
    dCriteriaCount.add(Restrictions.ilike("this.name", name, MatchMode.ANYWHERE));
    populatePageOfDataGrid();
}

From source file:db.helpers.FestivalHelper.java

public List<Festival> getFestivals(String name, String location, String artist, Date dateFrom, Date dateTo) {
    List<Festival> festivals = new ArrayList<>();
    session = HibernateUtil.getSessionFactory().getCurrentSession();
    org.hibernate.Transaction tx = session.beginTransaction();
    try {/* ww  w.  j  ava 2  s  .  c o m*/
        Criteria c = session.createCriteria(Festival.class);
        if (name != null && !("".equals(name))) {
            c.add(Restrictions.ilike("name", name, MatchMode.ANYWHERE));
        }
        if (location != null && !("".equals(location))) {
            c.add(Restrictions.ilike("location", location, MatchMode.ANYWHERE));
        }
        if (dateFrom != null) {
            c.add(Restrictions.ge("dateStart", dateFrom));
        }
        if (dateTo != null) {
            c.add(Restrictions.le("dateEnd", dateTo));
        }
        if (artist != null && !("".equals(artist))) {
            c.createAlias("performances", "performance");
            c.add(Restrictions.ilike("performance.artist", artist, MatchMode.ANYWHERE));
        }
        festivals = c.list();
        tx.commit();
    } catch (HibernateException ex) {
        tx.rollback();
    }
    return festivals;
}

From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java

@Override
public Page<T> findAllByFuzzySearch(String search, Set<Criterion> criterions, String... associations) {
    Criteria criteria = getCriteria();/*from   w  w  w  . jav a2 s .  co  m*/
    for (String association : associations) {
        criteria.setFetchMode(association, FetchMode.JOIN);
    }
    List<Criterion> predicates = new ArrayList<>();
    for (String indexedPropery : getIndexedProperties()) {
        if (!StringUtils.isEmpty(search)) {
            String[] searchTerms = search.split(" ");
            for (String searchTerm : searchTerms) {
                predicates.add(Restrictions.ilike(indexedPropery, searchTerm, MatchMode.ANYWHERE));
            }
        }
    }
    if (!predicates.isEmpty()) {
        criteria.add(Restrictions.or(predicates.toArray(new Criterion[predicates.size()])));
    }
    if (criterions != null) {
        for (Criterion c : criterions) {
            criteria.add(c);
        }
    }
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    @SuppressWarnings("unchecked")
    List<T> objects = criteria.list();
    sort(objects);
    PageImpl<T> page = new PageImpl<>(objects);
    return page;
}

From source file:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply an "ilike" constraint on the named property.
 * /*  w w w.java 2s  .  c  om*/
 * <p>
 *   Note: This implementation differs from {@link Restrictions#ilike(String, String, MatchMode)}
 *   because it checks for empty strings and applies {@link CustomRestrictions#isEmpty(String)}
 *   instead.
 * </p>
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @param value the actual value the property should be similiar to
 * @param matchMode the {@link MatchMode} being used
 * @return a new {@link Criterion}
 */
public static Criterion ilike(String propertyName, String value, MatchMode matchMode) {
    return StringUtils.isEmpty(value) ? CustomRestrictions.isEmpty(propertyName)
            : Restrictions.ilike(propertyName, value, matchMode);
}

From source file:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply a "not ilike" constraint on the named property.
 * //from w  w  w .j a  v a  2s  .c om
 * <p>
 *   This implementation handles empty values correctly.
 * </p>
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @param value the actual value the property should be similiar to
 * @param matchMode the {@link MatchMode} being used
 * @return a new {@link Criterion}
 */
public static Criterion notIlike(String propertyName, String value, MatchMode matchMode) {
    if (StringUtils.isEmpty(value)) {
        return CustomRestrictions.isNotEmpty(propertyName);
    } else {
        return Restrictions.or(Restrictions.not(Restrictions.ilike(propertyName, value, matchMode)),
                CustomRestrictions.isEmpty(propertyName));
    }
}