|
From: <gca...@us...> - 2014-08-01 17:01:16
|
Revision: 4585
http://openutils.svn.sourceforge.net/openutils/?rev=4585&view=rev
Author: gcatania
Date: 2014-08-01 17:01:13 +0000 (Fri, 01 Aug 2014)
Log Message:
-----------
BSHD-25 improve error reporting in getValueFromCollection()
Modified Paths:
--------------
trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java
trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java
trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java
Modified: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java
===================================================================
--- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2014-07-08 11:15:38 UTC (rev 4584)
+++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2014-08-01 17:01:13 UTC (rev 4585)
@@ -306,7 +306,7 @@
Object propertyValue = classMetadata.getPropertyValue(entity, propertyName);
if (propertyType.isCollectionType())
{
- propertyValue = ExampleTreeUtils.getValueFromCollection(propertyValue);
+ propertyValue = ExampleTreeUtils.getValueFromCollection(propertyName, propertyValue);
}
if (propertyValue == null)
{
@@ -365,7 +365,7 @@
* workaround to {@link Example} not exposing internal property selectors
* @author gcatania
*/
-@SuppressWarnings({"serial", "static-method"})
+@SuppressWarnings({"serial", "static-method" })
class ExampleTreePropertySelectorSupport
{
@@ -378,6 +378,7 @@
static final class AllPropertySelector implements PropertySelector
{
+ @Override
public boolean include(Object object, String propertyName, Type type)
{
return true;
@@ -392,6 +393,7 @@
static final class NotNullPropertySelector implements PropertySelector
{
+ @Override
public boolean include(Object object, String propertyName, Type type)
{
return object != null;
@@ -406,6 +408,7 @@
static final class NotNullOrZeroPropertySelector implements PropertySelector
{
+ @Override
public boolean include(Object object, String propertyName, Type type)
{
return object != null && (!(object instanceof Number) || ((Number) object).longValue() != 0);
Modified: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java
===================================================================
--- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2014-07-08 11:15:38 UTC (rev 4584)
+++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2014-08-01 17:01:13 UTC (rev 4585)
@@ -25,6 +25,7 @@
package it.openutils.hibernate.example;
import java.lang.reflect.Array;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
@@ -87,13 +88,15 @@
}
/**
- * retrieves a value from a collection
+ * retrieves a value from a collection property
+ * @param propertyName the property name (will be reported in the exception)
* @param collectionValue the collection
* @return a value
* @see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879
* @throws IllegalArgumentException if the input collection contains more than one value
*/
- public static Object getValueFromCollection(Object collectionValue) throws IllegalArgumentException
+ public static Object getValueFromCollection(String propertyName, Object collectionValue)
+ throws IllegalArgumentException
{
if (collectionValue != null)
{
@@ -107,8 +110,10 @@
}
if (size > 1)
{
- throw new IllegalArgumentException("More than one element in filter collection is unsupported.\n"
- + coll);
+ throw new IllegalArgumentException(MessageFormat.format(
+ "More than one element in filter collection is unsupported.\nproperty: {0}, value: {1}",
+ propertyName,
+ coll));
}
}
Class< ? extends Object> clazz = collectionValue.getClass();
@@ -121,7 +126,13 @@
}
if (length > 1)
{
- throw new IllegalArgumentException("More than one element in filter array is unsupported.");
+ throw new IllegalArgumentException(
+ MessageFormat
+ .format(
+ "More than one element in filter array is unsupported.\nproperty: {0}, value: {1} - length: {2}",
+ propertyName,
+ collectionValue,
+ length));
}
}
// TODO other cases?
Modified: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java
===================================================================
--- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2014-07-08 11:15:38 UTC (rev 4584)
+++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2014-08-01 17:01:13 UTC (rev 4585)
@@ -141,7 +141,7 @@
if (propertyType.isCollectionType())
{
- propertyValue = ExampleTreeUtils.getValueFromCollection(propertyValue);
+ propertyValue = ExampleTreeUtils.getValueFromCollection(propertyName, propertyValue);
}
if (propertyValue == null)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|