From: <fg...@us...> - 2011-06-04 07:59:35
|
Revision: 3498 http://openutils.svn.sourceforge.net/openutils/?rev=3498&view=rev Author: fgiust Date: 2011-06-04 07:59:28 +0000 (Sat, 04 Jun 2011) Log Message: ----------- BSHD-9 pagination Added Paths: ----------- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResult.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultImpl.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultUtils.java Added: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResult.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResult.java (rev 0) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResult.java 2011-06-04 07:59:28 UTC (rev 3498) @@ -0,0 +1,75 @@ +/** + * + * openutils base Spring-Hibernate DAO for java 5.0 (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) ${project.inceptionYear}-2011, 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.paging; + +import java.io.Serializable; +import java.util.Collection; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface PaginatedResult<T> extends Serializable +{ + + /** + * Gets the maximum number of results per page + * @return the maximum number of results per page + */ + int getItemsPerPage(); + + /** + * Gets the page number (1, 2, 3...) + * @return the page number (1, 2, 3...) + */ + int getPage(); + + /** + * Gets the total number of results that would be retrieved without pagination. + * @return the total number of results that would be retrieved without pagination. + */ + int getTotalSize(); + + /** + * Gets the total number of pages + * @return total number of pages + */ + int getNumberOfPages(); + + /** + * Gets an iterator over the results + * @return an iterator over the results + */ + Collection<T> getItems(); + + /** + * Returns the fist result if available, null otherwise. + * @return the fist result if available, null otherwise. + */ + T getFirstResult(); + +} Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResult.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultImpl.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultImpl.java (rev 0) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultImpl.java 2011-06-04 07:59:28 UTC (rev 3498) @@ -0,0 +1,120 @@ +/** + * + * openutils base Spring-Hibernate DAO for java 5.0 (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) ${project.inceptionYear}-2011, 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.paging; + +import java.util.Collection; + + +/** + * @author fgiust + * @version $Id$ + */ +public class PaginatedResultImpl<T> implements PaginatedResult<T> +{ + + private final int itemsPerPage; + + private final int pageNumberStartingFromOne; + + private final int totalSize; + + private Collection<T> results; + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * @param itemsPerPage + * @param pageNumberStartingFromOne + * @param totalSize + */ + public PaginatedResultImpl(int itemsPerPage, int pageNumberStartingFromOne, int totalSize) + { + this.itemsPerPage = itemsPerPage; + this.pageNumberStartingFromOne = pageNumberStartingFromOne; + this.totalSize = totalSize; + } + + /** + * {@inheritDoc} + */ + public int getItemsPerPage() + { + return itemsPerPage; + } + + /** + * {@inheritDoc} + */ + public int getPage() + { + return pageNumberStartingFromOne; + } + + /** + * {@inheritDoc} + */ + public int getTotalSize() + { + return totalSize; + } + + /** + * {@inheritDoc} + */ + public int getNumberOfPages() + { + return itemsPerPage > 0 ? (int) Math.round(Math.ceil(((float) totalSize / (float) itemsPerPage))) : 1; + } + + /** + * {@inheritDoc} + */ + public Collection<T> getItems() + { + return this.results; + } + + /** + * {@inheritDoc} + */ + public T getFirstResult() + { + if (this.results != null && this.results.size() > 0) + { + return this.results.iterator().next(); + } + return null; + } + + public void setResults(Collection<T> results) + { + this.results = results; + } + +} Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultUtils.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultUtils.java (rev 0) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultUtils.java 2011-06-04 07:59:28 UTC (rev 3498) @@ -0,0 +1,91 @@ +/** + * + * openutils base Spring-Hibernate DAO for java 5.0 (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) ${project.inceptionYear}-2011, 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.paging; + +import java.util.Collection; + +import org.hibernate.Criteria; +import org.hibernate.criterion.Projections; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fgiust + * @version $Id$ + */ +public final class PaginatedResultUtils +{ + + /** + * Logger. + */ + static Logger log = LoggerFactory.getLogger(PaginatedResultUtils.class); + + /** + * Executes a criteria query and returns a paginated result. + * @param <T> element type + * @param criteria criteria query + * @param pagesize number of elements per page + * @param pageNumberStartingFromOne page number, starting from 1 + * @return an instance of Paginated result + */ + @SuppressWarnings("unchecked") + public static <T> PaginatedResult<T> search(Criteria criteria, int pagesize, int pageNumberStartingFromOne) + { + if (pagesize > 0) + { + criteria.setMaxResults(pagesize); + } + + if (pageNumberStartingFromOne > 1 && pagesize > 0) + { + int firstresult = (pageNumberStartingFromOne - 1) * pagesize; + log.debug("Setting first result {}", firstresult); + criteria.setFirstResult(firstresult); + } + + Collection<T> results = criteria.list(); + + // reset firstresult for count + criteria.setFirstResult(0); + Number count = (Number) criteria.setProjection(Projections.count("id")).uniqueResult(); + + if (count == null) + { + count = 0; + } + + PaginatedResultImpl<T> result = new PaginatedResultImpl<T>( + pagesize, + pageNumberStartingFromOne, + count.intValue()); + + result.setResults(results); + + return result; + } +} Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/paging/PaginatedResultUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gca...@us...> - 2012-06-29 15:10:29
|
Revision: 4076 http://openutils.svn.sourceforge.net/openutils/?rev=4076&view=rev Author: gcatania Date: 2012-06-29 15:10:22 +0000 (Fri, 29 Jun 2012) Log Message: ----------- BSHD-15 source code refactor and cleanup Modified Paths: -------------- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java Added Paths: ----------- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ExcludeBackrefPropertySelector.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 2012-06-29 14:26:07 UTC (rev 4075) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2012-06-29 15:10:22 UTC (rev 4076) @@ -25,11 +25,10 @@ package it.openutils.hibernate.example; +import it.openutils.hibernate.selectors.ExcludeBackrefPropertySelector; + import java.io.Serializable; -import java.lang.reflect.Array; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -37,7 +36,6 @@ import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.StringUtils; import org.hibernate.Criteria; import org.hibernate.EntityMode; import org.hibernate.Hibernate; @@ -50,7 +48,6 @@ import org.hibernate.criterion.Restrictions; import org.hibernate.engine.SessionImplementor; import org.hibernate.metadata.ClassMetadata; -import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.type.Type; @@ -67,7 +64,7 @@ private Character escapeCharacter; - private PropertySelector selector = new ExcludeBackrefPropertySelector(); // BSHD-15 + private PropertySelector selector = new ExcludeBackrefPropertySelector(ExampleTreePropertySelectorSupport.NOT_NULL); // BSHD-15 private MatchMode matchMode; @@ -260,7 +257,7 @@ private void createSubExamples(Criteria crit, Object entity, String[] walkedProperties) { - String associationPath = getAssociationPath(walkedProperties); + String associationPath = ExampleTreeUtils.getPath(walkedProperties); crit.add(example(entity, associationPath)); for (Criterion c : getAdditionalConditions(associationPath)) { @@ -281,7 +278,7 @@ continue; } String propertyName = names[i]; - if (alreadyWalked(walkedProperties, propertyName)) + if (ExampleTreeUtils.alreadyWalked(walkedProperties, propertyName)) { continue; } @@ -289,7 +286,7 @@ Object propertyValue = classMetadata.getPropertyValue(entity, propertyName, entityMode); if (propertyType.isCollectionType()) { - propertyValue = getValueFromCollection(propertyValue); + propertyValue = ExampleTreeUtils.getValueFromCollection(propertyValue); } if (propertyValue == null) { @@ -298,7 +295,7 @@ } Criteria subCrit = crit.createCriteria(propertyName); - String[] subProperties = append(walkedProperties, propertyName); + String[] subProperties = ExampleTreeUtils.append(walkedProperties, propertyName); createSubExamples(subCrit, propertyValue, subProperties); } } @@ -322,11 +319,6 @@ } } - private String getAssociationPath(String[] walkedProperties) - { - return walkedProperties.length > 0 ? StringUtils.join(walkedProperties, '.') : StringUtils.EMPTY; - } - private Example example(Object entity, String associationPath) { Example ex = Example.create(entity); @@ -364,128 +356,13 @@ return result; } - /** - * check the property with the input name was already walked in the input path - * @param path the current path - * @param propertyName the property name about to be walked - * @return true if the property with the input name was already walked in the input path - */ - private boolean alreadyWalked(String[] walkedProperties, String propertyName) - { - if (walkedProperties.length <= 2) - { - return false; - } - String parent = walkedProperties[walkedProperties.length - 1]; - boolean lastWasChild = false; - for (int i = walkedProperties.length - 2; i > 0; i--) - { - String currPropertyName = walkedProperties[i]; - if (currPropertyName.equals(propertyName)) - { - lastWasChild = true; - continue; - } - if (lastWasChild) - { - if (currPropertyName.equals(parent)) - { - return true; - } - else - { - lastWasChild = false; - } - } - } - return false; - } - - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - private Object getValueFromCollection(Object collectionValue) - { - if (collectionValue != null) - { - if (collectionValue instanceof Collection< ? >) - { - Collection< ? > coll = (Collection< ? >) collectionValue; - int size = coll.size(); - if (size == 1) - { - return coll.iterator().next(); - } - if (size > 1) - { - throw new IllegalArgumentException("More than one element in filter collection is unsupported."); - } - } - Class< ? extends Object> clazz = collectionValue.getClass(); - if (clazz.isArray()) - { - int length = Array.getLength(collectionValue); - if (length == 1) - { - return Array.get(collectionValue, 0); - } - if (length > 1) - { - throw new IllegalArgumentException("More than one element in filter array is unsupported."); - } - } - // TODO other cases? - } - return null; - } - - private String[] append(String[] propertyNames, String propertyName) - { - String[] result = Arrays.copyOf(propertyNames, propertyNames.length + 1); - result[propertyNames.length] = propertyName; - return result; - } } - } /** - * support for BSHD-15 - * @author gcatania - * @version $Id$ - */ -class ExcludeBackrefPropertySelector implements PropertySelector -{ - - private static final long serialVersionUID = -2803322309158823550L; - - private final PropertySelector selector; - - public ExcludeBackrefPropertySelector(PropertySelector selector) - { - this.selector = selector; - } - - public ExcludeBackrefPropertySelector() - { - selector = ExampleTreePropertySelectorSupport.NOT_NULL; - } - - public boolean include(Object propertyValue, String propertyName, Type type) - { - if (BackrefPropertyAccessor.UNKNOWN.equals(propertyValue)) - { - return false; - } - return selector.include(propertyValue, propertyName, type); - } - -} - - -/** * workaround to {@link Example} not exposing internal property selectors * @author gcatania - * @version $Id$ */ @SuppressWarnings({"serial", "static-method"}) class ExampleTreePropertySelectorSupport Added: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java (rev 0) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2012-06-29 15:10:22 UTC (rev 4076) @@ -0,0 +1,125 @@ +/** + * Copyright (c) Energeya LLC. All rights reserved. http://www.energeya.com + */ +package it.openutils.hibernate.example; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Collection; + +import org.apache.commons.lang3.StringUtils; + + +/** + * @author gcatania + * @version $Id$ + */ +final class ExampleTreeUtils +{ + + private ExampleTreeUtils() + { + } + + /** + * check the property with the input name was already walked in the input path + * @param path the current path + * @param propertyName the property name about to be walked + * @return true if the property with the input name was already walked in the input path + */ + public static boolean alreadyWalked(String[] walkedProperties, String propertyName) + { + if (walkedProperties.length <= 2) + { + return false; + } + String parent = walkedProperties[walkedProperties.length - 1]; + boolean lastWasChild = false; + for (int i = walkedProperties.length - 2; i > 0; i--) + { + String currPropertyName = walkedProperties[i]; + if (currPropertyName.equals(propertyName)) + { + lastWasChild = true; + continue; + } + if (lastWasChild) + { + if (currPropertyName.equals(parent)) + { + return true; + } + else + { + lastWasChild = false; + } + } + } + return false; + } + + /** + * retrieves a value from a collection + * @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 + { + if (collectionValue != null) + { + if (collectionValue instanceof Collection< ? >) + { + Collection< ? > coll = (Collection< ? >) collectionValue; + int size = coll.size(); + if (size == 1) + { + return coll.iterator().next(); + } + if (size > 1) + { + throw new IllegalArgumentException("More than one element in filter collection is unsupported."); + } + } + Class< ? extends Object> clazz = collectionValue.getClass(); + if (clazz.isArray()) + { + int length = Array.getLength(collectionValue); + if (length == 1) + { + return Array.get(collectionValue, 0); + } + if (length > 1) + { + throw new IllegalArgumentException("More than one element in filter array is unsupported."); + } + } + // TODO other cases? + } + return null; + } + + /** + * @param strings an array of strings + * @param s the string to append + * @return a new array containing the input string array plus the input string at the end + */ + public static String[] append(String[] strings, String s) + { + String[] result = Arrays.copyOf(strings, strings.length + 1); + result[strings.length] = s; + return result; + } + + /** + * constructs the association path from an array of property names + * @param propertyNames the walked properties + * @return the association path + */ + public static String getPath(String[] propertyNames) + { + return propertyNames.length > 0 ? StringUtils.join(propertyNames, '.') : StringUtils.EMPTY; + } + +} Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native 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 2012-06-29 14:26:07 UTC (rev 4075) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2012-06-29 15:10:22 UTC (rev 4076) @@ -25,15 +25,13 @@ package it.openutils.hibernate.example; -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.Collection; +import it.openutils.hibernate.selectors.ExcludeBackrefPropertySelector; + import java.util.HashMap; import java.util.Map; import java.util.Set; import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.hibernate.Criteria; import org.hibernate.EntityMode; import org.hibernate.Hibernate; @@ -117,7 +115,7 @@ private void createSubExamples(Criteria crit, Object entity, String[] walkedProperties) { - String path = getPath(walkedProperties); + String path = ExampleTreeUtils.getPath(walkedProperties); Map<String, FilterMetadata> currFilterMetadata = getFilterMetadata(path); crit.add(example(entity, currFilterMetadata.keySet())); ClassMetadata classMetadata = sessionFactory.getClassMetadata(Hibernate.getClass(entity)); @@ -126,7 +124,7 @@ for (int i = 0; i < types.length; i++) { String propertyName = names[i]; - if (alreadyWalked(walkedProperties, propertyName)) + if (ExampleTreeUtils.alreadyWalked(walkedProperties, propertyName)) { continue; } @@ -147,7 +145,7 @@ if (propertyType.isCollectionType()) { - propertyValue = getValueFromCollection(propertyValue); + propertyValue = ExampleTreeUtils.getValueFromCollection(propertyValue); } if (propertyValue == null) { @@ -156,7 +154,7 @@ } Criteria subCrit = crit.createCriteria(propertyName); - String[] subProperties = append(walkedProperties, propertyName); + String[] subProperties = ExampleTreeUtils.append(walkedProperties, propertyName); createSubExamples(subCrit, propertyValue, subProperties); } } @@ -185,15 +183,10 @@ return result; } - private String getPath(String[] walkedProperties) - { - return walkedProperties.length > 0 ? StringUtils.join(walkedProperties, '.') : StringUtils.EMPTY; - } - private Example example(Object entity, Set<String> propertiesToExclude) { Example ex = Example.create(entity); - ex.setPropertySelector(new ExcludeBackrefPropertySelector()); // BSHD-15 + ex.setPropertySelector(new ExcludeBackrefPropertySelector(ExampleTreePropertySelectorSupport.NOT_NULL)); // BSHD-15 for (String propertyName : propertiesToExclude) { // skip properties handled by filterMetadata @@ -202,84 +195,6 @@ return ex; } - /** - * check the property with the input name was already walked in the input path - * @param path the current path - * @param propertyName the property name about to be walked - * @return true if the property with the input name was already walked in the input path - */ - private boolean alreadyWalked(String[] walkedProperties, String propertyName) - { - if (walkedProperties.length <= 2) - { - return false; - } - String parent = walkedProperties[walkedProperties.length - 1]; - boolean lastWasChild = false; - for (int i = walkedProperties.length - 2; i > 0; i--) - { - String currPropertyName = walkedProperties[i]; - if (currPropertyName.equals(propertyName)) - { - lastWasChild = true; - continue; - } - if (lastWasChild) - { - if (currPropertyName.equals(parent)) - { - return true; - } - else - { - lastWasChild = false; - } - } - } - return false; - } - - private Object getValueFromCollection(Object collectionValue) - { - if (collectionValue != null) - { - if (collectionValue instanceof Collection< ? >) - { - Collection< ? > coll = (Collection< ? >) collectionValue; - int size = coll.size(); - if (size == 1) - { - return coll.iterator().next(); - } - if (size > 1) - { - throw new IllegalArgumentException("More than one element in filter collection is unsupported."); - } - } - Class< ? extends Object> clazz = collectionValue.getClass(); - if (clazz.isArray()) - { - int length = Array.getLength(collectionValue); - if (length == 1) - { - return Array.get(collectionValue, 0); - } - if (length > 1) - { - throw new IllegalArgumentException("More than one element in filter array is unsupported."); - } - } - // TODO other cases? - } - return null; - } - - private String[] append(String[] propertyNames, String propertyName) - { - String[] result = Arrays.copyOf(propertyNames, propertyNames.length + 1); - result[propertyNames.length] = propertyName; - return result; - } } } Added: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ExcludeBackrefPropertySelector.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ExcludeBackrefPropertySelector.java (rev 0) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ExcludeBackrefPropertySelector.java 2012-06-29 15:10:22 UTC (rev 4076) @@ -0,0 +1,44 @@ +/** + * Copyright (c) Energeya LLC. All rights reserved. http://www.energeya.com + */ +package it.openutils.hibernate.selectors; + +import java.io.Serializable; + +import org.hibernate.criterion.Example.PropertySelector; +import org.hibernate.property.BackrefPropertyAccessor; +import org.hibernate.type.Type; + + +/** + * utility selector to avoid class cast exceptions on {@link BackrefPropertyAccessor.UNKNOWN} + * @see BSHD-15 + * @author gcatania + * @version $Id$ + */ +public class ExcludeBackrefPropertySelector implements PropertySelector, Serializable +{ + + private static final long serialVersionUID = -2803322309158823550L; + + private final PropertySelector selector; + + public ExcludeBackrefPropertySelector(PropertySelector selector) + { + if (selector == null) + { + throw new NullPointerException("Null selector."); + } + this.selector = selector; + } + + public boolean include(Object propertyValue, String propertyName, Type type) + { + if (BackrefPropertyAccessor.UNKNOWN.equals(propertyValue)) + { + return false; + } + return selector.include(propertyValue, propertyName, type); + } + +} Property changes on: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/selectors/ExcludeBackrefPropertySelector.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |