From: <fg...@us...> - 2006-10-18 12:30:57
|
Revision: 93 http://svn.sourceforge.net/openutils/?rev=93&view=rev Author: fgiust Date: 2006-10-18 05:30:41 -0700 (Wed, 18 Oct 2006) Log Message: ----------- [maven-scm] copy for tag openutils-bshd5-1.0.2 Added Paths: ----------- tags/openutils-bshd5-1.0.2/ tags/openutils-bshd5-1.0.2/pom.xml tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Removed Paths: ------------- tags/openutils-bshd5-1.0.2/pom.xml tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Copied: tags/openutils-bshd5-1.0.2 (from rev 80, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-1.0.2/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-bshd5-1.0.2/pom.xml 2006-10-18 12:30:41 UTC (rev 93) @@ -1,46 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>1.1-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.0.cr4</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-1.0.2/pom.xml (from rev 92, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-1.0.2/pom.xml (rev 0) +++ tags/openutils-bshd5-1.0.2/pom.xml 2006-10-18 12:30:41 UTC (rev 93) @@ -0,0 +1,52 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>1.0.2</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.0.cr5</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.2</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.2</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-1.0.2</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2006-10-18 12:30:41 UTC (rev 93) @@ -1,421 +0,0 @@ -package it.openutils.dao.hibernate; - -import it.openutils.hibernate.example.EnhancedExample; -import it.openutils.hibernate.example.FilterMetadata; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.hibernate.Criteria; -import org.hibernate.Hibernate; -import org.hibernate.HibernateException; -import org.hibernate.ObjectNotFoundException; -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.criterion.CriteriaSpecification; -import org.hibernate.criterion.Order; -import org.hibernate.type.Type; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.orm.hibernate3.HibernateCallback; -import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - - -/** - * Base Hibernate DAO. - * @author Fabrizio Giustina - * @version $Id$ - */ -public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport - implements - HibernateDAO<T, K> -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(HibernateDAOImpl.class); - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String) - */ - public List<T> find(String query) - { - return getHibernateTemplate().find(query); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll() - */ - public List<T> findAll() - { - return findAll(getDefaultOrder()); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll(org.hibernate.criterion.Order[]) - */ - public List<T> findAll(final Order[] orderProperties) - { - - 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]); - } - - } - return crit.list(); - } - }); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String, java.lang.Object, org.hibernate.type.Type) - */ - public List<T> find(String query, Object obj, Type type) - { - return find(query, new Object[]{obj}, new Type[]{type}); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(String, Object[], Type[]) - */ - 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(); - } - }); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) - */ - public T load(K key) - { - T result = (T) getHibernateTemplate().load(getReferenceClass(), key); - Hibernate.initialize(result); - return result; - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) - */ - 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; - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#saveOrUpdate(null) - */ - public void saveOrUpdate(final T obj) - { - getHibernateTemplate().saveOrUpdate(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#update(null) - */ - public void update(T obj) - { - getHibernateTemplate().update(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#delete(null) - */ - public boolean delete(final K key) - { - - return (Boolean) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - ses.delete(ses.load(getReferenceClass(), key)); - return true; - } - }); - - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#refresh(null) - */ - public void refresh(T obj) - { - getHibernateTemplate().refresh(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#merge(T) - */ - public T merge(final T obj) - { - return (T) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - return ses.merge(obj); - } - }); - - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#save(java.lang.Object) - */ - public K save(T obj) - { - return (K) getHibernateTemplate().save(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFilteredFirst(T) - */ - public T findFilteredFirst(final T filter) - { - return getFirstInCollection(findFiltered(filter, 1, 0)); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) - */ - public List<T> findFiltered(final T filter) - { - return findFiltered(filter, new HashMap<String, FilterMetadata>(0)); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(java.lang.Object, org.hibernate.criterion.Order[]) - */ - public List<T> findFiltered(T filter, Order[] orderProperties) - { - return findFiltered(filter, orderProperties, new HashMap<String, FilterMetadata>(0), Integer.MAX_VALUE, 0); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) - */ - public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata) - { - return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - public List<T> findFiltered(final T filter, final int maxResults, final int page) - { - return findFiltered(filter, new HashMap<String, FilterMetadata>(0), maxResults, page); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - 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); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, - final int maxResults, final int page) - { - 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 (null != orderProperties && orderProperties.length > 0) - { - for (Order order : orderProperties) - { - if (order != null) - { - crit.addOrder(order); - } - } - } - - EnhancedExample.create(crit, filter, metadata); - - return crit.list(); - } - }); - } - - /** - * 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 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]; - } - - /** - * Obtain an instance of Query for a named query string defined in the mapping file. - * @param name the name of a query defined externally - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final int marResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - 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 array - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int marResults) - { - - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - if (null != params) - { - for (int i = 0; i < params.length; i++) - { - q.setParameter(i, params[i]); - } - } - 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 - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Map params, final int marResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - if (params != null) - { - for (Iterator i = params.entrySet().iterator(); i.hasNext();) - { - Map.Entry entry = (Map.Entry) i.next(); - setParameterValue(q, (String) entry.getKey(), entry.getValue()); - } - } - return q.list(); - } - }); - } - - /** - * 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 - */ - 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 Copied: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (from rev 84, trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java) =================================================================== --- tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (rev 0) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2006-10-18 12:30:41 UTC (rev 93) @@ -0,0 +1,428 @@ +package it.openutils.dao.hibernate; + +import it.openutils.hibernate.example.EnhancedExample; +import it.openutils.hibernate.example.FilterMetadata; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.HibernateException; +import org.hibernate.ObjectNotFoundException; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.CriteriaSpecification; +import org.hibernate.criterion.Order; +import org.hibernate.type.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.orm.hibernate3.HibernateCallback; +import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + + +/** + * Base Hibernate DAO. + * @author Fabrizio Giustina + * @version $Id$ + */ +public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport + implements + HibernateDAO<T, K> +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(HibernateDAOImpl.class); + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String) + */ + @SuppressWarnings("unchecked") + public List<T> find(String query) + { + return getHibernateTemplate().find(query); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findAll() + */ + public List<T> findAll() + { + return findAll(getDefaultOrder()); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findAll(org.hibernate.criterion.Order[]) + */ + @SuppressWarnings("unchecked") + public List<T> findAll(final Order[] orderProperties) + { + + 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]); + } + + } + return crit.list(); + } + }); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String, java.lang.Object, org.hibernate.type.Type) + */ + public List<T> find(String query, Object obj, Type type) + { + return find(query, new Object[]{obj}, new Type[]{type}); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#find(String, Object[], Type[]) + */ + @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(); + } + }); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) + */ + @SuppressWarnings("unchecked") + public T load(K key) + { + T result = (T) getHibernateTemplate().load(getReferenceClass(), key); + Hibernate.initialize(result); + return result; + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) + */ + @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; + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#saveOrUpdate(null) + */ + public void saveOrUpdate(final T obj) + { + getHibernateTemplate().saveOrUpdate(obj); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#update(null) + */ + public void update(T obj) + { + getHibernateTemplate().update(obj); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#delete(null) + */ + public boolean delete(final K key) + { + + return (Boolean) getHibernateTemplate().execute(new HibernateCallback() + { + + public Object doInHibernate(Session ses) throws HibernateException + { + ses.delete(ses.load(getReferenceClass(), key)); + return true; + } + }); + + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#refresh(null) + */ + public void refresh(T obj) + { + getHibernateTemplate().refresh(obj); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#merge(T) + */ + @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); + } + }); + + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#save(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public K save(T obj) + { + return (K) getHibernateTemplate().save(obj); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFilteredFirst(T) + */ + public T findFilteredFirst(final T filter) + { + return getFirstInCollection(findFiltered(filter, 1, 0)); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) + */ + public List<T> findFiltered(final T filter) + { + return findFiltered(filter, new HashMap<String, FilterMetadata>(0)); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(java.lang.Object, org.hibernate.criterion.Order[]) + */ + public List<T> findFiltered(T filter, Order[] orderProperties) + { + return findFiltered(filter, orderProperties, new HashMap<String, FilterMetadata>(0), Integer.MAX_VALUE, 0); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) + */ + public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata) + { + return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + */ + public List<T> findFiltered(final T filter, final int maxResults, final int page) + { + return findFiltered(filter, new HashMap<String, FilterMetadata>(0), maxResults, page); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + */ + 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); + } + + /** + * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) + */ + @SuppressWarnings("unchecked") + public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, + final int maxResults, final int page) + { + 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 (null != orderProperties && orderProperties.length > 0) + { + for (Order order : orderProperties) + { + if (order != null) + { + crit.addOrder(order); + } + } + } + + EnhancedExample.create(crit, filter, metadata); + + return crit.list(); + } + }); + } + + /** + * 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 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]; + } + + /** + * Obtain an instance of Query for a named query string defined in the mapping file. + * @param name the name of a query defined externally + * @return Query + */ + protected List< ? > getNamedQuery(final String name, final int marResults) + { + return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() + { + + public Object doInHibernate(Session ses) throws HibernateException + { + Query q = ses.getNamedQuery(name); + q.setMaxResults(marResults); + 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 array + * @return Query + */ + protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int marResults) + { + + return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() + { + + public Object doInHibernate(Session ses) throws HibernateException + { + Query q = ses.getNamedQuery(name); + q.setMaxResults(marResults); + if (null != params) + { + for (int i = 0; i < params.length; i++) + { + q.setParameter(i, params[i]); + } + } + 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 + * @return Query + */ + protected List< ? > getNamedQuery(final String name, final Map<String, Object> params, final int marResults) + { + return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() + { + + public Object doInHibernate(Session ses) throws HibernateException + { + Query q = ses.getNamedQuery(name); + q.setMaxResults(marResults); + if (params != null) + { + for (Map.Entry<String, Object> entry : params.entrySet()) + { + setParameterValue(q, entry.getKey(), entry.getValue()); + } + } + return q.list(); + } + }); + } + + /** + * 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; + } + +} \ No newline at end of file Deleted: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2006-10-18 12:30:41 UTC (rev 93) @@ -1,73 +0,0 @@ -package it.openutils.dao.hibernate; - -import java.util.Date; - - -/** - * @author fgiust - * @version $Revision$ ($Author$) - */ -public class MutableDateRange extends Date -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * range start. - */ - private Date from; - - /** - * range end. - */ - private Date to; - - /** - * Getter for <code>from</code>. - * @return Returns the from. - */ - public Date getFrom() - { - return this.from; - } - - /** - * Setter for <code>from</code>. - * @param from The from to set. - */ - public void setFrom(Date from) - { - this.from = from; - } - - /** - * Getter for <code>to</code>. - * @return Returns the to. - */ - public Date getTo() - { - return this.to; - } - - /** - * Setter for <code>to</code>. - * @param to The to to set. - */ - public void setTo(Date to) - { - this.to = to; - } - - /** - * Returns <code>true</code> if at least one date is set. - * @return <code>true</code> if at least one date is set - */ - public boolean isSet() - { - return this.to != null || this.from != null; - } - -} Copied: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java (from rev 86, trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java) =================================================================== --- tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java (rev 0) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2006-10-18 12:30:41 UTC (rev 93) @@ -0,0 +1,74 @@ +package it.openutils.dao.hibernate; + +import java.util.Date; + + +/** + * @author fgiust + * @version $Id: $ + * @deprecated use FilterMetadata + */ +public class MutableDateRange extends Date +{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * range start. + */ + private Date from; + + /** + * range end. + */ + private Date to; + + /** + * Getter for <code>from</code>. + * @return Returns the from. + */ + public Date getFrom() + { + return this.from; + } + + /** + * Setter for <code>from</code>. + * @param from The from to set. + */ + public void setFrom(Date from) + { + this.from = from; + } + + /** + * Getter for <code>to</code>. + * @return Returns the to. + */ + public Date getTo() + { + return this.to; + } + + /** + * Setter for <code>to</code>. + * @param to The to to set. + */ + public void setTo(Date to) + { + this.to = to; + } + + /** + * Returns <code>true</code> if at least one date is set. + * @return <code>true</code> if at least one date is set + */ + public boolean isSet() + { + return this.to != null || this.from != null; + } + +} Deleted: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-10-18 12:30:41 UTC (rev 93) @@ -1,327 +0,0 @@ -package it.openutils.hibernate.example; - -import it.openutils.dao.hibernate.MutableDateRange; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id$ - */ -public class EnhancedExample -{ - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(crit, filter); - } - - /** - * Logger. - */ - private static Log log = LogFactory.getLog(EnhancedExample.class); - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - if (isSimpleType(value)) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - // @todo handle nested properties - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - fmd.createFilter(crit, propertyName, value); - - } - else if (value instanceof MutableDateRange) - { - Date from = ((MutableDateRange) value).getFrom(); - Date to = ((MutableDateRange) value).getTo(); - if (from != null && to != null) - { - if (log.isDebugEnabled()) - { - log.debug("crit.add(Restrictions.between(" + propertyName + "," + from + ", " + to + ")"); - } - crit.add(Restrictions.between(propertyName, from, to)); - } - else if (from != null) - { - if (log.isDebugEnabled()) - { - log.debug("crit.add(Restrictions.ge(" + propertyName + "," + from + ")"); - } - crit.add(Restrictions.ge(propertyName, from)); - } - else if (to != null) - { - if (log.isDebugEnabled()) - { - log.debug("crit.add(Restrictions.le(" + propertyName + ", " + to + ")"); - } - crit.add(Restrictions.le(propertyName, to)); - } - } - else - { - if (containsSomething(value)) - { - if (log.isDebugEnabled()) - { - log.debug("crit.createCriteria(" + propertyName + ")"); - } - - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - Iterator iterator = ((Collection) value).iterator(); - - if (iterator.hasNext()) - { - Object element = iterator.next(); - Criteria childrenCriteria = crit.createCriteria(propertyName); - fillCriteria(childrenCriteria, element); - } - } - else - { - Criteria childrenCriteria = crit.createCriteria(propertyName); - fillCriteria(childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - else if (bean instanceof MutableDateRange) - { - return ((MutableDateRange) bean).isSet(); - } - - if (bean instanceof Collection) - { - // log.debug("**COL**"); - Collection coll = ((Collection) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - // log.debug("**MAP**"); - Map coll = ((Map) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - if (log.isDebugEnabled()) - { - // log.debug(ClassUtils.getShortClassName(bean.getClass()) + " is empty"); - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - private void fillCriteria(Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - Iterator iterator = ((Collection) filter).iterator(); - while (iterator.hasNext()) - { - Object element = iterator.next(); - fillCriteria(crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - addCondition(crit, propertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || objClass.equals(Calendar.class); - } - -} Copied: tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 91, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-1.0.2/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-10-18 12:30:41 UTC (rev 93) @@ -0,0 +1,319 @@ +package it.openutils.hibernate.example; + +import it.openutils.dao.hibernate.MutableDateRange; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public class EnhancedExample +{ + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + throws HibernateException + { + new EnhancedExample(crit, filter, metadata); + } + + /** + * Adds contitions to an existing criteria or create sub-criteria for associations. + * @param crit Criteria + * @param propertyName property name in parent bean + * @param value property value + * @throws HibernateException exception while building the criteria + */ + private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) + throws HibernateException + { + if (isSimpleType(value)) + { + + // don't filter on empty strings! + if (value instanceof String && StringUtils.isBlank((String) value)) + { + return; + } + + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd == null) + { + fmd = FilterMetadata.EQUAL; + } + + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( + propertyName, + ".") : propertyName; + + fmd.createFilter(crit, simplePropertyName, value); + + } + else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata + // for this scope + { + Date from = ((MutableDateRange) value).getFrom(); + Date to = ((MutableDateRange) value).getTo(); + if (from != null && to != null) + { + log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); + crit.add(Restrictions.between(propertyName, from, to)); + } + else if (from != null) + { + + log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); + + crit.add(Restrictions.ge(propertyName, from)); + } + else if (to != null) + { + log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); + crit.add(Restrictions.le(propertyName, to)); + } + } + else + { + if (containsSomething(value)) + { + + // @todo handle multiple associations in lists? + // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 + if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) + { + // collection: the new criteria has already been created, now we only nee to analize content + + for (Object element : ((Collection) value)) + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, element); + } + } + else + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, value); + } + } + } + } + + /** + * Check if the bean contains at least a valid property. + * @param bean javabean + * @return <code>true</code> if the bean contains at least a valid property + */ + private boolean containsSomething(Object bean) + { + + if (bean == null) + { + return false; + } + if (isSimpleType(bean)) + { + return true; + } + else if (bean instanceof MutableDateRange) + { + return ((MutableDateRange) bean).isSet(); + } + + if (bean instanceof Collection) + { + + Collection coll = ((Collection) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.iterator().next())) + { + return true; + } + } + else if (bean instanceof Map) + { + Map coll = ((Map) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.values().iterator().next())) + { + return true; + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(bean); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(bean, "NULL"), e); + return false; + } + + for (Map.Entry<String, Object> property : properties.entrySet()) + { + + if (!PropertyUtils.isWriteable(bean, property.getKey())) + { + // skip readonly properties + continue; + } + + Object propertyValue = property.getValue(); + if (propertyValue == null) + { + continue; + } + + if (isSimpleType(propertyValue) || containsSomething(propertyValue)) + { + return true; + } + } + + return false; + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException + { + if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) + { + // collection: the new criteria has already been created, now we only need to analize content + for (Object element : ((Collection) filter)) + { + fillCriteria(parentPropertyName, crit, element); + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(filter); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + throw new DataRetrievalFailureException( + "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(filter, "NULL") + + ":" + + e.getClass(), + e); + } + + Iterator<String> iterator = properties.keySet().iterator(); + while (iterator.hasNext()) + { + String propertyName = iterator.next(); + + Object value = properties.get(propertyName); + + // add only non-null values, ignore read-only properties + if (value != null && PropertyUtils.isWriteable(filter, propertyName)) + { + String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName + + "." + + propertyName; + addCondition(crit, composedPropertyName, value, filter); + } + } + } + + /** + * Check if the given object is a simple java type + * @param object object to check + * @return <code>true</code>if the given object is a simple type + */ + private boolean isSimpleType(Object object) + { + + Class< ? extends Object> objClass = object.getClass(); + + return objClass.isPrimitive() + || objClass.equals(Integer.class) + || objClass.equals(Long.class) + || objClass.equals(Short.class) + || objClass.equals(Boolean.class) + || objClass.equals(String.class) + || objClass.equals(Double.class) + || objClass.equals(Float.class) + || objClass.equals(Date.class) + || objClass.equals(Byte.class) + || objClass.equals(BigDecimal.class) + || objClass.equals(Timestamp.class) + || objClass.equals(Character.class) + || objClass.equals(Calendar.class); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-11-06 22:48:12
|
Revision: 97 http://svn.sourceforge.net/openutils/?rev=97&view=rev Author: fgiust Date: 2006-11-06 14:48:02 -0800 (Mon, 06 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-1.0.1 Added Paths: ----------- tags/openutils-usermanagement-1.0.1/ tags/openutils-usermanagement-1.0.1/pom.xml Removed Paths: ------------- tags/openutils-usermanagement-1.0.1/pom.xml Copied: tags/openutils-usermanagement-1.0.1 (from rev 80, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-1.0.1/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-usermanagement-1.0.1/pom.xml 2006-11-06 22:48:02 UTC (rev 97) @@ -1,110 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>0.3-SNAPSHOT</version> - <description>Usermanagement classes</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring</artifactId> - <version>1.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.cr2</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.1.2.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-1.0.1/pom.xml (from rev 96, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-1.0.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-1.0.1/pom.xml 2006-11-06 22:48:02 UTC (rev 97) @@ -0,0 +1,116 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>1.0.1</version> + <description>Usermanagement classes</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-spring</artifactId> + <version>1.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>1.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.cr2</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.0.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.0.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-1.0.1</url> + </scm> +</project> \ 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: <fg...@us...> - 2006-11-13 21:26:41
|
Revision: 111 http://svn.sourceforge.net/openutils/?rev=111&view=rev Author: fgiust Date: 2006-11-13 13:26:27 -0800 (Mon, 13 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-1.1 Added Paths: ----------- tags/openutils-usermanagement-1.1/ tags/openutils-usermanagement-1.1/pom.xml Removed Paths: ------------- tags/openutils-usermanagement-1.1/pom.xml Copied: tags/openutils-usermanagement-1.1 (from rev 109, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-1.1/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-1.1/pom.xml 2006-11-13 21:26:27 UTC (rev 111) @@ -1,116 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>1.1-SNAPSHOT</version> - <description>Usermanagement classes</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring</artifactId> - <version>1.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>1.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>1.0.2</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>1.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.ga</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.1.2.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-1.1/pom.xml (from rev 110, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-1.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-1.1/pom.xml 2006-11-13 21:26:27 UTC (rev 111) @@ -0,0 +1,121 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>1.1</version> + <description>Usermanagement classes</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-spring</artifactId> + <version>1.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>1.0.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.ga</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-1.1</url> + </scm> +</project> \ 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: <fg...@us...> - 2006-11-14 16:09:54
|
Revision: 115 http://svn.sourceforge.net/openutils/?rev=115&view=rev Author: fgiust Date: 2006-11-14 08:09:40 -0800 (Tue, 14 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-1.1.1 Added Paths: ----------- tags/openutils-usermanagement-1.1.1/ tags/openutils-usermanagement-1.1.1/pom.xml tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java Removed Paths: ------------- tags/openutils-usermanagement-1.1.1/pom.xml tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java Copied: tags/openutils-usermanagement-1.1.1 (from rev 109, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-1.1.1/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-1.1.1/pom.xml 2006-11-14 16:09:40 UTC (rev 115) @@ -1,116 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>1.1-SNAPSHOT</version> - <description>Usermanagement classes</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring</artifactId> - <version>1.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>1.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>1.0.2</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>1.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.ga</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.1.2.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-1.1.1/pom.xml (from rev 114, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-1.1.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-1.1.1/pom.xml 2006-11-14 16:09:40 UTC (rev 115) @@ -0,0 +1,121 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>1.1.1</version> + <description>Usermanagement classes</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-spring</artifactId> + <version>1.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>1.0.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.ga</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.1.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.1.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-1.1.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java =================================================================== --- trunk/openutils-usermanagement/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java 2006-11-14 16:09:40 UTC (rev 115) @@ -1,57 +0,0 @@ -package it.openutils.usermanagement.acegi; - -import it.openutils.usermanagement.dao.GroupDAO; -import it.openutils.usermanagement.dao.UserDAO; - -import org.acegisecurity.userdetails.UserDetails; -import org.acegisecurity.userdetails.UserDetailsService; -import org.acegisecurity.userdetails.UsernameNotFoundException; -import org.apache.commons.lang.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataAccessException; - - -public class HibernateUserDetailsServiceImpl implements UserDetailsService -{ - - private Logger log = LoggerFactory.getLogger(getClass()); - - private UserDAO userDao; - - private GroupDAO groupDao; - - public void setUserDao(UserDAO userDao) - { - this.userDao = userDao; - } - - public void setGroupDAO(GroupDAO groupDao) - { - this.groupDao = groupDao; - } - - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException - { - - log.debug("Login:: Loading User's Data"); - - it.openutils.usermanagement.dataobjects.User filter = new it.openutils.usermanagement.dataobjects.User(); - filter.setId(username); - it.openutils.usermanagement.dataobjects.User user = null; - - user = this.userDao.findFilteredFirst(filter); - - // warning: user can be null - if (user != null) - { - log.debug("Groups: {}, Roles {}", user.getGroups(), user.getRoles()); - log.debug("Authorities: {}", ArrayUtils.toString(user.getAuthorities())); - } - - log.debug("Login:: Returning User to Acegi: {}", user); - - return user; - } - -} Copied: tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java (from rev 113, trunk/openutils-usermanagement/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java) =================================================================== --- tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java (rev 0) +++ tags/openutils-usermanagement-1.1.1/src/main/java/it/openutils/usermanagement/acegi/HibernateUserDetailsServiceImpl.java 2006-11-14 16:09:40 UTC (rev 115) @@ -0,0 +1,59 @@ +package it.openutils.usermanagement.acegi; + +import it.openutils.usermanagement.dao.GroupDAO; +import it.openutils.usermanagement.dao.UserDAO; + +import org.acegisecurity.userdetails.UserDetails; +import org.acegisecurity.userdetails.UserDetailsService; +import org.acegisecurity.userdetails.UsernameNotFoundException; +import org.apache.commons.lang.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataAccessException; + + +public class HibernateUserDetailsServiceImpl implements UserDetailsService +{ + + private Logger log = LoggerFactory.getLogger(getClass()); + + private UserDAO userDao; + + private GroupDAO groupDao; + + public void setUserDao(UserDAO userDao) + { + this.userDao = userDao; + } + + public void setGroupDAO(GroupDAO groupDao) + { + this.groupDao = groupDao; + } + + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException + { + + log.debug("Login:: Loading User's Data"); + + it.openutils.usermanagement.dataobjects.User filter = new it.openutils.usermanagement.dataobjects.User(); + filter.setId(username); + it.openutils.usermanagement.dataobjects.User user = null; + + user = this.userDao.findFilteredFirst(filter); + + // mandatory: UserDetailsService can't return null + if (user == null) + { + throw new UsernameNotFoundException("Username " + username + " not found"); + } + + log.debug("Groups: {}, Roles {}", user.getGroups(), user.getRoles()); + log.debug("Authorities: {}", ArrayUtils.toString(user.getAuthorities())); + + log.debug("Login:: Returning User to Acegi: {}", user); + + return user; + } + +} Deleted: tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java =================================================================== --- trunk/openutils-usermanagement/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java 2006-11-14 16:09:40 UTC (rev 115) @@ -1,24 +0,0 @@ -package it.openutils.usermanagement.manager; - -import it.openutils.testing.junit.GenericsDbUnitTestCase; - -import org.acegisecurity.userdetails.UserDetails; -import org.acegisecurity.userdetails.UserDetailsService; - - -/** - * @author fgiust - * @version $Id$ - */ -public class HibernateUserDetailsServiceTest extends GenericsDbUnitTestCase<UserDetailsService> -{ - - public void testLoadUserByUsername() - { - - UserDetails user = instance.loadUserByUsername("UserUno"); - assertNotNull(user); - - } - -} Copied: tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java (from rev 113, trunk/openutils-usermanagement/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java) =================================================================== --- tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java (rev 0) +++ tags/openutils-usermanagement-1.1.1/src/test/java/it/openutils/usermanagement/manager/HibernateUserDetailsServiceTest.java 2006-11-14 16:09:40 UTC (rev 115) @@ -0,0 +1,39 @@ +package it.openutils.usermanagement.manager; + +import it.openutils.testing.junit.GenericsDbUnitTestCase; + +import org.acegisecurity.userdetails.UserDetails; +import org.acegisecurity.userdetails.UserDetailsService; +import org.acegisecurity.userdetails.UsernameNotFoundException; + + +/** + * @author fgiust + * @version $Id$ + */ +public class HibernateUserDetailsServiceTest extends GenericsDbUnitTestCase<UserDetailsService> +{ + + public void testLoadUserByUsername() + { + + UserDetails user = instance.loadUserByUsername("UserUno"); + assertNotNull(user); + + } + + public void testNotExistingUser() + { + try + { + instance.loadUserByUsername("notexisting"); + } + catch (UsernameNotFoundException e) + { + // as expected + return; + } + fail("Expected UsernameNotFoundException not thrown"); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-02-05 17:41:51
|
Revision: 203 http://svn.sourceforge.net/openutils/?rev=203&view=rev Author: fgiust Date: 2007-02-05 09:41:49 -0800 (Mon, 05 Feb 2007) Log Message: ----------- [maven-scm] copy for tag openutils-testing-junit-1.1 Added Paths: ----------- tags/openutils-testing-junit-1.1/ tags/openutils-testing-junit-1.1/pom.xml tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java Removed Paths: ------------- tags/openutils-testing-junit-1.1/pom.xml tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java Copied: tags/openutils-testing-junit-1.1 (from rev 198, trunk/openutils-testing-junit) Deleted: tags/openutils-testing-junit-1.1/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2007-02-05 17:20:24 UTC (rev 198) +++ tags/openutils-testing-junit-1.1/pom.xml 2007-02-05 17:41:49 UTC (rev 203) @@ -1,60 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-junit</artifactId> - <name>openutils test utils (junit)</name> - <version>1.1-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-testing-junit-1.1/pom.xml (from rev 202, trunk/openutils-testing-junit/pom.xml) =================================================================== --- tags/openutils-testing-junit-1.1/pom.xml (rev 0) +++ tags/openutils-testing-junit-1.1/pom.xml 2007-02-05 17:41:49 UTC (rev 203) @@ -0,0 +1,64 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-junit</artifactId> + <name>openutils test utils (junit)</name> + <version>1.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-1.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-02-05 17:20:24 UTC (rev 198) +++ tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-02-05 17:41:49 UTC (rev 203) @@ -1,204 +0,0 @@ -/* - * Copyright 2005 Fabrizio Giustina. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing.junit; - -import java.io.InputStream; - -import javax.sql.DataSource; - -import org.apache.commons.lang.ClassUtils; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.DatabaseSequenceFilter; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.FilteredDataSet; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.excel.XlsDataSet; -import org.dbunit.dataset.filter.ITableFilter; -import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.dataset.xml.XmlDataSet; -import org.dbunit.ext.mssql.InsertIdentityOperation; -import org.dbunit.operation.DatabaseOperation; -import org.hibernate.SessionFactory; -import org.springframework.orm.hibernate3.SessionFactoryUtils; - - -/** - * Base class for running DAO tests. - * @author fgiust - * @version $Revision $ ($Author $) - */ -public abstract class DbUnitTestCase extends SpringTestCase -{ - - /** - * Hibernate session factory. - */ - private SessionFactory sessionFactory; - - private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml"; - - protected static IDataSet truncateDataSet; - - /** - * {@inheritDoc} - */ - @Override - protected void setUp() throws Exception - { - super.setUp(); - - // insert values - IDataSet dataSet = null; - - String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - if (log.isDebugEnabled()) - { - log.debug("loading dataset {}", datesetFileName); - } - - dataSet = new XmlDataSet(testData); - } - else - { - // check for excel - datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls"; - testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - if (log.isDebugEnabled()) - { - log.debug("loading dataset {}", datesetFileName); - } - - dataSet = new XlsDataSet(testData); - } - } - - if (dataSet == null) - { - log.debug("No test data found with name [{}]", datesetFileName); - } - else - { - - DataSource dataSource = (DataSource) ctx.getBean("dataSource"); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); - - // truncate common tables - if (truncateDataSet == null) - { - log.debug("Generating sorted dataset for initial cleanup"); - IDataSet unsortedTruncateDataSet = connection.createDataSet(); - ITableFilter filter = new DatabaseSequenceFilter(connection); - truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); - log.debug("Sorted dataset generated"); - } - - IDataSet orderedDataset = dataSet; - - // if a sorted dataset is available, use table sequence for sorting - if (truncateDataSet == null) - { - ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); - orderedDataset = new FilteredDataSet(filter, dataSet); - } - - try - { - if (truncateDataSet != null) - { - DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); - } - if (dataSet != null) - { - InsertIdentityOperation.INSERT.execute(connection, orderedDataset); - } - } - finally - { - connection.close(); - } - } - - // mimic the Spring OpenSessionInViewFilter - this.sessionFactory = (SessionFactory) ctx.getBean("sessionFactory"); - - // SessionFactoryUtils.getSession(sessionFactory, true).setFlushMode(FlushMode.NEVER); - SessionFactoryUtils.initDeferredClose(this.sessionFactory); - - // @todo find a way to disable cache - // this.sessionFactory.openSession().setCacheMode(CacheMode.IGNORE); - } - - /** - * {@inheritDoc} - */ - @Override - protected void tearDown() throws Exception - { - // close open hibernate sessions, mimic the OpenSessionInViewFilter - SessionFactoryUtils.processDeferredClose(this.sessionFactory); - - // regenerate db initial state - String datesetFileName = "/initial-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - log.debug("Restoring db state"); - - IDataSet dataSet = new XmlDataSet(testData); - - DataSource dataSource = (DataSource) ctx.getBean("dataSource"); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); - - try - { - DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); - } - finally - { - connection.close(); - } - } - - super.tearDown(); - } - - /** - * Returns the full test name. - * @see junit.framework.TestCase#getName() - */ - @Override - public String getName() - { - return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName(); - } - - /** - * return the current Hibernate SessionFactory - * @return SessionFactory object - */ - public SessionFactory getSessionFactory() - { - return sessionFactory; - } -} \ No newline at end of file Copied: tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (from rev 201, trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java) =================================================================== --- tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (rev 0) +++ tags/openutils-testing-junit-1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-02-05 17:41:49 UTC (rev 203) @@ -0,0 +1,223 @@ +/* + * Copyright 2005 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing.junit; + +import java.io.InputStream; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.lang.ClassUtils; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.DatabaseSequenceFilter; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.FilteredDataSet; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.ITableFilter; +import org.dbunit.dataset.filter.SequenceTableFilter; +import org.dbunit.dataset.xml.XmlDataSet; +import org.dbunit.ext.mssql.InsertIdentityOperation; +import org.dbunit.operation.DatabaseOperation; +import org.hibernate.SessionFactory; +import org.springframework.orm.hibernate3.SessionFactoryUtils; + + +/** + * Base class for running DAO tests. + * @author fgiust + * @version $Revision $ ($Author $) + */ +public abstract class DbUnitTestCase extends SpringTestCase +{ + + /** + * Hibernate session factory. + */ + private SessionFactory sessionFactory; + + private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml"; + + protected static IDataSet truncateDataSet; + + /** + * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> + * @return <code>true</code> if deferred close should be used + */ + protected boolean mimicSessionFilter() + { + return true; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // insert values + IDataSet dataSet = null; + + String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + if (log.isDebugEnabled()) + { + log.debug("loading dataset {}", datesetFileName); + } + + dataSet = new XmlDataSet(testData); + } + else + { + // check for excel + datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls"; + testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + if (log.isDebugEnabled()) + { + log.debug("loading dataset {}", datesetFileName); + } + + dataSet = new XlsDataSet(testData); + } + } + + if (dataSet == null) + { + log.debug("No test data found with name [{}]", datesetFileName); + } + else + { + + DataSource dataSource = (DataSource) ctx.getBean("dataSource"); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); + + // truncate common tables + if (truncateDataSet == null) + { + log.debug("Generating sorted dataset for initial cleanup"); + IDataSet unsortedTruncateDataSet = connection.createDataSet(); + ITableFilter filter = new DatabaseSequenceFilter(connection); + truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); + log.debug("Sorted dataset generated"); + } + + IDataSet orderedDataset = dataSet; + + // if a sorted dataset is available, use table sequence for sorting + if (truncateDataSet == null) + { + ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); + orderedDataset = new FilteredDataSet(filter, dataSet); + } + + try + { + if (truncateDataSet != null) + { + DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); + } + if (dataSet != null) + { + InsertIdentityOperation.INSERT.execute(connection, orderedDataset); + } + } + finally + { + connection.close(); + } + } + + // mimic the Spring OpenSessionInViewFilter + if (mimicSessionFilter()) + { + Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); + if (sfbeans.isEmpty()) + { + fail("No bean of type org.hibernate.SessionFactory found in spring context"); + } + this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); + + SessionFactoryUtils.initDeferredClose(this.sessionFactory); + } + + } + + /** + * {@inheritDoc} + */ + @Override + protected void tearDown() throws Exception + { + if (mimicSessionFilter()) + { + // close open hibernate sessions, mimic the OpenSessionInViewFilter + SessionFactoryUtils.processDeferredClose(this.sessionFactory); + } + + // regenerate db initial state + String datesetFileName = "/initial-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + log.debug("Restoring db state"); + + IDataSet dataSet = new XmlDataSet(testData); + + DataSource dataSource = (DataSource) ctx.getBean("dataSource"); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); + + try + { + DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); + } + finally + { + connection.close(); + } + } + + super.tearDown(); + } + + /** + * Returns the full test name. + * @see junit.framework.TestCase#getName() + */ + @Override + public String getName() + { + return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName(); + } + + /** + * return the current Hibernate SessionFactory + * @return SessionFactory object + */ + protected SessionFactory getSessionFactory() + { + return sessionFactory; + } +} \ 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: <fg...@us...> - 2007-07-12 09:30:26
|
Revision: 360 http://svn.sourceforge.net/openutils/?rev=360&view=rev Author: fgiust Date: 2007-07-12 02:30:27 -0700 (Thu, 12 Jul 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-0.7.1 Added Paths: ----------- tags/openutils-dbmigration-0.7.1/ tags/openutils-dbmigration-0.7.1/pom.xml tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java Removed Paths: ------------- tags/openutils-dbmigration-0.7.1/pom.xml tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java Copied: tags/openutils-dbmigration-0.7.1 (from rev 353, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-0.7.1/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-07-03 22:04:13 UTC (rev 353) +++ tags/openutils-dbmigration-0.7.1/pom.xml 2007-07-12 09:30:27 UTC (rev 360) @@ -1,87 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration framework</name> - <version>0.8-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>poi</groupId> - <artifactId>poi</artifactId> - <version>2.5.1-final-20040804</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-0.7.1/pom.xml (from rev 359, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-0.7.1/pom.xml (rev 0) +++ tags/openutils-dbmigration-0.7.1/pom.xml 2007-07-12 09:30:27 UTC (rev 360) @@ -0,0 +1,93 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration framework</name> + <version>0.7.1</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>poi</groupId> + <artifactId>poi</artifactId> + <version>2.5.1-final-20040804</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.7.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.7.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.7.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/DbSetupManagerImpl.java 2007-07-03 22:04:13 UTC (rev 353) +++ tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java 2007-07-12 09:30:27 UTC (rev 360) @@ -1,203 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.migration; - -import it.openutils.migration.task.setup.DbTask; -import it.openutils.migration.task.update.DbUpdate; - -import java.util.Comparator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import javax.sql.DataSource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataAccessException; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallbackWithoutResult; -import org.springframework.transaction.support.TransactionTemplate; - - -/** - * DB setup manager: handles db setup and upgrade. - * @author fgiust - * @version $Id$ - */ -public class DbSetupManagerImpl implements DbSetupManager -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(DbSetupManagerImpl.class); - - private List<DbTask> setupTasks; - - private List<DbUpdate> updateTasks; - - private DataSource dataSource; - - private DbVersionManager versionManager; - - private TransactionTemplate transactionTemplate; - - private boolean enabled = true; - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } - - /** - * Sets the versionManager. - * @param versionManager the versionManager to set - */ - public void setVersionManager(DbVersionManager versionManager) - { - this.versionManager = versionManager; - } - - /** - * Sets the transactionTemplate. - * @param transactionTemplate the transactionTemplate to set - */ - public void setTransactionTemplate(TransactionTemplate transactionTemplate) - { - this.transactionTemplate = transactionTemplate; - } - - /** - * Setter for <code>dataSource</code>. - * @param dataSource The dataSource to set. - */ - public void setDataSource(DataSource dataSource) - { - this.dataSource = dataSource; - } - - /** - * Sets the tasks. - * @param setupTasks the tasks to set - */ - public void setSetupTasks(List<DbTask> setupTasks) - { - this.setupTasks = setupTasks; - } - - /** - * Sets the updateTasks. - * @param updateTasks the updateTasks to set - */ - public void setUpdateTasks(List<DbUpdate> updateTasks) - { - this.updateTasks = updateTasks; - } - - /** - * @see it.openutils.dbupdate.DbSetupManager#updateDDL() - */ - public void updateDDL() - { - - if (!enabled) - { - log.info("DB migration is disabled, not running tasks."); - return; - } - - transactionTemplate.execute(new TransactionCallbackWithoutResult() - { - - @Override - protected void doInTransactionWithoutResult(TransactionStatus status) - { - if (setupTasks != null) - { - executeSetupTasks(); - } - if (updateTasks != null) - { - executeUpdateTasks(); - } - } - }); - - } - - /** - * - */ - private void executeSetupTasks() - { - log.info("Preparing db, checking {} setup tasks.", setupTasks.size()); - for (DbTask task : setupTasks) - { - log.info(task.getDescription()); - task.execute(dataSource); - } - - } - - /** - * - */ - private void executeUpdateTasks() - { - - int initialVersion = versionManager.getCurrentVersion(); - int currentVersion = initialVersion; - - Set<DbUpdate> sortedMigrations = new TreeSet<DbUpdate>(new Comparator<DbUpdate>() - { - - public int compare(DbUpdate o1, DbUpdate o2) - { - return o1.getVersion() - o2.getVersion(); - } - - }); - sortedMigrations.addAll(updateTasks); - - log.info("Found {} migrations, looking for updates to run...", updateTasks.size()); - for (DbUpdate update : sortedMigrations) - { - if (update.getVersion() > currentVersion) - { - currentVersion = update.getVersion(); - - log.info("Preparing migration to version {}. {}", update.getVersion(), update.getDescription()); - try - { - update.execute(dataSource); - } - catch (DataAccessException e) - { - log.error("\n***********\n\n\nDatabase upgrade from version " - + initialVersion - + " to version " - + currentVersion - + " FAILED!\n\n\n***********\n", e); - } - versionManager.setNewVersion(currentVersion); - } - } - if (currentVersion != initialVersion) - { - log.info("Database upgraded from version {} to version {}", initialVersion, currentVersion); - } - else - { - log.info("No Database upgrade is needed. Current version is {} ", initialVersion); - } - // org.springframework.jdbc.BadSqlGrammarException: - // java.sql.SQLException: ORA-00959: tablespace 'XDM_DATA' inesistente - - } -} Copied: tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java (from rev 357, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/DbSetupManagerImpl.java) =================================================================== --- tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java (rev 0) +++ tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/DbSetupManagerImpl.java 2007-07-12 09:30:27 UTC (rev 360) @@ -0,0 +1,203 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.migration; + +import it.openutils.migration.task.setup.DbTask; +import it.openutils.migration.task.update.DbUpdate; + +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import javax.sql.DataSource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataAccessException; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.TransactionCallbackWithoutResult; +import org.springframework.transaction.support.TransactionTemplate; + + +/** + * DB setup manager: handles db setup and upgrade. + * @author fgiust + * @version $Id$ + */ +public class DbSetupManagerImpl implements DbSetupManager +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(DbSetupManagerImpl.class); + + private List<DbTask> setupTasks; + + private List<DbUpdate> updateTasks; + + private DataSource dataSource; + + private DbVersionManager versionManager; + + private TransactionTemplate transactionTemplate; + + private boolean enabled = true; + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + /** + * Sets the versionManager. + * @param versionManager the versionManager to set + */ + public void setVersionManager(DbVersionManager versionManager) + { + this.versionManager = versionManager; + } + + /** + * Sets the transactionTemplate. + * @param transactionTemplate the transactionTemplate to set + */ + public void setTransactionTemplate(TransactionTemplate transactionTemplate) + { + this.transactionTemplate = transactionTemplate; + } + + /** + * Setter for <code>dataSource</code>. + * @param dataSource The dataSource to set. + */ + public void setDataSource(DataSource dataSource) + { + this.dataSource = dataSource; + } + + /** + * Sets the tasks. + * @param setupTasks the tasks to set + */ + public void setSetupTasks(List<DbTask> setupTasks) + { + this.setupTasks = setupTasks; + } + + /** + * Sets the updateTasks. + * @param updateTasks the updateTasks to set + */ + public void setUpdateTasks(List<DbUpdate> updateTasks) + { + this.updateTasks = updateTasks; + } + + /** + * @see it.openutils.dbupdate.DbSetupManager#updateDDL() + */ + public void updateDDL() + { + + if (!enabled) + { + log.info("DB migration is disabled, not running tasks."); + return; + } + + transactionTemplate.execute(new TransactionCallbackWithoutResult() + { + + @Override + protected void doInTransactionWithoutResult(TransactionStatus status) + { + if (setupTasks != null) + { + executeSetupTasks(); + } + if (updateTasks != null) + { + executeUpdateTasks(); + } + } + }); + + } + + /** + * + */ + private void executeSetupTasks() + { + log.info("Preparing db, checking {} setup tasks.", setupTasks.size()); + for (DbTask task : setupTasks) + { + log.debug(task.getDescription()); + task.execute(dataSource); + } + + } + + /** + * + */ + private void executeUpdateTasks() + { + + int initialVersion = versionManager.getCurrentVersion(); + int currentVersion = initialVersion; + + Set<DbUpdate> sortedMigrations = new TreeSet<DbUpdate>(new Comparator<DbUpdate>() + { + + public int compare(DbUpdate o1, DbUpdate o2) + { + return o1.getVersion() - o2.getVersion(); + } + + }); + sortedMigrations.addAll(updateTasks); + + log.info("Found {} migrations, looking for updates to run...", updateTasks.size()); + for (DbUpdate update : sortedMigrations) + { + if (update.getVersion() > currentVersion) + { + currentVersion = update.getVersion(); + + log.info("Preparing migration to version {}. {}", update.getVersion(), update.getDescription()); + try + { + update.execute(dataSource); + } + catch (DataAccessException e) + { + log.error("\n***********\n\n\nDatabase upgrade from version " + + initialVersion + + " to version " + + currentVersion + + " FAILED!\n\n\n***********\n", e); + } + versionManager.setNewVersion(currentVersion); + } + } + if (currentVersion != initialVersion) + { + log.info("Database upgraded from version {} to version {}", initialVersion, currentVersion); + } + else + { + log.info("No Database upgrade is needed. Current version is {} ", initialVersion); + } + // org.springframework.jdbc.BadSqlGrammarException: + // java.sql.SQLException: ORA-00959: tablespace 'XDM_DATA' inesistente + + } +} Deleted: tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java 2007-07-03 22:04:13 UTC (rev 353) +++ tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java 2007-07-12 09:30:27 UTC (rev 360) @@ -1,143 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.migration.task.setup; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * @author fgiust - * @version $Id$ - */ -public class GenericScriptBasedConditionalTask implements DbTask -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(GenericScriptBasedConditionalTask.class); - - /** - * Script list to execute - */ - protected List<Resource> scripts; - - private String check; - - /** - * Sets the scripts. - * @param scripts the scripts to set - */ - public void setScripts(List<Resource> scripts) - { - this.scripts = scripts; - } - - /** - * Sets the check. - * @param check the check to set - */ - public void setCheck(String check) - { - this.check = check; - } - - /** - * @param script The script resource - * @return The script name - */ - protected String objectNameFromFileName(Resource script) - { - return StringUtils.substringBeforeLast(script.getFilename(), "."); - } - - /** - * {@inheritDoc} - */ - public String getDescription() - { - if (scripts == null) - { - return "Nothing to do, no scripts configured"; - } - - StringBuffer result = new StringBuffer(); - if (!scripts.isEmpty()) - { - result.append("Checking :\n"); - for (Resource script : scripts) - { - result.append(" - " + objectNameFromFileName(script) + "\n"); - } - - } - return result.toString(); - } - - /** - * {@inheritDoc} - */ - public void execute(DataSource dataSource) - { - - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); - - for (Resource script : scripts) - { - int result = jdbcTemplate.queryForInt(check, this.objectNameFromFileName(script)); - if (result == 0) - { - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - String scriptContent; - InputStream is = null; - - try - { - is = script.getInputStream(); - scriptContent = IOUtils.toString(is, "UTF8"); - } - catch (IOException e) - { - log.error( - "Unable to execute db task \"{}\", script \"{}\" can't be read.", - getDescription(), - script); - return; - } - finally - { - IOUtils.closeQuietly(is); - } - - String[] ddls = StringUtils.split(scriptContent, ";"); - - for (String ddl : ddls) - { - if (StringUtils.isNotBlank(ddl)) - { - log.debug("Executing:\n{}", ddl); - jdbcTemplate.update(ddl); - } - } - } - } - - } -} Copied: tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java (from rev 358, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java) =================================================================== --- tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java (rev 0) +++ tags/openutils-dbmigration-0.7.1/src/main/java/it/openutils/migration/task/setup/GenericScriptBasedConditionalTask.java 2007-07-12 09:30:27 UTC (rev 360) @@ -0,0 +1,165 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.migration.task.setup; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * @author fgiust + * @version $Id$ + */ +public class GenericScriptBasedConditionalTask implements DbTask +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(GenericScriptBasedConditionalTask.class); + + /** + * Script list to execute + */ + protected List<Resource> scripts; + + /** + * Check statement. + */ + protected String check; + + /** + * Custom description. + */ + protected String description; + + /** + * Sets the scripts. + * @param scripts the scripts to set + */ + public void setScripts(List<Resource> scripts) + { + this.scripts = scripts; + } + + /** + * Sets the check. + * @param check the check to set + */ + public void setCheck(String check) + { + this.check = check; + } + + /** + * Sets the description. + * @param description the description to set + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * @param script The script resource + * @return The script name + */ + protected String objectNameFromFileName(Resource script) + { + return StringUtils.substringBeforeLast(script.getFilename(), "."); + } + + /** + * {@inheritDoc} + */ + public String getDescription() + { + if (StringUtils.isNotEmpty(description)) + { + return description; + } + + if (scripts == null) + { + return "Nothing to do, no scripts configured"; + } + + StringBuffer result = new StringBuffer(); + if (!scripts.isEmpty()) + { + result.append("Checking :\n"); + for (Resource script : scripts) + { + result.append(" - " + objectNameFromFileName(script) + "\n"); + } + + } + return result.toString(); + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + + for (Resource script : scripts) + { + int result = jdbcTemplate.queryForInt(check, this.objectNameFromFileName(script)); + if (result == 0) + { + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + String scriptContent; + InputStream is = null; + + try + { + is = script.getInputStream(); + scriptContent = IOUtils.toString(is, "UTF8"); + } + catch (IOException e) + { + log.error( + "Unable to execute db task \"{}\", script \"{}\" can't be read.", + getDescription(), + script); + return; + } + finally + { + IOUtils.closeQuietly(is); + } + + String[] ddls = StringUtils.split(scriptContent, ";"); + + for (String ddl : ddls) + { + if (StringUtils.isNotBlank(ddl)) + { + log.debug("Executing:\n{}", ddl); + jdbcTemplate.update(ddl); + } + } + } + } + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-07-30 10:41:47
|
Revision: 373 http://openutils.svn.sourceforge.net/openutils/?rev=373&view=rev Author: fgiust Date: 2007-07-30 03:41:50 -0700 (Mon, 30 Jul 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-deployment-1.0.8 Added Paths: ----------- tags/openutils-deployment-1.0.8/ tags/openutils-deployment-1.0.8/pom.xml Removed Paths: ------------- tags/openutils-deployment-1.0.8/pom.xml Copied: tags/openutils-deployment-1.0.8 (from rev 370, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.8/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2007-07-24 10:17:23 UTC (rev 370) +++ tags/openutils-deployment-1.0.8/pom.xml 2007-07-30 10:41:50 UTC (rev 373) @@ -1,71 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.0.8-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0.1</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>2.0.1</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.8/pom.xml (from rev 372, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.8/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.8/pom.xml 2007-07-30 10:41:50 UTC (rev 373) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.8</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0.1</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>2.0.1</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.8</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.8</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.8</url> + </scm> +</project> \ 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: <mol...@us...> - 2007-09-13 13:53:50
|
Revision: 432 http://openutils.svn.sourceforge.net/openutils/?rev=432&view=rev Author: molaschi Date: 2007-09-13 06:53:54 -0700 (Thu, 13 Sep 2007) Log Message: ----------- [maven-scm] copy for tag 1.1 Added Paths: ----------- tags/1.1/ tags/1.1/pom.xml Removed Paths: ------------- tags/1.1/pom.xml Copied: tags/1.1 (from rev 430, trunk/openutils-testing-junit-dwr) Deleted: tags/1.1/pom.xml =================================================================== --- trunk/openutils-testing-junit-dwr/pom.xml 2007-09-10 09:37:30 UTC (rev 430) +++ tags/1.1/pom.xml 2007-09-13 13:53:54 UTC (rev 432) @@ -1,107 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-junit-dwr</artifactId> - <name>openutils test utils (junit) for dwr</name> - <version>1.1-SNAPSHOT</version> - <description>openutils test utils for dwr</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - </dependency> - <dependency> - <groupId>httpunit</groupId> - <artifactId>httpunit</artifactId> - <version>1.6.2</version> - <exclusions> - <exclusion> - <groupId>xerces</groupId> - <artifactId>xmlParserAPIs</artifactId> - </exclusion> - <exclusion> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - </exclusion> - <exclusion> - <groupId>nekohtml</groupId> - <artifactId>nekohtml</artifactId> - </exclusion> - <exclusion> - <groupId>rhino</groupId> - <artifactId>js</artifactId> - </exclusion> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - </exclusion> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>tomcat</groupId> - <artifactId>jasper-compiler-jdt</artifactId> - <version>5.5.12</version> - </dependency> - <dependency> - <groupId>tomcat</groupId> - <artifactId>naming-resources</artifactId> - <version>5.5.15</version> - </dependency> - <dependency> - <groupId>tomcat</groupId> - <artifactId>jasper-runtime</artifactId> - <version>5.5.12</version> - </dependency> - <dependency> - <groupId>tomcat</groupId> - <artifactId>jasper-compiler</artifactId> - <version>5.5.12</version> - </dependency> - <dependency> - <groupId>tomcat</groupId> - <artifactId>naming-factory</artifactId> - <version>5.5.15</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jstl</artifactId> - <version>1.1.2</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jsp-api</artifactId> - <version>2.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-el</groupId> - <artifactId>commons-el</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>rhino</groupId> - <artifactId>js</artifactId> - <version>1.6R6-candidate2</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/1.1/pom.xml (from rev 431, trunk/openutils-testing-junit-dwr/pom.xml) =================================================================== --- tags/1.1/pom.xml (rev 0) +++ tags/1.1/pom.xml 2007-09-13 13:53:54 UTC (rev 432) @@ -0,0 +1,113 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-junit-dwr</artifactId> + <name>openutils test utils (junit) for dwr</name> + <version>1.1</version> + <description>openutils test utils for dwr</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </dependency> + <dependency> + <groupId>httpunit</groupId> + <artifactId>httpunit</artifactId> + <version>1.6.2</version> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xmlParserAPIs</artifactId> + </exclusion> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>nekohtml</groupId> + <artifactId>nekohtml</artifactId> + </exclusion> + <exclusion> + <groupId>rhino</groupId> + <artifactId>js</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </exclusion> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>jasper-compiler-jdt</artifactId> + <version>5.5.12</version> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>naming-resources</artifactId> + <version>5.5.15</version> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>jasper-runtime</artifactId> + <version>5.5.12</version> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>jasper-compiler</artifactId> + <version>5.5.12</version> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>naming-factory</artifactId> + <version>5.5.15</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + <version>1.1.2</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-el</groupId> + <artifactId>commons-el</artifactId> + <version>1.0</version> + </dependency> + <dependency> + <groupId>rhino</groupId> + <artifactId>js</artifactId> + <version>1.6R6-candidate2</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/1.1</url> + </scm> +</project> \ 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: <fc...@us...> - 2007-10-26 11:06:48
|
Revision: 485 http://openutils.svn.sourceforge.net/openutils/?rev=485&view=rev Author: fcarone Date: 2007-10-26 04:06:52 -0700 (Fri, 26 Oct 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-spring-rmibernate-1.0.2 Added Paths: ----------- tags/openutils-spring-rmibernate-1.0.2/ tags/openutils-spring-rmibernate-1.0.2/pom.xml tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/HibernateLazyLoaderCallbackFilter.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java Removed Paths: ------------- tags/openutils-spring-rmibernate-1.0.2/pom.xml tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java Copied: tags/openutils-spring-rmibernate-1.0.2 (from rev 475, trunk/openutils-spring-rmibernate) Deleted: tags/openutils-spring-rmibernate-1.0.2/pom.xml =================================================================== --- trunk/openutils-spring-rmibernate/pom.xml 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/pom.xml 2007-10-26 11:06:52 UTC (rev 485) @@ -1,122 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-spring-rmibernate</artifactId> - <name>openutils base Spring-Hibernate RMI remote lazy loading support</name> - <version>1.0.1-SNAPSHOT</version> - <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> - <properties> - <spring.version>2.0.6</spring.version> - </properties> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <!-- replaces commons-logging --> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.4.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-spring-rmibernate-1.0.2/pom.xml (from rev 484, trunk/openutils-spring-rmibernate/pom.xml) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/pom.xml (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/pom.xml 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,128 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-spring-rmibernate</artifactId> + <name>openutils base Spring-Hibernate RMI remote lazy loading support</name> + <version>1.0.2</version> + <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> + <properties> + <spring.version>2.0.6</spring.version> + </properties> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <!-- replaces commons-logging --> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.4.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-rmibernate-1.0.2</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,54 +0,0 @@ -package it.openutils.spring.rmibernate.client; - -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.remoting.rmi.RmiProxyFactoryBean; - - -/** - * ProxyFactoryBean for automatic injection of remote lazy loading proxies - * @author mmolaschi - * @version $Id: $ - */ -public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean -{ - - /** - * Store the hibernate lazy service to be used by remote lazy loading - */ - public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>(); - - private HibernateLazyService hibernateLazyService; - - /** - * {@inheritDoc} - */ - @Override - public Object invoke(MethodInvocation invocation) throws Throwable - { - // store the lazy service for this thread - if (hibernateLazyService == null) - { - // if hibernateLazyService is null this means that this service IS hibernateLazyService - hibernateLazyServiceTL.set((HibernateLazyService)this.getObject()); - } - else - { - hibernateLazyServiceTL.set(hibernateLazyService); - } - - // proceed with rmi call - return super.invoke(invocation); - } - - /** - * Sets the hibernateLazyService. - * @param hibernateLazyService the hibernateLazyService to set - */ - public void setHibernateLazyService(HibernateLazyService hibernateLazyService) - { - this.hibernateLazyService = hibernateLazyService; - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,59 @@ +package it.openutils.spring.rmibernate.client; + +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.remoting.rmi.RmiProxyFactoryBean; + + +/** + * ProxyFactoryBean for automatic injection of remote lazy loading proxies + * @author mmolaschi + * @version $Id$ + */ +public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean +{ + + /** + * + */ + private static final long serialVersionUID = 6545259150454309616L; + + /** + * Store the hibernate lazy service to be used by remote lazy loading + */ + public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>(); + + private HibernateLazyService hibernateLazyService; + + /** + * {@inheritDoc} + */ + @Override + public Object invoke(MethodInvocation invocation) throws Throwable + { + // store the lazy service for this thread + if (hibernateLazyService == null) + { + // if hibernateLazyService is null this means that this service IS hibernateLazyService + hibernateLazyServiceTL.set((HibernateLazyService)this.getObject()); + } + else + { + hibernateLazyServiceTL.set(hibernateLazyService); + } + + // proceed with rmi call + return super.invoke(invocation); + } + + /** + * Sets the hibernateLazyService. + * @param hibernateLazyService the hibernateLazyService to set + */ + public void setHibernateLazyService(HibernateLazyService hibernateLazyService) + { + this.hibernateLazyService = hibernateLazyService; + } + +} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,43 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.spring.rmibernate.client.aspects; + +import java.io.Serializable; +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class ClientSerializationInterceptor implements MethodInterceptor, Serializable +{ + + /** + * + */ + private static final long serialVersionUID = -2694751376173790718L; + + private HibernateLazyLoaderAspect hibernateLazyLoaderAspect; + + /** + * @param hlla + */ + public ClientSerializationInterceptor(HibernateLazyLoaderAspect hibernateLazyLoaderAspect) + { + this.hibernateLazyLoaderAspect = hibernateLazyLoaderAspect; + } + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + return hibernateLazyLoaderAspect.loadObject(); + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,75 +0,0 @@ -package it.openutils.spring.rmibernate.client.aspects; - -import it.openutils.spring.rmibernate.client.HibernateRmiProxyFactoryBean; -import it.openutils.spring.rmibernate.client.pagination.Paginator; -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import java.io.Serializable; - -import net.sf.cglib.proxy.LazyLoader; - - -/** - * Aspect that does remote lazy loading on cglib proxy - * @author mmolaschi - * @version $Id: $ - */ -public class HibernateLazyLoaderAspect implements LazyLoader, Serializable -{ - - private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>(); - - private String className; - - private String fieldName; - - private Serializable id; - - /** - * Constructor - * @param className parent class name - * @param fieldName field to be lazy loaded - * @param id id of current entity - */ - public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id) - { - this.className = className; - this.fieldName = fieldName; - this.id = id; - } - - /** - * Set pagination for next calls in current thread - * @param from starting row number - * @param size max number of rows - */ - public static void setPagination(int from, int size) - { - paginator.set(new Paginator(from, size)); - } - - /** - * Disable pagination for next calls in current thread - */ - public static void resetPagination() - { - paginator.set(null); - } - - /** - * {@inheritDoc} - */ - public Object loadObject() throws Exception - { - // Load from remote - HibernateLazyService hls = HibernateRmiProxyFactoryBean.hibernateLazyServiceTL.get(); - - if (paginator.get() != null) - { - return hls.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize()); - } - - return hls.invoke(className, fieldName, id); - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,86 @@ +package it.openutils.spring.rmibernate.client.aspects; + +import it.openutils.spring.rmibernate.client.pagination.Paginator; +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import java.io.Serializable; + +import net.sf.cglib.proxy.LazyLoader; + + +/** + * Aspect that does remote lazy loading on cglib proxy + * @author mmolaschi + * @version $Id$ + */ +public class HibernateLazyLoaderAspect implements LazyLoader, Serializable +{ + + /** + * UID + */ + private static final long serialVersionUID = -365731708075101363L; + + private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>(); + + private String className; + + private String fieldName; + + private Serializable id; + + private Object localReference; + + private HibernateLazyService hibernateLazyService; + + /** + * Constructor + * @param className parent class name + * @param fieldName field to be lazy loaded + * @param id id of current entity + */ + public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id, HibernateLazyService hibernateLazyService) + { + this.className = className; + this.fieldName = fieldName; + this.id = id; + this.hibernateLazyService = hibernateLazyService; + } + + /** + * Set pagination for next calls in current thread + * @param from starting row number + * @param size max number of rows + */ + public static void setPagination(int from, int size) + { + paginator.set(new Paginator(from, size)); + } + + /** + * Disable pagination for next calls in current thread + */ + public static void resetPagination() + { + paginator.set(null); + } + + /** + * {@inheritDoc} + */ + public Object loadObject() throws Exception + { + // @todo handle localreference with paginator + // Load from remote + if (paginator.get() != null) + { + return hibernateLazyService.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize()); + } + if (localReference == null) + { + localReference = hibernateLazyService.invoke(className, fieldName, id); + } + return localReference; + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,68 +0,0 @@ -package it.openutils.spring.rmibernate.client.pagination; - -/** - * @author mmolaschi - * @version $Id: $ - */ -public class Paginator -{ - - private int from; - - private int size; - - /** - * - */ - public Paginator() - { - - } - - /** - * @param from starting row number - * @param size max rows - */ - public Paginator(int from, int size) - { - this.from = from; - this.size = size; - } - - /** - * Get starting row number - * @return starting row number - */ - public int getFrom() - { - return from; - } - - /** - * Set starting row number - * @param from starting row number - */ - public void setFrom(int from) - { - this.from = from; - } - - /** - * Get max number of rows - * @return max number of rows - */ - public int getSize() - { - return size; - } - - /** - * Set max number of rows - * @param size max number of rows - */ - public void setSize(int size) - { - this.size = size; - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,68 @@ +package it.openutils.spring.rmibernate.client.pagination; + +/** + * @author mmolaschi + * @version $Id$ + */ +public class Paginator +{ + + private int from; + + private int size; + + /** + * + */ + public Paginator() + { + + } + + /** + * @param from starting row number + * @param size max rows + */ + public Paginator(int from, int size) + { + this.from = from; + this.size = size; + } + + /** + * Get starting row number + * @return starting row number + */ + public int getFrom() + { + return from; + } + + /** + * Set starting row number + * @param from starting row number + */ + public void setFrom(int from) + { + this.from = from; + } + + /** + * Get max number of rows + * @return max number of rows + */ + public int getSize() + { + return size; + } + + /** + * Set max number of rows + * @param size max number of rows + */ + public void setSize(int size) + { + this.size = size; + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,27 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import java.lang.reflect.Method; - -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - - -/** - * @author mmolaschi - * @version $Id: $ - */ -public class EmptyMethodInterceptor implements MethodInterceptor -{ - - public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor(); - - /** - * {@inheritDoc} - */ - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - // TODO Auto-generated method stub - return proxy.invokeSuper(obj, args); - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,27 @@ +package it.openutils.spring.rmibernate.server.aspects; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * @author mmolaschi + * @version $Id$ + */ +public class EmptyMethodInterceptor implements MethodInterceptor +{ + + public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor(); + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + // TODO Auto-generated method stub + return proxy.invokeSuper(obj, args); + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,58 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.hibernate.SessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * Main server interceptor on rmi calls - * @author mmolaschi - * @version $Id: $ - */ -public class HibernateLazyRmiInterceptor implements MethodInterceptor -{ - - /** - * log - */ - protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class); - - private SessionFactory sessionFactory; - - /** - * Contructor - * @param sessionFactory hibernate session factory - */ - public HibernateLazyRmiInterceptor(SessionFactory sessionFactory) - { - this.sessionFactory = sessionFactory; - } - - /** - * {@inheritDoc} - */ - public Object invoke(MethodInvocation invocation) throws Throwable - { - try - { - Object retVal = invocation.proceed(); - - SerializationInterceptor.clean(); - // Proxy class for serialization work - return SerializationInterceptor.getEnhancedObject(retVal, sessionFactory); - } - catch (Throwable ex) - { - if (logger.isInfoEnabled()) - { - logger.info("Processing of " + " remote call resulted in exception: ", ex); - } - - throw ex; - } - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,61 @@ +package it.openutils.spring.rmibernate.server.aspects; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.hibernate.SessionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Main server interceptor on rmi calls + * @author mmolaschi + * @version $Id$ + */ +public class HibernateLazyRmiInterceptor implements MethodInterceptor +{ + + /** + * log + */ + protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class); + + private SessionFactory sessionFactory; + + /** + * Contructor + * @param sessionFactory hibernate session factory + */ + public HibernateLazyRmiInterceptor(SessionFactory sessionFactory) + { + this.sessionFactory = sessionFactory; + } + + /** + * {@inheritDoc} + */ + public Object invoke(MethodInvocation invocation) throws Throwable + { + logger.debug("Catched invocation: {}", invocation); + try + { + Object retVal = invocation.proceed(); + + SerializationInterceptor.clean(); + // Proxy class for serialization work + Object result = SerializationInterceptor.getEnhancedObject(retVal, sessionFactory); + logger.debug("Returning enhanced object {}", result); + return result; + } + catch (Throwable ex) + { + if (logger.isInfoEnabled()) + { + logger.info("Processing of " + " remote call resulted in exception: ", ex); + } + + throw ex; + } + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,40 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import it.openutils.spring.rmibernate.shared.LazyReference; - -import java.lang.reflect.Method; - -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - - -/** - * Aspect on lazy fields to intercept writeReplace - * @author mmolaschi - * @version $Id: $ - */ -public class LazyReferenceAspect implements MethodInterceptor -{ - - private LazyReference lazyReference; - - public LazyReference getLazyReference() - { - return lazyReference; - } - - public void setLazyReference(LazyReference lazyReference) - { - this.lazyReference = lazyReference; - } - - /** - * {@inheritDoc} - */ - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - // TODO Auto-generated method stub - return lazyReference; - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,39 @@ +package it.openutils.spring.rmibernate.server.aspects; + +import it.openutils.spring.rmibernate.shared.LazyReference; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * Aspect on lazy fields to intercept writeReplace + * @author mmolaschi + * @version $Id$ + */ +public class LazyReferenceAspect implements MethodInterceptor +{ + + private LazyReference lazyReference; + + public LazyReference getLazyReference() + { + return lazyReference; + } + + public void setLazyReference(LazyReference lazyReference) + { + this.lazyReference = lazyReference; + } + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + return lazyReference; + } + +} Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-17 17:06:38 UTC (rev 475) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -1,334 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; -import it.openutils.spring.rmibernate.shared.LazyReference; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.CallbackFilter; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; -import net.sf.cglib.proxy.NoOp; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.collections.SetUtils; -import org.apache.commons.collections.Transformer; -import org.hibernate.EntityMode; -import org.hibernate.SessionFactory; -import org.hibernate.collection.PersistentCollection; -import org.hibernate.collection.PersistentSet; -import org.hibernate.proxy.HibernateProxy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.ReflectionUtils; - - -/** - * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls - * @author mmolaschi - * @version $Id: $ - */ -public class SerializationInterceptor implements MethodInterceptor -{ - - private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); - - private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>()); - - /** - * log - */ - private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class); - - /** - * non proxied object - */ - private Object original; - - /** - * hibernate sessionfactory - */ - private SessionFactory sessionFactory; - - /** - * Constructor - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - */ - private SerializationInterceptor(Object o, SessionFactory sessionFactory) - { - this.original = o; - this.sessionFactory = sessionFactory; - } - - public static void clean() - { - processed.set(null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory) - { - return getEnhancedObject(o, sessionFactory, null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @param lazyRef reference to a lazy field - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef) - { - if (o == null) - { - return null; - } - - if (!(o instanceof HibernateProxy) - && !(o instanceof PersistentSet) - && processed.get() != null - && processed.get().contains(o)) - { - return o; - } - - // check if there is an empty constructor - try - { - o.getClass().getConstructor(new Class[]{}); - } - catch (NoSuchMethodException ex) - { - return o; - } - - // check if object can be subclassed - if (Modifier.isFinal(o.getClass().getModifiers())) - { - return o; - } - - try - { - // get class - Class clazz = o.getClass(); - - // if it is an hibernateproxy get superclass - if (o instanceof HibernateProxy) - { - clazz = o.getClass().getSuperclass(); - if (clazz == null) - { - clazz = o.getClass().getInterfaces()[0]; - } - } - - Callback callback = null; - - // if this is a lazy field user lazyreferenceaspect - if (lazyRef != null) - { - LazyReferenceAspect lra = new LazyReferenceAspect(); - lra.setLazyReference(lazyRef); - callback = lra; - } - else - { - // user default interceptor - callback = new SerializationInterceptor(o, sessionFactory); - } - - synchronized (proxies) - { - if (proxies.containsKey(clazz)) - { - Factory proxy = (Factory)proxies.get(clazz); - return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE }); - } - } - // create proxy to listen on writeReplace method calls - Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter() - { - - public int accept(Method method) - { - if (method.getName().equals("writeReplace")) - { - return 0; - } - else - { - return 1; - } - } - - }, new Callback[]{callback, NoOp.INSTANCE }); - - // store proxy - proxies.put(clazz, ((Factory)proxy).newInstance(new Callback[]{EmptyMethodInterceptor.INSTANCE, NoOp.INSTANCE })); - return proxy; - } - catch (Throwable t) - { - log.warn(t.getMessage(), t); - return o; - } - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - - try - { - if (original == null) - { - return null; - } - - if (processed.get() == null) - { - processed.set(new ArrayList<Object>()); - } - - // add to processed objects - processed.get().add(original); - - if (original.getClass().isPrimitive()) - { - return original; - } - else if (original.getClass().isArray()) - { - // replace array entries with proxied ones - Object[] array = (Object[]) original; - for (int i = 0; i < array.length; i++) - { - array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory); - } - return array; - } - else if (original instanceof Collection) - { - // replace collection entries with proxied ones - Collection collection = (Collection) original; - CollectionUtils.transform(collection, transformer(sessionFactory)); - return collection; - } - else if (original instanceof Map) - { - // replace map entries with proxied ones - Map map = (Map) original; - MapUtils.transformedMap(map, transformer(sessionFactory), transformer(sessionFactory)); - return map; - } - else if (original instanceof Set) - { - // replace set entries with proxied ones - Set set = (Set) original; - SetUtils.transformedSet(set, transformer(sessionFactory)); - return set; - } - else - { - // cycle on bean fields - ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() - { - - /** - * {@inheritDoc} - */ - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException - { - // set field accessible - field.setAccessible(true); - - // get original value - Object oldValue = field.get(original); - - // get new value - Object newValue = null; - - if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) - { - // if this field is a hibernate proxy or a persistent collection store reference - LazyReference lazyRef = new LazyReference(); - lazyRef.setFieldClassName(field.getType().getName()); - lazyRef.setClassName(original.getClass().getName()); - lazyRef.setFieldName(field.getName()); - // load id - lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( - original, - EntityMode.POJO)); - - // get proxy for lazy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); - } - else - { - // get default proxy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); - } - - // if there is a variation store it - if (newValue != oldValue) - { - field.set(original, newValue); - } - } - - }); - } - - return original; - - } - catch (Throwable t) - { - log.error(t.getMessage(), t); - return original; - } - } - - /** - * Get transformer for collection, map or set injection of proxied objects - * @param factory hibernate session factory - * @return transformer - */ - private Transformer transformer(SessionFactory factory) - { - return new Transformer() - { - - public Object transform(Object input) - { - return SerializationInterceptor.getEnhancedObject(input, sessionFactory); - } - - }; - } - -} Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (from rev 483, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485) @@ -0,0 +1,371 @@ +package it.openutils.spring.rmibernate.server.aspects; + +import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; +import it.openutils.spring.rmibernate.shared.LazyReference; +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; +import net.sf.cglib.proxy.NoOp; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections.SetUtils; +import org.apache.commons.collections.Transformer; +import org.hibernate.EntityMode; +import org.hibernate.SessionFactory; +import org.hibernate.collection.PersistentCollection; +import org.hibernate.collection.PersistentSet; +import org.hibernate.proxy.HibernateProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ReflectionUtils; + + +/** + * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls + * @author mmolaschi + * @version $Id$ + */ +public class SerializationInterceptor implements MethodInterceptor +{ + + private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); + + private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>(); + + private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>()); + + /** + * log + */ + private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class); + + /** + * non proxied object + */ + private Object original; + + /** + * hibernate sessionfactory + */ + private SessionFactory sessionFactory; + + /** + * Constructor + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + */ + private SerializationInterceptor(Object o, SessionFactory sessionFactory) + { + this.original = o; + this.sessionFactory = sessionFactory; + } + + /** + * Cleans the processed beans cache + */ + public static void clean() + { + processed.set(null); + } + + /** + * Get proxy object intercepting writeReplace calls + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + * @return proxied object + */ + public static Object getEnhancedObject(Object o, SessionFactory sessionFactory) + { + return getEnhancedObject(o, sessionFactory, null); + } + + /** + * Get proxy object intercepting writeReplace calls + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + * @param lazyRef reference to a lazy field + * @return proxied object + */ + public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef) + { + if (o == null) + { + return null; + } + + if (!(o instanceof HibernateProxy) + && !(o instanceof PersistentSet) + && processed.get() != null + && processed.get().contains(o)) + { + return o; + } + + if (o.getClass().getName().startsWith("java.") && !((o instanceof Collection) || (o instanceof Map))) + { + return o; + } + + // check if there is an empty constructor + try + { + o.getClass().getConstructor(new Class[]{}); + } + catch (NoSuchMethodException ex) + { + return o; + } + + // check if object can be subclassed + if (Modifier.isFinal(o.getClass().getModifiers())) + { + return o; + } + + try + { + // get class + Class clazz = o.getClass(); + + // if it is an hibernateproxy get superclass + if (o instanceof HibernateProxy) + { + clazz = o.getClass().getSuperclass(); + if (clazz == null) + { + clazz = o.getClass().getInterfaces()[0]; + } + } + + Callback callback = null; + + // if this is a lazy field user lazyreferenceaspect + if (lazyRef != null) + { + LazyReferenceAspect lra = new LazyReferenceAspect(); + lra.setLazyReference(lazyRef); + callback = lra; + } + else + { + // user default interceptor + callback = new SerializationInterceptor(o, sessionFactory); + } + + synchronized (proxies) + { + if (proxies.containsKey(clazz)) + { + Factory proxy = (Factory) proxies.get(clazz); + return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE }); + } + } + // create proxy to listen on writeReplace method calls + Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter() + { + + public int accept(Method method) + { + if (method.getName().equals("writeReplace")) + { + return 0; + } + else + { + return 1; + } + } + + }, new Callback[]{callback, NoOp.INSTANCE }); + + // store proxy + proxies.put(clazz, ((Factory) proxy).newInstance(new Callback[]{ + EmptyMethodInterceptor.INSTANCE, + NoOp.INSTANCE })); + return proxy; + } + catch (Throwable t) + { + log.warn(t.getMessage(), t); + return o; + } + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + try + { + if (original == null) + { + return null; + } + + if (original.getClass().getName().startsWith("java.") + && !(original instanceof Collection) + || (original instanceof Map)) + { + return original; + } + + if (processed.get() == null) + { + processed.set(new ArrayList<Object>()); + } + + // add to processed objects + processed.get().add(original); + + if (original.getClass().isPrimitive()) + { + log.debug("Non enhancing primitive type: {}", original.getClass().getName()); + return original; + } + else if (original.getClass().isArray()) + { + // replace array entries with proxied ones + Object[] array = (Object[]) original; + for (int i = 0; i < array.length; i++) + { + array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory); + } + return array; + } + else if (original instanceof Set) + { + // replace set entries with proxied ones + Set set = (Set) original; + SetUtils.transformedSet(set, transformer(sessionFactory)); + return set; + } + else if (original instanceof Collection) + { + // replace collection entries with proxied ones + Collection collection = (Collection) original; + CollectionUtils.transform(collection, transformer(sessionFactory)); + return collection; + } + else if (original instanceof Map) + { + // replace map entries with proxied ones + Map map = (Map) original; + MapUtils.transformedMap(map, transformer(sessionFactory), transformer(sessionFactory)); + return map; + } + else + { + // cycle on bean fields + ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() + { + + /** + * {@inheritDoc} + */ + public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException + { + // set field accessible + field.setAccessible(true); + + // get original value + Object oldValue = field.get(original); + + // get new value + Object newValue = null; + + if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) + { + // if this field is a hibernate proxy or a persistent collection store reference + LazyReference lazyRef = new LazyReference(); + lazyRef.setFieldClassName(field.getType().getName()); + lazyRef.setClassName(original.getClass().getName()); + lazyRef.setFieldName(field.getName()); + // load id + lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( + original, + EntityMode.POJO)); + + // get proxy for lazy + newValue = SerializationInt... [truncated message content] |
From: <fc...@us...> - 2007-10-31 18:00:26
|
Revision: 490 http://openutils.svn.sourceforge.net/openutils/?rev=490&view=rev Author: fcarone Date: 2007-10-31 11:00:30 -0700 (Wed, 31 Oct 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-spring-rmibernate-1.0.3 Added Paths: ----------- tags/openutils-spring-rmibernate-1.0.3/ tags/openutils-spring-rmibernate-1.0.3/pom.xml tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java Removed Paths: ------------- tags/openutils-spring-rmibernate-1.0.3/pom.xml tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java Copied: tags/openutils-spring-rmibernate-1.0.3 (from rev 487, trunk/openutils-spring-rmibernate) Deleted: tags/openutils-spring-rmibernate-1.0.3/pom.xml =================================================================== --- trunk/openutils-spring-rmibernate/pom.xml 2007-10-31 11:05:02 UTC (rev 487) +++ tags/openutils-spring-rmibernate-1.0.3/pom.xml 2007-10-31 18:00:30 UTC (rev 490) @@ -1,122 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-spring-rmibernate</artifactId> - <name>openutils base Spring-Hibernate RMI remote lazy loading support</name> - <version>1.0.3-SNAPSHOT</version> - <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> - <properties> - <spring.version>2.0.6</spring.version> - </properties> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <!-- replaces commons-logging --> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.4.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-spring-rmibernate-1.0.3/pom.xml (from rev 489, trunk/openutils-spring-rmibernate/pom.xml) =================================================================== --- tags/openutils-spring-rmibernate-1.0.3/pom.xml (rev 0) +++ tags/openutils-spring-rmibernate-1.0.3/pom.xml 2007-10-31 18:00:30 UTC (rev 490) @@ -0,0 +1,128 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-spring-rmibernate</artifactId> + <name>openutils base Spring-Hibernate RMI remote lazy loading support</name> + <version>1.0.3</version> + <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> + <properties> + <spring.version>2.0.6</spring.version> + </properties> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <!-- replaces commons-logging --> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.4.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-rmibernate-1.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-31 11:05:02 UTC (rev 487) +++ tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-31 18:00:30 UTC (rev 490) @@ -1,374 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; -import it.openutils.spring.rmibernate.shared.LazyReference; -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.CallbackFilter; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; -import net.sf.cglib.proxy.NoOp; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.collections.SetUtils; -import org.apache.commons.collections.Transformer; -import org.hibernate.EntityMode; -import org.hibernate.SessionFactory; -import org.hibernate.collection.PersistentCollection; -import org.hibernate.collection.PersistentSet; -import org.hibernate.proxy.HibernateProxy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.ReflectionUtils; - - -/** - * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls - * @author mmolaschi - * @version $Id$ - */ -public class SerializationInterceptor implements MethodInterceptor -{ - - private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); - - private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>(); - - private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>()); - - /** - * log - */ - private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class); - - /** - * non proxied object - */ - private Object original; - - /** - * hibernate sessionfactory - */ - private SessionFactory sessionFactory; - - /** - * Constructor - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - */ - private SerializationInterceptor(Object o, SessionFactory sessionFactory) - { - this.original = o; - this.sessionFactory = sessionFactory; - } - - /** - * Cleans the processed beans cache - */ - public static void clean() - { - processed.set(null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory) - { - return getEnhancedObject(o, sessionFactory, null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @param lazyRef reference to a lazy field - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef) - { - if (o == null) - { - return null; - } - - if (!(o instanceof HibernateProxy) - && !(o instanceof PersistentSet) - && processed.get() != null - && processed.get().contains(o)) - { - return o; - } - - if (o.getClass().getName().startsWith("java.") && !((o instanceof Collection) || (o instanceof Map))) - { - return o; - } - - // check if there is an empty constructor - try - { - o.getClass().getConstructor(new Class[]{}); - } - catch (NoSuchMethodException ex) - { - return o; - } - - // check if object can be subclassed - if (Modifier.isFinal(o.getClass().getModifiers())) - { - return o; - } - - try - { - // get class - Class clazz = o.getClass(); - - // if it is an hibernateproxy get superclass - if (o instanceof HibernateProxy) - { - clazz = o.getClass().getSuperclass(); - if (clazz == null) - { - clazz = o.getClass().getInterfaces()[0]; - } - } - - Callback callback = null; - - // if this is a lazy field user lazyreferenceaspect - if (lazyRef != null) - { - LazyReferenceAspect lra = new LazyReferenceAspect(); - lra.setLazyReference(lazyRef); - callback = lra; - } - else - { - // user default interceptor - callback = new SerializationInterceptor(o, sessionFactory); - } - - synchronized (proxies) - { - if (proxies.containsKey(clazz)) - { - Factory proxy = (Factory) proxies.get(clazz); - return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE }); - } - } - // create proxy to listen on writeReplace method calls - Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter() - { - - public int accept(Method method) - { - if (method.getName().equals("writeReplace")) - { - return 0; - } - else - { - return 1; - } - } - - }, new Callback[]{callback, NoOp.INSTANCE }); - - // store proxy - proxies.put(clazz, ((Factory) proxy).newInstance(new Callback[]{ - EmptyMethodInterceptor.INSTANCE, - NoOp.INSTANCE })); - return proxy; - } - catch (Throwable t) - { - log.warn(t.getMessage(), t); - return o; - } - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - try - { - if (original == null) - { - return null; - } - - if (original.getClass().getName().startsWith("java.") - && !(original instanceof Collection) - || (original instanceof Map)) - { - return original; - } - - if (processed.get() == null) - { - processed.set(new ArrayList<Object>()); - } - - // add to processed objects - processed.get().add(original); - - if (original.getClass().isPrimitive()) - { - log.debug("Non enhancing primitive type: {}", original.getClass().getName()); - return original; - } - else if (original.getClass().isArray()) - { - // replace array entries with proxied ones - Object[] array = (Object[]) original; - for (int i = 0; i < array.length; i++) - { - array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory); - } - return array; - } - else if (original instanceof Set) - { - // replace set entries with proxied ones - Set set = (Set) original; - Set transformed = SetUtils.transformedSet(new HashSet(), transformer(sessionFactory)); - transformed.addAll(set); - return transformed; - } - else if (original instanceof Collection) - { - // replace collection entries with proxied ones - Collection collection = (Collection) original; - CollectionUtils.transform(collection, transformer(sessionFactory)); - return collection; - } - else if (original instanceof Map) - { - // replace map entries with proxied ones - Map map = (Map) original; - Map transformed = MapUtils.transformedMap(new HashMap(), transformer(sessionFactory), transformer(sessionFactory)); - transformed.putAll(map); - return transformed; - } - else - { - // cycle on bean fields - ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() - { - - /** - * {@inheritDoc} - */ - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException - { - // set field accessible - field.setAccessible(true); - - // get original value - Object oldValue = field.get(original); - - // get new value - Object newValue = null; - - if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) - { - // if this field is a hibernate proxy or a persistent collection store reference - LazyReference lazyRef = new LazyReference(); - lazyRef.setFieldClassName(field.getType().getName()); - lazyRef.setClassName(original.getClass().getName()); - lazyRef.setFieldName(field.getName()); - // load id - lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( - original, - EntityMode.POJO)); - - // get proxy for lazy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); - } - else - { - // get default proxy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); - } - - // if there is a variation store it - if (newValue != oldValue) - { - field.set(original, newValue); - } - } - - }); - } - - return original; - - } - catch (Throwable t) - { - log.error(t.getMessage(), t); - return original; - } - } - - /** - * Get transformer for collection, map or set injection of proxied objects - * @param factory hibernate session factory - * @return transformer - */ - private Transformer transformer(SessionFactory factory) - { - return new Transformer() - { - - public Object transform(Object input) - { - return SerializationInterceptor.getEnhancedObject(input, sessionFactory); - } - - }; - } - - /** - * Sets the hibernateLazyService. - * @param hibernateLazyService the hibernateLazyService to set - */ - public static void setHibernateLazyService(HibernateLazyService hibernateLazyService) - { - SerializationInterceptor.hibernateLazyService.set(hibernateLazyService); - } - - /** - * Returns the hibernateLazyService. - * @return the hibernateLazyService - */ - public static HibernateLazyService getHibernateLazyService() - { - return hibernateLazyService.get(); - } -} Copied: tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (from rev 488, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-1.0.3/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-31 18:00:30 UTC (rev 490) @@ -0,0 +1,413 @@ +package it.openutils.spring.rmibernate.server.aspects; + +import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; +import it.openutils.spring.rmibernate.shared.LazyReference; +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; +import net.sf.cglib.proxy.NoOp; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.ListUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections.SetUtils; +import org.apache.commons.collections.Transformer; +import org.hibernate.EntityMode; +import org.hibernate.SessionFactory; +import org.hibernate.collection.PersistentCollection; +import org.hibernate.collection.PersistentSet; +import org.hibernate.proxy.HibernateProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ReflectionUtils; +import org.apache.commons.lang.builder.HashCodeBuilder; + + +/** + * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls + * @author mmolaschi + * @version $Id$ + */ +public class SerializationInterceptor implements MethodInterceptor +{ + + private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); + + private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>(); + + private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>()); + + /** + * log + */ + private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class); + + /** + * non proxied object + */ + private Object original; + + /** + * hibernate sessionfactory + */ + private SessionFactory sessionFactory; + + /** + * Constructor + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + */ + private SerializationInterceptor(Object o, SessionFactory sessionFactory) + { + this.original = o; + this.sessionFactory = sessionFactory; + } + + /** + * Cleans the processed beans cache + */ + public static void clean() + { + processed.set(null); + } + + /** + * Get proxy object intercepting writeReplace calls + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + * @return proxied object + */ + public static Object getEnhancedObject(Object o, SessionFactory sessionFactory) + { + return getEnhancedObject(o, sessionFactory, null); + } + + /** + * Get proxy object intercepting writeReplace calls + * @param o object to be proxied + * @param sessionFactory hibernate sessionfactory + * @param lazyRef reference to a lazy field + * @return proxied object + */ + public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef) + { + if (o == null) + { + return null; + } + + if (!(o instanceof HibernateProxy) + && !(o instanceof PersistentSet) + && processed.get() != null + && processed.get().contains(o)) + { + return o; + } + + if (o.getClass().getName().startsWith("java.") && !((o instanceof Collection) || (o instanceof Map))) + { + return o; + } + + // check if there is an empty constructor + try + { + o.getClass().getConstructor(new Class[]{}); + } + catch (NoSuchMethodException ex) + { + return o; + } + + // check if object can be subclassed + if (Modifier.isFinal(o.getClass().getModifiers())) + { + return o; + } + + try + { + // get class + Class clazz = o.getClass(); + + // if it is an hibernateproxy get superclass + if (o instanceof HibernateProxy) + { + clazz = o.getClass().getSuperclass(); + if (clazz == null) + { + clazz = o.getClass().getInterfaces()[0]; + } + } + + Callback callback = null; + + // if this is a lazy field user lazyreferenceaspect + if (lazyRef != null) + { + LazyReferenceAspect lra = new LazyReferenceAspect(); + lra.setLazyReference(lazyRef); + callback = lra; + } + else + { + // user default interceptor + callback = new SerializationInterceptor(o, sessionFactory); + } + + synchronized (proxies) + { + if (proxies.containsKey(clazz)) + { + Factory proxy = (Factory) proxies.get(clazz); + return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE }); + } + } + // create proxy to listen on writeReplace method calls + Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter() + { + + public int accept(Method method) + { + if (method.getName().equals("writeReplace")) + { + return 0; + } + if (method.getName().equals("hashCode")) + { + return 0; + } + else + { + return 1; + } + } + + }, new Callback[]{callback, NoOp.INSTANCE }); + + // store proxy + proxies.put(clazz, ((Factory) proxy).newInstance(new Callback[]{ + EmptyMethodInterceptor.INSTANCE, + NoOp.INSTANCE })); + return proxy; + } + catch (Throwable t) + { + log.warn(t.getMessage(), t); + return o; + } + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + if (method.getName().equals("hashCode")) + { + return hashCode(); + } + try + { + if (original == null) + { + return null; + } + + if (original.getClass().getName().startsWith("java.") + && !(original instanceof Collection) + || (original instanceof Map)) + { + return original; + } + + if (processed.get() == null) + { + processed.set(new ArrayList<Object>()); + } + + // add to processed objects + processed.get().add(original); + + if (original.getClass().isPrimitive()) + { + log.debug("Non enhancing primitive type: {}", original.getClass().getName()); + return original; + } + else if (original.getClass().isArray()) + { + // replace array entries with proxied ones + Object[] array = (Object[]) original; + for (int i = 0; i < array.length; i++) + { + array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory); + } + return array; + } + else if (original instanceof Set) + { + // replace set entries with proxied ones + Set set = (Set) original; + Set transformed = SetUtils.transformedSet(new HashSet(), transformer(sessionFactory)); + transformed.addAll(set); + Set result = new HashSet(); + result.addAll(transformed); + return result; + } + else if (original instanceof List) + { + List list = (List) original; + List transformed = ListUtils.transformedList(new ArrayList(), transformer(sessionFactory)); + transformed.addAll(list); + List result = new ArrayList(); + result.addAll(transformed); + return result; + } + else if (original instanceof Collection) + { + // replace collection entries with proxied ones + Collection collection = (Collection) original; + CollectionUtils.transform(collection, transformer(sessionFactory)); + return collection; + } + else if (original instanceof Map) + { + // replace map entries with proxied ones + Map map = (Map) original; + Map transformed = MapUtils.transformedMap( + new HashMap(), + transformer(sessionFactory), + transformer(sessionFactory)); + transformed.putAll(map); + Map result = new HashMap(); + result.putAll(transformed); + return result; + } + else + { + // cycle on bean fields + ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() + { + + /** + * {@inheritDoc} + */ + public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException + { + // set field accessible + field.setAccessible(true); + + // get original value + Object oldValue = field.get(original); + + // get new value + Object newValue = null; + + if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) + { + // if this field is a hibernate proxy or a persistent collection store reference + LazyReference lazyRef = new LazyReference(); + lazyRef.setFieldClassName(field.getType().getName()); + lazyRef.setClassName(original.getClass().getName()); + lazyRef.setFieldName(field.getName()); + // load id + lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( + original, + EntityMode.POJO)); + + // get proxy for lazy + newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); + } + else + { + // get default proxy + newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); + } + + // if there is a variation store it + if (newValue != oldValue) + { + field.set(original, newValue); + } + } + + }); + } + + return original; + + } + catch (Throwable t) + { + log.error(t.getMessage(), t); + return original; + } + } + + /** + * Get transformer for collection, map or set injection of proxied objects + * @param factory hibernate session factory + * @return transformer + */ + private Transformer transformer(SessionFactory factory) + { + return new Transformer() + { + + public Object transform(Object input) + { + return SerializationInterceptor.getEnhancedObject(input, sessionFactory); + } + + }; + } + + /** + * Sets the hibernateLazyService. + * @param hibernateLazyService the hibernateLazyService to set + */ + public static void setHibernateLazyService(HibernateLazyService hibernateLazyService) + { + SerializationInterceptor.hibernateLazyService.set(hibernateLazyService); + } + + /** + * Returns the hibernateLazyService. + * @return the hibernateLazyService + */ + public static HibernateLazyService getHibernateLazyService() + { + return hibernateLazyService.get(); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + return new HashCodeBuilder(-469032761, 855711273) + .appendSuper(super.hashCode()) + .append(this.original) + .toHashCode(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2007-11-05 17:49:01
|
Revision: 494 http://openutils.svn.sourceforge.net/openutils/?rev=494&view=rev Author: molaschi Date: 2007-11-05 08:39:02 -0800 (Mon, 05 Nov 2007) Log Message: ----------- [maven-scm] copy for tag openutils-spring-1.0.3 Added Paths: ----------- tags/openutils-spring-1.0.3/ tags/openutils-spring-1.0.3/pom.xml Removed Paths: ------------- tags/openutils-spring-1.0.3/pom.xml Copied: tags/openutils-spring-1.0.3 (from rev 492, trunk/openutils-spring) Deleted: tags/openutils-spring-1.0.3/pom.xml =================================================================== --- trunk/openutils-spring/pom.xml 2007-11-05 16:36:06 UTC (rev 492) +++ tags/openutils-spring-1.0.3/pom.xml 2007-11-05 16:39:02 UTC (rev 494) @@ -1,101 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-spring</artifactId> - <name>openutils spring tools</name> - <version>1.0.3-SNAPSHOT</version> - <description /> - <properties> - <spring.version>2.0.6</spring.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>jstl:jar</artifactId> - </exclusion> - <exclusion> - <groupId>taglibs</groupId> - <artifactId>standard</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>struts</groupId> - <artifactId>struts</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - <version>${spring.version}</version> - </dependency> - <dependency> - <groupId>net.sf.json-lib</groupId> - <artifactId>json-lib</artifactId> - <version>1.1</version> - <classifier>jdk15</classifier> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-spring-1.0.3/pom.xml (from rev 493, trunk/openutils-spring/pom.xml) =================================================================== --- tags/openutils-spring-1.0.3/pom.xml (rev 0) +++ tags/openutils-spring-1.0.3/pom.xml 2007-11-05 16:39:02 UTC (rev 494) @@ -0,0 +1,106 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-spring</artifactId> + <name>openutils spring tools</name> + <version>1.0.3</version> + <description /> + <properties> + <spring.version>2.0.6</spring.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>jstl:jar</artifactId> + </exclusion> + <exclusion> + <groupId>taglibs</groupId> + <artifactId>standard</artifactId> + </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>struts</groupId> + <artifactId>struts</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + <version>${spring.version}</version> + </dependency> + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <version>1.1</version> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-1.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-1.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-1.0.3</url> + </scm> +</project> \ 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: <fg...@us...> - 2008-01-27 10:55:10
|
Revision: 555 http://openutils.svn.sourceforge.net/openutils/?rev=555&view=rev Author: fgiust Date: 2008-01-27 02:55:14 -0800 (Sun, 27 Jan 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-bshd5-2.0 Added Paths: ----------- tags/openutils-bshd5-2.0/ tags/openutils-bshd5-2.0/pom.xml tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/FilterMetadata.java tags/openutils-bshd5-2.0/src/site/apt/ tags/openutils-bshd5-2.0/src/site/apt/configuration.apt tags/openutils-bshd5-2.0/src/site/apt/index.apt tags/openutils-bshd5-2.0/src/site/site.xml Removed Paths: ------------- tags/openutils-bshd5-2.0/pom.xml tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/FilterMetadata.java tags/openutils-bshd5-2.0/src/site/site.xml Copied: tags/openutils-bshd5-2.0 (from rev 536, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-2.0/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2008-01-20 17:02:17 UTC (rev 536) +++ tags/openutils-bshd5-2.0/pom.xml 2008-01-27 10:55:14 UTC (rev 555) @@ -1,115 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>6</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>2.0-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-2.0/pom.xml (from rev 554, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-2.0/pom.xml (rev 0) +++ tags/openutils-bshd5-2.0/pom.xml 2008-01-27 10:55:14 UTC (rev 555) @@ -0,0 +1,114 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>2.0</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-2.0</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2008-01-20 17:02:17 UTC (rev 536) +++ tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2008-01-27 10:55:14 UTC (rev 555) @@ -1,607 +0,0 @@ -package it.openutils.dao.hibernate; - -import it.openutils.hibernate.example.EnhancedExample; -import it.openutils.hibernate.example.FilterMetadata; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.aopalliance.aop.AspectException; -import org.hibernate.Criteria; -import org.hibernate.Hibernate; -import org.hibernate.HibernateException; -import org.hibernate.ObjectNotFoundException; -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.aop.framework.AopContext; -import org.springframework.orm.hibernate3.HibernateCallback; -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 - */ -public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport - implements - HibernateDAO<T, K> -{ - - private Class<T> referenceClass; - - private boolean aopenabled; - - public HibernateDAOImpl() - { - super(); - } - - /** - * @param referenceClass - */ - @SuppressWarnings({"unchecked" }) - public HibernateDAOImpl(Class referenceClass) - { - super(); - this.referenceClass = referenceClass; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List<T> find(String query) - { - return getHibernateTemplate().find(query); - } - - /** - * {@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, 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]); - } - - } - 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} - */ - @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(); - } - }); - } - - /** - * {@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} - */ - public void saveOrUpdate(final T obj) - { - getHibernateTemplate().saveOrUpdate(obj); - } - - /** - * {@inheritDoc} - */ - public void update(T obj) - { - getHibernateTemplate().update(obj); - } - - /** - * {@inheritDoc} - */ - public boolean delete(final K key) - { - - return (Boolean) getHibernateTemplate().execute(new HibernateCallback() - { - - 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 evict(T obj) - { - getHibernateTemplate().evict(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} - */ - public T findFilteredFirst(final T filter, List<Criterion> criteria) - { - return getFirstInCollection(findFiltered(filter, null, getDefaultFilterMetadata(), 1, 0, criteria)); - } - - /** - * {@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); - } - - /** - * {@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 int maxResults, final int page) - { - return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); - } - - /** - * {@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(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} - */ - @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, additionalCriteria)); - } - - /** - * 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; - } - - public void setReferenceClass(Class<T> referenceClass) - { - this.referenceClass = referenceClass; - } - - /** - * 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]; - } - - /** - * 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() - { - - 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. 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) - { - - 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(); - } - }); - } - - /** - * 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 (params != null) - { - for (Map.Entry<String, Object> entry : params.entrySet()) - { - setParameterValue(q, entry.getKey(), entry.getValue()); - } - } - return q.list(); - } - }); - } - - /** - * 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 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; - } - - /** - * 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") - private HibernateDAO<T, K> getThis() - { - if (!aopenabled) - { - return this; - } - - 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; - } - catch (IllegalStateException e) - { - logger.warn("Cannot access proxy: " + e.getMessage()); - aopenabled = false; - return this; - } - } - - /** - * @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; - - 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; - } - - 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(); - } - } - -} \ No newline at end of file Copied: tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (from rev 551, trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java) =================================================================== --- tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (rev 0) +++ tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2008-01-27 10:55:14 UTC (rev 555) @@ -0,0 +1,611 @@ +package it.openutils.dao.hibernate; + +import it.openutils.hibernate.example.EnhancedExample; +import it.openutils.hibernate.example.FilterMetadata; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.aopalliance.aop.AspectException; +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.HibernateException; +import org.hibernate.ObjectNotFoundException; +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.aop.framework.AopContext; +import org.springframework.orm.hibernate3.HibernateCallback; +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 + */ +public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport + implements + HibernateDAO<T, K> +{ + + private Class<T> referenceClass; + + private boolean aopenabled; + + /** + * Instantiates a new DAO instance + */ + public HibernateDAOImpl() + { + super(); + } + + /** + * Sets the class of the persistent bean managed by this DAO + * @param referenceClass the class for the bean managed by this DAO + */ + @SuppressWarnings({"unchecked" }) + public HibernateDAOImpl(Class referenceClass) + { + super(); + this.referenceClass = referenceClass; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> find(String query) + { + return getHibernateTemplate().find(query); + } + + /** + * {@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, 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]); + } + + } + 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} + */ + @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(); + } + }); + } + + /** + * {@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} + */ + public void saveOrUpdate(final T obj) + { + getHibernateTemplate().saveOrUpdate(obj); + } + + /** + * {@inheritDoc} + */ + public void update(T obj) + { + getHibernateTemplate().update(obj); + } + + /** + * {@inheritDoc} + */ + public boolean delete(final K key) + { + + return (Boolean) getHibernateTemplate().execute(new HibernateCallback() + { + + 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 evict(T obj) + { + getHibernateTemplate().evict(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} + */ + public T findFilteredFirst(final T filter, List<Criterion> criteria) + { + return getFirstInCollection(findFiltered(filter, null, getDefaultFilterMetadata(), 1, 0, criteria)); + } + + /** + * {@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); + } + + /** + * {@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 int maxResults, final int page) + { + return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); + } + + /** + * {@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(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} + */ + @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, additionalCriteria)); + } + + /** + * 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; + } + + public void setReferenceClass(Class<T> referenceClass) + { + this.referenceClass = referenceClass; + } + + /** + * 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]; + } + + /** + * 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() + { + + 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. 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) + { + + 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(); + } + }); + } + + /** + * 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 (params != null) + { + for (Map.Entry<String, Object> entry : params.entrySet()) + { + setParameterValue(q, entry.getKey(), entry.getValue()); + } + } + return q.list(); + } + }); + } + + /** + * 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 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; + } + + /** + * 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") + private HibernateDAO<T, K> getThis() + { + if (!aopenabled) + { + return this; + } + + 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; + } + catch (IllegalStateException e) + { + logger.warn("Cannot access proxy: " + e.getMessage()); + aopenabled = false; + return this; + } + } + + /** + * @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; + + 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; + } + + 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(); + } + } + +} \ No newline at end of file Deleted: tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2008-01-20 17:02:17 UTC (rev 536) +++ tags/openutils-bshd5-2.0/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2008-01-27 10:55:14 UTC (rev 555) @@ -1,75 +0,0 @@ -package it.openutils.dao.hibernate; - -import java.util.Date; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - * @deprecated use FilterMetadata - */ -@Deprecated -public class MutableDateRange extends Date -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * range start. - */ - private Date from; - - /** - * range end. - */ - private Date to; - - /** - * Getter for <code>from</code>. - * @return Returns the from. - */ - public Date getFrom() - { - return this.from; - } - - /** - * Setter for <code>from</code>. - * @param from The from to set. - */ - public void setFrom(Date from) - { - this.from = from; - } - - /** - * Getter for <code>to</code>. - * @return Returns the to. - */ - public Date getTo() - { - return this.to; - } - - /** - * Setter for <code>to</code>. - * @param to The to to set. - */ - public void setTo(Date to) - { - this.to = to; - } - - /** - * Returns <code>true</code> if at least one date is set. - * @return <code>true</code> if at least one date is set - */ - public boolean isSet() - { - return this.to != null || this.from != null; - } - -} Deleted: tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-01-20 17:02:17 UTC (rev 536) +++ tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-01-27 10:55:14 UTC (rev 555) @@ -1,332 +0,0 @@ -package it.openutils.hibernate.example; - -import it.openutils.dao.hibernate.MutableDateRange; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - */ -public class EnhancedExample -{ - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(null, crit, filter); - } - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - - if (isSimpleType(value) || value.getClass().isEnum()) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - fmd.createFilter(crit, simplePropertyName, value); - - } - else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata - // for this scope - { - Date from = ((MutableDateRange) value).getFrom(); - Date to = ((MutableDateRange) value).getTo(); - if (from != null && to != null) - { - log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to }); - crit.add(Restrictions.between(propertyName, from, to)); - } - else if (from != null) - { - - log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); - - crit.add(Restrictions.ge(propertyName, from)); - } - else if (to != null) - { - log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); - crit.add(Restrictions.le(propertyName, to)); - } - } - else - { - if (containsSomething(value)) - { - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - - for (Object element : ((Collection< ? extends Object>) value)) - { - - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, element); - } - } - else if ((value instanceof Map) && !((Map) value).isEmpty()) - { - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd != null) - { - fmd.createFilter(crit, simplePropertyName, value); - } - else - { - log.warn( - "Maps are not handled without a FilterMetadata. Property is {} and value is {}.", - propertyName, - value); - } - } - else - { - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - else if (bean instanceof MutableDateRange) - { - return ((MutableDateRange) bean).isSet(); - } - - if (bean instanceof Collection) - { - - Collection coll = ((Collection) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - Map coll = ((Map) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - for (Object element : ((Collection) filter)) - { - fillCriteria(parentPropertyName, crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName - + "." - + propertyName; - addCondition(crit, composedPropertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || Calendar.class.isAssignableFrom(objClass); - } - -} Copied: tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 551, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-2.0/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-01-27 10:55:14 UTC (rev 555) @@ -0,0 +1,305 @@ +package it.openutils.hibernate.example; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public final class EnhancedExample +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @param metadata Map of property names - ... [truncated message content] |
From: <fg...@us...> - 2008-02-11 20:42:21
|
Revision: 609 http://openutils.svn.sourceforge.net/openutils/?rev=609&view=rev Author: fgiust Date: 2008-02-11 12:42:07 -0800 (Mon, 11 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-deployment-2.0.1 Added Paths: ----------- tags/openutils-deployment-2.0.1/ tags/openutils-deployment-2.0.1/pom.xml tags/openutils-deployment-2.0.1/src/site/changes/ Removed Paths: ------------- tags/openutils-deployment-2.0.1/pom.xml Copied: tags/openutils-deployment-2.0.1 (from rev 606, trunk/openutils-deployment) Deleted: tags/openutils-deployment-2.0.1/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2008-02-11 20:36:23 UTC (rev 606) +++ tags/openutils-deployment-2.0.1/pom.xml 2008-02-11 20:42:07 UTC (rev 609) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>2.0.1-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-deployment-2.0.1/pom.xml (from rev 608, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-2.0.1/pom.xml (rev 0) +++ tags/openutils-deployment-2.0.1/pom.xml 2008-02-11 20:42:07 UTC (rev 609) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>2.0.1</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-2.0.1</url> + </scm> +</project> \ No newline at end of file Copied: tags/openutils-deployment-2.0.1/src/site/changes (from rev 607, trunk/openutils-deployment/src/site/changes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-03-03 14:36:04
|
Revision: 716 http://openutils.svn.sourceforge.net/openutils/?rev=716&view=rev Author: fcarone Date: 2008-03-03 06:35:57 -0800 (Mon, 03 Mar 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-spring-rmibernate-2.0 Added Paths: ----------- tags/openutils-spring-rmibernate-2.0/ tags/openutils-spring-rmibernate-2.0/pom.xml tags/openutils-spring-rmibernate-2.0/src/ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/HibernateLazyLoaderCallbackFilter.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java Removed Paths: ------------- tags/openutils-spring-rmibernate-2.0/pom.xml tags/openutils-spring-rmibernate-2.0/src/ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/HibernateLazyLoaderCallbackFilter.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java Copied: tags/openutils-spring-rmibernate-2.0 (from rev 615, trunk/openutils-spring-rmibernate) Deleted: tags/openutils-spring-rmibernate-2.0/pom.xml =================================================================== --- trunk/openutils-spring-rmibernate/pom.xml 2008-02-12 16:57:54 UTC (rev 615) +++ tags/openutils-spring-rmibernate-2.0/pom.xml 2008-03-03 14:35:57 UTC (rev 716) @@ -1,112 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-spring-rmibernate</artifactId> - <name>hibernate remote lazy loading</name> - <version>2.0-SNAPSHOT</version> - <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <!-- replaces commons-logging --> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.4.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - </exclusion> - <exclusion> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-spring-rmibernate-2.0/pom.xml (from rev 715, trunk/openutils-spring-rmibernate/pom.xml) =================================================================== --- tags/openutils-spring-rmibernate-2.0/pom.xml (rev 0) +++ tags/openutils-spring-rmibernate-2.0/pom.xml 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,117 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-spring-rmibernate</artifactId> + <name>hibernate remote lazy loading</name> + <version>2.0</version> + <description>openutils base Spring-Hibernate RMI remote lazy loading support</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <!-- replaces commons-logging --> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.4.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + </exclusion> + <exclusion> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-rmibernate-2.0</url> + </scm> +</project> \ No newline at end of file Copied: tags/openutils-spring-rmibernate-2.0/src (from rev 614, trunk/openutils-spring-rmibernate/src) Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,59 +0,0 @@ -package it.openutils.spring.rmibernate.client; - -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.remoting.rmi.RmiProxyFactoryBean; - - -/** - * ProxyFactoryBean for automatic injection of remote lazy loading proxies - * @author mmolaschi - * @version $Id$ - */ -public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean -{ - - /** - * - */ - private static final long serialVersionUID = 6545259150454309616L; - - /** - * Store the hibernate lazy service to be used by remote lazy loading - */ - public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>(); - - private HibernateLazyService hibernateLazyService; - - /** - * {@inheritDoc} - */ - @Override - public Object invoke(MethodInvocation invocation) throws Throwable - { - // store the lazy service for this thread - if (hibernateLazyService == null) - { - // if hibernateLazyService is null this means that this service IS hibernateLazyService - hibernateLazyServiceTL.set((HibernateLazyService)this.getObject()); - } - else - { - hibernateLazyServiceTL.set(hibernateLazyService); - } - - // proceed with rmi call - return super.invoke(invocation); - } - - /** - * Sets the hibernateLazyService. - * @param hibernateLazyService the hibernateLazyService to set - */ - public void setHibernateLazyService(HibernateLazyService hibernateLazyService) - { - this.hibernateLazyService = hibernateLazyService; - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,72 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.client; + +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.remoting.rmi.RmiProxyFactoryBean; + + +/** + * ProxyFactoryBean for automatic injection of remote lazy loading proxies + * @author mmolaschi + * @version $Id$ + */ +public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean +{ + + /** + * Store the hibernate lazy service to be used by remote lazy loading + */ + public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>(); + + private static final long serialVersionUID = 6545259150454309616L; + + private HibernateLazyService hibernateLazyService; + + /** + * {@inheritDoc} + */ + @Override + public Object invoke(MethodInvocation invocation) throws Throwable + { + // store the lazy service for this thread + if (hibernateLazyService == null) + { + // if hibernateLazyService is null this means that this service IS hibernateLazyService + hibernateLazyServiceTL.set((HibernateLazyService) this.getObject()); + } + else + { + hibernateLazyServiceTL.set(hibernateLazyService); + } + + // proceed with rmi call + return super.invoke(invocation); + } + + /** + * Sets the hibernateLazyService. + * @param hibernateLazyService the hibernateLazyService to set + */ + public void setHibernateLazyService(HibernateLazyService hibernateLazyService) + { + this.hibernateLazyService = hibernateLazyService; + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,43 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.spring.rmibernate.client.aspects; - -import java.io.Serializable; -import java.lang.reflect.Method; - -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - - -/** - * @author fcarone - * @version $Id: $ - */ -public class ClientSerializationInterceptor implements MethodInterceptor, Serializable -{ - - /** - * - */ - private static final long serialVersionUID = -2694751376173790718L; - - private HibernateLazyLoaderAspect hibernateLazyLoaderAspect; - - /** - * @param hlla - */ - public ClientSerializationInterceptor(HibernateLazyLoaderAspect hibernateLazyLoaderAspect) - { - this.hibernateLazyLoaderAspect = hibernateLazyLoaderAspect; - } - - /** - * {@inheritDoc} - */ - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - return hibernateLazyLoaderAspect.loadObject(); - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,56 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.client.aspects; + +import java.io.Serializable; +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class ClientSerializationInterceptor implements MethodInterceptor, Serializable +{ + + /** + * + */ + private static final long serialVersionUID = -2694751376173790718L; + + private HibernateLazyLoaderAspect hibernateLazyLoaderAspect; + + /** + * @param hlla + */ + public ClientSerializationInterceptor(HibernateLazyLoaderAspect hibernateLazyLoaderAspect) + { + this.hibernateLazyLoaderAspect = hibernateLazyLoaderAspect; + } + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + return hibernateLazyLoaderAspect.loadObject(); + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,86 +0,0 @@ -package it.openutils.spring.rmibernate.client.aspects; - -import it.openutils.spring.rmibernate.client.pagination.Paginator; -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import java.io.Serializable; - -import net.sf.cglib.proxy.LazyLoader; - - -/** - * Aspect that does remote lazy loading on cglib proxy - * @author mmolaschi - * @version $Id$ - */ -public class HibernateLazyLoaderAspect implements LazyLoader, Serializable -{ - - /** - * UID - */ - private static final long serialVersionUID = -365731708075101363L; - - private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>(); - - private String className; - - private String fieldName; - - private Serializable id; - - private Object localReference; - - private HibernateLazyService hibernateLazyService; - - /** - * Constructor - * @param className parent class name - * @param fieldName field to be lazy loaded - * @param id id of current entity - */ - public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id, HibernateLazyService hibernateLazyService) - { - this.className = className; - this.fieldName = fieldName; - this.id = id; - this.hibernateLazyService = hibernateLazyService; - } - - /** - * Set pagination for next calls in current thread - * @param from starting row number - * @param size max number of rows - */ - public static void setPagination(int from, int size) - { - paginator.set(new Paginator(from, size)); - } - - /** - * Disable pagination for next calls in current thread - */ - public static void resetPagination() - { - paginator.set(null); - } - - /** - * {@inheritDoc} - */ - public Object loadObject() throws Exception - { - // @todo handle localreference with paginator - // Load from remote - if (paginator.get() != null) - { - return hibernateLazyService.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize()); - } - if (localReference == null) - { - localReference = hibernateLazyService.invoke(className, fieldName, id); - } - return localReference; - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,102 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.client.aspects; + +import it.openutils.spring.rmibernate.client.pagination.Paginator; +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import java.io.Serializable; + +import net.sf.cglib.proxy.LazyLoader; + + +/** + * Aspect that does remote lazy loading on cglib proxy + * @author mmolaschi + * @version $Id$ + */ +public class HibernateLazyLoaderAspect implements LazyLoader, Serializable +{ + + /** + * UID + */ + private static final long serialVersionUID = -365731708075101363L; + + private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>(); + + private String className; + + private String fieldName; + + private Serializable id; + + private Object localReference; + + private HibernateLazyService hibernateLazyService; + + /** + * Constructor + * @param className parent class name + * @param fieldName field to be lazy loaded + * @param id id of current entity + */ + public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id, HibernateLazyService hibernateLazyService) + { + this.className = className; + this.fieldName = fieldName; + this.id = id; + this.hibernateLazyService = hibernateLazyService; + } + + /** + * Set pagination for next calls in current thread + * @param from starting row number + * @param size max number of rows + */ + public static void setPagination(int from, int size) + { + paginator.set(new Paginator(from, size)); + } + + /** + * Disable pagination for next calls in current thread + */ + public static void resetPagination() + { + paginator.set(null); + } + + /** + * {@inheritDoc} + */ + public Object loadObject() throws Exception + { + // @todo handle localreference with paginator + // Load from remote + if (paginator.get() != null) + { + return hibernateLazyService.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize()); + } + if (localReference == null) + { + localReference = hibernateLazyService.invoke(className, fieldName, id); + } + return localReference; + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,68 +0,0 @@ -package it.openutils.spring.rmibernate.client.pagination; - -/** - * @author mmolaschi - * @version $Id$ - */ -public class Paginator -{ - - private int from; - - private int size; - - /** - * - */ - public Paginator() - { - - } - - /** - * @param from starting row number - * @param size max rows - */ - public Paginator(int from, int size) - { - this.from = from; - this.size = size; - } - - /** - * Get starting row number - * @return starting row number - */ - public int getFrom() - { - return from; - } - - /** - * Set starting row number - * @param from starting row number - */ - public void setFrom(int from) - { - this.from = from; - } - - /** - * Get max number of rows - * @return max number of rows - */ - public int getSize() - { - return size; - } - - /** - * Set max number of rows - * @param size max number of rows - */ - public void setSize(int size) - { - this.size = size; - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,84 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.client.pagination; + +/** + * @author mmolaschi + * @version $Id$ + */ +public class Paginator +{ + + private int from; + + private int size; + + /** + * + */ + public Paginator() + { + + } + + /** + * @param from starting row number + * @param size max rows + */ + public Paginator(int from, int size) + { + this.from = from; + this.size = size; + } + + /** + * Get starting row number + * @return starting row number + */ + public int getFrom() + { + return from; + } + + /** + * Set starting row number + * @param from starting row number + */ + public void setFrom(int from) + { + this.from = from; + } + + /** + * Get max number of rows + * @return max number of rows + */ + public int getSize() + { + return size; + } + + /** + * Set max number of rows + * @param size max number of rows + */ + public void setSize(int size) + { + this.size = size; + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,27 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import java.lang.reflect.Method; - -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - - -/** - * @author mmolaschi - * @version $Id$ - */ -public class EmptyMethodInterceptor implements MethodInterceptor -{ - - public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor(); - - /** - * {@inheritDoc} - */ - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - // TODO Auto-generated method stub - return proxy.invokeSuper(obj, args); - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,42 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.server.aspects; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * @author mmolaschi + * @version $Id$ + */ +public class EmptyMethodInterceptor implements MethodInterceptor +{ + + public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor(); + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + return proxy.invokeSuper(obj, args); + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,61 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.hibernate.SessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * Main server interceptor on rmi calls - * @author mmolaschi - * @version $Id$ - */ -public class HibernateLazyRmiInterceptor implements MethodInterceptor -{ - - /** - * log - */ - protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class); - - private SessionFactory sessionFactory; - - /** - * Contructor - * @param sessionFactory hibernate session factory - */ - public HibernateLazyRmiInterceptor(SessionFactory sessionFactory) - { - this.sessionFactory = sessionFactory; - } - - /** - * {@inheritDoc} - */ - public Object invoke(MethodInvocation invocation) throws Throwable - { - logger.debug("Catched invocation: {}", invocation); - try - { - Object retVal = invocation.proceed(); - - SerializationInterceptor.clean(); - // Proxy class for serialization work - Object result = SerializationInterceptor.getEnhancedObject(retVal, sessionFactory); - logger.debug("Returning enhanced object {}", result); - return result; - } - catch (Throwable ex) - { - if (logger.isInfoEnabled()) - { - logger.info("Processing of " + " remote call resulted in exception: ", ex); - } - - throw ex; - } - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,75 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.server.aspects; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.hibernate.SessionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Main server interceptor on rmi calls + * @author mmolaschi + * @version $Id$ + */ +public class HibernateLazyRmiInterceptor implements MethodInterceptor +{ + + /** + * log + */ + protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class); + + private SessionFactory sessionFactory; + + /** + * Contructor + * @param sessionFactory hibernate session factory + */ + public HibernateLazyRmiInterceptor(SessionFactory sessionFactory) + { + this.sessionFactory = sessionFactory; + } + + /** + * {@inheritDoc} + */ + public Object invoke(MethodInvocation invocation) throws Throwable + { + logger.debug("Catched invocation: {}", invocation); + try + { + Object retVal = invocation.proceed(); + + SerializationInterceptor.clean(); + // Proxy class for serialization work + return SerializationInterceptor.getEnhancedObject(retVal, sessionFactory); + } + catch (Throwable ex) + { + if (logger.isInfoEnabled()) + { + logger.info("Processing of " + " remote call resulted in exception: ", ex); + } + + throw ex; + } + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,39 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import it.openutils.spring.rmibernate.shared.LazyReference; - -import java.lang.reflect.Method; - -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - - -/** - * Aspect on lazy fields to intercept writeReplace - * @author mmolaschi - * @version $Id$ - */ -public class LazyReferenceAspect implements MethodInterceptor -{ - - private LazyReference lazyReference; - - public LazyReference getLazyReference() - { - return lazyReference; - } - - public void setLazyReference(LazyReference lazyReference) - { - this.lazyReference = lazyReference; - } - - /** - * {@inheritDoc} - */ - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - return lazyReference; - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (from rev 714, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,55 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.server.aspects; + +import it.openutils.spring.rmibernate.shared.LazyReference; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + + +/** + * Aspect on lazy fields to intercept writeReplace + * @author mmolaschi + * @version $Id$ + */ +public class LazyReferenceAspect implements MethodInterceptor +{ + + private LazyReference lazyReference; + + public LazyReference getLazyReference() + { + return lazyReference; + } + + public void setLazyReference(LazyReference lazyReference) + { + this.lazyReference = lazyReference; + } + + /** + * {@inheritDoc} + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable + { + return lazyReference; + } + +} Deleted: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -1,413 +0,0 @@ -package it.openutils.spring.rmibernate.server.aspects; - -import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; -import it.openutils.spring.rmibernate.shared.LazyReference; -import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.CallbackFilter; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; -import net.sf.cglib.proxy.NoOp; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.ListUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.collections.SetUtils; -import org.apache.commons.collections.Transformer; -import org.hibernate.EntityMode; -import org.hibernate.SessionFactory; -import org.hibernate.collection.PersistentCollection; -import org.hibernate.collection.PersistentSet; -import org.hibernate.proxy.HibernateProxy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.ReflectionUtils; -import org.apache.commons.lang.builder.HashCodeBuilder; - - -/** - * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls - * @author mmolaschi - * @version $Id$ - */ -public class SerializationInterceptor implements MethodInterceptor -{ - - private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); - - private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>(); - - private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>()); - - /** - * log - */ - private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class); - - /** - * non proxied object - */ - private Object original; - - /** - * hibernate sessionfactory - */ - private SessionFactory sessionFactory; - - /** - * Constructor - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - */ - private SerializationInterceptor(Object o, SessionFactory sessionFactory) - { - this.original = o; - this.sessionFactory = sessionFactory; - } - - /** - * Cleans the processed beans cache - */ - public static void clean() - { - processed.set(null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory) - { - return getEnhancedObject(o, sessionFactory, null); - } - - /** - * Get proxy object intercepting writeReplace calls - * @param o object to be proxied - * @param sessionFactory hibernate sessionfactory - * @param lazyRef reference to a lazy field - * @return proxied object - */ - public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef) - { - if (o == null) - { - return null; - } - - if (!(o instanceof HibernateProxy) - && !(o instanceof PersistentSet) - && processed.get() != null - && processed.get().contains(o)) - { - return o; - } - - if (o.getClass().getName().startsWith("java.") && !((o instanceof Collection) || (o instanceof Map))) - { - return o; - } - - // check if there is an empty constructor - try - { - o.getClass().getConstructor(new Class[]{}); - } - catch (NoSuchMethodException ex) - { - return o; - } - - // check if object can be subclassed - if (Modifier.isFinal(o.getClass().getModifiers())) - { - return o; - } - - try - { - // get class - Class clazz = o.getClass(); - - // if it is an hibernateproxy get superclass - if (o instanceof HibernateProxy) - { - clazz = o.getClass().getSuperclass(); - if (clazz == null) - { - clazz = o.getClass().getInterfaces()[0]; - } - } - - Callback callback = null; - - // if this is a lazy field user lazyreferenceaspect - if (lazyRef != null) - { - LazyReferenceAspect lra = new LazyReferenceAspect(); - lra.setLazyReference(lazyRef); - callback = lra; - } - else - { - // user default interceptor - callback = new SerializationInterceptor(o, sessionFactory); - } - - synchronized (proxies) - { - if (proxies.containsKey(clazz)) - { - Factory proxy = (Factory) proxies.get(clazz); - return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE }); - } - } - // create proxy to listen on writeReplace method calls - Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter() - { - - public int accept(Method method) - { - if (method.getName().equals("writeReplace")) - { - return 0; - } - if (method.getName().equals("hashCode")) - { - return 0; - } - else - { - return 1; - } - } - - }, new Callback[]{callback, NoOp.INSTANCE }); - - // store proxy - proxies.put(clazz, ((Factory) proxy).newInstance(new Callback[]{ - EmptyMethodInterceptor.INSTANCE, - NoOp.INSTANCE })); - return proxy; - } - catch (Throwable t) - { - log.warn(t.getMessage(), t); - return o; - } - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable - { - if (method.getName().equals("hashCode")) - { - return hashCode(); - } - try - { - if (original == null) - { - return null; - } - - if (original.getClass().getName().startsWith("java.") - && !(original instanceof Collection) - || (original instanceof Map)) - { - return original; - } - - if (processed.get() == null) - { - processed.set(new ArrayList<Object>()); - } - - // add to processed objects - processed.get().add(original); - - if (original.getClass().isPrimitive()) - { - log.debug("Non enhancing primitive type: {}", original.getClass().getName()); - return original; - } - else if (original.getClass().isArray()) - { - // replace array entries with proxied ones - Object[] array = (Object[]) original; - for (int i = 0; i < array.length; i++) - { - array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory); - } - return array; - } - else if (original instanceof Set) - { - // replace set entries with proxied ones - Set set = (Set) original; - Set transformed = SetUtils.transformedSet(new HashSet(), transformer(sessionFactory)); - transformed.addAll(set); - Set result = new HashSet(); - result.addAll(transformed); - return result; - } - else if (original instanceof List) - { - List list = (List) original; - List transformed = ListUtils.transformedList(new ArrayList(), transformer(sessionFactory)); - transformed.addAll(list); - List result = new ArrayList(); - result.addAll(transformed); - return result; - } - else if (original instanceof Collection) - { - // replace collection entries with proxied ones - Collection collection = (Collection) original; - CollectionUtils.transform(collection, transformer(sessionFactory)); - return collection; - } - else if (original instanceof Map) - { - // replace map entries with proxied ones - Map map = (Map) original; - Map transformed = MapUtils.transformedMap( - new HashMap(), - transformer(sessionFactory), - transformer(sessionFactory)); - transformed.putAll(map); - Map result = new HashMap(); - result.putAll(transformed); - return result; - } - else - { - // cycle on bean fields - ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() - { - - /** - * {@inheritDoc} - */ - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException - { - // set field accessible - field.setAccessible(true); - - // get original value - Object oldValue = field.get(original); - - // get new value - Object newValue = null; - - if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) - { - // if this field is a hibernate proxy or a persistent collection store reference - LazyReference lazyRef = new LazyReference(); - lazyRef.setFieldClassName(field.getType().getName()); - lazyRef.setClassName(original.getClass().getName()); - lazyRef.setFieldName(field.getName()); - // load id - lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( - original, - EntityMode.POJO)); - - // get proxy for lazy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); - } - else - { - // get default proxy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); - } - - // if there is a variation store it - if (newValue != oldValue) - { - field.set(original, newValue); - } - } - - }); - } - - return original; - - } - catch (Throwable t) - { - log.error(t.getMessage(), t); - return original; - } - } - - /** - * Get transformer for collection, map or set injection of proxied objects - * @param factory hibernate session factory - * @return transformer - */ - private Transformer transformer(SessionFactory factory) - { - return new Transformer() - { - - public Object transform(Object input) - { - return SerializationInterceptor.getEnhancedObject(input, sessionFactory); - } - - }; - } - - /** - * Sets the hibernateLazyService. - * @param hibernateLazyService the hibernateLazyService to set - */ - public static void setHibernateLazyService(HibernateLazyService hibernateLazyService) - { - SerializationInterceptor.hibernateLazyService.set(hibernateLazyService); - } - - /** - * Returns the hibernateLazyService. - * @return the hibernateLazyService - */ - public static HibernateLazyService getHibernateLazyService() - { - return hibernateLazyService.get(); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - return new HashCodeBuilder(-469032761, 855711273) - .appendSuper(super.hashCode()) - .append(this.original) - .toHashCode(); - } - -} Copied: tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (from rev 713, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java) =================================================================== --- tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (rev 0) +++ tags/openutils-spring-rmibernate-2.0/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2008-03-03 14:35:57 UTC (rev 716) @@ -0,0 +1,435 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.spring.rmibernate.server.aspects; + +import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer; +import it.openutils.spring.rmibernate.shared.LazyReference; +import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; +import net.sf.cglib.proxy.NoOp; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.ListUtils; +import org... [truncated message content] |
From: <fg...@us...> - 2006-11-06 22:53:51
|
Revision: 102 http://svn.sourceforge.net/openutils/?rev=102&view=rev Author: fgiust Date: 2006-11-06 14:53:40 -0800 (Mon, 06 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-1.0.1 Added Paths: ----------- tags/openutils-usermanagement-1.0.1/ tags/openutils-usermanagement-1.0.1/pom.xml Removed Paths: ------------- tags/openutils-usermanagement-1.0.1/pom.xml Copied: tags/openutils-usermanagement-1.0.1 (from rev 80, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-1.0.1/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2006-10-08 20:46:20 UTC (rev 80) +++ tags/openutils-usermanagement-1.0.1/pom.xml 2006-11-06 22:53:40 UTC (rev 102) @@ -1,110 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>0.3-SNAPSHOT</version> - <description>Usermanagement classes</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring</artifactId> - <version>1.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.cr2</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.1.2.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-1.0.1/pom.xml (from rev 101, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-1.0.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-1.0.1/pom.xml 2006-11-06 22:53:40 UTC (rev 102) @@ -0,0 +1,116 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>1.0.1</version> + <description>Usermanagement classes</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-spring</artifactId> + <version>1.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>1.0.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.ga</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.0.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-1.0.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-1.0.1</url> + </scm> +</project> \ 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: <fg...@us...> - 2006-11-13 21:18:19
|
Revision: 107 http://svn.sourceforge.net/openutils/?rev=107&view=rev Author: fgiust Date: 2006-11-13 13:18:10 -0800 (Mon, 13 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-dataobjects-1.1 Added Paths: ----------- tags/openutils-usermanagement-dataobjects-1.1/ tags/openutils-usermanagement-dataobjects-1.1/pom.xml Removed Paths: ------------- tags/openutils-usermanagement-dataobjects-1.1/pom.xml Copied: tags/openutils-usermanagement-dataobjects-1.1 (from rev 105, trunk/openutils-usermanagement-dataobjects) Deleted: tags/openutils-usermanagement-dataobjects-1.1/pom.xml =================================================================== --- trunk/openutils-usermanagement-dataobjects/pom.xml 2006-11-13 21:16:40 UTC (rev 105) +++ tags/openutils-usermanagement-dataobjects-1.1/pom.xml 2006-11-13 21:18:10 UTC (rev 107) @@ -1,74 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement-dataobjects</name> - <version>1.1-SNAPSHOT</version> - <description>Usermanagement dataobjects</description> - <dependencies> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.ga</version> - <exclusions> - <exclusion> - <!-- not needed here, just load annotations --> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </exclusion> - <exclusion> - <groupId>oro</groupId> - <artifactId>oro</artifactId> - </exclusion> - <exclusion> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-dataobjects-1.1/pom.xml (from rev 106, trunk/openutils-usermanagement-dataobjects/pom.xml) =================================================================== --- tags/openutils-usermanagement-dataobjects-1.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-dataobjects-1.1/pom.xml 2006-11-13 21:18:10 UTC (rev 107) @@ -0,0 +1,79 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement-dataobjects</name> + <version>1.1</version> + <description>Usermanagement dataobjects</description> + <dependencies> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.ga</version> + <exclusions> + <exclusion> + <!-- not needed here, just load annotations --> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </exclusion> + <exclusion> + <groupId>oro</groupId> + <artifactId>oro</artifactId> + </exclusion> + <exclusion> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-dataobjects-1.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-dataobjects-1.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-dataobjects-1.1</url> + </scm> +</project> \ 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: <fg...@us...> - 2006-11-15 17:47:20
|
Revision: 119 http://svn.sourceforge.net/openutils/?rev=119&view=rev Author: fgiust Date: 2006-11-15 09:47:15 -0800 (Wed, 15 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.1 Added Paths: ----------- tags/openutils-deployment-1.0.1/ tags/openutils-deployment-1.0.1/pom.xml Removed Paths: ------------- tags/openutils-deployment-1.0.1/pom.xml Copied: tags/openutils-deployment-1.0.1 (from rev 117, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.1/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.1/pom.xml 2006-11-15 17:47:15 UTC (rev 119) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.1-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.1/pom.xml (from rev 118, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.1/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.1/pom.xml 2006-11-15 17:47:15 UTC (rev 119) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.1</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.1</url> + </scm> +</project> \ 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: <fg...@us...> - 2006-11-16 09:31:57
|
Revision: 123 http://svn.sourceforge.net/openutils/?rev=123&view=rev Author: fgiust Date: 2006-11-16 01:31:51 -0800 (Thu, 16 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.2 Added Paths: ----------- tags/openutils-deployment-1.0.2/ tags/openutils-deployment-1.0.2/pom.xml tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Removed Paths: ------------- tags/openutils-deployment-1.0.2/pom.xml tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Copied: tags/openutils-deployment-1.0.2 (from rev 117, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.2/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.2/pom.xml 2006-11-16 09:31:51 UTC (rev 123) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.1-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.2/pom.xml (from rev 122, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.2/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.2/pom.xml 2006-11-16 09:31:51 UTC (rev 123) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.2</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.2</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.2</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.2</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 09:31:51 UTC (rev 123) @@ -1,155 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.File; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.web.context.ServletContextAware; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware -{ - - private String fileLocation; - - private String defaultEnvironment; - - private ServletContext servletContext; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * {@inheritDoc} - */ - public void setServletContext(ServletContext servletContext) - { - this.servletContext = servletContext; - } - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - */ - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - private String getRootPath() - { - if (servletContext != null) - { - return servletContext.getRealPath("/"); - } - return "src/main/webapp/"; - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null) - { - try - { - url = servletContext.getResource(resource); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - } - else - { - try - { - return new File(getRootPath(), resource).toURL(); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - // test - } - return url; - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - - try - { - hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); - } - - System.setProperty("env", hostname); - - String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); - URL propertyUrl = null; - - propertyUrl = getResource(resolvedLocation); - - if (propertyUrl == null) - { - log.info("No environment specific properties found at {}, using default", resolvedLocation); - resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); - - propertyUrl = getResource(resolvedLocation); - - } - - if (propertyUrl == null) - { - log.error("No default properties found at {}", resolvedLocation); - } - else - { - Resource resource = new UrlResource(propertyUrl); - super.setLocation(resource); - } - } - - super.postProcessBeanFactory(beanFactory); - } - -} Copied: tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 121, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-1.0.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 09:31:51 UTC (rev 123) @@ -0,0 +1,167 @@ +package it.openutils.deployment.spring; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.web.context.ServletContextAware; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +{ + + private String fileLocation; + + private String defaultEnvironment; + + private ServletContext servletContext; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * {@inheritDoc} + */ + public void setServletContext(ServletContext servletContext) + { + this.servletContext = servletContext; + } + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Setter for <code>defaultEnvironment</code>. + * @param defaultEnvironment The defaultEnvironment to set. + */ + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + private String getRootPath() + { + if (servletContext != null) + { + return servletContext.getRealPath("/"); + } + return "src/main/webapp/"; + } + + private URL getResource(String resource) + { + URL url = null; + + if (servletContext != null) + { + try + { + url = servletContext.getResource(resource); + + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } + } + else + { + try + { + return new File(getRootPath(), resource).toURL(); + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + // test + } + return url; + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + if (fileLocation != null) + { + + String hostname = null; + + try + { + hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + } + catch (UnknownHostException e) + { + log.error(e.getMessage()); + } + + System.setProperty("env", hostname); + + String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); + URL propertyUrl = null; + + propertyUrl = getResource(resolvedLocation); + + if (propertyUrl == null) + { + log.info("No environment specific properties found at {}, using default", resolvedLocation); + resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); + + propertyUrl = getResource(resolvedLocation); + + } + + if (propertyUrl == null) + { + log.error("No default properties found at {}", resolvedLocation); + } + else + { + Resource resource = new UrlResource(propertyUrl); + super.setLocation(resource); + } + } + + super.postProcessBeanFactory(beanFactory); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-11-16 10:09:39
|
Revision: 127 http://svn.sourceforge.net/openutils/?rev=127&view=rev Author: fgiust Date: 2006-11-16 02:09:39 -0800 (Thu, 16 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.3 Added Paths: ----------- tags/openutils-deployment-1.0.3/ tags/openutils-deployment-1.0.3/pom.xml tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Removed Paths: ------------- tags/openutils-deployment-1.0.3/pom.xml tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Copied: tags/openutils-deployment-1.0.3 (from rev 117, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.3/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.3/pom.xml 2006-11-16 10:09:39 UTC (rev 127) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.1-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.3/pom.xml (from rev 126, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.3/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.3/pom.xml 2006-11-16 10:09:39 UTC (rev 127) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.3</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.3</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.3</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 10:09:39 UTC (rev 127) @@ -1,155 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.File; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.web.context.ServletContextAware; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware -{ - - private String fileLocation; - - private String defaultEnvironment; - - private ServletContext servletContext; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * {@inheritDoc} - */ - public void setServletContext(ServletContext servletContext) - { - this.servletContext = servletContext; - } - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - */ - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - private String getRootPath() - { - if (servletContext != null) - { - return servletContext.getRealPath("/"); - } - return "src/main/webapp/"; - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null) - { - try - { - url = servletContext.getResource(resource); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - } - else - { - try - { - return new File(getRootPath(), resource).toURL(); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - // test - } - return url; - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - - try - { - hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); - } - - System.setProperty("env", hostname); - - String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); - URL propertyUrl = null; - - propertyUrl = getResource(resolvedLocation); - - if (propertyUrl == null) - { - log.info("No environment specific properties found at {}, using default", resolvedLocation); - resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); - - propertyUrl = getResource(resolvedLocation); - - } - - if (propertyUrl == null) - { - log.error("No default properties found at {}", resolvedLocation); - } - else - { - Resource resource = new UrlResource(propertyUrl); - super.setLocation(resource); - } - } - - super.postProcessBeanFactory(beanFactory); - } - -} Copied: tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 125, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 10:09:39 UTC (rev 127) @@ -0,0 +1,170 @@ +package it.openutils.deployment.spring; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.web.context.ServletContextAware; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +{ + + private String fileLocation; + + private String defaultEnvironment; + + private ServletContext servletContext; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * {@inheritDoc} + */ + public void setServletContext(ServletContext servletContext) + { + this.servletContext = servletContext; + } + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Setter for <code>defaultEnvironment</code>. + * @param defaultEnvironment The defaultEnvironment to set. + */ + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + private String getRootPath() + { + if (servletContext != null) + { + return servletContext.getRealPath("/"); + } + return "src/main/webapp/"; + } + + private URL getResource(String resource) + { + URL url = null; + + if (servletContext != null) + { + try + { + url = servletContext.getResource(resource); + + if (url != null) + { + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } + + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } + } + else + { + try + { + return new File(getRootPath(), resource).toURL(); + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + // test + } + return url; + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + if (fileLocation != null) + { + + String hostname = null; + + try + { + hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + } + catch (UnknownHostException e) + { + log.error(e.getMessage()); + } + + System.setProperty("env", hostname); + + String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); + URL propertyUrl = null; + + propertyUrl = getResource(resolvedLocation); + + if (propertyUrl == null) + { + log.info("No environment specific properties found at {}, using default", resolvedLocation); + resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); + + propertyUrl = getResource(resolvedLocation); + + } + + if (propertyUrl == null) + { + log.error("No default properties found at {}", resolvedLocation); + } + else + { + Resource resource = new UrlResource(propertyUrl); + super.setLocation(resource); + } + } + + super.postProcessBeanFactory(beanFactory); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-11-20 19:49:49
|
Revision: 131 http://svn.sourceforge.net/openutils/?rev=131&view=rev Author: fgiust Date: 2006-11-20 11:40:26 -0800 (Mon, 20 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-usermanagement-dataobjects-1.1.1 Added Paths: ----------- tags/openutils-usermanagement-dataobjects-1.1.1/ tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java Removed Paths: ------------- tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java Copied: tags/openutils-usermanagement-dataobjects-1.1.1 (from rev 109, trunk/openutils-usermanagement-dataobjects) Deleted: tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml =================================================================== --- trunk/openutils-usermanagement-dataobjects/pom.xml 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml 2006-11-20 19:40:26 UTC (rev 131) @@ -1,73 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement-dataobjects</name> - <version>1.1.1-SNAPSHOT</version> - <description>Usermanagement dataobjects</description> - <dependencies> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.ga</version> - <exclusions> - <exclusion> - <!-- not needed here, just load annotations --> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.2</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </exclusion> - <exclusion> - <groupId>oro</groupId> - <artifactId>oro</artifactId> - </exclusion> - <exclusion> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml (from rev 130, trunk/openutils-usermanagement-dataobjects/pom.xml) =================================================================== --- tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-dataobjects-1.1.1/pom.xml 2006-11-20 19:40:26 UTC (rev 131) @@ -0,0 +1,79 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement-dataobjects</name> + <version>1.1.1</version> + <description>Usermanagement dataobjects</description> + <dependencies> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.ga</version> + <exclusions> + <exclusion> + <!-- not needed here, just load annotations --> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.2</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </exclusion> + <exclusion> + <groupId>oro</groupId> + <artifactId>oro</artifactId> + </exclusion> + <exclusion> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-dataobjects-1.1.1</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-dataobjects-1.1.1</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-dataobjects-1.1.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java =================================================================== --- trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/Group.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java 2006-11-20 19:40:26 UTC (rev 131) @@ -1,110 +0,0 @@ -package it.openutils.usermanagement.dataobjects; - -import java.io.Serializable; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; - -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; - - -/** - * @author fberar - * @version $Revision$ ($Author$) - */ -@Entity -@Table(name = "APP_GROUP") -public class Group implements Serializable -{ - - /** - * stable serialVersionUID. - */ - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "ID_GROUP", length = 100) - private String id; - - @Column(name = "DESCRIPTION", length = 255, nullable = false) - private String description; - - @Column(name = "ENABLED", nullable = false) - private Boolean enabled; - - @ManyToMany(cascade = CascadeType.PERSIST, targetEntity = Role.class, fetch = FetchType.EAGER) - @Fetch(FetchMode.SUBSELECT) - @JoinTable(name = "APP_GROUP_ROLE", joinColumns = @JoinColumn(name = "ID_GROUP"), inverseJoinColumns = @JoinColumn(name = "ID_ROLE")) - private Set<Role> roles; - - /** - * Getter for <code>id</code>. - * @return Returns the id. - */ - public String getId() - { - return this.id; - } - - /** - * Setter for <code>id</code>. - * @param id The id to set. - */ - public void setId(String id) - { - this.id = id; - } - - public Boolean getEnabled() - { - return this.enabled; - } - - public void setEnabled(Boolean enabled) - { - this.enabled = enabled; - } - - public String getDescription() - { - return description; - } - - public void setDescription(String description) - { - this.description = description; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( - "description", - this.description).append("enabled", this.enabled).toString(); - } - - public Set<Role> getRoles() - { - return roles; - } - - public void setRoles(Set<Role> roles) - { - this.roles = roles; - } - -} Copied: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java (from rev 129, trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/Group.java) =================================================================== --- tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java (rev 0) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Group.java 2006-11-20 19:40:26 UTC (rev 131) @@ -0,0 +1,155 @@ +package it.openutils.usermanagement.dataobjects; + +import java.io.Serializable; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + + +/** + * @author fberar + * @version $Revision$ ($Author$) + */ +@Entity +@Table(name = "APP_GROUP") +public class Group implements Serializable +{ + + /** + * stable serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "ID_GROUP", length = 100) + private String id; + + @Column(name = "DESCRIPTION", length = 255, nullable = false) + private String description; + + @Column(name = "ENABLED", nullable = false) + private Boolean enabled; + + @ManyToMany(cascade = CascadeType.PERSIST, targetEntity = Role.class, fetch = FetchType.EAGER) + @Fetch(FetchMode.SUBSELECT) + @JoinTable(name = "APP_GROUP_ROLE", joinColumns = @JoinColumn(name = "ID_GROUP"), inverseJoinColumns = @JoinColumn(name = "ID_ROLE")) + private Set<Role> roles; + + /** + * Getter for <code>id</code>. + * @return Returns the id. + */ + public String getId() + { + return this.id; + } + + /** + * Setter for <code>id</code>. + * @param id The id to set. + */ + public void setId(String id) + { + this.id = id; + } + + public Boolean getEnabled() + { + return this.enabled; + } + + public void setEnabled(Boolean enabled) + { + this.enabled = enabled; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( + "description", + this.description).append("enabled", this.enabled).toString(); + } + + public Set<Role> getRoles() + { + return roles; + } + + public void setRoles(Set<Role> roles) + { + this.roles = roles; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final Group other = (Group) obj; + if (this.id == null) + { + if (other.id != null) + { + return false; + } + } + else if (!this.id.equals(other.id)) + { + return false; + } + return true; + } + +} Deleted: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java =================================================================== --- trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/Role.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java 2006-11-20 19:40:26 UTC (rev 131) @@ -1,74 +0,0 @@ -package it.openutils.usermanagement.dataobjects; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - - -/** - * @author fberar - * @version $Revision$ ($Author$) - */ -@Entity -@Table(name = "APP_ROLE") -public class Role implements Serializable -{ - - /** - * stable serialVersionUID. - */ - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "ID_ROLE", length = 100) - private String id; - - @Column(name = "DESCRIPTION", length = 255, nullable = false) - private String description; - - /** - * Getter for <code>id</code>. - * @return Returns the id. - */ - public String getId() - { - return this.id; - } - - /** - * Setter for <code>id</code>. - * @param id The id to set. - */ - public void setId(String id) - { - this.id = id; - } - - public String getDescription() - { - return description; - } - - public void setDescription(String description) - { - this.description = description; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( - "description", - this.description).toString(); - } - -} Copied: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java (from rev 129, trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/Role.java) =================================================================== --- tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java (rev 0) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/Role.java 2006-11-20 19:40:26 UTC (rev 131) @@ -0,0 +1,117 @@ +package it.openutils.usermanagement.dataobjects; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + + +/** + * @author fberar + * @version $Revision$ ($Author$) + */ +@Entity +@Table(name = "APP_ROLE") +public class Role implements Serializable +{ + + /** + * stable serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "ID_ROLE", length = 100) + private String id; + + @Column(name = "DESCRIPTION", length = 255, nullable = false) + private String description; + + /** + * Getter for <code>id</code>. + * @return Returns the id. + */ + public String getId() + { + return this.id; + } + + /** + * Setter for <code>id</code>. + * @param id The id to set. + */ + public void setId(String id) + { + this.id = id; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( + "description", + this.description).toString(); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final Role other = (Role) obj; + if (this.id == null) + { + if (other.id != null) + return false; + } + else if (!this.id.equals(other.id)) + { + return false; + } + return true; + } + +} Deleted: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java =================================================================== --- trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/User.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java 2006-11-20 19:40:26 UTC (rev 131) @@ -1,246 +0,0 @@ -package it.openutils.usermanagement.dataobjects; - -import java.io.Serializable; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; - -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.GrantedAuthorityImpl; -import org.acegisecurity.userdetails.UserDetails; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; - - -/** - * @author fberar - * @version $Revision$ ($Author$) - */ -@Entity -@Table(name = "APP_USER") -public class User implements Serializable, UserDetails -{ - - /** - * stable serialVersionUID. - */ - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "ID_USER", length = 50) - private String id; - - @Column(name = "PASSWORD", nullable = false, length = 50) - private String password; - - @Column(name = "ENABLED", nullable = false) - private Boolean enabled; - - @Column(name = "NAME", nullable = false, length = 80) - private String name; - - @Column(name = "SURNAME", nullable = false, length = 80) - private String surname; - - @Column(name = "EMAIL", nullable = false, length = 150) - private String email; - - @ManyToMany(cascade = CascadeType.PERSIST, targetEntity = Group.class, fetch = FetchType.EAGER) - @Fetch(FetchMode.SUBSELECT) - @JoinTable(name = "APP_USER_GROUP", joinColumns = @JoinColumn(name = "ID_USER"), inverseJoinColumns = @JoinColumn(name = "ID_GROUP")) - private Set<Group> groups; - - public Set<Group> getGroups() - { - return groups; - } - - public void setGroups(Set<Group> groups) - { - this.groups = groups; - } - - /** - * Getter for <code>id</code>. - * @return Returns the id. - */ - public String getId() - { - return this.id; - } - - /** - * Setter for <code>id</code>. - * @param id The id to set. - */ - public void setId(String id) - { - this.id = id; - } - - public Boolean getEnabled() - { - return this.enabled; - } - - public void setEnabled(Boolean enabled) - { - this.enabled = enabled; - } - - public String getPassword() - { - return password; - } - - public void setPassword(String password) - { - this.password = password; - } - - public Set<Role> getRoles() - { - if (groups == null) - { - return null; - } - - Set<Role> roles = new HashSet<Role>(); - - for (Group group : groups) - { - roles.addAll(group.getRoles()); - } - - return roles; - } - - /** - * @see UserDetails.isAccountNonExpired() - */ - public boolean isAccountNonExpired() - { - return (this.enabled == null) ? false : this.enabled.booleanValue(); - } - - /** - * @see UserDetails.isAccountNonLocked() - */ - public boolean isAccountNonLocked() - { - return (this.enabled == null) ? false : this.enabled.booleanValue(); - } - - /** - * @see UserDetails.isCredentialsNonExpired() - */ - public boolean isCredentialsNonExpired() - { - return (this.enabled == null) ? false : this.enabled.booleanValue(); - } - - /** - * @see UserDetails.getAuthorities() - */ - public GrantedAuthority[] getAuthorities() - { - if (this.getRoles() == null) - { - return null; - } - - GrantedAuthority[] auths = new GrantedAuthorityImpl[this.getRoles().size()]; - Iterator<Role> iter = this.getRoles().iterator(); - int i = 0; - while (iter.hasNext()) - { - Role r = iter.next(); - auths[i] = new GrantedAuthorityImpl(r.getId()); - i++; - } - - return auths; - } - - /** - * @see UserDetails.getUsername() - */ - public String getUsername() - { - return this.id; - } - - /** - * @see UserDetails.isEnabled() - */ - public boolean isEnabled() - { - return (this.enabled == null) ? false : this.enabled.booleanValue(); - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public String getSurname() - { - return surname; - } - - public void setSurname(String surname) - { - this.surname = surname; - } - - /** - * Getter for <code>email</code>. - * @return Returns the email. - */ - public String getEmail() - { - return this.email; - } - - /** - * Setter for <code>email</code>. - * @param email The email to set. - */ - public void setEmail(String email) - { - this.email = email; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( - "enabled", - this.enabled).append("name", this.name).append("surname", this.surname).append( - "authorities", - this.getAuthorities()).append("username", this.getUsername()).append("email", this.email).append( - "password", - this.password).toString(); - } - -} Copied: tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java (from rev 129, trunk/openutils-usermanagement-dataobjects/src/main/java/it/openutils/usermanagement/dataobjects/User.java) =================================================================== --- tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java (rev 0) +++ tags/openutils-usermanagement-dataobjects-1.1.1/src/main/java/it/openutils/usermanagement/dataobjects/User.java 2006-11-20 19:40:26 UTC (rev 131) @@ -0,0 +1,301 @@ +package it.openutils.usermanagement.dataobjects; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.GrantedAuthorityImpl; +import org.acegisecurity.userdetails.UserDetails; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + + +/** + * @author fberar + * @version $Revision$ ($Author$) + */ +@Entity +@Table(name = "APP_USER") +public class User implements Serializable, UserDetails +{ + + /** + * stable serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "ID_USER", length = 50) + private String id; + + @Column(name = "PASSWORD", nullable = false, length = 50) + private String password; + + @Column(name = "ENABLED", nullable = false) + private Boolean enabled; + + @Column(name = "NAME", nullable = false, length = 80) + private String name; + + @Column(name = "SURNAME", nullable = false, length = 80) + private String lastname; + + @Column(name = "EMAIL", nullable = false, length = 150) + private String email; + + @ManyToMany(cascade = CascadeType.PERSIST, targetEntity = Group.class, fetch = FetchType.EAGER) + @Fetch(FetchMode.SUBSELECT) + @JoinTable(name = "APP_USER_GROUP", joinColumns = @JoinColumn(name = "ID_USER"), inverseJoinColumns = @JoinColumn(name = "ID_GROUP")) + private Set<Group> groups; + + public Set<Group> getGroups() + { + return groups; + } + + public void setGroups(Set<Group> groups) + { + this.groups = groups; + } + + /** + * Getter for <code>id</code>. + * @return Returns the id. + */ + public String getId() + { + return this.id; + } + + /** + * Setter for <code>id</code>. + * @param id The id to set. + */ + public void setId(String id) + { + this.id = id; + } + + public Boolean getEnabled() + { + return this.enabled; + } + + public void setEnabled(Boolean enabled) + { + this.enabled = enabled; + } + + public String getPassword() + { + return password; + } + + public void setPassword(String password) + { + this.password = password; + } + + public Set<Role> getRoles() + { + if (groups == null) + { + return null; + } + + Set<Role> roles = new HashSet<Role>(); + + for (Group group : groups) + { + roles.addAll(group.getRoles()); + } + + return roles; + } + + /** + * @see UserDetails.isAccountNonExpired() + */ + public boolean isAccountNonExpired() + { + return (this.enabled == null) ? false : this.enabled.booleanValue(); + } + + /** + * @see UserDetails.isAccountNonLocked() + */ + public boolean isAccountNonLocked() + { + return (this.enabled == null) ? false : this.enabled.booleanValue(); + } + + /** + * @see UserDetails.isCredentialsNonExpired() + */ + public boolean isCredentialsNonExpired() + { + return (this.enabled == null) ? false : this.enabled.booleanValue(); + } + + /** + * @see UserDetails.getAuthorities() + */ + public GrantedAuthority[] getAuthorities() + { + if (this.getRoles() == null) + { + return null; + } + + GrantedAuthority[] auths = new GrantedAuthorityImpl[this.getRoles().size()]; + Iterator<Role> iter = this.getRoles().iterator(); + int i = 0; + while (iter.hasNext()) + { + Role r = iter.next(); + auths[i] = new GrantedAuthorityImpl(r.getId()); + i++; + } + + return auths; + } + + /** + * @see UserDetails.getUsername() + */ + public String getUsername() + { + return this.id; + } + + /** + * @see UserDetails.isEnabled() + */ + public boolean isEnabled() + { + return Boolean.TRUE.equals(this.enabled); + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getSurname() + { + return lastname; + } + + public void setSurname(String surname) + { + this.lastname = surname; + } + + public void setLastname(String lastname) + { + this.lastname = lastname; + } + + public String getLastname() + { + return lastname; + } + + /** + * Getter for <code>email</code>. + * @return Returns the email. + */ + public String getEmail() + { + return this.email; + } + + /** + * Setter for <code>email</code>. + * @param email The email to set. + */ + public void setEmail(String email) + { + this.email = email; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", this.id).append( + "enabled", + this.enabled).append("name", this.name).append("surname", this.lastname).append( + "authorities", + this.getAuthorities()).append("username", this.getUsername()).append("email", this.email).append( + "password", + this.password).toString(); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final User other = (User) obj; + if (this.id == null) + { + if (other.id != null) + { + return false; + } + } + else if (!this.id.equals(other.id)) + { + return false; + } + return true; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-12-09 20:16:33
|
Revision: 137 http://svn.sourceforge.net/openutils/?rev=137&view=rev Author: fgiust Date: 2006-12-09 12:16:31 -0800 (Sat, 09 Dec 2006) Log Message: ----------- [maven-scm] copy for tag openutils-bshd5-1.0.3 Added Paths: ----------- tags/openutils-bshd5-1.0.3/ tags/openutils-bshd5-1.0.3/pom.xml tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Removed Paths: ------------- tags/openutils-bshd5-1.0.3/pom.xml tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Copied: tags/openutils-bshd5-1.0.3 (from rev 109, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-1.0.3/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-bshd5-1.0.3/pom.xml 2006-12-09 20:16:31 UTC (rev 137) @@ -1,46 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>1.0.3-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.0.cr5</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-1.0.3/pom.xml (from rev 136, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-1.0.3/pom.xml (rev 0) +++ tags/openutils-bshd5-1.0.3/pom.xml 2006-12-09 20:16:31 UTC (rev 137) @@ -0,0 +1,52 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>1.0.3</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.0.cr5</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-1.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-12-09 20:16:31 UTC (rev 137) @@ -1,319 +0,0 @@ -package it.openutils.hibernate.example; - -import it.openutils.dao.hibernate.MutableDateRange; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - */ -public class EnhancedExample -{ - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(null, crit, filter); - } - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - if (isSimpleType(value)) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - - fmd.createFilter(crit, simplePropertyName, value); - - } - else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata - // for this scope - { - Date from = ((MutableDateRange) value).getFrom(); - Date to = ((MutableDateRange) value).getTo(); - if (from != null && to != null) - { - log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); - crit.add(Restrictions.between(propertyName, from, to)); - } - else if (from != null) - { - - log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); - - crit.add(Restrictions.ge(propertyName, from)); - } - else if (to != null) - { - log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); - crit.add(Restrictions.le(propertyName, to)); - } - } - else - { - if (containsSomething(value)) - { - - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - - for (Object element : ((Collection) value)) - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, element); - } - } - else - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - else if (bean instanceof MutableDateRange) - { - return ((MutableDateRange) bean).isSet(); - } - - if (bean instanceof Collection) - { - - Collection coll = ((Collection) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - Map coll = ((Map) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - for (Object element : ((Collection) filter)) - { - fillCriteria(parentPropertyName, crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName - + "." - + propertyName; - addCondition(crit, composedPropertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || objClass.equals(Calendar.class); - } - -} Copied: tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 134, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-12-09 20:16:31 UTC (rev 137) @@ -0,0 +1,319 @@ +package it.openutils.hibernate.example; + +import it.openutils.dao.hibernate.MutableDateRange; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public class EnhancedExample +{ + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + throws HibernateException + { + new EnhancedExample(crit, filter, metadata); + } + + /** + * Adds contitions to an existing criteria or create sub-criteria for associations. + * @param crit Criteria + * @param propertyName property name in parent bean + * @param value property value + * @throws HibernateException exception while building the criteria + */ + private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) + throws HibernateException + { + if (isSimpleType(value)) + { + + // don't filter on empty strings! + if (value instanceof String && StringUtils.isBlank((String) value)) + { + return; + } + + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd == null) + { + fmd = FilterMetadata.EQUAL; + } + + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( + propertyName, + ".") : propertyName; + + fmd.createFilter(crit, simplePropertyName, value); + + } + else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata + // for this scope + { + Date from = ((MutableDateRange) value).getFrom(); + Date to = ((MutableDateRange) value).getTo(); + if (from != null && to != null) + { + log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); + crit.add(Restrictions.between(propertyName, from, to)); + } + else if (from != null) + { + + log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); + + crit.add(Restrictions.ge(propertyName, from)); + } + else if (to != null) + { + log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); + crit.add(Restrictions.le(propertyName, to)); + } + } + else + { + if (containsSomething(value)) + { + + // @todo handle multiple associations in lists? + // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 + if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) + { + // collection: the new criteria has already been created, now we only nee to analize content + + for (Object element : ((Collection) value)) + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, element); + } + } + else + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, value); + } + } + } + } + + /** + * Check if the bean contains at least a valid property. + * @param bean javabean + * @return <code>true</code> if the bean contains at least a valid property + */ + private boolean containsSomething(Object bean) + { + + if (bean == null) + { + return false; + } + if (isSimpleType(bean)) + { + return true; + } + else if (bean instanceof MutableDateRange) + { + return ((MutableDateRange) bean).isSet(); + } + + if (bean instanceof Collection) + { + + Collection coll = ((Collection) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.iterator().next())) + { + return true; + } + } + else if (bean instanceof Map) + { + Map coll = ((Map) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.values().iterator().next())) + { + return true; + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(bean); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(bean, "NULL"), e); + return false; + } + + for (Map.Entry<String, Object> property : properties.entrySet()) + { + + if (!PropertyUtils.isWriteable(bean, property.getKey())) + { + // skip readonly properties + continue; + } + + Object propertyValue = property.getValue(); + if (propertyValue == null) + { + continue; + } + + if (isSimpleType(propertyValue) || containsSomething(propertyValue)) + { + return true; + } + } + + return false; + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException + { + if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) + { + // collection: the new criteria has already been created, now we only need to analize content + for (Object element : ((Collection) filter)) + { + fillCriteria(parentPropertyName, crit, element); + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(filter); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + throw new DataRetrievalFailureException( + "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(filter, "NULL") + + ":" + + e.getClass(), + e); + } + + Iterator<String> iterator = properties.keySet().iterator(); + while (iterator.hasNext()) + { + String propertyName = iterator.next(); + + Object value = properties.get(propertyName); + + // add only non-null values, ignore read-only properties + if (value != null && PropertyUtils.isWriteable(filter, propertyName)) + { + String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName + + "." + + propertyName; + addCondition(crit, composedPropertyName, value, filter); + } + } + } + + /** + * Check if the given object is a simple java type + * @param object object to check + * @return <code>true</code>if the given object is a simple type + */ + private boolean isSimpleType(Object object) + { + + Class< ? extends Object> objClass = object.getClass(); + + return objClass.isPrimitive() + || objClass.equals(Integer.class) + || objClass.equals(Long.class) + || objClass.equals(Short.class) + || objClass.equals(Boolean.class) + || objClass.equals(String.class) + || objClass.equals(Double.class) + || objClass.equals(Float.class) + || objClass.equals(Date.class) + || objClass.equals(Byte.class) + || objClass.equals(BigDecimal.class) + || objClass.equals(Timestamp.class) + || objClass.equals(Character.class) + || Calendar.class.isAssignableFrom(objClass); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-12-09 20:18:16
|
Revision: 139 http://svn.sourceforge.net/openutils/?rev=139&view=rev Author: fgiust Date: 2006-12-09 12:18:16 -0800 (Sat, 09 Dec 2006) Log Message: ----------- [maven-scm] copy for tag openutils-bshd5-1.0.3 Added Paths: ----------- tags/openutils-bshd5-1.0.3/ tags/openutils-bshd5-1.0.3/pom.xml tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Removed Paths: ------------- tags/openutils-bshd5-1.0.3/pom.xml tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Copied: tags/openutils-bshd5-1.0.3 (from rev 109, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-1.0.3/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-bshd5-1.0.3/pom.xml 2006-12-09 20:18:16 UTC (rev 139) @@ -1,46 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>1.0.3-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.0.cr5</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-1.0.3/pom.xml (from rev 136, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-1.0.3/pom.xml (rev 0) +++ tags/openutils-bshd5-1.0.3/pom.xml 2006-12-09 20:18:16 UTC (rev 139) @@ -0,0 +1,52 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>1.0.3</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.0.cr5</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-1.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-11-13 21:23:57 UTC (rev 109) +++ tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-12-09 20:18:16 UTC (rev 139) @@ -1,319 +0,0 @@ -package it.openutils.hibernate.example; - -import it.openutils.dao.hibernate.MutableDateRange; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - */ -public class EnhancedExample -{ - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(null, crit, filter); - } - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - if (isSimpleType(value)) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - - fmd.createFilter(crit, simplePropertyName, value); - - } - else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata - // for this scope - { - Date from = ((MutableDateRange) value).getFrom(); - Date to = ((MutableDateRange) value).getTo(); - if (from != null && to != null) - { - log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); - crit.add(Restrictions.between(propertyName, from, to)); - } - else if (from != null) - { - - log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); - - crit.add(Restrictions.ge(propertyName, from)); - } - else if (to != null) - { - log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); - crit.add(Restrictions.le(propertyName, to)); - } - } - else - { - if (containsSomething(value)) - { - - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - - for (Object element : ((Collection) value)) - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, element); - } - } - else - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - else if (bean instanceof MutableDateRange) - { - return ((MutableDateRange) bean).isSet(); - } - - if (bean instanceof Collection) - { - - Collection coll = ((Collection) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - Map coll = ((Map) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - for (Object element : ((Collection) filter)) - { - fillCriteria(parentPropertyName, crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName - + "." - + propertyName; - addCondition(crit, composedPropertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || objClass.equals(Calendar.class); - } - -} Copied: tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 134, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-1.0.3/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2006-12-09 20:18:16 UTC (rev 139) @@ -0,0 +1,319 @@ +package it.openutils.hibernate.example; + +import it.openutils.dao.hibernate.MutableDateRange; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public class EnhancedExample +{ + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + throws HibernateException + { + new EnhancedExample(crit, filter, metadata); + } + + /** + * Adds contitions to an existing criteria or create sub-criteria for associations. + * @param crit Criteria + * @param propertyName property name in parent bean + * @param value property value + * @throws HibernateException exception while building the criteria + */ + private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) + throws HibernateException + { + if (isSimpleType(value)) + { + + // don't filter on empty strings! + if (value instanceof String && StringUtils.isBlank((String) value)) + { + return; + } + + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd == null) + { + fmd = FilterMetadata.EQUAL; + } + + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( + propertyName, + ".") : propertyName; + + fmd.createFilter(crit, simplePropertyName, value); + + } + else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata + // for this scope + { + Date from = ((MutableDateRange) value).getFrom(); + Date to = ((MutableDateRange) value).getTo(); + if (from != null && to != null) + { + log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); + crit.add(Restrictions.between(propertyName, from, to)); + } + else if (from != null) + { + + log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); + + crit.add(Restrictions.ge(propertyName, from)); + } + else if (to != null) + { + log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); + crit.add(Restrictions.le(propertyName, to)); + } + } + else + { + if (containsSomething(value)) + { + + // @todo handle multiple associations in lists? + // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 + if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) + { + // collection: the new criteria has already been created, now we only nee to analize content + + for (Object element : ((Collection) value)) + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, element); + } + } + else + { + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils + .substringAfterLast(propertyName, ".") : propertyName; + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, value); + } + } + } + } + + /** + * Check if the bean contains at least a valid property. + * @param bean javabean + * @return <code>true</code> if the bean contains at least a valid property + */ + private boolean containsSomething(Object bean) + { + + if (bean == null) + { + return false; + } + if (isSimpleType(bean)) + { + return true; + } + else if (bean instanceof MutableDateRange) + { + return ((MutableDateRange) bean).isSet(); + } + + if (bean instanceof Collection) + { + + Collection coll = ((Collection) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.iterator().next())) + { + return true; + } + } + else if (bean instanceof Map) + { + Map coll = ((Map) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.values().iterator().next())) + { + return true; + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(bean); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(bean, "NULL"), e); + return false; + } + + for (Map.Entry<String, Object> property : properties.entrySet()) + { + + if (!PropertyUtils.isWriteable(bean, property.getKey())) + { + // skip readonly properties + continue; + } + + Object propertyValue = property.getValue(); + if (propertyValue == null) + { + continue; + } + + if (isSimpleType(propertyValue) || containsSomething(propertyValue)) + { + return true; + } + } + + return false; + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException + { + if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) + { + // collection: the new criteria has already been created, now we only need to analize content + for (Object element : ((Collection) filter)) + { + fillCriteria(parentPropertyName, crit, element); + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(filter); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + throw new DataRetrievalFailureException( + "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(filter, "NULL") + + ":" + + e.getClass(), + e); + } + + Iterator<String> iterator = properties.keySet().iterator(); + while (iterator.hasNext()) + { + String propertyName = iterator.next(); + + Object value = properties.get(propertyName); + + // add only non-null values, ignore read-only properties + if (value != null && PropertyUtils.isWriteable(filter, propertyName)) + { + String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName + + "." + + propertyName; + addCondition(crit, composedPropertyName, value, filter); + } + } + } + + /** + * Check if the given object is a simple java type + * @param object object to check + * @return <code>true</code>if the given object is a simple type + */ + private boolean isSimpleType(Object object) + { + + Class< ? extends Object> objClass = object.getClass(); + + return objClass.isPrimitive() + || objClass.equals(Integer.class) + || objClass.equals(Long.class) + || objClass.equals(Short.class) + || objClass.equals(Boolean.class) + || objClass.equals(String.class) + || objClass.equals(Double.class) + || objClass.equals(Float.class) + || objClass.equals(Date.class) + || objClass.equals(Byte.class) + || objClass.equals(BigDecimal.class) + || objClass.equals(Timestamp.class) + || objClass.equals(Character.class) + || Calendar.class.isAssignableFrom(objClass); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-01-27 19:56:18
|
Revision: 153 http://svn.sourceforge.net/openutils/?rev=153&view=rev Author: fgiust Date: 2007-01-27 11:56:19 -0800 (Sat, 27 Jan 2007) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.4 Added Paths: ----------- tags/openutils-deployment-1.0.4/ tags/openutils-deployment-1.0.4/pom.xml tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Removed Paths: ------------- tags/openutils-deployment-1.0.4/pom.xml tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Copied: tags/openutils-deployment-1.0.4 (from rev 146, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.4/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-deployment-1.0.4/pom.xml 2007-01-27 19:56:19 UTC (rev 153) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.0.4-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0.1</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.4/pom.xml (from rev 152, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.4/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.4/pom.xml 2007-01-27 19:56:19 UTC (rev 153) @@ -0,0 +1,64 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.4</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0.1</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.4</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:56:19 UTC (rev 153) @@ -1,170 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.File; -import java.io.IOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.web.context.ServletContextAware; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware -{ - - private String fileLocation; - - private String defaultEnvironment; - - private ServletContext servletContext; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * {@inheritDoc} - */ - public void setServletContext(ServletContext servletContext) - { - this.servletContext = servletContext; - } - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - */ - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - private String getRootPath() - { - if (servletContext != null) - { - return servletContext.getRealPath("/"); - } - return "src/main/webapp/"; - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null) - { - try - { - url = servletContext.getResource(resource); - - if (url != null) - { - // check needed for servletUnit - // we need to check for a connection because getResource always returns a URL, also if the resource - // doesn't exists - url.openConnection().connect(); - } - - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - catch (IOException e) - { - // ignore, URL is not a valid resource - url = null; - } - } - else - { - try - { - return new File(getRootPath(), resource).toURL(); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - // test - } - return url; - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - - try - { - hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); - } - - System.setProperty("env", hostname); - - String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); - URL propertyUrl = null; - - propertyUrl = getResource(resolvedLocation); - - if (propertyUrl == null) - { - log.info("No environment specific properties found at {}, using default", resolvedLocation); - resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); - - propertyUrl = getResource(resolvedLocation); - - } - - if (propertyUrl == null) - { - log.error("No default properties found at {}", resolvedLocation); - } - else - { - Resource resource = new UrlResource(propertyUrl); - super.setLocation(resource); - } - } - - super.postProcessBeanFactory(beanFactory); - } - -} Copied: tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 151, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:56:19 UTC (rev 153) @@ -0,0 +1,212 @@ +package it.openutils.deployment.spring; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.util.ResourceUtils; +import org.springframework.web.context.ServletContextAware; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +{ + + /** + * Application name (webapp name) variable. + */ + private static final String PROPERTY_APPL = "${appl}"; + + /** + * Environment (server name) variable. + */ + private static final String PROPERTY_ENV = "${env}"; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * @deprecated use defaultLocation + */ + @Deprecated + private String defaultEnvironment; + + private ServletContext servletContext; + + private String fileLocation; + + /** + * {@inheritDoc} + */ + public void setServletContext(ServletContext servletContext) + { + this.servletContext = servletContext; + } + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Setter for <code>defaultEnvironment</code>. + * @param defaultEnvironment The defaultEnvironment to set. + * @deprecated use defaultLocation + */ + @Deprecated + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + if (fileLocation != null) + { + + String hostname = null; + try + { + hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + } + catch (UnknownHostException e) + { + log.error(e.getMessage()); // should not happen + } + + if (hostname != null) + { + System.setProperty("env", hostname); + } + + String applName = getApplicationName(); + if (applName != null) + { + System.setProperty("appl", applName); + } + + URL propertyUrl = null; + + String replacedLocations = StringUtils.replace(fileLocation, PROPERTY_ENV, hostname); + replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); + + String[] locations = StringUtils.split(replacedLocations, ","); + + for (String loc : locations) + { + propertyUrl = getResource(StringUtils.strip(loc)); + if (propertyUrl != null) + { + break; + } + log.debug("Property file not found at {}", loc); + } + + if (propertyUrl == null && defaultEnvironment != null) + { + log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " + + "as the last comma separated value in \"fileLocation\""); + propertyUrl = getResource(StringUtils.replace(fileLocation, PROPERTY_ENV, this.defaultEnvironment)); + + } + + if (propertyUrl == null) + { + log.error("No properties found at {}", replacedLocations); + } + else + { + Resource resource = new UrlResource(propertyUrl); + super.setLocation(resource); + } + } + + super.postProcessBeanFactory(beanFactory); + } + + private URL getResource(String resource) + { + URL url = null; + + if (servletContext != null) + { + try + { + url = servletContext.getResource(resource); + + if (url != null) + { + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } + + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } + } + else + { + try + { + url = ResourceUtils.getURL(resource); + } + catch (FileNotFoundException e) + { + // ignore, can be normal + } + } + return url; + } + + private String getApplicationName() + { + if (servletContext != null) + { + String url = servletContext.getRealPath("/"); + url = StringUtils.replace(url, "\\", "/"); + if (url.endsWith("/")) + { + url = StringUtils.substringBeforeLast(url, "/"); + } + + return StringUtils.substringAfterLast(url, "/"); + } + return null; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-01-30 17:23:15
|
Revision: 161 http://svn.sourceforge.net/openutils/?rev=161&view=rev Author: fgiust Date: 2007-01-30 09:23:10 -0800 (Tue, 30 Jan 2007) Log Message: ----------- [maven-scm] copy for tag openutils-bshd5-1.0.4 Added Paths: ----------- tags/openutils-bshd5-1.0.4/ tags/openutils-bshd5-1.0.4/pom.xml tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Removed Paths: ------------- tags/openutils-bshd5-1.0.4/pom.xml tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Copied: tags/openutils-bshd5-1.0.4 (from rev 146, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-1.0.4/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-bshd5-1.0.4/pom.xml 2007-01-30 17:23:10 UTC (rev 161) @@ -1,46 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>1.0.4-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <optional>true</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-1.0.4/pom.xml (from rev 160, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-1.0.4/pom.xml (rev 0) +++ tags/openutils-bshd5-1.0.4/pom.xml 2007-01-30 17:23:10 UTC (rev 161) @@ -0,0 +1,52 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>1.0.4</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <optional>true</optional> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-1.0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-1.0.4</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-01-30 17:23:10 UTC (rev 161) @@ -1,428 +0,0 @@ -package it.openutils.dao.hibernate; - -import it.openutils.hibernate.example.EnhancedExample; -import it.openutils.hibernate.example.FilterMetadata; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.Criteria; -import org.hibernate.Hibernate; -import org.hibernate.HibernateException; -import org.hibernate.ObjectNotFoundException; -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.criterion.CriteriaSpecification; -import org.hibernate.criterion.Order; -import org.hibernate.type.Type; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.orm.hibernate3.HibernateCallback; -import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - - -/** - * Base Hibernate DAO. - * @author Fabrizio Giustina - * @version $Id$ - */ -public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport - implements - HibernateDAO<T, K> -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(HibernateDAOImpl.class); - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String) - */ - @SuppressWarnings("unchecked") - public List<T> find(String query) - { - return getHibernateTemplate().find(query); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll() - */ - public List<T> findAll() - { - return findAll(getDefaultOrder()); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findAll(org.hibernate.criterion.Order[]) - */ - @SuppressWarnings("unchecked") - public List<T> findAll(final Order[] orderProperties) - { - - 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]); - } - - } - return crit.list(); - } - }); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(java.lang.String, java.lang.Object, org.hibernate.type.Type) - */ - public List<T> find(String query, Object obj, Type type) - { - return find(query, new Object[]{obj}, new Type[]{type}); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#find(String, Object[], Type[]) - */ - @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(); - } - }); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) - */ - @SuppressWarnings("unchecked") - public T load(K key) - { - T result = (T) getHibernateTemplate().load(getReferenceClass(), key); - Hibernate.initialize(result); - return result; - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#load(java.io.Serializable) - */ - @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; - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#saveOrUpdate(null) - */ - public void saveOrUpdate(final T obj) - { - getHibernateTemplate().saveOrUpdate(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#update(null) - */ - public void update(T obj) - { - getHibernateTemplate().update(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#delete(null) - */ - public boolean delete(final K key) - { - - return (Boolean) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - ses.delete(ses.load(getReferenceClass(), key)); - return true; - } - }); - - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#refresh(null) - */ - public void refresh(T obj) - { - getHibernateTemplate().refresh(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#merge(T) - */ - @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); - } - }); - - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#save(java.lang.Object) - */ - @SuppressWarnings("unchecked") - public K save(T obj) - { - return (K) getHibernateTemplate().save(obj); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFilteredFirst(T) - */ - public T findFilteredFirst(final T filter) - { - return getFirstInCollection(findFiltered(filter, 1, 0)); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) - */ - public List<T> findFiltered(final T filter) - { - return findFiltered(filter, new HashMap<String, FilterMetadata>(0)); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(java.lang.Object, org.hibernate.criterion.Order[]) - */ - public List<T> findFiltered(T filter, Order[] orderProperties) - { - return findFiltered(filter, orderProperties, new HashMap<String, FilterMetadata>(0), Integer.MAX_VALUE, 0); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(T) - */ - public List<T> findFiltered(final T filter, final Map<String, FilterMetadata> metadata) - { - return findFiltered(filter, metadata, Integer.MAX_VALUE, 0); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - public List<T> findFiltered(final T filter, final int maxResults, final int page) - { - return findFiltered(filter, new HashMap<String, FilterMetadata>(0), maxResults, page); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - 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); - } - - /** - * @see it.openutils.dao.hibernate.HibernateDAO#findFiltered(null, int, int) - */ - @SuppressWarnings("unchecked") - public List<T> findFiltered(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, - final int maxResults, final int page) - { - 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 (null != orderProperties && orderProperties.length > 0) - { - for (Order order : orderProperties) - { - if (order != null) - { - crit.addOrder(order); - } - } - } - - EnhancedExample.create(crit, filter, metadata); - - return crit.list(); - } - }); - } - - /** - * 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 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]; - } - - /** - * Obtain an instance of Query for a named query string defined in the mapping file. - * @param name the name of a query defined externally - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final int marResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - 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 array - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Serializable[] params, final int marResults) - { - - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - if (null != params) - { - for (int i = 0; i < params.length; i++) - { - q.setParameter(i, params[i]); - } - } - 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 - * @return Query - */ - protected List< ? > getNamedQuery(final String name, final Map<String, Object> params, final int marResults) - { - return (List< ? >) getHibernateTemplate().execute(new HibernateCallback() - { - - public Object doInHibernate(Session ses) throws HibernateException - { - Query q = ses.getNamedQuery(name); - q.setMaxResults(marResults); - if (params != null) - { - for (Map.Entry<String, Object> entry : params.entrySet()) - { - setParameterValue(q, entry.getKey(), entry.getValue()); - } - } - return q.list(); - } - }); - } - - /** - * 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; - } - -} \ No newline at end of file Copied: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (from rev 158, trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java) =================================================================== --- tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java (rev 0) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2007-01-30 17:23:10 UTC (rev 161) @@ -0,0 +1,441 @@ +package it.openutils.dao.hibernate; + +import it.openutils.hibernate.example.EnhancedExample; +import it.openutils.hibernate.example.FilterMetadata; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.HibernateException; +import org.hibernate.ObjectNotFoundException; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.CriteriaSpecification; +import org.hibernate.criterion.Order; +import org.hibernate.type.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.orm.hibernate3.HibernateCallback; +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 + */ +public abstract class HibernateDAOImpl<T extends Object, K extends Serializable> extends HibernateDaoSupport + implements + HibernateDAO<T, K> +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(HibernateDAOImpl.class); + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> find(String query) + { + return getHibernateTemplate().find(query); + } + + /** + * {@inheritDoc} + */ + public List<T> findAll() + { + return findAll(getDefaultOrder()); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<T> findAll(final Order[] orderProperties) + { + + 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]); + } + + } + return crit.list(); + } + }); + } + + /** + * {@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() + { + + 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 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 update(T obj) + { + getHibernateTemplate().update(obj); + } + + /** + * {@inheritDoc} + */ + public boolean delete(final K key) + { + + return (Boolean) getHibernateTemplate().execute(new HibernateCallback() + { + + 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} + */ + @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} + */ + 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); + } + + /** + * {@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 int maxResults, final int page) + { + return findFiltered(filter, getDefaultFilterMetadata(), maxResults, page); + } + + /** + * {@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(final T filter, final Order[] customOrder, final Map<String, FilterMetadata> metadata, + final int maxResults, final int page) + { + 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 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 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]; + } + + /** + * 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() + { + + 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. 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) + { + + 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(); + } + }); + } + + /** + * 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 (params != null) + { + for (Map.Entry<String, Object> entry : params.entrySet()) + { + setParameterValue(q, entry.getKey(), entry.getValue()); + } + } + return q.list(); + } + }); + } + + /** + * 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 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 Deleted: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2007-01-30 17:23:10 UTC (rev 161) @@ -1,74 +0,0 @@ -package it.openutils.dao.hibernate; - -import java.util.Date; - - -/** - * @author fgiust - * @version $Id: $ - * @deprecated use FilterMetadata - */ -public class MutableDateRange extends Date -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * range start. - */ - private Date from; - - /** - * range end. - */ - private Date to; - - /** - * Getter for <code>from</code>. - * @return Returns the from. - */ - public Date getFrom() - { - return this.from; - } - - /** - * Setter for <code>from</code>. - * @param from The from to set. - */ - public void setFrom(Date from) - { - this.from = from; - } - - /** - * Getter for <code>to</code>. - * @return Returns the to. - */ - public Date getTo() - { - return this.to; - } - - /** - * Setter for <code>to</code>. - * @param to The to to set. - */ - public void setTo(Date to) - { - this.to = to; - } - - /** - * Returns <code>true</code> if at least one date is set. - * @return <code>true</code> if at least one date is set - */ - public boolean isSet() - { - return this.to != null || this.from != null; - } - -} Copied: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java (from rev 157, trunk/openutils-bshd5/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java) =================================================================== --- tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java (rev 0) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/dao/hibernate/MutableDateRange.java 2007-01-30 17:23:10 UTC (rev 161) @@ -0,0 +1,75 @@ +package it.openutils.dao.hibernate; + +import java.util.Date; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + * @deprecated use FilterMetadata + */ +@Deprecated +public class MutableDateRange extends Date +{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * range start. + */ + private Date from; + + /** + * range end. + */ + private Date to; + + /** + * Getter for <code>from</code>. + * @return Returns the from. + */ + public Date getFrom() + { + return this.from; + } + + /** + * Setter for <code>from</code>. + * @param from The from to set. + */ + public void setFrom(Date from) + { + this.from = from; + } + + /** + * Getter for <code>to</code>. + * @return Returns the to. + */ + public Date getTo() + { + return this.to; + } + + /** + * Setter for <code>to</code>. + * @param to The to to set. + */ + public void setTo(Date to) + { + this.to = to; + } + + /** + * Returns <code>true</code> if at least one date is set. + * @return <code>true</code> if at least one date is set + */ + public boolean isSet() + { + return this.to != null || this.from != null; + } + +} Deleted: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2007-01-30 17:23:10 UTC (rev 161) @@ -1,319 +0,0 @@ -package it.openutils.hibernate.example; - -import it.openutils.dao.hibernate.MutableDateRange; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - */ -public class EnhancedExample -{ - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(null, crit, filter); - } - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - if (isSimpleType(value)) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - - fmd.createFilter(crit, simplePropertyName, value); - - } - else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata - // for this scope - { - Date from = ((MutableDateRange) value).getFrom(); - Date to = ((MutableDateRange) value).getTo(); - if (from != null && to != null) - { - log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); - crit.add(Restrictions.between(propertyName, from, to)); - } - else if (from != null) - { - - log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); - - crit.add(Restrictions.ge(propertyName, from)); - } - else if (to != null) - { - log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); - crit.add(Restrictions.le(propertyName, to)); - } - } - else - { - if (containsSomething(value)) - { - - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - - for (Object element : ((Collection) value)) - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, element); - } - } - else - { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - else if (bean instanceof MutableDateRange) - { - return ((MutableDateRange) bean).isSet(); - } - - if (bean instanceof Collection) - { - - Collection coll = ((Collection) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - Map coll = ((Map) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - for (Object element : ((Collection) filter)) - { - fillCriteria(parentPropertyName, crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName - + "." - + propertyName; - addCondition(crit, composedPropertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || Calendar.class.isAssignableFrom(objClass); - } - -} Copied: tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 159, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-1.0.4/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2007-01-30 17:23:10 UTC (rev 161) @@ -0,0 +1,332 @@ +package it.openutils.hibernate.example; + +import it.openutils.dao.hibernate.MutableDateRange; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public class EnhancedExample +{ + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + throws HibernateException + { + new EnhancedExample(crit, filter, metadata); + } + + /** + * Adds contitions to an existing criteria or create sub-criteria for associations. + * @param crit Criteria + * @param propertyName property name in parent bean + * @param value property value + * @throws HibernateException exception while building the criteria + */ + private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) + throws HibernateException + { + + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( + propertyName, + ".") : propertyName; + + if (isSimpleType(value)) + { + + // don't filter on empty strings! + if (value instanceof String && StringUtils.isBlank((String) value)) + { + return; + } + + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd == null) + { + fmd = FilterMetadata.EQUAL; + } + + fmd.createFilter(crit, simplePropertyName, value); + + } + else if (value instanceof MutableDateRange) // @todo MutableDateRange should be removed, use a FilterMetadata + // for this scope + { + Date from = ((MutableDateRange) value).getFrom(); + Date to = ((MutableDateRange) value).getTo(); + if (from != null && to != null) + { + log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to }); + crit.add(Restrictions.between(propertyName, from, to)); + } + else if (from != null) + { + + log.debug("crit.add(Restrictions.ge({}, {})", propertyName, to); + + crit.add(Restrictions.ge(propertyName, from)); + } + else if (to != null) + { + log.debug("crit.add(Restrictions.le({}, {})", propertyName, to); + crit.add(Restrictions.le(propertyName, to)); + } + } + else + { + if (containsSomething(value)) + { + // @todo handle multiple associations in lists? + // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 + if ((value instanceof Set || value instanceof List) && !((Collection) value).isEmpty()) + { + // collection: the new criteria has already been created, now we only nee to analize content + + for (Object element : ((Collection< ? extends Object>) value)) + { + + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, element); + } + } + else if ((value instanceof Map) && !((Map) value).isEmpty()) + { + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd != null) + { + fmd.createFilter(crit, simplePropertyName, value); + } + else + { + log.warn( + "Maps are not handled without a FilterMetadata. Property is {} and value is {}.", + propertyName, + value); + } + } + else + { + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, value); + } + } + } + } + + /** + * Check if the bean contains at least a valid property. + * @param bean javabean + * @return <code>true</code> if the bean contains at least a valid property + */ + private boolean containsSomething(Object bean) + { + + if (bean == null) + { + return false; + } + if (isSimpleType(bean)) + { + return true; + } + else if (bean instanceof MutableDateRange) + { + return ((MutableDateRange) bean).isSet(); + } + + if (bean instanceof Collection) + { + + Collection coll = ((Collection) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.iterator().next())) + { + return true; + } + } + else if (bean instanceof Map) + { + Map coll = ((Map) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.values().iterator().next())) + { + return true; + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(bean); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(bean, "NULL"), e); + return false; + } + + for (Map.Entry<String, Object> property : properties.entrySet()) + { + + if (!PropertyUtils.isWriteable(bean, property.getKey())) + { + // skip readonly properties + continue; + } + + Object propertyValue = property.getValue(); + if (propertyValue == null) + { + continue; + } + + if (isSimpleType(propertyValue) || containsSomething(propertyValue)) + { + return true; + } + } + + return false; + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException + { + if ((filter instanceof Set || filter instanceof List) && !((Collection) filter).isEmpty()) + { + // collection: the new criteria has already been created, now we only need to analize content + for (Object element : ((Collection) filter)) + { + fillCriteria(parentPropertyName, crit, element); + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(filter); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + throw new DataRetrievalFailureException( + "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(filter, "NULL") + + ":" + + e.getClass(), + e); + } + + Iterator<String> iterator = properties.keySet().iterator(); + while (iterator.hasNext()) + { + String propertyName = iterator.next(); + + Object value = properties.get(propertyName); + + // add only non-null values, ignore read-only properties + if (value != null && PropertyUtils.isWriteable(filter, propertyName)) + { + String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName + + "." + + propertyName; + addCondition(crit, composedPropertyName, value, filter); + } + } + } + + /** + * Check if the given object is a simple java type + * @param object object to check + * @return <code>true</code>if the given object is a simple type + */ + private boolean isSimpleType(Object object) + { + + Class< ? extends Object> objClass = object.getClass(); + + return objClass.isPrimitive() + || objClass.equals(Integer.class) + || objClass.equals(Long.class) + || objClass.equals(Short.class) + || objClass.equals(Boolean.class) + || objClass.equals(String.class) + || objClass.equals(Double.class) + || objClass.equals(Float.class) + || objClass.equals(Date.class) + || objClass.equals(Byte.class) + || objClass.equals(BigDecimal.class) + || objClass.equals(Timestamp.class) + || objClass.equals(Character.class) + || Calendar.class.isAssignableFrom(objClass); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-02-05 17:43:05
|
Revision: 206 http://svn.sourceforge.net/openutils/?rev=206&view=rev Author: fgiust Date: 2007-02-05 09:42:52 -0800 (Mon, 05 Feb 2007) Log Message: ----------- [maven-scm] copy for tag openutils-testing-testng-1.1 Added Paths: ----------- tags/openutils-testing-testng-1.1/ tags/openutils-testing-testng-1.1/pom.xml tags/openutils-testing-testng-1.1/src/ tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java Removed Paths: ------------- tags/openutils-testing-testng-1.1/pom.xml tags/openutils-testing-testng-1.1/src/ tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java Copied: tags/openutils-testing-testng-1.1 (from rev 201, trunk/openutils-testing-testng) Deleted: tags/openutils-testing-testng-1.1/pom.xml =================================================================== --- trunk/openutils-testing-testng/pom.xml 2007-02-05 17:40:35 UTC (rev 201) +++ tags/openutils-testing-testng-1.1/pom.xml 2007-02-05 17:42:52 UTC (rev 206) @@ -1,61 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-testng</artifactId> - <name>openutils test utils (testng)</name> - <version>1.1-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-testing-testng-1.1/pom.xml (from rev 205, trunk/openutils-testing-testng/pom.xml) =================================================================== --- tags/openutils-testing-testng-1.1/pom.xml (rev 0) +++ tags/openutils-testing-testng-1.1/pom.xml 2007-02-05 17:42:52 UTC (rev 206) @@ -0,0 +1,65 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-testng</artifactId> + <name>openutils test utils (testng)</name> + <version>1.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-testng-1.1</url> + </scm> +</project> \ No newline at end of file Copied: tags/openutils-testing-testng-1.1/src (from rev 198, trunk/openutils-testing-testng/src) Deleted: tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-02-05 17:20:24 UTC (rev 198) +++ tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-02-05 17:42:52 UTC (rev 206) @@ -1,248 +0,0 @@ -/* - * Copyright 2005 Fabrizio Giustina. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing.testng; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.sql.SQLException; -import java.text.MessageFormat; - -import javax.sql.DataSource; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.dbunit.DatabaseUnitException; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.DatabaseSequenceFilter; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.DataSetException; -import org.dbunit.dataset.FilteredDataSet; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.excel.XlsDataSet; -import org.dbunit.dataset.filter.AbstractTableFilter; -import org.dbunit.dataset.filter.ITableFilter; -import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.dataset.xml.XmlDataSet; -import org.dbunit.operation.DatabaseOperation; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - - -/** - * @author fgiust - * @version $Id$ - */ -@Test -public class DbUnitTestCase extends SpringTestCase -{ - - /** - * name for the dataSource bean in Spring context. - */ - private static final String DATASOURCE_BEAN_NAME = "dataSource"; - - /** - * Pattern for dbunit file loaded before a test. MessageFormat format with two placeholders: class name and - * extension. - */ - private static final String DATAFILE_PATTERN = "/{0}-load.{1}"; - - protected static IDataSet truncateDataSet; - - /** - * Optional schema (needed for ORACLE). - * @return <code>null</code> - */ - protected String getSchema() - { - return null; - } - - /** - * Setup the Database before running the test method. - * @throws Exception Any exception. - */ - @BeforeMethod - protected void setUpDbUnit() throws Exception - { - // check for xml - IDataSet dataSet = loadDataSet(getDataFileName("xml")); - - if (dataSet == null) - { - // check for excel - dataSet = loadDataSet(getDataFileName("xls")); - } - - if (dataSet != null) - { - importDataSet(dataSet); - } - else - { - log.debug("No test data found with name [{}]", getDataFileName("xml/xls")); - } - } - - /** - * Exports a database to an Excel file - * @param fileName The file name we save the Excel dump to. - * @throws IOException An IO Exception. - * @throws DataSetException A dataset exception. - * @throws SQLException A SQL Exception. - */ - protected void exportDbToXls(String fileName) throws IOException, DataSetException, SQLException - { - IDatabaseConnection connection = getDbUnitConnection(); - - IDataSet fullDataSet = connection.createDataSet(); - - File outFile = new File(fileName); - OutputStream fos = new FileOutputStream(outFile); - XlsDataSet.write(fullDataSet, fos); - fos.close(); - } - - /** - * Cleans the database after we run the tests. - * @throws Exception Any exception. - */ - @AfterMethod - protected void tearDownDbUnit() throws Exception - { - - // regenerate db initial state - String datesetFileName = "/initial-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - log.debug("Restoring db state"); - - IDataSet dataSet = new XmlDataSet(testData); - - IDatabaseConnection connection = getDbUnitConnection(); - - try - { - DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); - } - finally - { - connection.close(); - } - } - } - - private void importDataSet(IDataSet dataSet) throws SQLException, DataSetException, DatabaseUnitException - { - IDatabaseConnection connection = getDbUnitConnection(); - - if (truncateDataSet == null) - { - log.debug("Generating sorted dataset for initial cleanup"); - IDataSet unsortedTruncateDataSet = connection.createDataSet(); - - ITableFilter filter = new DatabaseSequenceFilter(connection); - truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); - - truncateDataSet = new FilteredDataSet(new AbstractTableFilter() - { - - @Override - public boolean isValidName(String tableName) throws DataSetException - { - return !StringUtils.contains(tableName, "$"); - } - }, truncateDataSet); - - log.debug("Sorted dataset generated"); - } - - IDataSet orderedDataset = new FilteredDataSet(new AbstractTableFilter() - { - - @Override - public boolean isValidName(String tableName) throws DataSetException - { - return !StringUtils.contains(tableName, "$"); - } - }, dataSet); - - log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); - log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); - - // if a sorted dataset is available, use table sequence for sorting - if (truncateDataSet != null) - { - ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); - orderedDataset = new FilteredDataSet(filter, dataSet); - } - - try - { - - if (truncateDataSet != null) - { - DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); - } - if (dataSet != null) - { - DatabaseOperation.INSERT.execute(connection, orderedDataset); - } - } - finally - { - connection.close(); - } - } - - /** - * @return - * @throws SQLException - */ - private IDatabaseConnection getDbUnitConnection() throws SQLException - { - DataSource dataSource = (DataSource) ctx.getBean(DATASOURCE_BEAN_NAME); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection(), getSchema()); - return connection; - } - - private String getDataFileName(String extension) - { - return MessageFormat.format(DATAFILE_PATTERN, ClassUtils.getShortClassName(getClass()), extension); - } - - private IDataSet loadDataSet(String datesetFile) throws IOException, DataSetException - { - InputStream is = getClass().getResourceAsStream(datesetFile); - IDataSet dataSet = null; - - if (is != null) - { - log.debug("loading dataset {}", datesetFile); - dataSet = datesetFile.endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is); - is.close(); - } - - return dataSet; - } -} Copied: tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java (from rev 201, trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java) =================================================================== --- tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java (rev 0) +++ tags/openutils-testing-testng-1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-02-05 17:42:52 UTC (rev 206) @@ -0,0 +1,285 @@ +/* + * Copyright 2005 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing.testng; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.SQLException; +import java.text.MessageFormat; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.dbunit.DatabaseUnitException; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.DatabaseSequenceFilter; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.FilteredDataSet; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.AbstractTableFilter; +import org.dbunit.dataset.filter.ITableFilter; +import org.dbunit.dataset.filter.SequenceTableFilter; +import org.dbunit.dataset.xml.XmlDataSet; +import org.dbunit.operation.DatabaseOperation; +import org.hibernate.SessionFactory; +import org.springframework.orm.hibernate3.SessionFactoryUtils; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +@Test +public class DbUnitTestCase extends SpringTestCase +{ + + /** + * name for the dataSource bean in Spring context. + */ + private static final String DATASOURCE_BEAN_NAME = "dataSource"; + + /** + * Pattern for dbunit file loaded before a test. MessageFormat format with two placeholders: class name and + * extension. + */ + private static final String DATAFILE_PATTERN = "/{0}-load.{1}"; + + protected static IDataSet truncateDataSet; + + /** + * Hibernate session factory. + */ + private SessionFactory sessionFactory; + + /** + * Optional schema (needed for ORACLE). + * @return <code>null</code> + */ + protected String getSchema() + { + return null; + } + + /** + * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> + * @return <code>true</code> if deferred close should be used + */ + protected boolean mimicSessionFilter() + { + return true; + } + + /** + * Setup the Database before running the test method. + * @throws Exception Any exception. + */ + @SuppressWarnings("unchecked") + @BeforeMethod + protected void setUpDbUnit() throws Exception + { + // mimic the Spring OpenSessionInViewFilter + if (mimicSessionFilter()) + { + Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); + if (sfbeans.isEmpty()) + { + Assert.fail("No bean of type org.hibernate.SessionFactory found in spring context"); + } + this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); + + SessionFactoryUtils.initDeferredClose(this.sessionFactory); + } + + // check for xml + IDataSet dataSet = loadDataSet(getDataFileName("xml")); + + if (dataSet == null) + { + // check for excel + dataSet = loadDataSet(getDataFileName("xls")); + } + + if (dataSet != null) + { + importDataSet(dataSet); + } + else + { + log.debug("No test data found with name [{}]", getDataFileName("xml/xls")); + } + } + + /** + * Exports a database to an Excel file + * @param fileName The file name we save the Excel dump to. + * @throws IOException An IO Exception. + * @throws DataSetException A dataset exception. + * @throws SQLException A SQL Exception. + */ + protected void exportDbToXls(String fileName) throws IOException, DataSetException, SQLException + { + IDatabaseConnection connection = getDbUnitConnection(); + + IDataSet fullDataSet = connection.createDataSet(); + + File outFile = new File(fileName); + OutputStream fos = new FileOutputStream(outFile); + XlsDataSet.write(fullDataSet, fos); + fos.close(); + } + + /** + * Cleans the database after we run the tests. + * @throws Exception Any exception. + */ + @AfterMethod + protected void tearDownDbUnit() throws Exception + { + if (mimicSessionFilter()) + { + // close open hibernate sessions, mimic the OpenSessionInViewFilter + SessionFactoryUtils.processDeferredClose(this.sessionFactory); + } + + // regenerate db initial state + String datesetFileName = "/initial-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + log.debug("Restoring db state"); + + IDataSet dataSet = new XmlDataSet(testData); + + IDatabaseConnection connection = getDbUnitConnection(); + + try + { + DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); + } + finally + { + connection.close(); + } + } + } + + private void importDataSet(IDataSet dataSet) throws SQLException, DataSetException, DatabaseUnitException + { + IDatabaseConnection connection = getDbUnitConnection(); + + if (truncateDataSet == null) + { + log.debug("Generating sorted dataset for initial cleanup"); + IDataSet unsortedTruncateDataSet = connection.createDataSet(); + + ITableFilter filter = new DatabaseSequenceFilter(connection); + truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); + + truncateDataSet = new FilteredDataSet(new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + return !StringUtils.contains(tableName, "$"); + } + }, truncateDataSet); + + log.debug("Sorted dataset generated"); + } + + IDataSet orderedDataset = new FilteredDataSet(new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + return !StringUtils.contains(tableName, "$"); + } + }, dataSet); + + log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); + log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); + + // if a sorted dataset is available, use table sequence for sorting + if (truncateDataSet != null) + { + ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); + orderedDataset = new FilteredDataSet(filter, dataSet); + } + + try + { + + if (truncateDataSet != null) + { + DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); + } + if (dataSet != null) + { + DatabaseOperation.INSERT.execute(connection, orderedDataset); + } + } + finally + { + connection.close(); + } + } + + /** + * @return + * @throws SQLException + */ + private IDatabaseConnection getDbUnitConnection() throws SQLException + { + DataSource dataSource = (DataSource) ctx.getBean(DATASOURCE_BEAN_NAME); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection(), getSchema()); + return connection; + } + + private String getDataFileName(String extension) + { + return MessageFormat.format(DATAFILE_PATTERN, ClassUtils.getShortClassName(getClass()), extension); + } + + private IDataSet loadDataSet(String datesetFile) throws IOException, DataSetException + { + InputStream is = getClass().getResourceAsStream(datesetFile); + IDataSet dataSet = null; + + if (is != null) + { + log.debug("loading dataset {}", datesetFile); + dataSet = datesetFile.endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is); + is.close(); + } + + return dataSet; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |