@SuppressWarnings("unchecked")
 public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
   DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
   Example example = Example.create(exampleInstance);
   for (String exclude : excludeProperty) {
     example.excludeProperty(exclude);
   }
   crit.add(example);
   return getHibernateTemplate().findByCriteria(crit);
 }
 @Override
 public List<Template> findAllByExample(Template exampleObject, List<String> excludedProperties) {
   Criteria criteriaQuery = getSession().createCriteria(getPersistentClass());
   Example example = Example.create(exampleObject);
   for (String excludeProperty : excludedProperties) {
     example.excludeProperty(excludeProperty);
   }
   criteriaQuery.add(example);
   return criteriaQuery.list();
 }
예제 #3
0
 @Override
 public List<E> getByExample(E exampleInstance, String[] excludeProperty) {
   Example example = Example.create(exampleInstance);
   if (excludeProperty != null) {
     for (String str : excludeProperty) {
       example.excludeProperty(str);
     }
   }
   return ht.findByExample(example);
 }
	@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();
	}
예제 #5
0
파일: GenericDAOImpl.java 프로젝트: qza/qaf
 @SuppressWarnings("unchecked")
 public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
   String[] exclude = (excludeProperty != null) ? excludeProperty : excludeDefault;
   Criteria crit = getSession().createCriteria(persistentClass);
   Example example = Example.create(exampleInstance);
   example.enableLike();
   example.ignoreCase();
   for (String ex : exclude) {
     example.excludeProperty(ex);
   }
   crit.add(example);
   return crit.list();
 }
예제 #6
0
  @SuppressWarnings("unchecked")
  public List<T> findByExample(
      T instance,
      Set<String> excludedProperties,
      Set<String> includedCollections,
      int fromRecord,
      int toRecord) {
    try {
      Example exampleInstance = create(instance);

      // Exclude the properties
      if (excludedProperties != null) {
        for (String excludedProperty : excludedProperties) {
          exampleInstance = exampleInstance.excludeProperty(excludedProperty);
        }
      }

      Criteria myCriteria =
          sessionFactory.getCurrentSession().createCriteria(clazz.getCanonicalName());

      if (includedCollections != null) {
        // Include the collections
        for (String includedCollection : includedCollections) {
          myCriteria.setFetchMode(includedCollection, FetchMode.JOIN);
        }
      }

      // set the LIMIT
      if (fromRecord >= 0 && toRecord >= 0) {
        if (fromRecord < toRecord) {
          myCriteria.setFirstResult(fromRecord);
          myCriteria.setMaxResults(toRecord - fromRecord);
        } else {
          myCriteria.setFirstResult(toRecord);
          myCriteria.setMaxResults(fromRecord - toRecord);
        }
      }

      // Only get distinct Root entities
      myCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

      // get the results
      List<T> results = (List<T>) myCriteria.add(exampleInstance).list();
      return results;
    } catch (RuntimeException re) {
      throw re;
    }
  }