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:com.jubination.model.dao.DataAnalyticsDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object readPropertyByDate(Object paramId) {
    List<DataAnalytics> list = null;

    session = getSessionFactory().getCurrentSession();
    list = session.createCriteria(DataAnalytics.class)
            .add(Restrictions.like("date", (String) paramId, MatchMode.START)).list();

    return (T) list;

}

From source file:com.jubinationre.model.dao.CallAPIMessageDAOImpl.java

public Object getByProperty(Object entity, String listType) {
    List<CallAPIMessage> list = new ArrayList<CallAPIMessage>();
    switch (listType) {
    case "Number":
        String number = (String) entity;
        try {/*  w  w  w. j  a v a 2s  .c o  m*/
            session = getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(CallAPIMessage.class, "call");
            criteria.add(Restrictions.eq("CallTo", number));
            list = criteria.list();
            session.getTransaction().commit();

        } catch (Exception e) {
            session.getTransaction().rollback();
            System.out.println("Error in building CallAPIMessage and its properties at CallAPIDAO " + e);
            e.printStackTrace();
        }

        break;
    case "OrderId":
        Long orderId = (Long) entity;
        try {
            session = getSessionFactory().openSession();
            session.beginTransaction();
            list.add((CallAPIMessage) session.get(CallAPIMessage.class, (Long) orderId));
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
            System.out.println("Error in building CallAPIMessage and its properties at CallAPIDAO " + e);
            e.printStackTrace();

        }

        break;
    case "Sid":
        String sid = (String) entity;
        try {
            session = getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(CallAPIMessage.class, "call");
            criteria.add(Restrictions.eq("Sid", sid));
            list = criteria.list();
            session.getTransaction().commit();

        } catch (Exception e) {
            session.getTransaction().rollback();
            System.out.println("Error in deleting Items and its properties at ItemsDAO " + e);
            e.printStackTrace();
        }
        break;
    case "DateCreated":
        String dateCreated = (String) entity;
        try {
            session = getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(CallAPIMessage.class, "call");
            criteria.add(Restrictions.like("DateCreated", dateCreated, MatchMode.START));
            list = criteria.list();
            session.getTransaction().commit();

        } catch (Exception e) {
            session.getTransaction().rollback();
            System.out.println("Error in deleting Items and its properties at ItemsDAO " + e);
            e.printStackTrace();
        }
        break;
    case "PendingOnDate":
        String pendingOnDate = (String) entity;
        try {
            session = getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(CallAPIMessage.class, "call");
            criteria.add(Restrictions.or(
                    Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                            Restrictions.like("TrackStatus", "did not", MatchMode.ANYWHERE)),
                    Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                            Restrictions.like("TrackStatus", "Pressed 2", MatchMode.START)),
                    Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                            Restrictions.like("Status", "failed", MatchMode.START)),
                    Restrictions.and(Restrictions.like("DateCreated", pendingOnDate, MatchMode.START),
                            Restrictions.like("Status", "no-answer", MatchMode.START))));
            list = criteria.list();
            session.getTransaction().commit();

        } catch (Exception e) {
            session.getTransaction().rollback();
            System.out.println("Error in deleting Items and its properties at ItemsDAO " + e);
            e.printStackTrace();
        }
        break;
    default:
        System.err.println("Not a valid option");
        break;
    }
    return list;
}

From source file:com.lakeside.data.sqldb.PageBaseDao.java

License:Apache License

/**
 * ??Criterion,./* w w  w .  j  ava 2  s.com*/
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    try {

        //?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.lp.server.artikel.ejbfac.ArtikelFacBean.java

License:Open Source License

public String generiereNeueArtikelnummer(String beginnArtikelnummer, TheClientDto theClientDto) {

    if (beginnArtikelnummer == null) {

        beginnArtikelnummer = "";

        try {/* ww w.  ja v  a2 s.  c o m*/
            // PJ18234
            ParametermandantDto parameter = getParameterFac().getMandantparameter(theClientDto.getMandant(),
                    ParameterFac.KATEGORIE_ARTIKEL, ParameterFac.PARAMETER_STARTWERT_ARTIKELNUMMER);
            String startwert = parameter.getCWert();
            if (startwert != null && startwert.trim().length() > 1) {
                beginnArtikelnummer = startwert.trim();
            }
        } catch (RemoteException e) {
            throwEJBExceptionLPRespectOld(e);
        }
    }

    Session session = FLRSessionFactory.getFactory().openSession();

    org.hibernate.Criteria crit = session.createCriteria(FLRArtikel.class);
    crit.add(Restrictions.like("c_nr", beginnArtikelnummer, MatchMode.START));
    crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant()));

    String[] art = new String[1];
    art[0] = ArtikelFac.ARTIKELART_HANDARTIKEL;
    crit.add(Restrictions.not(Restrictions.in(ArtikelFac.FLR_ARTIKEL_ARTIKELART_C_NR, art)));

    crit.addOrder(Order.desc("c_nr"));
    crit.setMaxResults(1);
    List<?> results = crit.list();
    Iterator<?> resultListIterator = results.iterator();

    if (results.size() > 0) {
        FLRArtikel flrArtikel = (FLRArtikel) resultListIterator.next();

        String letzteArtikelnummer = flrArtikel.getC_nr();
        int iStartZahl = -1;
        int iEndeZahl = -1;
        boolean bEndeFound = false;
        int i = 0;
        while (i < letzteArtikelnummer.length()) {

            char c = letzteArtikelnummer.charAt(i);
            // wenn 0-9
            if (c > 47 && c < 58) {
                iStartZahl = i;
                iEndeZahl = iStartZahl;
                for (int j = i; j < letzteArtikelnummer.length(); j++) {
                    char d = letzteArtikelnummer.charAt(j);
                    if (d > 47 && d < 58) {
                        iEndeZahl = j;
                        if (j == letzteArtikelnummer.length() - 1) {
                            bEndeFound = true;
                        }
                    } else {
                        bEndeFound = true;
                        break;
                    }
                }
            }
            i++;
            if (bEndeFound) {
                break;
            }
        }
        if (iStartZahl >= 0 && iEndeZahl >= 0) {
            String zahlenteil = letzteArtikelnummer.substring(iStartZahl, iEndeZahl + 1);

            long zahl = new Long(zahlenteil);

            while (1 == 1) {

                zahl++;

                String zahlenteilNeu = new String(zahl + "");

                if (zahlenteilNeu.length() > zahlenteil.length()) {
                    // PJ 14917
                    String s = "";
                    for (int k = 0; k < zahlenteilNeu.length(); k++) {
                        s += "?";
                    }

                    return letzteArtikelnummer.substring(0, iStartZahl) + s
                            + letzteArtikelnummer.substring(iEndeZahl + 1);
                }

                int iNeueLaenge = zahlenteilNeu.length();
                if (iNeueLaenge < zahlenteil.length()) {
                    iNeueLaenge = zahlenteil.length();
                }
                zahlenteilNeu = Helper.fitString2LengthAlignRight(zahl + "", iNeueLaenge, '0');
                // Neue Artikelnummer zusammenbauen

                String neueArtNr = letzteArtikelnummer.substring(0, iStartZahl) + zahlenteilNeu
                        + letzteArtikelnummer.substring(iEndeZahl + 1);

                Query query = em.createNamedQuery("ArtikelfindByCNrMandantCNr");
                query.setParameter(1, neueArtNr);
                query.setParameter(2, theClientDto.getMandant());
                Collection<?> cl = query.getResultList();
                if (cl.size() > 0) {

                    continue;

                }

                return neueArtNr;
            }

        }
    }
    session.close();

    return beginnArtikelnummer;
}

From source file:com.lp.server.personal.ejbfac.PersonalFacBean.java

License:Open Source License

private String generiereNeuePersonalnummer(TheClientDto theClientDto) {

    String beginnArtikelnummer = "";

    Session session = FLRSessionFactory.getFactory().openSession();

    org.hibernate.Criteria crit = session.createCriteria(FLRPersonal.class);
    crit.add(Restrictions.like("c_personalnummer", beginnArtikelnummer, MatchMode.START));
    crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant()));

    crit.addOrder(Order.desc("c_personalnummer"));
    // crit.setMaxResults(1);
    // List<?> results = crit.list();
    // Iterator<?> resultListIterator = results.iterator();

    // if (results.size() > 0) {
    // FLRPersonal flrArtikel = (FLRPersonal) resultListIterator.next();

    FLRPersonal flrArtikel = getLetztesFLRPersonal(crit.list());
    if (flrArtikel != null) {
        String letzteArtikelnummer = flrArtikel.getC_personalnummer();
        int iStartZahl = -1;
        int iEndeZahl = -1;
        boolean bEndeFound = false;
        int i = beginnArtikelnummer.length();
        while (i < letzteArtikelnummer.length()) {

            char c = letzteArtikelnummer.charAt(i);
            // wenn 0-9
            if (c > 47 && c < 58) {
                iStartZahl = i;//  w ww .  j a  v  a 2  s.co m
                iEndeZahl = iStartZahl;
                for (int j = i; j < letzteArtikelnummer.length(); j++) {
                    char d = letzteArtikelnummer.charAt(j);
                    if (d > 47 && d < 58) {
                        iEndeZahl = j;
                        if (j == letzteArtikelnummer.length() - 1) {
                            bEndeFound = true;
                        }
                    } else {
                        bEndeFound = true;
                        break;
                    }
                }
            }
            i++;
            if (bEndeFound) {
                break;
            }
        }
        if (iStartZahl >= 0 && iEndeZahl >= 0) {
            String zahlenteil = letzteArtikelnummer.substring(iStartZahl, iEndeZahl + 1);
            long zahl = new Long(zahlenteil);
            zahl++;
            // Neue Artikelnummer zusammenbauen
            String neueArtNr = letzteArtikelnummer.substring(0, iStartZahl) + zahl
                    + letzteArtikelnummer.substring(iEndeZahl + 1);

            return neueArtNr;
        }
    }
    session.close();

    return beginnArtikelnummer;
}

From source file:com.lushapp.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,./* ww  w. j a  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;
    String value;
    Character ESCAPE = '!';
    // ?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case NE:
        criterion = Restrictions.ne(propertyName, propertyValue);
        break;
    case LIKE:
        // 
        value = (String) propertyValue;
        if ((ESCAPE.toString()).equals(value)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        } else {
            criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.ANYWHERE, ESCAPE,
                    true);
        }
        break;
    case SLIKE:
        // 
        value = (String) propertyValue;
        if ((ESCAPE.toString()).equals(value)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.START);
        } else {
            criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.START, ESCAPE, true);
        }
        break;
    case ELIKE:
        // 
        value = (String) propertyValue;
        if ((ESCAPE.toString()).equals(value)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.END);
        } else {
            criterion = new LikeExpression(propertyName, (String) propertyValue, MatchMode.END, ESCAPE, true);
        }
        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);
        break;
    case ISNULL:
        criterion = Restrictions.isNull(propertyName);
    }
    return criterion;
}

From source file:com.lushapp.modules.sys.web.AviationBuyersController.java

License:Apache License

/**
 * combogrid//  w w  w  .  j a  v a2  s  .  co m
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "combogrid" })
@ResponseBody
public Datagrid<AviationBuyers> combogrid(@RequestParam(value = "ids", required = false) List<Long> ids,
        String loginNameOrName, Integer rows) throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
        //in?
        Criterion inCriterion = Restrictions.in("id", ids);

        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
            criterion = Restrictions.or(inCriterion, criterion1);
        } else {
            criterion = inCriterion;
        }
        //??
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
    } else {
        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            criterion = Restrictions.or(loginNameCriterion, nameCriterion);
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        }
    }

    //
    Page<AviationBuyers> p = new Page<AviationBuyers>(rows);//
    p = aviationBuyersManager.findByCriteria(p, criterions);
    Datagrid<AviationBuyers> dg = new Datagrid<AviationBuyers>(p.getTotalCount(), p.getResult());
    return dg;
}

From source file:com.lushapp.modules.sys.web.AviationOrderController.java

License:Apache License

/**
 * combogrid/*from  w ww.  j  a  v  a  2  s.  c  o  m*/
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "combogrid" })
@ResponseBody
public Datagrid<AviationOrder> combogrid(@RequestParam(value = "ids", required = false) List<Long> ids,
        String loginNameOrName, Integer rows) throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
        //in?
        Criterion inCriterion = Restrictions.in("id", ids);

        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
            criterion = Restrictions.or(inCriterion, criterion1);
        } else {
            criterion = inCriterion;
        }
        //??
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
    } else {
        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            criterion = Restrictions.or(loginNameCriterion, nameCriterion);
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        }
    }

    //
    Page<AviationOrder> p = new Page<AviationOrder>(rows);//
    p = aviationOrderManager.findByCriteria(p, criterions);
    Datagrid<AviationOrder> dg = new Datagrid<AviationOrder>(p.getTotalCount(), p.getResult());
    return dg;
}

From source file:com.lushapp.modules.sys.web.AviationSuppliersController.java

License:Apache License

/**
 * combogrid/*from  w w  w.  j a  va  2  s.c  o  m*/
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "combogrid" })
@ResponseBody
public Datagrid<AviationSuppliers> combogrid(@RequestParam(value = "ids", required = false) List<Long> ids,
        String loginNameOrName, Integer rows) throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
        //in?
        Criterion inCriterion = Restrictions.in("id", ids);

        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
            criterion = Restrictions.or(inCriterion, criterion1);
        } else {
            criterion = inCriterion;
        }
        //??
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
    } else {
        if (StringUtils.isNotBlank(loginNameOrName)) {
            Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
            Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
            criterion = Restrictions.or(loginNameCriterion, nameCriterion);
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        }
    }

    //
    Page<AviationSuppliers> p = new Page<AviationSuppliers>(rows);//
    p = aviationSuppliersManager.findByCriteria(p, criterions);
    Datagrid<AviationSuppliers> dg = new Datagrid<AviationSuppliers>(p.getTotalCount(), p.getResult());
    return dg;
}

From source file:com.lushapp.modules.sys.web.OrganController.java

License:Apache License

/**
 * combogrid//from www  .jav a2 s.  c  o m
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "combogrid" })
@ResponseBody
public Datagrid<Organ> combogrid(String nameOrCode,
        @RequestParam(value = "ids", required = false) List<Long> ids, Integer rows) throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
        //in?
        Criterion inCriterion = Restrictions.in("id", ids);

        if (StringUtils.isNotBlank(nameOrCode)) {
            Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
            Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
            Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion);
            criterion = Restrictions.or(inCriterion, criterion1);
        } else {
            criterion = inCriterion;
        }
        //??
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
    } else {
        if (StringUtils.isNotBlank(nameOrCode)) {
            Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
            Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
            criterion = Restrictions.or(nameCriterion, codeCriterion);
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        }
    }

    //
    Page<Organ> p = new Page<Organ>(rows);//
    p = organManager.findByCriteria(p, criterions);
    Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult());
    return dg;
}