You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2006/04/04 22:22:19 UTC

svn commit: r391428 - /incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java

Author: clombart
Date: Tue Apr  4 15:22:14 2006
New Revision: 391428

URL: http://svn.apache.org/viewcvs?rev=391428&view=rev
Log:
Override the changes made by Alex because thoses changes break the unit tests. 
It was not possible to detect the modifications during a compare - sorry.
Alex, can you check if the unit tests are working on your local machine ? thanks

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java?rev=391428&r1=391427&r2=391428&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java Tue Apr  4 15:22:14 2006
@@ -1,283 +1,281 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- *                     as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.portals.graffito.jcr.query.impl;
-
-
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
-import org.apache.portals.graffito.jcr.query.Filter;
-
-/**
- * {@link org.apache.portals.graffito.jcr.query.Filter}
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- * @author <a href="mailto:the_mindstorm[at]evolva[dot]ro">Alex Popescu</a>
- */
-public class FilterImpl implements Filter {
-    private final static Log log = LogFactory.getLog(FilterImpl.class);
-
-    private Class clazz;
-    private String scope = "";
-    private StringBuffer jcrExpression = new StringBuffer();
-
-    private ClassDescriptor classDescriptor;
-    private Map atomicTypeConverters;
-
-    /**
-     * Constructor
-     *
-     * @param classDescriptor
-     * @param atomicTypeConverters
-     * @param clazz
-     */
-    public FilterImpl(ClassDescriptor classDescriptor, Map atomicTypeConverters, Class clazz) {
-        this.clazz = clazz;
-        this.atomicTypeConverters = atomicTypeConverters;
-        this.classDescriptor = classDescriptor;
-    }
-
-    /**
-     *
-     * @see org.apache.portals.graffito.jcr.query.Filter#getFilterClass()
-     */
-    public Class getFilterClass() {
-        return clazz;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#setScope(java.lang.String)
-     */
-    public void setScope(String scope) {
-        this.scope = scope;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#getScope()
-     */
-    public String getScope() {
-        return this.scope;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addContains(java.lang.String, java.lang.String)
-     */
-    public Filter addContains(String scope, String fullTextSearch) {
-        String jcrExpression = null;
-        if (scope.equals(".")) {
-            jcrExpression = "jcr:contains(., '" + fullTextSearch + "')";
-        }
-        else {
-            jcrExpression = "jcr:contains(@" + this.getJcrFieldName(scope) + ", '" + fullTextSearch + "')";
-        }
-
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addBetween(java.lang.String, java.lang.Object, java.lang.Object)
-     */
-    public Filter addBetween(String fieldAttributeName, Object value1, Object value2) {
-        String jcrExpression = "( @" + this.getJcrFieldName(fieldAttributeName) + " >= "
-            + this.getStringValue(value1)
-            + " and @" + this.getJcrFieldName(fieldAttributeName) + " <= "
-            + this.getStringValue(value2) + ")";
-
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addEqualTo(java.lang.String, java.lang.Object)
-     */
-    public Filter addEqualTo(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " = "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addGreaterOrEqualThan(java.lang.String, java.lang.Object)
-     */
-    public Filter addGreaterOrEqualThan(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " >= "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addGreaterThan(java.lang.String, java.lang.Object)
-     */
-    public Filter addGreaterThan(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " > "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
-     */
-    public Filter addLessOrEqualThan(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " <= "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
-     */
-    public Filter addLessThan(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " < "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addLike(java.lang.String, java.lang.Object)
-     */
-    public Filter addLike(String fieldAttributeName, Object value) {
-        String jcrExpression = "jcr:like(" + "@" + this.getJcrFieldName(fieldAttributeName) + ", '"
-            + value + "')";
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addNotEqualTo(java.lang.String, java.lang.Object)
-     */
-    public Filter addNotEqualTo(String fieldAttributeName, Object value) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " != "
-            + this.getStringValue(value);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addNotNull(java.lang.String)
-     */
-    public Filter addNotNull(String fieldAttributeName) {
-        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName);
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addIsNull(java.lang.String)
-     */
-    public Filter addIsNull(String fieldAttributeName) {
-        String jcrExpression = "not(@" + this.getJcrFieldName(fieldAttributeName) + ")";
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addOrFilter(org.apache.portals.graffito.jcr.query.Filter)
-     */
-    public Filter addOrFilter(Filter filter) {
-        if ((null == jcrExpression) || "".equals(jcrExpression.toString())) {
-            jcrExpression = new StringBuffer(((FilterImpl) filter).getJcrExpression());
-        }
-        else {
-            jcrExpression = new StringBuffer("(");
-            jcrExpression.append(jcrExpression)
-                         .append(")  or ( ")
-                         .append(((FilterImpl) filter).getJcrExpression())
-                         .append(")");
-        }
-
-        return this;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.query.Filter#addAndFilter(Filter)
-     */
-    public Filter addAndFilter(Filter filter) {
-        if ((null == jcrExpression) || "".equals(jcrExpression.toString())) {
-            jcrExpression = new StringBuffer(((FilterImpl) filter).getJcrExpression());
-        }
-        else {
-            jcrExpression = new StringBuffer("(");
-            jcrExpression.append(jcrExpression)
-                         .append(") and  ( ")
-                         .append(((FilterImpl) filter).getJcrExpression())
-                         .append(")");
-        }
-
-        return this;
-
-    }
-
-    public Filter addJCRExpression(String jcrExpression) {
-        addExpression(jcrExpression);
-
-        return this;
-    }
-
-    private String getJcrFieldName(String fieldAttribute) {
-        String jcrFieldName = classDescriptor.getJcrName(fieldAttribute);
-        if (jcrFieldName == null) {
-            log.error("Impossible to find the jcrFieldName for the attribute :" + fieldAttribute);
-        }
-
-        return jcrFieldName;
-
-    }
-
-    private String getStringValue(Object value) {
-        AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
-
-        return atomicTypeConverter.getStringValue(value);
-    }
-
-    public String getJcrExpression() {
-        return this.jcrExpression.toString();
-    }
-
-    private void addExpression(String jcrExpression) {
-        if (this.jcrExpression.length() > 0) {
-            this.jcrExpression.append(" and ");
-        }
-        
-        this.jcrExpression.append(jcrExpression);
-    }
-
-    public String toString() {
-        return getJcrExpression();
-    }
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.query.impl;
+
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.query.Filter;
+
+/**
+ * {@link org.apache.portals.graffito.jcr.query.Filter}
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * @author <a href="mailto:the_mindstorm[at]evolva[dot]ro">Alex Popescu</a>
+ */
+public class FilterImpl implements Filter {
+    private final static Log log = LogFactory.getLog(FilterImpl.class);
+
+    private Class claszz;
+    private String scope = "";
+    private String jcrExpression = "";
+
+    private ClassDescriptor classDescriptor;
+    private Map atomicTypeConverters;
+
+    /**
+     * Constructor
+     *
+     * @param classDescriptor
+     * @param atomicTypeConverters
+     * @param clazz
+     */
+    public FilterImpl(ClassDescriptor classDescriptor, Map atomicTypeConverters, Class clazz) {
+        this.claszz = clazz;
+        this.atomicTypeConverters = atomicTypeConverters;
+        this.classDescriptor = classDescriptor;
+    }
+
+    /**
+     *
+     * @see org.apache.portals.graffito.jcr.query.Filter#getFilterClass()
+     */
+    public Class getFilterClass() {
+        return claszz;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#setScope(java.lang.String)
+     */
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#getScope()
+     */
+    public String getScope() {
+        return this.scope;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addContains(java.lang.String, java.lang.String)
+     */
+    public Filter addContains(String scope, String fullTextSearch) {
+        String jcrExpression = null;
+        if (scope.equals(".")) {
+            jcrExpression = "jcr:contains(., '" + fullTextSearch + "')";
+        }
+        else {
+            jcrExpression = "jcr:contains(@" + this.getJcrFieldName(scope) + ", '" + fullTextSearch
+                + "')";
+        }
+
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addBetween(java.lang.String, java.lang.Object, java.lang.Object)
+     */
+    public Filter addBetween(String fieldAttributeName, Object value1, Object value2) {
+        String jcrExpression = "( @" + this.getJcrFieldName(fieldAttributeName) + " >= "
+            + this.getStringValue(value1)
+            + " and @" + this.getJcrFieldName(fieldAttributeName) + " <= "
+            + this.getStringValue(value2) + ")";
+
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addEqualTo(java.lang.String, java.lang.Object)
+     */
+    public Filter addEqualTo(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " = "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addGreaterOrEqualThan(java.lang.String, java.lang.Object)
+     */
+    public Filter addGreaterOrEqualThan(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " >= "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addGreaterThan(java.lang.String, java.lang.Object)
+     */
+    public Filter addGreaterThan(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " > "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
+     */
+    public Filter addLessOrEqualThan(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " <= "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
+     */
+    public Filter addLessThan(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " < "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addLike(java.lang.String, java.lang.Object)
+     */
+    public Filter addLike(String fieldAttributeName, Object value) {
+        String jcrExpression = "jcr:like(" + "@" + this.getJcrFieldName(fieldAttributeName) + ", '"
+            + value + "')";
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addNotEqualTo(java.lang.String, java.lang.Object)
+     */
+    public Filter addNotEqualTo(String fieldAttributeName, Object value) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " != "
+            + this.getStringValue(value);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addNotNull(java.lang.String)
+     */
+    public Filter addNotNull(String fieldAttributeName) {
+        String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName);
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addIsNull(java.lang.String)
+     */
+    public Filter addIsNull(String fieldAttributeName) {
+        String jcrExpression = "not(@" + this.getJcrFieldName(fieldAttributeName) + ")";
+        addExpression(jcrExpression);
+
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addOrFilter(org.apache.portals.graffito.jcr.query.Filter)
+     */
+    public Filter addOrFilter(Filter filter) {
+    	   if ( null == jcrExpression || "".equals(jcrExpression) )
+    	   {
+    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		   
+    	   }
+    	   else
+    	   {
+    	         jcrExpression =   "(" + jcrExpression + ")  or ( "  +  ((FilterImpl) filter).getJcrExpression() + ")";
+    	   }
+        return this;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addAndFilter(Filter)
+     */
+    public Filter addAndFilter(Filter filter) {
+ 	   if ( null == jcrExpression || "".equals(jcrExpression) )
+	   {
+		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		   
+	   }
+	   else
+	   {
+	         jcrExpression =   "(" + jcrExpression + ") and  ( "  +  ((FilterImpl) filter).getJcrExpression() + ")";
+	   }
+       return this;
+
+    }
+    
+
+    public Filter addJCRExpression(String jcrExpression) {
+       addExpression(jcrExpression);
+
+        return this;
+    }
+
+    private String getJcrFieldName(String fieldAttribute) {
+        String jcrFieldName = classDescriptor.getJcrName(fieldAttribute);
+        if (jcrFieldName == null) {
+            log.error("Impossible to find the jcrFieldName for the attribute :" + fieldAttribute);
+        }
+
+        return jcrFieldName;
+
+    }
+
+    private String getStringValue(Object value) {
+        AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(
+                value.getClass());
+
+        return atomicTypeConverter.getStringValue(value);
+    }
+
+    public String getJcrExpression() {
+    	     return this.jcrExpression;
+    }
+
+    private void addExpression(String jcrExpression) {
+            
+    	     if (this.jcrExpression.length() >0) {
+              	this.jcrExpression += " and ";
+        }
+        this.jcrExpression += jcrExpression ;
+    }
+
+	public String toString() {
+		return getJcrExpression();
+	}
+    
+   
+}
\ No newline at end of file