jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r713214 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/query/ main/java/org/apache/jackrabbit/ocm/query/impl/ test/java/org/apache/jackrabbit/ocm/manager/query/
Date Tue, 11 Nov 2008 22:58:04 GMT
Author: clombart
Date: Tue Nov 11 14:58:03 2008
New Revision: 713214

URL: http://svn.apache.org/viewvc?rev=713214&view=rev
Log:
Patch for JCR-1844 (Convenience method to Or multiple values with a single filter) provided
by Shrirang.

Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java?rev=713214&r1=713213&r2=713214&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
Tue Nov 11 14:58:03 2008
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.ocm.query;
 
 
-
 /**
  *
  * JCR Filter interface.
@@ -79,7 +78,7 @@
 	Filter addGreaterThan(String arg0, Object arg1);
 
 	Filter addLessOrEqualThan(String arg0, Object arg1);
-	
+
 	Filter addLessThan(String arg0, Object arg1);
 
 	Filter addLike(String arg0, Object arg1);
@@ -89,15 +88,17 @@
 	Filter addNotNull(String arg0);
 
 	Filter addIsNull(String arg0);
-	
+
+	Filter addOrFilter(String fieldAttributeName, String[] valueList);
+
 	Filter addOrFilter(Filter arg0);
 
 	Filter addAndFilter(Filter filter);
-	
+
 	Filter addJCRExpression(String jcrExpression);
-	
+
     Class getFilterClass();
     Object clone();
-	
+
 
 }

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java?rev=713214&r1=713213&r2=713214&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
Tue Nov 11 14:58:03 2008
@@ -18,6 +18,7 @@
 package org.apache.jackrabbit.ocm.query.impl;
 
 
+
 import java.util.Map;
 
 import javax.jcr.ValueFactory;
@@ -224,6 +225,18 @@
         return this;
     }
 
+    public Filter addOrFilter(String fieldAttributeName, String[] valueList) {
+        String jcrExpression = "";
+        for(Object object: valueList){
+        jcrExpression =	"@" + this.getJcrFieldName(fieldAttributeName) + " = "
+        + this.getStringValue(fieldAttributeName, object);
+        orExpression(jcrExpression);
+        }
+        addExpression(jcrExpression);
+        return this;
+    }
+    
+    
     /**
      * @see org.apache.jackrabbit.ocm.query.Filter#addOrFilter(org.apache.jackrabbit.ocm.query.Filter)
      */
@@ -269,6 +282,13 @@
         return this;
     }
 
+    public Filter orJCRExpression(String jcrExpression) {
+        orExpression(jcrExpression);
+
+         return this;
+     }
+   
+    
     private String getJcrFieldName(String fieldAttribute) {
         String jcrFieldName = classDescriptor.getJcrName(fieldAttribute);
         if (jcrFieldName == null) {
@@ -318,6 +338,15 @@
         this.jcrExpression += jcrExpression ;
     }
 
+    private void orExpression(String jcrExpression) {
+
+	     if (this.jcrExpression.length() >0) {
+         	this.jcrExpression += " or ";
+	     }
+	     this.jcrExpression += jcrExpression ;
+    }
+    
+    
 	public String toString() {
 		return getJcrExpression();
 	}

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java?rev=713214&r1=713213&r2=713214&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
Tue Nov 11 14:58:03 2008
@@ -195,6 +195,69 @@
 
     }
 
+    /**
+     * Build an or expression within a single filter
+     * @author Shrirang Edgaonkar
+     */
+    public void testGetObjectsOrForSingleFilter() {
+
+        try {
+
+            // Build the Query Object
+            QueryManager queryManager = this.getQueryManager();
+            Filter filter1 = queryManager.createFilter(Paragraph.class);
+            filter1.addOrFilter("text", new String[]{"Para 1","Para 2"});
+            filter1.setScope("/test/");
+
+            Query query = queryManager.createQuery(filter1);
+
+            ObjectContentManager ocm = this.getObjectContentManager();
+            Collection result = ocm.getObjects(query);
+            assertEquals("Invalid number of objects - should be = 2", 2, result.size());
+
+            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
+            assertTrue("Invalid paragraph found", this.containsText(paragraphs,"Para 1"));
+            assertTrue("Invalid paragraph found", this.containsText(paragraphs,"Para 2"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+
+    }
+
+    /**
+     * Build an or expression within a single filter
+     * @author Shrirang Edgaonkar
+     */
+    public void testGetObjectsOrWithAndForSingleFilter() {
+
+        try {
+
+            // Build the Query Object
+            QueryManager queryManager = this.getQueryManager();
+            Filter filter1 = queryManager.createFilter(Paragraph.class);
+            filter1.addOrFilter("text", new String[]{"Para 1","Another Para "}).addLike("text",
"Para%");
+            filter1.setScope("/test/");
+
+            Query query = queryManager.createQuery(filter1);
+
+            ObjectContentManager ocm = this.getObjectContentManager();
+            Collection result = ocm.getObjects(query);
+            assertEquals("Invalid number of objects - should be = 1", 1, result.size());
+
+            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
+            assertTrue("Invalid paragraph found", this.containsText(paragraphs,"Para 1"));
+            //assertTrue("Invalid paragraph found", this.containsText(paragraphs,"Para 2"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+
+    }
+   
+    
     public void testGetObjectOrderBy() {
 
         try {



Mime
View raw message