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


    }

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

   * @return
   */
  public Collection searchByExample(Object exampleEntity){
    Collection found = new ArrayList();
    Session session = getSessionFactory().getCurrentSession();
    Example example = Example.create(exampleEntity).ignoreCase().excludeZeroes();
    found = session
      .createCriteria(exampleEntity.getClass())
      .add(example).list();
    return found;
  }
View Full Code Here

   * @return
   */
  public Collection searchCustomer(Customer exampleEntity){
    Collection found = new ArrayList();
    Session session = this.getSessionFactory().getCurrentSession();
    Example example = Example.create(exampleEntity).ignoreCase().excludeZeroes();
   
    if (exampleEntity.getName() == null){
       found = session
      .createCriteria(exampleEntity.getClass())
      .add(example.enableLike(MatchMode.START).excludeProperty("name")).list();
   
     
    }
    if (exampleEntity.getSurname() == null){
       found = session
        .createCriteria(exampleEntity.getClass())
        .add(example.enableLike(MatchMode.START).excludeProperty("surname")).list();
    }
    else {
       found = session
        .createCriteria(exampleEntity.getClass())
        .add(example.enableLike(MatchMode.START)).list();
    }
   
    return found;
   
   
View Full Code Here

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

    return count.intValue();
  }

  @SuppressWarnings("unchecked")
  public List<T> findByExample(T exampleObject) {
    Example example = Example.create(exampleObject).excludeZeroes()
        .enableLike().ignoreCase();

    List<T> list = getHibernateTemplate().createCriteria(domainClass).add(
        example).list();
View Full Code Here

     * (non-Javadoc)
     * @see org.dayatang.domain.EntityRepository#findByExample(org.dayatang.domain.Entity, org.dayatang.domain.ExampleSettings)
     */
    @Override
    public <T extends Entity, E extends T> List<T> findByExample(final E example, final ExampleSettings<T> settings) {
        Example theExample = Example.create(example);
        if (settings.isLikeEnabled()) {
            theExample.enableLike(MatchMode.ANYWHERE);
        }
        if (settings.isIgnoreCaseEnabled()) {
            theExample.ignoreCase();
        }
        if (settings.isExcludeNone()) {
            theExample.excludeNone();
        }
        if (settings.isExcludeZeroes()) {
            theExample.excludeZeroes();
        }
        for (String propName : settings.getExcludedProperties()) {
            theExample.excludeProperty(propName);
        }
        return getSession().createCriteria(settings.getEntityClass()).add(theExample).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

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.