From: <fg...@us...> - 2007-01-30 14:53:48
|
Revision: 157 http://svn.sourceforge.net/openutils/?rev=157&view=rev Author: fgiust Date: 2007-01-30 06:53:48 -0800 (Tue, 30 Jan 2007) Log Message: ----------- javadocs only Modified Paths: -------------- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 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-01-27 20:19:06 UTC (rev 156) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-01-30 14:53:48 UTC (rev 157) @@ -28,7 +28,9 @@ /** * Base Hibernate DAO. * @author Fabrizio Giustina - * @version $Id$ + * @version $Id: $ + * @param <T> Persistence class + * @param <K> Object Key */ public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport implements @@ -41,7 +43,7 @@ private static Logger log = LoggerFactory.getLogger(HibernateDAOImpl.class); /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> find(String query) @@ -50,7 +52,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll() + * {@inheritDoc} */ public List<T> findAll() { @@ -58,7 +60,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll(org.hibernate.criterion.Order[]) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> findAll(final Order[] orderProperties) @@ -84,15 +86,15 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String, java.lang.Object, org.hibernate.type.Type) + * {@inheritDoc} */ public List<T> find(String query, Object obj, Type type) { - return find(query, new Object[]{obj}, new Type[]{type}); + return find(query, new Object[]{obj }, new Type[]{type }); } /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(String, Object[], Type[]) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> find(final String query, final Object[] obj, final Type[] type) @@ -109,7 +111,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public T load(K key) @@ -120,7 +122,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public T loadIfAvailable(K key) @@ -149,7 +151,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#saveOrUpdate(null) + * {@inheritDoc} */ public void saveOrUpdate(final T obj) { @@ -157,7 +159,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#update(null) + * {@inheritDoc} */ public void update(T obj) { @@ -165,7 +167,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#delete(null) + * {@inheritDoc} */ public boolean delete(final K key) { @@ -183,7 +185,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#refresh(null) + * {@inheritDoc} */ public void refresh(T obj) { @@ -191,7 +193,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#merge(T) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public T merge(final T obj) @@ -208,7 +210,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#save(java.lang.Object) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public K save(T obj) @@ -217,7 +219,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFilteredFirst(T) + * {@inheritDoc} */ public T findFilteredFirst(final T filter) { @@ -225,7 +227,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) + * {@inheritDoc} */ public List<T> findFiltered(final T filter) { @@ -233,7 +235,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(java.lang.Object, org.hibernate.criterion.Order[]) + * {@inheritDoc} */ public List<T> findFiltered(T filter, Order[] orderProperties) { @@ -241,7 +243,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) + * {@inheritDoc} */ public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata) { @@ -249,7 +251,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + * {@inheritDoc} */ public List<T> findFiltered(final T filter, final int maxResults, final int page) { @@ -257,7 +259,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + * {@inheritDoc} */ public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata, final int maxResults, final int page) @@ -266,7 +268,7 @@ } /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + * {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, @@ -285,7 +287,7 @@ crit.setMaxResults(maxResults); crit.setFirstResult(maxResults * page); - if (null != orderProperties && orderProperties.length > 0) + if (orderProperties != null && orderProperties.length > 0) { for (Order order : orderProperties) { @@ -295,9 +297,7 @@ } } } - EnhancedExample.create(crit, filter, metadata); - return crit.list(); } }); @@ -321,9 +321,10 @@ /** * Obtain an instance of Query for a named query string defined in the mapping file. * @param name the name of a query defined externally + * @param maxResults max number of results * @return Query */ - protected List< ? > getNamedQuery(final String name, final int marResults) + protected List< ? > getNamedQuery(final String name, final int maxResults) { return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() { @@ -331,7 +332,7 @@ public Object doInHibernate(Session ses) throws HibernateException { Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); + q.setMaxResults(maxResults); return q.list(); } }); @@ -341,9 +342,10 @@ * Obtain an instance of Query for a named query string defined in the mapping file. Use the parameters given. * @param name the name of a query defined externally * @param params the parameter array + * @param maxResults max number of results * @return Query */ - protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int marResults) + protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int maxResults) { return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() @@ -352,7 +354,7 @@ public Object doInHibernate(Session ses) throws HibernateException { Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); + q.setMaxResults(maxResults); if (null != params) { for (int i = 0; i < params.length; i++) @@ -369,9 +371,10 @@ * Obtain an instance of Query for a named query string defined in the mapping file. Use the parameters given. * @param name the name of a query defined externally * @param params the parameter Map + * @param maxResults max number of results * @return Query */ - protected List< ? > getNamedQuery(final String name, final Map<String, Object> params, final int marResults) + protected List< ? > getNamedQuery(final String name, final Map<String, Object> params, final int maxResults) { return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() { @@ -379,7 +382,7 @@ public Object doInHibernate(Session ses) throws HibernateException { Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); + q.setMaxResults(maxResults); if (params != null) { for (Map.Entry<String, Object> entry : params.entrySet()) Modified: trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2007-01-27 20:19:06 UTC (rev 156) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2007-01-30 14:53:48 UTC (rev 157) @@ -4,10 +4,11 @@ /** - * @author fgiust + * @author Fabrizio Giustina * @version $Id: $ * @deprecated use FilterMetadata */ +@Deprecated public class MutableDateRange extends Date { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
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. |
From: <mup...@us...> - 2007-09-20 07:42:19
|
Revision: 439 http://openutils.svn.sourceforge.net/openutils/?rev=439&view=rev Author: muppet68 Date: 2007-09-20 00:42:19 -0700 (Thu, 20 Sep 2007) Log Message: ----------- Added evict method to remove object from hibernate session 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-09-19 09:51:54 UTC (rev 438) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2007-09-20 07:42:19 UTC (rev 439) @@ -80,6 +80,12 @@ void refresh(T obj); /** + * Remove the given object from the Session cache. + * @param obj Object + */ + void evict(T obj); + + /** * Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent * instance currently associated with the session, it will be loaded. Return the persistent instance. If the given * instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not 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-09-19 09:51:54 UTC (rev 438) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-09-20 07:42:19 UTC (rev 439) @@ -26,528 +26,521 @@ import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - /** * Base Hibernate DAO. + * * @author Fabrizio Giustina * @version $Id$ - * @param <T> Persistence class - * @param <K> Object Key + * @param <T> + * Persistence class + * @param <K> + * Object Key */ -public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport - implements - HibernateDAO<T, K> -{ +public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> + extends HibernateDaoSupport implements HibernateDAO<T, K> { - /** - * @author carone - * @version $Id$ - */ - private final class HibernateCallbackForExecution implements HibernateCallback - { + /** + * @author carone + * @version $Id$ + */ + private final class HibernateCallbackForExecution implements + HibernateCallback { - /** - * - */ - private final T filter; + /** + * + */ + private final T filter; - /** - * - */ - private final int page; + /** + * + */ + private final int page; - /** - * - */ - private final int maxResults; + /** + * + */ + private final int maxResults; - /** - * - */ - private final Map<String, FilterMetadata> metadata; + /** + * + */ + private final Map<String, FilterMetadata> metadata; - /** - * - */ - private final Order[] orderProperties; + /** + * + */ + private final Order[] orderProperties; - private List<Criterion> additionalCriteria; + private List<Criterion> additionalCriteria; - /** - * @param filter - * @param page - * @param maxResults - * @param metadata - * @param orderProperties - */ - private HibernateCallbackForExecution( - T filter, - int page, - int maxResults, - Map<String, FilterMetadata> metadata, - Order[] orderProperties, - List<Criterion> additionalCriteria) - { - this.filter = filter; - this.page = page; - this.maxResults = maxResults; - this.metadata = metadata; - this.orderProperties = orderProperties; - this.additionalCriteria = additionalCriteria; - } + /** + * @param filter + * @param page + * @param maxResults + * @param metadata + * @param orderProperties + */ + private HibernateCallbackForExecution(T filter, int page, + int maxResults, Map<String, FilterMetadata> metadata, + 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 - { - Criteria crit = ses.createCriteria(filter.getClass()); - crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); - crit.setMaxResults(maxResults); - crit.setFirstResult(maxResults * page); + 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); - if (additionalCriteria != null && !additionalCriteria.isEmpty()) - { - for (Criterion criterion : additionalCriteria) - { - crit.add(criterion); - } - } - return crit.list(); - } - } + if (orderProperties != null && orderProperties.length > 0) { + for (Order order : orderProperties) { + if (order != null) { + crit.addOrder(order); + } + } + } + EnhancedExample.create(crit, filter, metadata); + if (additionalCriteria != null && !additionalCriteria.isEmpty()) { + for (Criterion criterion : additionalCriteria) { + crit.add(criterion); + } + } + return crit.list(); + } + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> find(String query) - { - return getHibernateTemplate().find(query); - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> find(String query) { + return getHibernateTemplate().find(query); + } - /** - * {@inheritDoc} - */ - public List<T> findAll() - { - return findAll(getDefaultOrder()); - } + /** + * {@inheritDoc} + */ + public List<T> findAll() { + return findAll(getDefaultOrder()); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> findAll(final Order[] orderProperties) - { - return getThis().findAll(orderProperties, new ArrayList<Criterion>()); - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> findAll(final Order[] orderProperties) { + return getThis().findAll(orderProperties, new ArrayList<Criterion>()); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> findAll(final Order[] orderProperties, final List<Criterion> criteria) - { - return (List<T>) getHibernateTemplate().execute(new HibernateCallback() - { + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> findAll(final Order[] orderProperties, + final List<Criterion> criteria) { + return (List<T>) getHibernateTemplate().execute( + new HibernateCallback() { - public Object doInHibernate(Session ses) throws HibernateException - { - Criteria crit = ses.createCriteria(getReferenceClass()); - if (null != orderProperties) - { - for (int j = 0; j < orderProperties.length; j++) - { - crit.addOrder(orderProperties[j]); - } + public Object doInHibernate(Session ses) + throws HibernateException { + Criteria crit = ses.createCriteria(getReferenceClass()); + if (null != orderProperties) { + for (int j = 0; j < orderProperties.length; j++) { + crit.addOrder(orderProperties[j]); + } - } - if (criteria != null) - { - for (Criterion criterion : criteria) - { - crit.add(criterion); - } - } - return crit.list(); - } - }); - } + } + if (criteria != null) { + for (Criterion criterion : criteria) { + crit.add(criterion); + } + } + return crit.list(); + } + }); + } - /** - * {@inheritDoc} - */ - public List<T> find(String query, Object obj, Type type) - { - return find(query, new Object[]{obj }, new Type[]{type }); - } + /** + * {@inheritDoc} + */ + public List<T> find(String query, Object obj, Type type) { + return find(query, new Object[] { obj }, new Type[] { type }); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> find(final String query, final Object[] obj, final Type[] type) - { - return (List<T>) getHibernateTemplate().execute(new HibernateCallback() - { + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> find(final String query, final Object[] obj, + final Type[] type) { + return (List<T>) getHibernateTemplate().execute( + new HibernateCallback() { - public Object doInHibernate(Session ses) throws HibernateException - { - // hibernate 3 - return ses.createQuery(query).setParameters(obj, type).list(); - } - }); - } + public Object doInHibernate(Session ses) + throws HibernateException { + // hibernate 3 + return ses.createQuery(query).setParameters(obj, type) + .list(); + } + }); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public T load(K key) - { - T result = (T) getHibernateTemplate().load(getReferenceClass(), key); - Hibernate.initialize(result); - return result; - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public T load(K key) { + T result = (T) getHibernateTemplate().load(getReferenceClass(), key); + Hibernate.initialize(result); + return result; + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public T loadIfAvailable(K key) - { - T result; - try - { - result = (T) getHibernateTemplate().load(getReferenceClass(), key); - Hibernate.initialize(result); - } - catch (ObjectNotFoundException e) - { - // during lazy initialization - return null; - } - catch (HibernateObjectRetrievalFailureException e) - { - // during load - if (e.getCause() instanceof ObjectNotFoundException) - { - return null; - } - throw e; - } - return result; - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public T loadIfAvailable(K key) { + T result; + try { + result = (T) getHibernateTemplate().load(getReferenceClass(), key); + Hibernate.initialize(result); + } catch (ObjectNotFoundException e) { + // during lazy initialization + return null; + } catch (HibernateObjectRetrievalFailureException e) { + // during load + if (e.getCause() instanceof ObjectNotFoundException) { + return null; + } + throw e; + } + return result; + } - /** - * {@inheritDoc} - */ - public void saveOrUpdate(final T obj) - { - getHibernateTemplate().saveOrUpdate(obj); - } + /** + * {@inheritDoc} + */ + public void saveOrUpdate(final T obj) { + getHibernateTemplate().saveOrUpdate(obj); + } - /** - * {@inheritDoc} - */ - public void update(T obj) - { - getHibernateTemplate().update(obj); - } + /** + * {@inheritDoc} + */ + public void update(T obj) { + getHibernateTemplate().update(obj); + } - /** - * {@inheritDoc} - */ - public boolean delete(final K key) - { + /** + * {@inheritDoc} + */ + public boolean delete(final K key) { - return (Boolean) getHibernateTemplate().execute(new HibernateCallback() - { + return (Boolean) getHibernateTemplate().execute( + new HibernateCallback() { - public Object doInHibernate(Session ses) throws HibernateException - { - ses.delete(ses.load(getReferenceClass(), key)); - return true; - } - }); + public Object doInHibernate(Session ses) + throws HibernateException { + ses.delete(ses.load(getReferenceClass(), key)); + return true; + } + }); - } + } - /** - * {@inheritDoc} - */ - public void refresh(T obj) - { - getHibernateTemplate().refresh(obj); - } + /** + * {@inheritDoc} + */ + public void refresh(T obj) { + getHibernateTemplate().refresh(obj); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public T merge(final T obj) - { - return (T) getHibernateTemplate().execute(new HibernateCallback() - { + /** + * {@inheritDoc} + */ + public void evict(T obj) { + getHibernateTemplate().evict(obj); + } - public Object doInHibernate(Session ses) throws HibernateException - { - return ses.merge(obj); - } - }); + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public T merge(final T obj) { + return (T) getHibernateTemplate().execute(new HibernateCallback() { - } + public Object doInHibernate(Session ses) throws HibernateException { + return ses.merge(obj); + } + }); - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public K save(T obj) - { - return (K) getHibernateTemplate().save(obj); - } + } - /** - * {@inheritDoc} - */ - public T findFilteredFirst(final T filter) - { - return getFirstInCollection(findFiltered(filter, 1, 0)); - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public K save(T obj) { + return (K) getHibernateTemplate().save(obj); + } - /** - * {@inheritDoc} - */ - public T findFilteredFirst(final T filter, List<Criterion> criteria) - { - return getFirstInCollection(findFiltered(filter, null, getDefaultFilterMetadata(), 1, 0, criteria)); - } + /** + * {@inheritDoc} + */ + public T findFilteredFirst(final T filter) { + return getFirstInCollection(findFiltered(filter, 1, 0)); + } - /** - * {@inheritDoc} - */ - public List<T> findFiltered(final T filter) - { - return findFiltered(filter, getDefaultFilterMetadata()); - } + /** + * {@inheritDoc} + */ + public T findFilteredFirst(final T filter, List<Criterion> criteria) { + return getFirstInCollection(findFiltered(filter, null, + getDefaultFilterMetadata(), 1, 0, criteria)); + } - /** - * @return - * This is needed as for http://opensource.atlassian.com/projects/spring/browse/SPR-2226 - */ - @SuppressWarnings("unchecked") - private HibernateDAO<T, K> getThis() - { - try - { - return (HibernateDAO<T, K>) AopContext.currentProxy(); - } - catch (AspectException exc) - { - logger.debug("Not running inside an AOP proxy, so no proxy can be returned: " + exc.getMessage()); - return this; - } - } + /** + * {@inheritDoc} + */ + public List<T> findFiltered(final T filter) { + return findFiltered(filter, getDefaultFilterMetadata()); + } - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter, Order[] orderProperties) - { - return findFiltered(filter, orderProperties, getDefaultFilterMetadata(), Integer.MAX_VALUE, 0); - } + /** + * @return This is needed as for + * http://opensource.atlassian.com/projects/spring/browse/SPR-2226 + */ + @SuppressWarnings("unchecked") + private HibernateDAO<T, K> getThis() { + try { + return (HibernateDAO<T, K>) AopContext.currentProxy(); + } catch (AspectException exc) { + logger + .debug("Not running inside an AOP proxy, so no proxy can be returned: " + + exc.getMessage()); + return this; + } + } - /** - * {@inheritDoc} - */ - public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata) - { - return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); - } + /** + * {@inheritDoc} + */ + public List<T> findFiltered(T filter, Order[] orderProperties) { + return findFiltered(filter, orderProperties, + getDefaultFilterMetadata(), Integer.MAX_VALUE, 0); + } - /** - * {@inheritDoc} - */ - public List<T> findFiltered(final T filter, final int maxResults, final int page) - { - return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); - } + /** + * {@inheritDoc} + */ + public List<T> findFiltered(final T filter, + final Map<String, FilterMetadata> metadata) { + return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); + } - /** - * {@inheritDoc} - */ - public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata, final int maxResults, - final int page) - { - return findFiltered(filter, null, metadata, maxResults, page); - } + /** + * {@inheritDoc} + */ + public List<T> findFiltered(final T filter, final int maxResults, + final int page) { + return findFiltered(filter, getDefaultFilterMetadata(), maxResults, + page); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, - final int maxResults, final int page) - { - return getThis().findFiltered(filter, customOrder, metadata, maxResults, page, new ArrayList<Criterion>()); - } + /** + * {@inheritDoc} + */ + public List<T> findFiltered(final T filter, + final Map<String, FilterMetadata> metadata, final int maxResults, + final int page) { + return findFiltered(filter, null, metadata, maxResults, page); + } - /** - * {@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(); + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> findFiltered(final T filter, final Order[] customOrder, + final Map<String, FilterMetadata> metadata, final int maxResults, + final int page) { + return getThis().findFiltered(filter, customOrder, metadata, + maxResults, page, new ArrayList<Criterion>()); + } - return (List<T>) getHibernateTemplate().execute( - new HibernateCallbackForExecution(filter, page, maxResults, metadata, orderProperties, additionalCriteria)); - } + /** + * {@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 the specific Object class that will be used for class-specific implementation of this DAO. - * @return the reference Class - */ - protected abstract Class<T> getReferenceClass(); + return (List<T>) getHibernateTemplate().execute( + new HibernateCallbackForExecution(filter, page, maxResults, + metadata, orderProperties, additionalCriteria)); + } - /** - * Return a list of <code>Order</code> object to be used for the default ordering of the collection. - * @return the property name - */ - protected Order[] getDefaultOrder() - { - return new Order[0]; - } + /** + * Return the specific Object class that will be used for class-specific + * implementation of this DAO. + * + * @return the reference Class + */ + protected abstract Class<T> getReferenceClass(); - /** - * Obtain an instance of Query for a named query string defined in the mapping file. - * @param name the name of a query defined externally - * @param maxResults max number of results - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final int maxResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { + /** + * Return a list of <code>Order</code> object to be used for the default + * ordering of the collection. + * + * @return the property name + */ + protected Order[] getDefaultOrder() { + return new Order[0]; + } - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(maxResults); - return q.list(); - } - }); - } + /** + * Obtain an instance of Query for a named query string defined in the + * mapping file. + * + * @param name + * the name of a query defined externally + * @param maxResults + * max number of results + * @return Query + */ + protected List<?> getNamedQuery(final String name, final int maxResults) { + return (List<?>) getHibernateTemplate().execute( + new HibernateCallback() { - /** - * Obtain an instance of Query for a named query string defined in the mapping file. Use the parameters given. - * @param name the name of a query defined externally - * @param params the parameter array - * @param maxResults max number of results - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int maxResults) - { + public Object doInHibernate(Session ses) + throws HibernateException { + Query q = ses.getNamedQuery(name); + q.setMaxResults(maxResults); + return q.list(); + } + }); + } - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { + /** + * Obtain an instance of Query for a named query string defined in the + * mapping file. Use the parameters given. + * + * @param name + * the name of a query defined externally + * @param params + * the parameter array + * @param maxResults + * max number of results + * @return Query + */ + protected List<?> getNamedQuery(final String name, + final Serializable[] params, final int maxResults) { - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(maxResults); - if (null != params) - { - for (int i = 0; i < params.length; i++) - { - q.setParameter(i, params[i]); - } - } - return q.list(); - } - }); - } + return (List<?>) getHibernateTemplate().execute( + new HibernateCallback() { - /** - * Obtain an instance of Query for a named query string defined in the mapping file. Use the parameters given. - * @param name the name of a query defined externally - * @param params the parameter Map - * @param maxResults max number of results - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Map<String, Object> params, final int maxResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { + public Object doInHibernate(Session ses) + throws HibernateException { + Query q = ses.getNamedQuery(name); + q.setMaxResults(maxResults); + if (null != params) { + for (int i = 0; i < params.length; i++) { + q.setParameter(i, params[i]); + } + } + return q.list(); + } + }); + } - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(maxResults); - if (params != null) - { - for (Map.Entry<String, Object> entry : params.entrySet()) - { - setParameterValue(q, entry.getKey(), entry.getValue()); - } - } - return q.list(); - } - }); - } + /** + * Obtain an instance of Query for a named query string defined in the + * mapping file. Use the parameters given. + * + * @param name + * the name of a query defined externally + * @param params + * the parameter Map + * @param maxResults + * max number of results + * @return Query + */ + protected List<?> getNamedQuery(final String name, + final Map<String, Object> params, final int maxResults) { + return (List<?>) getHibernateTemplate().execute( + new HibernateCallback() { - /** - * Convenience method to set paramers in the query given based on the actual object type in passed in as the value. - * You may need to add more functionaly to this as desired (or not use this at all). - * @param query the Query to set - * @param key the key name - * @param value the object to set as the parameter - */ - protected void setParameterValue(Query query, String key, Object value) - { - if (null == key || null == value) - { - return; - } - query.setParameter(key, value); - } + public Object doInHibernate(Session ses) + throws HibernateException { + Query q = ses.getNamedQuery(name); + q.setMaxResults(maxResults); + if (params != null) { + for (Map.Entry<String, Object> entry : params + .entrySet()) { + setParameterValue(q, entry.getKey(), entry + .getValue()); + } + } + return q.list(); + } + }); + } - /** - * Returns the default set of FilterMetadata that will be applied to any query. The default implementation doesn't - * set any default filter, subclasses may override this. - * @return map of property name - filter metadata - */ - protected Map<String, FilterMetadata> getDefaultFilterMetadata() - { - return new HashMap<String, FilterMetadata>(0); - } + /** + * Convenience method to set paramers in the query given based on the actual + * object type in passed in as the value. You may need to add more + * functionaly to this as desired (or not use this at all). + * + * @param query + * the Query to set + * @param key + * the key name + * @param value + * the object to set as the parameter + */ + protected void setParameterValue(Query query, String key, Object value) { + if (null == key || null == value) { + return; + } + query.setParameter(key, value); + } - /** - * Returns the first object in the collection or null if the collection is null or empty. - * @param list collection - * @return first element in the list - */ - @SuppressWarnings("unchecked") - private T getFirstInCollection(Collection<T> list) - { - if (list != null && !list.isEmpty()) - { - Object result = list.iterator().next(); - Hibernate.initialize(result); - return (T) result; - } - return null; - } + /** + * Returns the default set of FilterMetadata that will be applied to any + * query. The default implementation doesn't set any default filter, + * subclasses may override this. + * + * @return map of property name - filter metadata + */ + protected Map<String, FilterMetadata> getDefaultFilterMetadata() { + return new HashMap<String, FilterMetadata>(0); + } + /** + * Returns the first object in the collection or null if the collection is + * null or empty. + * + * @param list + * collection + * @return first element in the list + */ + @SuppressWarnings("unchecked") + private T getFirstInCollection(Collection<T> list) { + if (list != null && !list.isEmpty()) { + Object result = list.iterator().next(); + Hibernate.initialize(result); + return (T) result; + } + return null; + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mup...@us...> - 2008-03-05 17:09:03
|
Revision: 718 http://openutils.svn.sourceforge.net/openutils/?rev=718&view=rev Author: muppet68 Date: 2008-03-05 09:08:56 -0800 (Wed, 05 Mar 2008) Log Message: ----------- Aggiunto metodo per ritornare solo sottoinsieme di propriet?\195?\160 di un oggetto 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 2008-03-03 14:36:22 UTC (rev 717) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2008-03-05 17:08:56 UTC (rev 718) @@ -141,7 +141,22 @@ */ List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, final int maxResults, final int page, List<Criterion> additionalCriteria); + + /** + * Return properties from 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 + * @param properties properties to be returned + * @return list of properties from all objects + */ + List<?> findFilteredProperties(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, + final int maxResults,final int page, List<Criterion> additionalCriteria, List<String> properties); + /** * 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. 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 2008-03-03 14:36:22 UTC (rev 717) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2008-03-05 17:08:56 UTC (rev 718) @@ -20,6 +20,9 @@ import org.hibernate.criterion.CriteriaSpecification; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; +import org.hibernate.criterion.ProjectionList; +import org.hibernate.criterion.Projections; +import org.hibernate.criterion.Property; import org.hibernate.type.Type; import org.springframework.aop.framework.AopContext; import org.springframework.orm.hibernate3.HibernateCallback; @@ -331,7 +334,7 @@ /** * {@inheritDoc} */ - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") public List<T> findFiltered(T filter, Order[] customOrder, Map<String, FilterMetadata> metadata, int maxResults, int page, List<Criterion> additionalCriteria) { @@ -339,10 +342,40 @@ .getDefaultOrder(); return (List<T>) getHibernateTemplate().execute( - new HibernateCallbackForExecution(filter, page, maxResults, metadata, orderProperties, additionalCriteria)); + new HibernateCallbackForExecution( + filter, + page, + maxResults, + metadata, + orderProperties, + additionalCriteria, + null)); } /** + * + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<?> findFilteredProperties(final T filter, final Order[] customOrder, + final Map<String, FilterMetadata> metadata, final int maxResults, final int page, + List<Criterion> additionalCriteria, List<String> properties) + { + final Order[] orderProperties = customOrder != null && customOrder.length > 0 ? customOrder : this + .getDefaultOrder(); + + return (List< ? >) getHibernateTemplate().execute( + new HibernateCallbackForExecution( + filter, + page, + maxResults, + metadata, + orderProperties, + additionalCriteria, + properties)); + } + + /** * Return the specific Object class that will be used for class-specific implementation of this DAO. * @return the reference Class */ @@ -550,6 +583,11 @@ private final Map<String, FilterMetadata> metadata; /** + * + */ + private final List<String> properties; + + /** * */ private final Order[] orderProperties; @@ -569,7 +607,8 @@ int maxResults, Map<String, FilterMetadata> metadata, Order[] orderProperties, - List<Criterion> additionalCriteria) + List<Criterion> additionalCriteria, + List<String> properties) { this.filter = filter; this.page = page; @@ -577,6 +616,7 @@ this.metadata = metadata; this.orderProperties = orderProperties; this.additionalCriteria = additionalCriteria; + this.properties = properties; } public Object doInHibernate(Session ses) throws HibernateException @@ -604,6 +644,17 @@ crit.add(criterion); } } + if (properties != null) + { + ProjectionList projectionList = Projections.projectionList(); + + for (String property : properties) + { + projectionList.add(Property.forName(property)); + } + + crit.setProjection(projectionList); + } return crit.list(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-06-09 16:46:23
|
Revision: 830 http://openutils.svn.sourceforge.net/openutils/?rev=830&view=rev Author: fcarone Date: 2008-06-09 09:46:26 -0700 (Mon, 09 Jun 2008) Log Message: ----------- findFilteredFirst with order added 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 2008-06-08 11:47:36 UTC (rev 829) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2008-06-09 16:46:26 UTC (rev 830) @@ -193,6 +193,14 @@ * 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. + * @return first object in the collection + */ + T findFilteredFirst(final T filter, final Order[] order); + + /** + * 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 */ 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 2008-06-08 11:47:36 UTC (rev 829) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2008-06-09 16:46:26 UTC (rev 830) @@ -276,6 +276,15 @@ /** * {@inheritDoc} */ + public T findFilteredFirst(final T filter, final Order[] order) + { + return getFirstInCollection(findFiltered(filter, order, getDefaultFilterMetadata(), 1, 0)); + } + + + /** + * {@inheritDoc} + */ public T findFilteredFirst(final T filter, List<Criterion> criteria) { return getFirstInCollection(findFiltered(filter, null, getDefaultFilterMetadata(), 1, 0, criteria)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |