From: <fc...@us...> - 2007-08-10 07:01:43
|
Revision: 394 http://openutils.svn.sourceforge.net/openutils/?rev=394&view=rev Author: fcarone Date: 2007-08-10 00:01:44 -0700 (Fri, 10 Aug 2007) Log Message: ----------- List<Criterion> added to all needed locations Modified Paths: -------------- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java Modified: trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2007-08-09 08:52:43 UTC (rev 393) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2007-08-10 07:01:44 UTC (rev 394) @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; +import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; import org.hibernate.type.Type; @@ -14,7 +15,7 @@ * @author Fabrizio Giustina * @version $Id$ * @param <T> Persistence class - * @param <K> Object Key + * @param <K> Object Key */ public interface HibernateDAO<T extends Object, K extends Serializable> { @@ -40,6 +41,14 @@ List<T> findAll(final Order[] orderProperties); /** + * Return all objects related to the implementation of this DAO with no filter. + * @param orderProperties <code>desc</code> or <code>asc</code> + * @param criteria Additional Criterion conditions + * @return a list of all instances + */ + List<T> findAll(final Order[] orderProperties, List<Criterion> criteria); + + /** * Execute a query. * @param query a query expressed in Hibernate's query language * @param obj filter value @@ -93,7 +102,7 @@ List<T> findFiltered(final T filter, final int maxResults, final int page); /** - * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. + * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. * @param filter an instance of the object with the properties you whish to filter on. * @param metadata filter metadata * @param maxResults maximum number of results @@ -106,7 +115,7 @@ * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. * @param filter an instance of the object with the properties you whish to filter on. * @param customOrder order criterias - * @param metadata filter metadata + * @param metadata filter metadata * @param maxResults maximum number of results * @param page result page (first result is maxResults * page) * @return list of objects @@ -117,8 +126,21 @@ /** * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. * @param filter an instance of the object with the properties you whish to filter on. + * @param customOrder order criterias + * @param metadata filter metadata + * @param maxResults maximum number of results + * @param page result page (first result is maxResults * page) + * @param additionalCriteria additional criteria * @return list of objects */ + List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, + final int maxResults, final int page, List<Criterion> additionalCriteria); + + /** + * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. + * @param filter an instance of the object with the properties you whish to filter on. + * @return list of objects + */ List<T> findFiltered(final T filter); /** @@ -132,7 +154,7 @@ /** * Return all objects related to the implementation of this DAO filtered using properties of the provided instance. * @param filter an instance of the object with the properties you whish to filter on. - * @param metadata filter metadata + * @param metadata filter metadata * @return list of objects */ List<T> findFiltered(final T filter, Map<String, FilterMetadata> metadata); @@ -146,6 +168,15 @@ T findFilteredFirst(final T filter); /** + * Return the first object related to the implementation of this DAO filtered using properties of the provided + * instance. + * @param filter an instance of the object with the properties you whish to filter on. + * @param criteria additional criterion + * @return first object in the collection + */ + T findFilteredFirst(final T filter, final List<Criterion> criteria); + + /** * Used by the base DAO classes but here for your modification Remove a persistent instance from the datastore. The * argument may be an instance associated with the receiving Session or a transient instance with an identifier * associated with existing persistent state. Modified: trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-08-09 08:52:43 UTC (rev 393) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-08-10 07:01:44 UTC (rev 394) @@ -16,6 +16,7 @@ import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.criterion.CriteriaSpecification; +import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; import org.hibernate.type.Type; import org.springframework.orm.hibernate3.HibernateCallback; @@ -43,30 +44,32 @@ { /** - * + * */ private final T filter; /** - * + * */ private final int page; /** - * + * */ private final int maxResults; /** - * + * */ private final Map<String, FilterMetadata> metadata; /** - * + * */ private final Order[] orderProperties; + private List<Criterion> additionalCriteria; + /** * @param filter * @param page @@ -79,13 +82,15 @@ int page, int maxResults, Map<String, FilterMetadata> metadata, - Order[] orderProperties) + Order[] orderProperties, + List<Criterion> additionalCriteria) { this.filter = filter; this.page = page; this.maxResults = maxResults; this.metadata = metadata; this.orderProperties = orderProperties; + this.additionalCriteria = additionalCriteria; } public Object doInHibernate(Session ses) throws HibernateException @@ -106,6 +111,13 @@ } } EnhancedExample.create(crit, filter, metadata); + if (additionalCriteria != null && !additionalCriteria.isEmpty()) + { + for (Criterion criterion : additionalCriteria) + { + crit.add(criterion); + } + } return crit.list(); } } @@ -342,11 +354,21 @@ public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, final int maxResults, final int page) { + return findFiltered(filter, customOrder, metadata, maxResults, page, null); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> findFiltered(T filter, Order[] customOrder, Map<String, FilterMetadata> metadata, int maxResults, + int page, List<Criterion> additionalCriteria) + { final Order[] orderProperties = customOrder != null && customOrder.length > 0 ? customOrder : this .getDefaultOrder(); return (List<T>) getHibernateTemplate().execute( - new HibernateCallbackForExecution(filter, page, maxResults, metadata, orderProperties)); + new HibernateCallbackForExecution(filter, page, maxResults, metadata, orderProperties, additionalCriteria)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |