From: <fg...@us...> - 2010-08-29 08:58:37
|
Revision: 2923 http://openutils.svn.sourceforge.net/openutils/?rev=2923&view=rev Author: fgiust Date: 2010-08-29 08:58:29 +0000 (Sun, 29 Aug 2010) Log Message: ----------- javadocs and code cleanup Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -19,9 +19,7 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; -import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.content2bean.Content2BeanException; import info.magnolia.content2bean.Content2BeanUtil; @@ -214,8 +212,7 @@ } catch (RepositoryException e) { - JCRQueryException jqe = new JCRQueryException(statement, e); - throw jqe; + throw new JCRQueryException(statement, e); } return new ResultIteratorImpl<K>(rows, hm) @@ -227,14 +224,8 @@ { try { - Content content = new AdvancedResultItemImpl(row, this.hm); - - return (K) Content2BeanUtil.toBean(content, true, theclass); + return (K) Content2BeanUtil.toBean(new AdvancedResultItemImpl(row, this.hm), true, theclass); } - catch (AccessDeniedException e) - { - throw new RuntimeException(e); - } catch (RepositoryException e) { throw new RuntimeException(e); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,6 +27,7 @@ import info.magnolia.link.LinkException; import info.magnolia.link.LinkTransformerManager; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -48,7 +49,7 @@ * @author fgiust * @version $Id$ */ -public class MappedDefaultContent extends DefaultContent +public class MappedDefaultContent extends DefaultContent implements Map<String, Object> { /** @@ -70,7 +71,7 @@ } /** - * @see java.util.Map#size() + * {@inheritDoc} */ public int size() { @@ -78,7 +79,7 @@ } /** - * @see java.util.Map#isEmpty() + * {@inheritDoc} */ public boolean isEmpty() { @@ -86,15 +87,15 @@ } /** - * @see java.util.Map#containsKey(java.lang.Object) + * {@inheritDoc} */ public boolean containsKey(Object key) { - return getNodeData((String) key).isExist() || hasProperty((String) key); + return getNodeData((String) key).isExist() || hasProperty(key); } /** - * @see java.util.Map#containsValue(java.lang.Object) + * {@inheritDoc} */ public boolean containsValue(Object value) { @@ -105,6 +106,8 @@ /** * Shortcut for Content.getNodeData(name).getString() or Content.getNodeData(name).getName(). * @see java.util.Map#get(Object) + * @param key property name + * @return property value */ public Object get(Object key) { @@ -117,16 +120,24 @@ { key = "UUID"; } - if (hasProperty((String) key)) + if (hasProperty(key)) { try { return PropertyUtils.getProperty(this, (String) key); } - catch (Exception e) + catch (IllegalAccessException e) { log.error("can't read property " + key + " from the node " + this, e); } + catch (InvocationTargetException e) + { + log.error("can't read property " + key + " from the node " + this, e); + } + catch (NoSuchMethodException e) + { + log.error("can't read property " + key + " from the node " + this, e); + } } } } @@ -187,6 +198,11 @@ return value; } + /** + * Check if there is a bean property with the given key + * @param key property name + * @return true if this is a valid javabean property + */ protected boolean hasProperty(Object key) { try @@ -200,16 +216,16 @@ } /** - * @see java.util.Map#put(java.lang.Object, java.lang.Object) + * {@inheritDoc} */ - public Object put(Object arg0, Object arg1) + public Object put(String key, Object value) { // not implemented, only get() is needed return null; } /** - * @see java.util.Map#remove(java.lang.Object) + * {@inheritDoc} */ public Object remove(Object key) { @@ -218,15 +234,15 @@ } /** - * @see java.util.Map#putAll(java.util.Map) + * {@inheritDoc} */ - public void putAll(Map t) + public void putAll(Map< ? extends String, ? extends Object> t) { // not implemented, only get() is needed } /** - * @see java.util.Map#clear() + * {@inheritDoc} */ public void clear() { @@ -234,51 +250,51 @@ } /** - * @see java.util.Map#keySet() + * {@inheritDoc} */ - public Set keySet() + public Set<String> keySet() { - Collection nodeDataCollection = getNodeDataCollection(); - Set keys = new HashSet(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Set<String> keys = new HashSet<String>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - keys.add(((NodeData) iter.next()).getName()); + keys.add(iter.next().getName()); } return keys; } /** - * @see java.util.Map#values() + * {@inheritDoc} */ - public Collection values() + public Collection<Object> values() { - Collection nodeDataCollection = getNodeDataCollection(); - Collection values = new ArrayList(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Collection<Object> values = new ArrayList<Object>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - values.add(((NodeData) iter.next()).getString()); + values.add(iter.next().getString()); } return values; } /** - * @see java.util.Map#entrySet() + * {@inheritDoc} */ - public Set entrySet() + public Set<Map.Entry<String, Object>> entrySet() { - Collection nodeDataCollection = getNodeDataCollection(); - Set keys = new HashSet(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Set<Map.Entry<String, Object>> keys = new HashSet<Map.Entry<String, Object>>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - NodeData nd = (NodeData) iter.next(); + NodeData nd = iter.next(); final String key = nd.getName(); final String value = nd.getString(); - keys.add(new Map.Entry() + keys.add(new Map.Entry<String, Object>() { - public Object getKey() + public String getKey() { return key; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -41,7 +41,7 @@ * @author fgiust * @version $Id$ */ -public class QueryExecutorHelper +public final class QueryExecutorHelper { /** @@ -49,6 +49,11 @@ */ private static Logger log = LoggerFactory.getLogger(QueryExecutorHelper.class); + private QueryExecutorHelper() + { + // don't instantiate + } + /** * Executes a jcr query. * @param stmt the statement of the jcr query @@ -56,8 +61,8 @@ * @param hm the HirarchyManager for obtaining the QueryManager * @param maxResults maximun number of results to retrieve * @param offset the index of the first result to retrieve (0, 1, 2, ...) - * @param spellCheckString - * @return + * @param spellCheckString the input string used for spell checking + * @return the execution result */ public static AdvancedResultImpl execute(String stmt, String language, HierarchyManager hm, int maxResults, int offset, String spellCheckString) Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -20,7 +20,8 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; /** - * The result of an advanced jcr query. + * The result of a jcr query. You can access to the actual result items using getItems(). This bean will also give you + * information about the total number of available items, the current page number, the total number of pages. * @author fgiust * @version $Id$ */ @@ -28,6 +29,11 @@ { /** + * An empty result. + */ + AdvancedResult EMPTY_RESULT = new EmptyResult(); + + /** * Gets the maximum number of results per page * @return the maximum number of results per page */ @@ -54,7 +60,8 @@ int getNumberOfPages(); /** - * Gets the suggestion from the spell checker + * Gets the suggestion from the spell checker. Note that spell checker must be configured in jackrabbit for this to + * work. See http://wiki.apache.org/jackrabbit/Search for details. * @return the suggestion from the spell checker */ String getSpellCheckerSuggestion(); @@ -68,6 +75,7 @@ /** * Gets an iterator over the results, transforming objects using content2bean while iterating * @param <K> destination class. + * @param theclass destination class. * @return an iterator over the results */ <K> ResultIterator<K> getItems(Class<K> theclass); @@ -78,10 +86,14 @@ */ AdvancedResultItem getFirstResult(); - public static AdvancedResult EMPTY_RESULT = new AdvancedResult() + /** + * @author fgiust + * @version $Id$ + */ + class EmptyResult implements AdvancedResult { - ResultIterator<AdvancedResultItem> iterator = new EmptyResultIterator(); + private ResultIterator<AdvancedResultItem> iterator = new EmptyResultIterator(); public int getTotalSize() { @@ -122,7 +134,7 @@ { return null; } - }; + } /** * @author fgiust Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -37,7 +37,8 @@ String getExcerpt(); /** - * Returns the excerpt. + * Returns the excerpt for a specific property. + * @param selector property to use for the excerpt * @return the excerpt */ String getExcerpt(String selector); @@ -49,7 +50,8 @@ double getScore(); /** - * Returns the score. + * Returns the score for a specific property. + * @param selector property to use for the score * @return the score */ double getScore(String selector); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -23,7 +23,6 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; /** @@ -38,7 +37,7 @@ * begin.set(1999, Calendar.JANUARY, 1); * Calendar end = Calendar.getInstance(); * end.set(2001, Calendar.DECEMBER, 31); - * + * * Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE) * .setBasePath("/pets") * .add(Restrictions.contains("@title", "Lucky")) @@ -50,7 +49,10 @@ * will be translated into the following xpath statement * * <pre> - * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))] order by @title descending + * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') + * and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') + * and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))] + * order by @title descending * </pre> * * Furthermore, you may want to have only a subset of the whole result set returned, much like in a MySQL limit clause. @@ -91,7 +93,6 @@ * This API was inspired by Hibernate's Criteria API. <br> * <br> * @see JCRCriteriaFactory#createCriteria() - * @see Restrictions * @see Order * @author Federico Grilli * @author fgiust @@ -130,9 +131,9 @@ Criteria setFirstResult(int firstResult); /** - * Get the results. <strong>The implementation should guarantee the caller that the returned Collection is never - * null</strong> + * Method kept in 2.x only for temporary backward compatibility. Always use execute(); * @return The Collection of matched query results. + * @throws JCRQueryException query exception * @deprecated use execute() */ @Deprecated @@ -153,7 +154,8 @@ Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); /** - * @param spellCheckString + * Sets the original input string for spell checking. + * @param spellCheckString the actual input string for spell checking * @return this (for method chaining) */ Criteria setSpellCheckString(String spellCheckString); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -58,6 +58,7 @@ /** * Sets the spellCheckString. * @param spellCheckString the spellCheckString to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setSpellCheckString(String spellCheckString) { @@ -68,6 +69,7 @@ /** * Sets the maxResults. * @param maxResults the maxResults to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setMaxResultsPerPage(int maxResults) { @@ -78,6 +80,7 @@ /** * Sets the offset. * @param offset the offset to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setOffset(int offset) { @@ -88,9 +91,9 @@ /** * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults * directly anymore. - * @param itemsPerPage - * @param pageNumberStartingFromOne - * @return + * @param itemsPerPage number of items per page + * @param pageNumberStartingFromOne page number (starting from 1) + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,10 +27,13 @@ /** + * Factory for criteria queries. Since mgnlcriteria 2.x always use the simple createCriteria() factory method. * @author fgrilli + * @author fgiust + * @author diego_schivo * @version $Id$ */ -public class JCRCriteriaFactory +public final class JCRCriteriaFactory { private JCRCriteriaFactory() @@ -38,7 +41,8 @@ } /** - * Creates a query criteria for dynamic query composition. + * Creates a query criteria for dynamic query composition. All the details can be set on the Criteria instance + * returned. * @return an AdvancedCriteriaImpl */ public static Criteria createCriteria() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -24,11 +24,15 @@ /** * Wraps a RowIterator, requiring subclasses to adapt each Row to a specific type. + * @param <T> the type of results you will get from this iterator. * @author fgiust * @version $Id$ */ public interface ResultIterator<T> extends RangeIterator { + /** + * {@inheritDoc} + */ T next(); } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,20 +27,22 @@ /** * Wraps a RowIterator, requiring subclasses to adapt each Row to a specific type. + * @param <T> type of results * @author fgiust * @version $Id$ */ public abstract class ResultIteratorImpl<T> implements ResultIterator<T> { + /** + * The jcr RowIterator + */ protected RowIterator rowIterator; - protected final HierarchyManager hm; - /** - * Local variable storing the next accessible result. Method hasNext() fetches it, method next() resets it. + * Magnolia Hierarchy Manager */ - private AdvancedResultItem next; + protected final HierarchyManager hm; /** * @param rowIterator @@ -101,7 +103,7 @@ /** * Transforms a Row instance, adapting it to a specific type. - * @param row + * @param row the jcr Row to wrap * @return a transformed version */ protected abstract T wrap(Row row); Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -0,0 +1,53 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright (C)2009 - 2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; + +import java.text.SimpleDateFormat; +import java.util.Locale; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Base abstract criterion, just to share some useful fields/constants that should not end up in the interface. + * @author fgiust + * @version $Id$ + */ +public abstract class BaseCriterion implements Criterion +{ + + /** + * Date format used for date formatting. + */ + protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSS", + Locale.ENGLISH); + + /** + * Stable serialVersionUID + */ + private static final long serialVersionUID = 42L; + + /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(getClass()); + +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -29,7 +29,7 @@ * @author fgrilli * @version $Id$ */ -public class BetweenExpression implements Criterion +public class BetweenExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = 6686395240415024541L; @@ -53,6 +53,9 @@ return propertyName + " between " + lo + " and " + hi; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(); @@ -69,11 +72,18 @@ else if (lo instanceof Calendar && hi instanceof Calendar) { Calendar cal = (Calendar) lo; - DATE_FORMAT.setCalendar(cal); - String fmt = DATE_FORMAT.format(cal.getTime()); Calendar cal2 = (Calendar) hi; - DATE_FORMAT.setCalendar(cal2); - String fmt2 = DATE_FORMAT.format(cal2.getTime()); + String fmt; + String fmt2; + + synchronized (DATE_FORMAT) + { + DATE_FORMAT.setCalendar(cal); + fmt = DATE_FORMAT.format(cal.getTime()); + DATE_FORMAT.setCalendar(cal2); + fmt2 = DATE_FORMAT.format(cal2.getTime()); + } + fragment.append(XS_DATETIME_FUNCTION + "('" + fmt Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -20,16 +20,11 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; import java.io.Serializable; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * An object-oriented representation of a query criterion that may be used as a restriction in a <tt>Criteria</tt> * query. Built-in criterion types are provided by the <tt>Restrictions</tt> factory class. This interface might be @@ -42,8 +37,9 @@ public interface Criterion extends Serializable { - Logger log = LoggerFactory.getLogger(Criterion.class); + String JCR_PRIMARYTYPE = "@jcr:primaryType"; + String ATTRIBUTE_SELECTOR = "@"; String JCR_PREFIX = "jcr:"; @@ -52,32 +48,16 @@ String ALL_ELEMENTS = "//*"; - String ANY_PROPERTY = "."; - String XS_DATETIME_FUNCTION = "xs:dateTime"; - String MIDNIGHT = "T00:00:00.000+00:00"; - - String T235959 = "T23:59:59.000+00:00"; - String NT_BASE = "nt:base"; - String NOT = " not("; - - String HYPHEN = "-"; - - int DAY_MAX = 10; - - int MONTH_MAX = 9; - - DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); - /** * Render the XPath fragment - * @param criteria - * @return String - * @throws JCRQueryException + * @param criteria input criteria + * @return converted XPATH expression + * @throws JCRQueryException if there is a problem converting the input criteria to a valid xpath expression */ - public String toXPathString(Criteria criteria) throws JCRQueryException; + String toXPathString(Criteria criteria) throws JCRQueryException; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -30,10 +30,8 @@ public class IsNotNullExpression implements Criterion { - private static final long serialVersionUID = -1955669039985775985L; + private static final long serialVersionUID = 42L; - protected static final String WHITESPACE = " "; - private String nodeName; public IsNotNullExpression(String nodeName) @@ -47,8 +45,11 @@ return nodeName; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { - return WHITESPACE + nodeName + WHITESPACE; + return " " + nodeName + " "; } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class IsNullExpression implements Criterion +public class IsNullExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -1600960388638847909L; @@ -48,7 +48,7 @@ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(); - fragment.append(Criterion.NOT).append(nodeName).append(") "); + fragment.append(" not(").append(nodeName).append(") "); log.debug("xpathString is {} ", fragment); return fragment.toString(); } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class JCRFunctionExpression implements Criterion +public class JCRFunctionExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -5570839091762158385L; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -28,7 +28,7 @@ * @author Federico Grilli * @version $Id$ */ -public class LogicalExpression implements Criterion +public class LogicalExpression extends BaseCriterion implements Criterion { /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,23 +32,6 @@ public abstract class MatchMode implements Serializable { - private static final long serialVersionUID = -7446324572335777782L; - - private final String name; - - private static final Map<String, MatchMode> INSTANCES = new HashMap<String, MatchMode>(); - - protected MatchMode(String name) - { - this.name = name; - } - - @Override - public String toString() - { - return name; - } - /** * Match the start of the string to the pattern */ @@ -88,6 +71,23 @@ } }; + private static final Map<String, MatchMode> INSTANCES = new HashMap<String, MatchMode>(); + + private static final long serialVersionUID = -7446324572335777782L; + + private final String name; + + protected MatchMode(String name) + { + this.name = name; + } + + @Override + public String toString() + { + return name; + } + static { INSTANCES.put(END.name, END); @@ -97,6 +97,8 @@ /** * convert the pattern, by appending/prepending "%" + * @param pattern input pattern + * @return formatted match string */ public abstract String toMatchString(String pattern); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class NotExpression implements Criterion +public class NotExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -5057676844499041929L; @@ -47,7 +47,7 @@ public String toXPathString(Criteria criteria) throws JCRQueryException { - StringBuilder fragment = new StringBuilder(Criterion.NOT); + StringBuilder fragment = new StringBuilder(" not("); fragment.append(expression.toXPathString(criteria)).append(") "); log.debug("xpathString is {} ", fragment); return fragment.toString(); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,24 +27,18 @@ * Represents an order imposed upon a <tt>Criteria</tt> result set * @author Federico Grilli */ -public class Order implements Criterion +public class Order extends BaseCriterion implements Criterion { /** - * - */ + * + */ private static final long serialVersionUID = -1228583450961430360L; private boolean ascending; private String nodeName; - @Override - public String toString() - { - return nodeName + ' ' + (ascending ? "ascending" : "descending"); - } - /** * Constructor for Order. */ @@ -54,6 +48,9 @@ this.ascending = ascending; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(" "); @@ -67,7 +64,7 @@ /** * Ascending order - * @param propertyName + * @param propertyName jcr property name, e.g. "@title" * @return Order */ public static Order asc(String propertyName) @@ -77,11 +74,17 @@ /** * Descending order - * @param propertyName + * @param propertyName jcr property name, e.g. "@title" * @return Order */ public static Order desc(String propertyName) { return new Order(propertyName, false); } + + @Override + public String toString() + { + return nodeName + ' ' + (ascending ? "ascending" : "descending"); + } } \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.TimeZone; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; @@ -31,11 +30,11 @@ * The <tt>criterion</tt> package may be used by applications as a framework for building new kinds of * <tt>Criterion</tt>. However, it is intended that most applications will simply use the built-in criterion types via * the static factory methods of this class. - * @see Criteria + * @author fgiust * @author Federico Grilli * @version $Id$ */ -public class Restrictions +public final class Restrictions { private static final Calendar MIDNIGHT_GMT; @@ -49,7 +48,7 @@ MIDNIGHT_GMT.set(Calendar.MILLISECOND, 0); } - Restrictions() + private Restrictions() { // cannot be instantiated } @@ -67,16 +66,6 @@ } /** - * @param nodeName - * @param value - * @return - */ - public static Criterion eqDate(String nodeName, Calendar value) - { - return betweenDates(nodeName, value, value); - } - - /** * Apply a "not equal" constraint to the named node * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an * attribute it must be preceded by the '@'character (eg. @nt:somenode) @@ -97,7 +86,7 @@ * "http://www.nabble.com/Explanation-and-solutions-of-some-Jackrabbit-queries-regarding-performance-td15028655.html" * >us...@ja... mailing list</a> <br> * <em> - * <ul> + * <ul> * <li>Question: My xpath is '//*[jcr:like(@propertyName, * '%somevalue%')]' and it takes minutes to complete. * @@ -137,7 +126,7 @@ * "http://www.nabble.com/Explanation-and-solutions-of-some-Jackrabbit-queries-regarding-performance-td15028655.html" * >us...@ja... mailing list</a> <br> * <em> - * <ul> + * <ul> * <li>Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete. * * <li>Answer: a jcr:like with % will be translated to a WildcardQuery lucene @@ -264,11 +253,27 @@ } /** - * @param nodeName - * @param lo - * @param hi - * @return + * Adds a date contraint: the input date must be included in the given date, excluding time (between 00:00 and 23:59 + * of the given date) + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) + * @param value date (time will be ignored) + * @return Criterion */ + public static Criterion eqDate(String nodeName, Calendar value) + { + return betweenDates(nodeName, value, value); + } + + /** + * Adds a date contraint: the input date must be included in the given dates (between 00:00 of the first date to + * 23:59 of the last date) + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) + * @param lo lower date + * @param hi higher date + * @return Criterion + */ public static Criterion betweenDates(String nodeName, Calendar lo, Calendar hi) { return between(nodeName, getDayStart(lo), getDayEnd(hi)); @@ -301,6 +306,8 @@ /** * Apply an "is null" constraint to the named node + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) * @return Criterion */ public static Criterion isNull(String nodeName) @@ -310,6 +317,8 @@ /** * Apply an "is not null" constraint to the named node + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) * @return Criterion */ public static Criterion isNotNull(String nodeName) @@ -319,8 +328,8 @@ /** * Return the conjuction of two expressions - * @param lhs - * @param rhs + * @param lhs left expression + * @param rhs right expression * @return Criterion */ public static LogicalExpression and(Criterion lhs, Criterion rhs) @@ -330,8 +339,8 @@ /** * Return the disjuction of two expressions - * @param lhs - * @param rhs + * @param lhs left expression + * @param rhs right expression * @return Criterion */ public static LogicalExpression or(Criterion lhs, Criterion rhs) @@ -341,7 +350,7 @@ /** * Return the negation of an expression - * @param expression + * @param expression to be negated * @return Criterion */ public static Criterion not(Criterion expression) @@ -350,40 +359,6 @@ } /** - * Apply a constraint expressed in xpath. - * @param xpath - * @param values - * @param types - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath, Object[] values) { throw new - * UnsupportedOperationException(); // return new XPathCriterion(sql, values, types); } - */ - - /** - * Apply a constraint expressed in xpath. - * @param xpath - * @param value - * @param type - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath, Object value) { throw new UnsupportedOperationException(); - * // return new XPathCriterion(sql, new Object[] { value }, new Type[] { // type } ); } - */ - - /** - * Apply a constraint expressed in xpath. - * @param xpath - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath) { throw new UnsupportedOperationException(); // return new - * XPathCriterion(sql, ArrayHelper.EMPTY_OBJECT_ARRAY, // ArrayHelper.EMPTY_TYPE_ARRAY); } - */ - - /** * Group expressions together in a single conjunction (A and B and C...) * @return Conjunction */ Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,7 +32,7 @@ * @author Federico Grilli * @version $Id$ */ -public class SimpleExpression implements Criterion +public class SimpleExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -1104419394978535803L; @@ -104,8 +104,13 @@ { fragment.append(propertyName).append(getOp()); Calendar cal = (Calendar) value; - DATE_FORMAT.setCalendar(cal); - String fmt = DATE_FORMAT.format(cal.getTime()); + String fmt; + + synchronized (DATE_FORMAT) + { + DATE_FORMAT.setCalendar(cal); + fmt = DATE_FORMAT.format(cal.getTime()); + } fragment.append(XS_DATETIME_FUNCTION + "('" + fmt + "+00:00" + "')) "); } else if (value != null) Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -39,8 +39,6 @@ import org.apache.jackrabbit.spi.commons.query.QueryNodeVisitor; import org.apache.jackrabbit.spi.commons.query.QueryRootNode; import org.apache.lucene.search.Query; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** @@ -53,11 +51,6 @@ private DefaultQueryNodeFactory proxiedQueryNodeFactory; - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AclSearchIndex.class); - public AclSearchIndex() { @@ -124,7 +117,6 @@ Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); sessionField.setAccessible(true); SessionImpl session = (SessionImpl) sessionField.get(visitor); - // adds acl constraints AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); return decorator.applyAcl(luceneQuery); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -61,9 +61,9 @@ protected List<OrderEntry> orderEntries = new ArrayList<OrderEntry>(); - protected int maxResults = 0; + protected int maxResults; - protected int offset = 0; + protected int offset; protected HierarchyManager hm; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,6 +32,7 @@ * @author fgrilli * @version $Id$ */ +@Deprecated public abstract class AbstractMagnoliaCriteriaImpl extends AbstractCriteriaImpl { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -44,6 +44,7 @@ * @author Federico Grilli * @version $Id$ */ +@Deprecated public class MagnoliaCriteriaImpl extends AbstractMagnoliaCriteriaImpl { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -55,8 +55,9 @@ /** - * Magnolia XPATH implementation of the <tt>Criteria</tt> interface which supports limiting the result set according to - * the underlying JCR implementation (e.g. Jackrabbit 1.4+) + * <strong>Deprecated in mgnlcriteria 2.x. Paging is now implemented at jcr level in AdvancedCriteria, this class should + * not be used anymore.</strong> Magnolia XPATH implementation of the <tt>Criteria</tt> interface which supports + * limiting the result set according to the underlying JCR implementation (e.g. Jackrabbit 1.4+) * @deprecated due to the way results are collected there is no guarantee that the offset specified is respected: for * example if your query matches both a page and a paragraph in it, and you ask for results of type mgnl:content those * two results will be merged into one. If you need paging use AdvancedCriteria and be sure to specify the desired @@ -97,6 +98,7 @@ super(hm); } + @Override @SuppressWarnings("unchecked") @Deprecated public Collection< ? > list() throws JCRQueryException @@ -148,7 +150,7 @@ stop = System.currentTimeMillis(); log.debug("Query executed in {} milliseconds", stop - start); - Collection retVal; + Collection<Content> retVal; field = managerClass.getDeclaredField(HIERARCHY_MANAGER); field.setAccessible(true); HierarchyManager hm = (HierarchyManager) field.get(queryManager); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -26,13 +26,14 @@ /** * A utility class to escape xpath strings + * @author fgiust * @author fgrilli * @version $Id$ */ public final class XPathTextUtils { - private static final Logger log = LoggerFactory.getLogger(XPathTextUtils.class); + private static Logger log = LoggerFactory.getLogger(XPathTextUtils.class); private XPathTextUtils() { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -31,6 +31,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; @@ -166,7 +167,7 @@ { Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); criteria.setBasePath(basePath); - criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.eq(Criterion.JCR_PRIMARYTYPE, "mgnl:content")); if (!StringUtils.isEmpty(title)) { criteria.add(Restrictions.eq("@title", title)); Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -21,6 +21,9 @@ import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.context.MgnlContext; + +import java.util.Map; + import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; @@ -37,6 +40,7 @@ /** + * Tests for Content2Bean transformation * @author fgiust * @version $Id$ */ @@ -59,6 +63,7 @@ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); } + @SuppressWarnings("unchecked") @Test public void testLoremAndIpsum() throws Exception { @@ -75,6 +80,11 @@ AdvancedResultItem item = items.next(); Assert.assertEquals(item.getTitle(), "lorem ipsum"); + // this is also a Map! + Assert.assertEquals(((Map<String, Object>) item).get("title"), "lorem ipsum"); + Assert.assertEquals(((Map<String, Object>) item).get("text"), "ohoh"); + Assert.assertEquals(((Map<String, Object>) item).get("number"), "5"); + ResultIterator<Page> itemsTransformed = advResult.getItems(Page.class); Assert.assertNotNull(itemsTransformed); Page page = itemsTransformed.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |