From: <fg...@us...> - 2007-01-30 17:11:52
|
Revision: 159 http://svn.sourceforge.net/openutils/?rev=159&view=rev Author: fgiust Date: 2007-01-30 09:09:39 -0800 (Tue, 30 Jan 2007) Log Message: ----------- handle Maps using filter metadata Modified Paths: -------------- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Modified: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2007-01-30 15:35:37 UTC (rev 158) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2007-01-30 17:09:39 UTC (rev 159) @@ -67,6 +67,11 @@ 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)) { @@ -83,10 +88,6 @@ fmd = FilterMetadata.EQUAL; } - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - fmd.createFilter(crit, simplePropertyName, value); } @@ -97,7 +98,7 @@ Date to = ((MutableDateRange) value).getTo(); if (from != null && to != null) { - log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to}); + log.debug("crit.add(Restrictions.between({},{}, {})", new Object[]{propertyName, from, to }); crit.add(Restrictions.between(propertyName, from, to)); } else if (from != null) @@ -117,26 +118,38 @@ { 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)) + for (Object element : ((Collection< ? extends Object>) 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 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 { - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils - .substringAfterLast(propertyName, ".") : propertyName; log.debug("crit.createCriteria({})", simplePropertyName); Criteria childrenCriteria = crit.createCriteria(simplePropertyName); fillCriteria(propertyName, childrenCriteria, value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |