Package org.hibernate.criterion

Examples of org.hibernate.criterion.Example


  public static Example getExampleCriterion(Object entity) {
    return getExampleCriterion(entity, null, MatchMode.ANYWHERE);
  }

  public static Example getExampleCriterion(Object entity, String[] excludePropertes, MatchMode mode) {
    Example example = Example.create(entity).setPropertySelector(new NotEmptyPropertySelector());
    if (null != mode) {
      example.enableLike(mode);
    }
    if (null != excludePropertes) {
      for (int i = 0; i < excludePropertes.length; i++) {
        example.excludeProperty(excludePropertes[i]);
      }
    }
    return example;
  }
View Full Code Here


        cursor.close();
        return count;
    }

    private Criteria prepareExampleCriteria(User exampleUser, String orderByProperty, boolean orderDescending, String... ignoreProperty) {
        Example example =  Example.create(exampleUser).enableLike(MatchMode.ANYWHERE).ignoreCase();

        // Sanitize input
        if (orderByProperty != null) {
            orderByProperty = orderByProperty.replaceAll("[^a-zA-Z0-9]", "");
        }

        for (String s : ignoreProperty) example.excludeProperty(s);

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

        Criteria crit = session.createCriteria(User.class).add(example);
        if (orderByProperty != null)
View Full Code Here

     * @return objekter
     * @see no.ugland.utransprod.dao.DAO#findByExampleLike(java.lang.Object)
     */
    @SuppressWarnings("unchecked")
    public final List<E> findByExampleLike(final E example) {
        Example exam = Example.create(example);
        exam.enableLike(MatchMode.ANYWHERE); // this is it.
        exam.ignoreCase();
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(clazz).add(exam);
       
        detachedCriteria = getCriteria(example, detachedCriteria);

        // DetachedCriteria c = DetachedCriteria.forClass(clazz).add(exam);
View Full Code Here

        return getHibernateTemplate().findByCriteria(detachedCriteria);
    }

    private DetachedCriteria getCriteria(final Object example, DetachedCriteria detachedCriteria) {
        Example exam = Example.create(example);
        exam.enableLike(MatchMode.ANYWHERE); // this is it.
        exam.ignoreCase();
       
       


        try {
View Full Code Here

  public final List<Order> findByOrder(final Order order) {
    return (List<Order>) getHibernateTemplate().execute(
        new HibernateCallback() {

          public Object doInHibernate(final Session session) {
            Example example = Example.create(order);
            example.enableLike(MatchMode.ANYWHERE);
            example.ignoreCase();
            example.excludeZeroes();

            Criteria crit = session.createCriteria(Order.class)
                .add(example);

            if (order.getCustomer() != null) {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public List<T> findByExample(T exampleInstance, String... excludeProperty) {
    Criteria crit = getSession().createCriteria(getClazz());
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
      example.excludeProperty(exclude);
    }
    crit.add(example);
    return crit.list();
  }
View Full Code Here

        Session s = openSession();

        Transaction t = s.beginTransaction();
        Componentizable master = getMaster("hibernate", "open sourc%", "open source1");
        Criteria crit = s.createCriteria(Componentizable.class);
        Example ex = Example.create(master).enableLike();
        crit.add(ex);
        List result = crit.list();
        assertNotNull(result);
        assertEquals(1, result.size());
View Full Code Here

        initData();
        Session s = openSession();
        Transaction t = s.beginTransaction();
        Componentizable master = getMaster("hibernate", null, "ope%");
        Criteria crit = s.createCriteria(Componentizable.class);
        Example ex = Example.create(master).enableLike();

        crit.add(Restrictions.or(Restrictions.not(ex), ex));

        List result = crit.list();
        assertNotNull(result);
View Full Code Here

        initData();
        Session s = openSession();
        Transaction t = s.beginTransaction();
        Componentizable master = getMaster("hibernate", null, "ope%");
        Criteria crit = s.createCriteria(Componentizable.class);
        Example ex = Example.create(master).enableLike()
            .excludeProperty("component.subComponent");
        crit.add(ex);
        List result = crit.list();
        assertNotNull(result);
        assertEquals(3, result.size());
View Full Code Here

    return getExampleCriterion(entity, null, MatchMode.ANYWHERE);
  }

  public static Example getExampleCriterion(Object entity, String[] excludePropertes,
      MatchMode mode) {
    Example example = Example.create(entity)
        .setPropertySelector(new NotEmptyPropertySelector());
    if (null != mode) {
      example.enableLike(mode);
    }
    if (null != excludePropertes) {
      for (int i = 0; i < excludePropertes.length; i++) {
        example.excludeProperty(excludePropertes[i]);
      }
    }
    return example;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.criterion.Example

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.