jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r598139 - in /jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src: main/java/org/apache/jackrabbit/ocm/manager/impl/ main/java/org/apache/jackrabbit/ocm/query/ main/java/org/apache/jackrabbit/ocm/query/impl/ test/java/org/apache/jackr...
Date Mon, 26 Nov 2007 05:42:13 GMT
Author: clombart
Date: Sun Nov 25 21:42:09 2007
New Revision: 598139

URL: http://svn.apache.org/viewvc?rev=598139&view=rev
Log:
Refactor the QueryManager and associated classes for supporting issue JCR-1198

Modified:
    jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java?rev=598139&r1=598138&r2=598139&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
Sun Nov 25 21:42:09 2007
@@ -58,6 +58,7 @@
 import org.apache.jackrabbit.ocm.mapper.Mapper;
 import org.apache.jackrabbit.ocm.mapper.impl.digester.DigesterMapperImpl;
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
+import org.apache.jackrabbit.ocm.query.Filter;
 import org.apache.jackrabbit.ocm.query.Query;
 import org.apache.jackrabbit.ocm.query.QueryManager;
 import org.apache.jackrabbit.ocm.query.impl.QueryManagerImpl;
@@ -547,8 +548,13 @@
     }
 
     /**
-     * 
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObjects(java.lang.Class,
java.lang.String)
+     * Returns a list of objects of that particular class which are directly
+     * under that path. This would not return the objects anywhere below the
+     * denoted path.
+     * 
+     * @param objectClass
+     * @param path
+     * @return
      */
     public Collection getObjects(Class objectClass, String path) throws ObjectContentManagerException
{
         try {
@@ -558,6 +564,25 @@
         } catch (RepositoryException e) {
             throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Impossible
to get the objects at " + path, e);
         }
+        
+        
+        String parentPath = NodeUtil.getParentPath(path);
+        if (! parentPath.equals("/")) {
+        	parentPath = parentPath + "/";
+        }
+        
+        String nodeName = NodeUtil.getNodeName(path);
+        // If nodeName is missing then include *.
+        if (nodeName == null || nodeName.length() == 0) {
+            nodeName = "*";
+        }
+        Filter filter = queryManager.createFilter(objectClass);
+        filter.setScope(parentPath);
+        filter.setNodeName(nodeName);
+        Query query = queryManager.createQuery(filter);
+        return getObjects(query);
+        
+        /*
         String jcrExpression = "";
         // Below code is incorrect as the JCR Expression should be formed in
         // Query manager. Since the existing implementation of
@@ -580,10 +605,13 @@
         if (classDescriptor.hasDiscriminator() && !classDescriptor.isAbstract() &&
(!classDescriptor.isInterface())) {
             jcrExpression += "[@" + ManagerConstant.DISCRIMINATOR_PROPERTY_NAME + "='" +
classDescriptor.getClassName() + "']";
         }
+        
         return getObjects(jcrExpression, javax.jcr.query.Query.XPATH);
+        */
+        
     }
 
-    // This method should go in NodeUtil?
+    /*
     private String getNodeType(ClassDescriptor classDescriptor) {
         String jcrNodeType = classDescriptor.getJcrType();
         if (jcrNodeType == null || jcrNodeType.equals("")) {
@@ -592,7 +620,8 @@
             return jcrNodeType;
         }
     }
-
+    */
+   
     /**
      * 
      * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObjectIterator(org.apache.jackrabbit.ocm.query.Query)

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java?rev=598139&r1=598138&r2=598139&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/Filter.java
Sun Nov 25 21:42:09 2007
@@ -48,6 +48,20 @@
     
     
     /**
+     * Set the node name used to build the jcr search expression. 
+     * 
+     * @param nodeName
+     */
+    void setNodeName(String nodeName);
+    
+    /**
+     * Get the node name used in the jcr expression
+     * @return
+     */
+    String getNodeName();
+    
+    
+    /**
      * Search content based on a fullTextSearch. 
      * Depending on the full text search engine, you can also filter on properties.
      * 

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java?rev=598139&r1=598138&r2=598139&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
Sun Nov 25 21:42:09 2007
@@ -39,6 +39,7 @@
 
     private Class claszz;
     private String scope = "";
+    private String nodeName = "*";
     private String jcrExpression = "";
 
     private ClassDescriptor classDescriptor;
@@ -79,9 +80,17 @@
      */
     public String getScope() {
         return this.scope;
-    }
+    }    
+    
+    public String getNodeName() {
+		return nodeName;
+	}
+
+	public void setNodeName(String nodeName) {
+		this.nodeName = nodeName;
+	}
 
-    /**
+	/**
      * @see org.apache.jackrabbit.ocm.query.Filter#addContains(java.lang.String, java.lang.String)
      */
     public Filter addContains(String scope, String fullTextSearch) {

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java?rev=598139&r1=598138&r2=598139&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
Sun Nov 25 21:42:09 2007
@@ -64,12 +64,12 @@
 
         String jcrExp = "";
 
-        // Add scope
+        // Add scope & node name
         if (((filter.getScope() != null) && (!filter.getScope().equals("")))) {
-            jcrExp += "/jcr:root" + filter.getScope() + "element(*, ";
+            jcrExp += "/jcr:root" + filter.getScope() + "element(" + filter.getNodeName()
+ ", ";
         }
         else {
-            jcrExp += "//element(*, ";
+            jcrExp += "//element(" + filter.getNodeName() + ", ";
         }
 
         // Add node type

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java?rev=598139&r1=598138&r2=598139&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
Sun Nov 25 21:42:09 2007
@@ -245,6 +245,8 @@
             result = ocm.getObjects(Page.class, "/folder/test");
             assertEquals("Invalid number of objects", 4, result.size());
 
+            result = ocm.getObjects(Page.class, "/folder");
+            assertEquals("Invalid number of objects", 0, result.size());
 
         } catch (Exception e) {
             e.printStackTrace();



Mime
View raw message