From: <fc...@us...> - 2007-02-02 09:20:12
|
Revision: 191 http://svn.sourceforge.net/openutils/?rev=191&view=rev Author: fcarone Date: 2007-02-02 01:19:59 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Comments and refactoring. 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 Property Changed: ---------------- 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-02-02 09:14:00 UTC (rev 190) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2007-02-02 09:19:59 UTC (rev 191) @@ -13,6 +13,8 @@ /** * @author Fabrizio Giustina * @version $Id$ + * @param <T> Persistence class + * @param <K> Object Key */ public interface HibernateDAO<T extends Object, K extends Serializable> { @@ -91,8 +93,9 @@ 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 * @param page result page (first result is maxResults * page) * @return list of objects @@ -102,6 +105,8 @@ /** * 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) * @return list of objects @@ -127,6 +132,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 * @return list of objects */ List<T> findFiltered(final T filter, Map<String, FilterMetadata> metadata); @@ -144,6 +150,7 @@ * argument may be an instance associated with the receiving Session or a transient instance with an identifier * associated with existing persistent state. * @param key key + * @return true if the object was successfully deleted, false otherwise */ boolean delete(final K key); 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-02-02 09:14:00 UTC (rev 190) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-02-02 09:19:59 UTC (rev 191) @@ -26,7 +26,7 @@ /** * Base Hibernate DAO. * @author Fabrizio Giustina - * @version $Id: $ + * @version $Id$ * @param <T> Persistence class * @param <K> Object Key */ @@ -36,6 +36,81 @@ { /** + * @author carone + * @version $Id$ + */ + private final class HibernateCallbackForExecution implements HibernateCallback + { + + /** + * + */ + private final T filter; + + /** + * + */ + private final int page; + + /** + * + */ + private final int maxResults; + + /** + * + */ + private final Map<String, FilterMetadata> metadata; + + /** + * + */ + private final Order[] orderProperties; + + /** + * @param filter + * @param page + * @param maxResults + * @param metadata + * @param orderProperties + */ + private HibernateCallbackForExecution( + T filter, + int page, + int maxResults, + Map<String, FilterMetadata> metadata, + Order[] orderProperties) + { + this.filter = filter; + this.page = page; + this.maxResults = maxResults; + this.metadata = metadata; + this.orderProperties = orderProperties; + } + + public Object doInHibernate(Session ses) throws HibernateException + { + Criteria crit = ses.createCriteria(filter.getClass()); + crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); + crit.setMaxResults(maxResults); + crit.setFirstResult(maxResults * page); + + if (orderProperties != null && orderProperties.length > 0) + { + for (Order order : orderProperties) + { + if (order != null) + { + crit.addOrder(order); + } + } + } + EnhancedExample.create(crit, filter, metadata); + return crit.list(); + } + } + + /** * {@inheritDoc} */ @SuppressWarnings("unchecked") @@ -270,30 +345,8 @@ final Order[] orderProperties = customOrder != null && customOrder.length > 0 ? customOrder : this .getDefaultOrder(); - return (List<T>) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Criteria crit = ses.createCriteria(filter.getClass()); - crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); - crit.setMaxResults(maxResults); - crit.setFirstResult(maxResults * page); - - if (orderProperties != null && orderProperties.length > 0) - { - for (Order order : orderProperties) - { - if (order != null) - { - crit.addOrder(order); - } - } - } - EnhancedExample.create(crit, filter, metadata); - return crit.list(); - } - }); + return (List<T>) getHibernateTemplate().execute( + new HibernateCallbackForExecution(filter, page, maxResults, metadata, orderProperties)); } /** Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |