From: <gca...@us...> - 2009-10-27 14:46:22
|
Revision: 1498 http://openutils.svn.sourceforge.net/openutils/?rev=1498&view=rev Author: gcatania Date: 2009-10-27 14:46:06 +0000 (Tue, 27 Oct 2009) Log Message: ----------- BSHD-2 reordered methods 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 2009-10-23 08:13:33 UTC (rev 1497) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAO.java 2009-10-27 14:46:06 UTC (rev 1498) @@ -21,13 +21,6 @@ { /** - * Execute a query. - * @param query a query expressed in Hibernate's query language - * @return a distinct list of instances (or arrays of instances) - */ - List<T> find(String query); - - /** * Return all objects related to the implementation of this DAO with no filter. * @return a list of all instances */ @@ -41,12 +34,11 @@ 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 + * Execute a query. + * @param query a query expressed in Hibernate's query language + * @return a distinct list of instances (or arrays of instances) */ - List<T> findAll(final Order[] orderProperties, List< ? extends Criterion> criteria); + List<T> find(String query); /** * Execute a query. @@ -67,123 +59,49 @@ List<T> find(final String query, final Object[] obj, final Type[] type); /** - * Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement - * long-running sessions that span many business tasks. This method is, however, useful in certain special - * circumstances. For example - * <ul> - * <li>where a database trigger alters the object state upon insert or update - * <li>after executing direct SQL (eg. a mass update) in the same session - * <li>after inserting a <tt>Blob</tt> or <tt>Clob</tt> - * </ul> - * @param obj Object - */ - 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 - * become associated with the session. This operation cascades to associated instances if the association is mapped - * with <tt>cascade="merge"</tt>.<br> - * <br> - * The semantics of this method are defined by JSR-220. - * @param obj a detached instance with state to be copied - * @return an updated persistent instance - */ - T merge(T obj); - - /** * 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 wish to filter on. - * @param maxResults maximum number of results - * @param page result page (first result is maxResults * page) * @return list of objects */ - List<T> findFiltered(final T filter, final int maxResults, final int page); + List<T> findFiltered(final T filter); /** * 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 wish to filter on. - * @param metadata filter metadata - * @param maxResults maximum number of results - * @param page result page (first result is maxResults * page) + * @param orderProperties the name of the property used for ordering * @return list of objects */ - List<T> findFiltered(final T filter, Map<String, ? extends FilterMetadata> metadata, final int maxResults, - final int page); + List<T> findFiltered(final T filter, final Order[] orderProperties); /** * 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 wish 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 */ - List<T> findFiltered(final T filter, final Order[] customOrder, - final Map<String, ? extends FilterMetadata> metadata, final int maxResults, final int page); + 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. * @param filter an instance of the object with the properties you wish 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, ? extends FilterMetadata> metadata, final int maxResults, final int page, - List< ? extends Criterion> additionalCriteria); + List<T> findFiltered(final T filter, Map<String, ? extends FilterMetadata> metadata); /** - * Return properties from 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 wish 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, ? extends FilterMetadata> metadata, final int maxResults, final int page, - List< ? extends 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 wish to filter on. * @return list of objects */ - List<T> findFiltered(final T filter); + List<T> findFiltered(final T filter, Map<String, ? extends FilterMetadata> metadata, final int maxResults, + final int page); /** - * 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 wish to filter on. - * @param orderProperties the name of the property used for ordering - * @return list of objects - */ - List<T> findFiltered(final T filter, final Order[] orderProperties); - - /** - * 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 wish to filter on. - * @param metadata filter metadata - * @return list of objects - */ - List<T> findFiltered(final T filter, Map<String, ? extends FilterMetadata> metadata); - - /** * 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 wish to filter on. @@ -209,15 +127,6 @@ T findFilteredFirst(final T filter, final List< ? extends 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. - * @param key key - * @return true if the object was successfully deleted, false otherwise - */ - boolean delete(final K key); - - /** * Load object matching the given key and return it. Throw an exception if not found. * @param key serializable key * @return Object @@ -239,11 +148,12 @@ T get(K key); /** - * Used by the base DAO classes but here for your modification Either save() or update() the given instance, - * depending upon the value of its identifier property. + * Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the + * identifier property if the assigned generator is used.) * @param obj Object + * @return generated id */ - void saveOrUpdate(final T obj); + K save(T obj); /** * Used by the base DAO classes but here for your modification Update the persistent state associated with the given @@ -254,11 +164,101 @@ void update(T obj); /** - * Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the - * identifier property if the assigned generator is used.) + * Used by the base DAO classes but here for your modification Either save() or update() the given instance, + * depending upon the value of its identifier property. * @param obj Object - * @return generated id */ - K save(T obj); + void saveOrUpdate(final T obj); + /** + * 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. + * @param key key + * @return true if the object was successfully deleted, false otherwise + */ + boolean delete(final K key); + + /** + * Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement + * long-running sessions that span many business tasks. This method is, however, useful in certain special + * circumstances. For example + * <ul> + * <li>where a database trigger alters the object state upon insert or update + * <li>after executing direct SQL (eg. a mass update) in the same session + * <li>after inserting a <tt>Blob</tt> or <tt>Clob</tt> + * </ul> + * @param obj Object + */ + 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 + * become associated with the session. This operation cascades to associated instances if the association is mapped + * with <tt>cascade="merge"</tt>.<br> + * <br> + * The semantics of this method are defined by JSR-220. + * @param obj a detached instance with state to be copied + * @return an updated persistent instance + */ + T merge(T obj); + + /** + * 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< ? extends Criterion> criteria); + + /** + * 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 wish 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 + */ + List<T> findFiltered(final T filter, final Order[] customOrder, + final Map<String, ? extends FilterMetadata> metadata, final int maxResults, final int page); + + /** + * 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 wish 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, ? extends FilterMetadata> metadata, final int maxResults, final int page, + List< ? extends 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 wish 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, ? extends FilterMetadata> metadata, final int maxResults, final int page, + List< ? extends Criterion> additionalCriteria, List<String> properties); + } 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 2009-10-23 08:13:33 UTC (rev 1497) +++ trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2009-10-27 14:46:06 UTC (rev 1498) @@ -63,15 +63,6 @@ /** * {@inheritDoc} */ - @SuppressWarnings("unchecked") - public List<T> find(String query) - { - return getHibernateTemplate().find(query); - } - - /** - * {@inheritDoc} - */ public List<T> findAll() { return findAll(getDefaultOrder()); @@ -89,32 +80,9 @@ * {@inheritDoc} */ @SuppressWarnings("unchecked") - public List<T> findAll(final Order[] orderProperties, final List< ? extends Criterion> criteria) + public List<T> find(String query) { - return (List<T>) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(final 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(); - } - }); + return getHibernateTemplate().find(query); } /** @@ -145,6 +113,70 @@ /** * {@inheritDoc} */ + public List<T> findFiltered(T filter) + { + return findFiltered(filter, getDefaultFilterMetadata()); + } + + /** + * {@inheritDoc} + */ + public List<T> findFiltered(T filter, Order[] orderProperties) + { + return findFiltered(filter, orderProperties, getDefaultFilterMetadata(), Integer.MAX_VALUE, 0); + } + + /** + * {@inheritDoc} + */ + public List<T> findFiltered(T filter, int maxResults, int page) + { + return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); + } + + /** + * {@inheritDoc} + */ + public List<T> findFiltered(T filter, Map<String, ? extends FilterMetadata> metadata) + { + return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); + } + + /** + * {@inheritDoc} + */ + public List<T> findFiltered(T filter, Map<String, ? extends FilterMetadata> metadata, int maxResults, int page) + { + return findFiltered(filter, getDefaultOrder(), metadata, maxResults, page); + } + + /** + * {@inheritDoc} + */ + public T findFilteredFirst(T filter) + { + return getFirstInCollection(findFiltered(filter, 1, 0)); + } + + /** + * {@inheritDoc} + */ + public T findFilteredFirst(T filter, final Order[] order) + { + return getFirstInCollection(findFiltered(filter, order, getDefaultFilterMetadata(), 1, 0)); + } + + /** + * {@inheritDoc} + */ + public T findFilteredFirst(T filter, List< ? extends Criterion> criteria) + { + return getFirstInCollection(findFiltered(filter, getDefaultOrder(), getDefaultFilterMetadata(), 1, 0, criteria)); + } + + /** + * {@inheritDoc} + */ public T load(K key) { @SuppressWarnings("unchecked") @@ -187,9 +219,10 @@ /** * {@inheritDoc} */ - public void saveOrUpdate(T obj) + @SuppressWarnings("unchecked") + public K save(T obj) { - getHibernateTemplate().saveOrUpdate(obj); + return (K) getHibernateTemplate().save(obj); } /** @@ -203,6 +236,14 @@ /** * {@inheritDoc} */ + public void saveOrUpdate(T obj) + { + getHibernateTemplate().saveOrUpdate(obj); + } + + /** + * {@inheritDoc} + */ public boolean delete(final K key) { @@ -255,78 +296,37 @@ * {@inheritDoc} */ @SuppressWarnings("unchecked") - public K save(T obj) + public List<T> findAll(final Order[] orderProperties, final List< ? extends Criterion> criteria) { - return (K) getHibernateTemplate().save(obj); - } + return (List<T>) getHibernateTemplate().execute(new HibernateCallback() + { - /** - * {@inheritDoc} - */ - public T findFilteredFirst(T filter) - { - return getFirstInCollection(findFiltered(filter, 1, 0)); - } + public Object doInHibernate(final Session ses) throws HibernateException + { + Criteria crit = ses.createCriteria(getReferenceClass()); + if (null != orderProperties) + { + for (int j = 0; j < orderProperties.length; j++) + { + crit.addOrder(orderProperties[j]); + } - /** - * {@inheritDoc} - */ - public T findFilteredFirst(T filter, final Order[] order) - { - return getFirstInCollection(findFiltered(filter, order, getDefaultFilterMetadata(), 1, 0)); + } + if (criteria != null) + { + for (Criterion criterion : criteria) + { + crit.add(criterion); + } + } + return crit.list(); + } + }); } /** * {@inheritDoc} */ - public T findFilteredFirst(T filter, List< ? extends Criterion> criteria) - { - return getFirstInCollection(findFiltered(filter, getDefaultOrder(), getDefaultFilterMetadata(), 1, 0, criteria)); - } - - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter) - { - return findFiltered(filter, getDefaultFilterMetadata()); - } - - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter, Order[] orderProperties) - { - return findFiltered(filter, orderProperties, getDefaultFilterMetadata(), Integer.MAX_VALUE, 0); - } - - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter, Map<String, ? extends FilterMetadata> metadata) - { - return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); - } - - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter, int maxResults, int page) - { - return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); - } - - /** - * {@inheritDoc} - */ - public List<T> findFiltered(T filter, Map<String, ? extends FilterMetadata> metadata, int maxResults, int page) - { - return findFiltered(filter, getDefaultOrder(), metadata, maxResults, page); - } - - /** - * {@inheritDoc} - */ public List<T> findFiltered(T filter, Order[] customOrder, Map<String, ? extends FilterMetadata> metadata, int maxResults, int page) { @@ -376,12 +376,12 @@ } /** - * Return the specific Object class that will be used for class-specific implementation of this DAO. - * @return the reference Class + * Sets the aopenabled. + * @param aopenabled the aopenabled to set */ - protected Class<T> getReferenceClass() + public void setAopenabled(boolean aopenabled) { - return referenceClass; + this.aopenabled = aopenabled; } public void setReferenceClass(Class<T> referenceClass) @@ -390,6 +390,15 @@ } /** + * Return the specific Object class that will be used for class-specific implementation of this DAO. + * @return the reference Class + */ + protected Class<T> getReferenceClass() + { + return referenceClass; + } + + /** * Return a list of <code>Order</code> object to be used for the default ordering of the collection. * @return the property name */ @@ -532,15 +541,6 @@ } /** - * Sets the aopenabled. - * @param aopenabled the aopenabled to set - */ - public void setAopenabled(boolean aopenabled) - { - this.aopenabled = aopenabled; - } - - /** * @return This is needed as for http://opensource.atlassian.com/projects/spring/browse/SPR-2226 */ @SuppressWarnings("unchecked") @@ -572,7 +572,7 @@ * @author carone * @version $Id$ */ - private class HibernateCallbackForExecution implements HibernateCallback + private final class HibernateCallbackForExecution implements HibernateCallback { private T filter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |