|
From: <gca...@us...> - 2012-05-21 09:16:48
|
Revision: 4048
http://openutils.svn.sourceforge.net/openutils/?rev=4048&view=rev
Author: gcatania
Date: 2012-05-21 09:16:37 +0000 (Mon, 21 May 2012)
Log Message:
-----------
Merged revisions 4045-4047 via svnmerge from
https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-bshd5
........
r4045 | gcatania | 2012-05-21 10:48:00 +0200 (Mon, 21 May 2012) | 1 line
BSHD-2 cleanup legacy example implementation
........
r4046 | gcatania | 2012-05-21 10:54:27 +0200 (Mon, 21 May 2012) | 1 line
BSHD-2 source cleanup
........
r4047 | gcatania | 2012-05-21 11:03:05 +0200 (Mon, 21 May 2012) | 1 line
dependency cleanup, updates
........
Revision Links:
--------------
http://openutils.svn.sourceforge.net/openutils/?rev=4045&view=rev
http://openutils.svn.sourceforge.net/openutils/?rev=4046&view=rev
http://openutils.svn.sourceforge.net/openutils/?rev=4047&view=rev
Modified Paths:
--------------
branches/openutils-bshd5-backport/pom.xml
branches/openutils-bshd5-backport/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java
Removed Paths:
-------------
branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/EnhancedExample.java
Property Changed:
----------------
branches/openutils-bshd5-backport/
branches/openutils-bshd5-backport/pom.xml
branches/openutils-bshd5-backport/src/
Property changes on: branches/openutils-bshd5-backport
___________________________________________________________________
Modified: svnmerge-integrated
- /trunk/openutils-bshd5:1-4039
+ /trunk/openutils-bshd5:1-4040,4042-4047
Added: svn:mergeinfo
+ /trunk/openutils-bshd5:4045-4047*
Modified: branches/openutils-bshd5-backport/pom.xml
===================================================================
--- branches/openutils-bshd5-backport/pom.xml 2012-05-21 09:03:05 UTC (rev 4047)
+++ branches/openutils-bshd5-backport/pom.xml 2012-05-21 09:16:37 UTC (rev 4048)
@@ -72,17 +72,6 @@
</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>
@@ -123,37 +112,6 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-annotations</artifactId>
- <version>${hibernate.annotations.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>avalon-framework</groupId>
- <artifactId>avalon-framework</artifactId>
- </exclusion>
- <exclusion>
- <groupId>logkit</groupId>
- <artifactId>logkit</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.8.0</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
@@ -164,7 +122,7 @@
<version>2.4</version>
</dependency>
<dependency>
- <groupId>javassist</groupId>
+ <groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
@@ -190,7 +148,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <version>5.14.6</version>
+ <version>6.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -199,11 +157,31 @@
<version>2.2.6</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>${hibernate.annotations.version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>logkit</groupId>
+ <artifactId>logkit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<properties>
<spring.version>2.5.5</spring.version>
<hibernate.version>3.3.1.GA</hibernate.version>
<hibernate.annotations.version>3.4.0.GA</hibernate.annotations.version>
- <javassist.version>3.8.0.GA</javassist.version>
+ <javassist.version>3.14.0-GA</javassist.version>
</properties>
-</project>
\ No newline at end of file
+</project>
Property changes on: branches/openutils-bshd5-backport/pom.xml
___________________________________________________________________
Added: svn:mergeinfo
+ /trunk/openutils-bshd5/pom.xml:4045-4047
Property changes on: branches/openutils-bshd5-backport/src
___________________________________________________________________
Added: svn:mergeinfo
+ /trunk/openutils-bshd5/src:4045-4047
Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java
===================================================================
--- branches/openutils-bshd5-backport/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2012-05-21 09:03:05 UTC (rev 4047)
+++ branches/openutils-bshd5-backport/src/main/java/it/openutils/dao/hibernate/HibernateDAOImpl.java 2012-05-21 09:16:37 UTC (rev 4048)
@@ -37,6 +37,7 @@
import java.util.Map;
import org.aopalliance.aop.AspectException;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
@@ -54,7 +55,6 @@
import org.springframework.aop.framework.AopContext;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-import org.springframework.util.CollectionUtils;
/**
@@ -132,7 +132,6 @@
return (List<T>) getHibernateTemplate().execute(new HibernateCallback()
{
- @SuppressWarnings("unchecked")
public List<T> doInHibernate(final Session ses) throws HibernateException
{
Criteria crit = ses.createCriteria(getReferenceClass());
@@ -158,7 +157,6 @@
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
public List<T> find(String query)
{
return getHibernateTemplate().find(query);
@@ -169,7 +167,7 @@
*/
public List<T> find(String query, Object paramValue, Type paramType)
{
- return getThis().find(query, new Object[]{paramValue }, new Type[]{paramType });
+ return getThis().find(query, new Object[]{paramValue}, new Type[]{paramType});
}
/**
@@ -180,7 +178,6 @@
return (List<T>) getHibernateTemplate().execute(new HibernateCallback()
{
- @SuppressWarnings("unchecked")
public List<T> doInHibernate(final Session ses) throws HibernateException
{
// hibernate 3
@@ -346,7 +343,6 @@
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
public K save(T obj)
{
return (K) getHibernateTemplate().save(obj);
@@ -408,7 +404,6 @@
return (T) getHibernateTemplate().execute(new HibernateCallback()
{
- @SuppressWarnings("unchecked")
public T doInHibernate(final Session ses) throws HibernateException
{
return (T) ses.merge(obj);
@@ -561,7 +556,6 @@
return (List<Object>) getHibernateTemplate().execute(new HibernateCallback()
{
- @SuppressWarnings("unchecked")
public List<Object> doInHibernate(final Session ses) throws HibernateException
{
Query q = ses.getNamedQuery(name);
@@ -593,7 +587,6 @@
return (List<Object>) getHibernateTemplate().execute(new HibernateCallback()
{
- @SuppressWarnings("unchecked")
public List<Object> doInHibernate(final Session ses) throws HibernateException
{
Query q = ses.getNamedQuery(name);
@@ -706,7 +699,6 @@
/**
* @return This is needed as for http://opensource.atlassian.com/projects/spring/browse/SPR-2226
*/
- @SuppressWarnings("unchecked")
private HibernateDAO<T, K> getThis()
{
try
@@ -864,7 +856,6 @@
return crit;
}
- @SuppressWarnings("unchecked")
public List<R> doInHibernate(Session session) throws HibernateException, SQLException
{
return createCriteria(session).list();
Deleted: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/EnhancedExample.java
===================================================================
--- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2012-05-21 09:03:05 UTC (rev 4047)
+++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2012-05-21 09:16:37 UTC (rev 4048)
@@ -1,337 +0,0 @@
-/**
- *
- * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
- *
- * Copyright(C) 2005-2012, Openmind S.r.l. http://www.openmindonline.it
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl-2.1.html
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-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.Collections;
-import java.util.Date;
-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;
-
-
-/**
- * @deprecated this example implementation does not take into account hibernate metadata, see BSHD-5. Use ExampleTree
- * instead
- * @author Fabrizio Giustina
- * @version $Id: $
- */
-@Deprecated
-public final class EnhancedExample
-{
-
- /**
- * Logger.
- */
- private static Logger log = LoggerFactory.getLogger(EnhancedExample.class);
-
- private Map<String, ? extends FilterMetadata> metadata;
-
- private EnhancedExample(
- final Criteria crit,
- final Object filter,
- final Map<String, ? extends FilterMetadata> metadata)
- {
- this.metadata = metadata == null ? Collections.<String, FilterMetadata> emptyMap() : 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 - filter metadata
- * @throws HibernateException exception while building the criteria
- */
- public static void create(final Criteria crit, final Object filter,
- final Map<String, ? extends 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(final Criteria crit, final String propertyName, final Object value,
- final 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 (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 need to analize content
-
- for (Object element : ((Collection< ? >) 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
- */
- @SuppressWarnings("unchecked")
- private boolean containsSomething(final Object bean)
- {
-
- if (bean == null)
- {
- return false;
- }
- if (isSimpleType(bean) || bean.getClass().isEnum())
- {
- return true;
- }
-
- 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
- */
- @SuppressWarnings("unchecked")
- private void fillCriteria(final String parentPropertyName, final Criteria crit, final 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(final 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.
|