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

Source Link

Document

Apply a "like" constraint to the named property using the provided match mode

Usage

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public String getItemNameSuggestion(String text) throws PigeException {
    Transaction tx = null;/*w ww  . jav a2 s  . c  om*/
    Session session = null;
    List<Item> results = null;
    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();
        results = (List<Item>) session.createCriteria(Item.class)
                .add(Restrictions.like(Item.NAME_REF, text, MatchMode.START)).list();
        tx.commit();
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
    if (results != null && results.size() > 0) {
        return results.get(0).getName();
    }
    return null;
}

From source file:ch.astina.hesperid.dao.hibernate.SystemHealthDAOHibernate.java

License:Apache License

@Override
public List<SystemHealth> findByLog(String searchString) {
    return session.createCriteria(SystemHealth.class)
            .add(Restrictions.like("log", searchString, MatchMode.ANYWHERE)).addOrder(Order.desc("id")).list();
}

From source file:ClasseDao.PagamentoDao.java

public java.util.List pesquisaPeloVenda(String nome) {

    java.util.List lista = null;//w  ww.  ja  v  a  2s.c om
    sessao = HibernateUtil.getSessionFactory().getCurrentSession();
    sessao.beginTransaction();
    try {
        lista = (java.util.List) sessao.createCriteria(Cliente.class)
                .add(Restrictions.like("nomeCliente", nome, MatchMode.START)).list();
        sessao.close();
        return lista;
    } catch (HibernateException e) {
        JOptionPane.showMessageDialog(null, "Nao foi possivel buscar o Cliente " + e);
    }

    return null;

}

From source file:ClasseDao.PerfilDao.java

public java.util.List pesquisaPeloNome(String nome) {

    java.util.List lista = null;// w w w  . ja va  2 s . com
    sessao = HibernateUtil.getSessionFactory().getCurrentSession();
    sessao.beginTransaction();
    try {
        lista = (java.util.List) sessao.createCriteria(Perfil.class)
                .add(Restrictions.like("nomePerfil", nome, MatchMode.ANYWHERE)).list();

        sessao.close();
        return lista;
    } catch (HibernateException e) {
        JOptionPane.showMessageDialog(null, "Nao foi possivel buscar o Perfil " + e);
    }

    return null;

}

From source file:ClasseDao.ProdutoDao.java

public java.util.List pesquisaPeloNome(String nome) {

    java.util.List lista = null;//from  w w w  .j  a v  a 2s  .c om
    sessao = HibernateUtil.getSessionFactory().getCurrentSession();
    sessao.beginTransaction();
    try {
        lista = (java.util.List) sessao.createCriteria(Produto.class)
                .add(Restrictions.like("nomeProduto", nome, MatchMode.START)).list();

        sessao.close();
        return lista;
    } catch (HibernateException e) {
        JOptionPane.showMessageDialog(null, "Nao foi possivel buscar o Produto " + e);
    }

    return null;

}

From source file:ClasseDao.UsuarioDao.java

public java.util.List pesquisaPeloNome(String nome) {

    java.util.List lista = null;//  w w  w .  j a v  a2 s.  c  om
    sessao = HibernateUtil.getSessionFactory().getCurrentSession();
    sessao.beginTransaction();
    try {
        lista = (java.util.List) sessao.createCriteria(Usuario.class)
                .add(Restrictions.like("nomeCliente", nome, MatchMode.START)).list();
        sessao.close();
        return lista;
    } catch (HibernateException e) {
        JOptionPane.showMessageDialog(null, "Nao foi possivel buscar o Cliente " + e);
    }

    return null;

}

From source file:cms.pageList.entity.SearcherLabel.java

License:Apache License

public String getIterativeString(TagLabel tagLabel, List<PropertyFilter> filters) {

    String strTag = tagLabel.getTagName();// ??

    // System.out.println("------------------------------------");

    if (tagLabel == null)
        return strTag;

    // //ww  w.java 2s  .  com

    // ??
    if ((!tagLabel.getOrderby().trim().equalsIgnoreCase(""))
            && (!tagLabel.getOrderbyType().trim().equalsIgnoreCase(""))) {

        String arcattStr = null;// 
        for (Long flagid : tagLabel.getflagIds()) {
            arcattStr += "," + flagid;
        }

        // 
        if (arcattStr != null) {
            // ?0,?
            if (tagLabel.getTypeid() == 0) {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0),
                        Restrictions.sqlRestriction(
                                "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                        + arcattStr + ") )"),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            } else {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.eq("typeid", tagLabel.getTypeid()), Restrictions.ge("arcrank", 0),
                        Restrictions.sqlRestriction(
                                "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                        + arcattStr + ") )"),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            }
        } else { // 

            // ?0,?
            if (tagLabel.getTypeid() == 0) {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            } else {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0), Restrictions.eq("typeid", tagLabel.getTypeid()),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            }

        }

    } else { // ?
        // ?0,?

        if (tagLabel.getTypeid() == 0) {
            addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0),
                    Restrictions.eq("typeid", tagLabel.getTypeid()));
        } else {
            addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0));
        }

    }

    /*strTag = "<s:iterator value=\"pagecontent.listLabel.get("
    + pfValue("getNum", filters)
    + ").getPage().getResult()\" status=\"st\">"
    + tagLabel.getBody() + "</s:iterator>";*/
    strTag = "<#list pagecontent.listLabel.get(" + pfValue("getNum", filters)
            + ").getPage().getResult() as xx >" + tagLabel.getBody() + "</#list>";

    return strTag;
}

From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from   w  ww .  ja v  a 2 s.c  om
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    AssertUtils.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}

From source file:cn.lhfei.fu.web.model.HomeworkBaseModel.java

License:Apache License

@Override
public List<SimpleExpression> wrapperFilter() {
    List<SimpleExpression> expList = new ArrayList<SimpleExpression>();

    if (academicYear != null) {// user routeId to filter 
        SimpleExpression exp = Restrictions.eq("academicYear", academicYear);
        expList.add(exp);//w ww.  j  ava2  s  .  co  m
    }
    if (null != semester && semester.trim().length() > 0) {
        SimpleExpression exp = Restrictions.eq("semester", semester.trim());
        expList.add(exp);
    }

    if (null != className && className.trim().length() > 0) {
        SimpleExpression exp = Restrictions.eq("className", className.trim());
        expList.add(exp);
    }
    if (null != courseName && courseName.trim().length() > 0) {
        SimpleExpression exp = Restrictions.eq("courseName", courseName.trim());
        expList.add(exp);
    }
    if (null != teacherName && teacherName.trim().length() > 0) {
        SimpleExpression exp = Restrictions.eq("teacherName", teacherName.trim());
        expList.add(exp);
    }
    if (null != majorName && majorName.trim().length() > 0) {
        SimpleExpression exp = Restrictions.eq("majorName", majorName.trim());
        expList.add(exp);
    }
    if (null != name && name.trim().length() > 0) {
        SimpleExpression exp = Restrictions.like("name", name.trim(), MatchMode.ANYWHERE);
        expList.add(exp);
    }
    if (null != teacherId && teacherId.trim().length() > 0) {// just not be all will be filter
        SimpleExpression exp = Restrictions.eq("teacherId", teacherId);
        expList.add(exp);
    }
    if (status > 0) {// just not be all will be filter
        SimpleExpression exp = Restrictions.eq("status", status);
        expList.add(exp);
    }

    return expList;
}

From source file:cn.newtouch.util.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,./* ww  w.ja va  2  s.  c  o m*/
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    // ?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}