incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apope...@apache.org
Subject svn commit: r390621 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr: mapper/impl/ mapper/model/ persistence/objectconverter/impl/ query/impl/
Date Sat, 01 Apr 2006 08:33:06 GMT
Author: apopescu
Date: Sat Apr  1 00:33:04 2006
New Revision: 390621

URL: http://svn.apache.org/viewcvs?rev=390621&view=rev
Log:
fixed formattings (broken indentation)
changed string manipulation to stringbuffer

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=390621&r1=390620&r2=390621&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
Sat Apr  1 00:33:04 2006
@@ -180,12 +180,11 @@
                             + cd.getClassName());
                 }
                 else {
-                	    log.debug("Class " +cd.getClassName() +  " extends " + cd.getSuperClass());
+            	    log.debug("Class " +cd.getClassName() +  " extends " + cd.getSuperClass());
                     cd.setSuperClassDescriptor(superClassDescriptor);
                 }
             }
-            else
-            {
+            else {
                 rootClassDescriptors.add(cd);	
             }
         }
@@ -203,12 +202,11 @@
      */
     private List  validateDescriptors(List errors, Collection classDescriptors ) {
         for(Iterator it = classDescriptors.iterator(); it.hasNext(); ) {
-             ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
+            ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
             try {
                 classDescriptor.afterPropertiesSet();
-                if (classDescriptor.hasDescendants())
-                {
-                	     errors = validateDescriptors(errors, classDescriptor.getDescendantClassDescriptors());
+                if (classDescriptor.hasDescendants()) {
+                    errors = validateDescriptors(errors, classDescriptor.getDescendantClassDescriptors());
                 }
             }
             catch(JcrMappingException jme) {

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?rev=390621&r1=390620&r2=390621&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
Sat Apr  1 00:33:04 2006
@@ -25,6 +25,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 
 /**
  *
@@ -198,7 +199,6 @@
      * @return all {@link BeanDescriptor} defined in this ClassDescriptor
      */
     public Collection getCollectionDescriptors() {
-    	   
         return this.collectionDescriptors.values();
     }
 
@@ -222,8 +222,6 @@
         }
 
         return null;
-        
-    
     }
 
     public FieldDescriptor getDiscriminatorFieldDescriptor() {       
@@ -259,8 +257,7 @@
         return (String) this.fieldNames.get(fieldName);
     }
     
-    public Map getFieldNames()
-    {
+    public Map getFieldNames() {
         return this.fieldNames;
     }
 
@@ -294,12 +291,6 @@
      *
      * @param mixinTypes command separated list of mixins
      */
-//    public void setJcrMixinTypesList(String[] mixinTypes) {
-//        if (null != mixinTypes) {
-//            setJcrMixinTypes(mixinTypes[0].split(","));
-//        }
-//    }
-
     public void setJcrMixinTypes(String[] mixinTypes) {
         if (null != mixinTypes && mixinTypes.length == 1) {
             jcrMixinTypes = mixinTypes[0].split(" *, *");
@@ -324,7 +315,6 @@
      * Revisit information in this descriptor and fills in more.
      */
     public void afterPropertiesSet() {
-
         validateClassName();        
         lookupSuperDescriptor();
         lookupInheritanceSettings();
@@ -333,15 +323,14 @@
 
 	private void validateClassName() {
 		try {
-			Class objectClass = Class.forName(this.className);
-		} catch (ClassNotFoundException e) {			
-			 throw new JcrMappingException("Class not found : " + className);
+            ReflectionUtils.forName(this.className);
+		} catch (JcrMappingException e) {			
+			 throw new JcrMappingException("Class used in descriptor not found : " + className);
 		}
 	}
 
 	private void lookupSuperDescriptor() {
-		
-        if (null !=superClassDescriptor) {
+        if (null != superClassDescriptor) {
             this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
             this.beanDescriptors = mergeBeans(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors());
             this.collectionDescriptors = mergeCollections(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors());
@@ -350,18 +339,15 @@
     }
 
     private void lookupInheritanceSettings() {
-	     if ((null != this.superClassDescriptor) || (this.hasDescendants() ))
-	     {
-	    	       if (this.hasDiscriminatorField())
-	    	       {
-	    	    	        this.extendsStrategy = NODETYPE_PER_HIERARCHY;
-	    	       }
-	    	       else
-	    	       {
-	    	    	       this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
-	    	       }
-	     }
-   }
+        if ((null != this.superClassDescriptor) || (this.hasDescendants() )) {
+            if (this.hasDiscriminatorField()) {
+                this.extendsStrategy = NODETYPE_PER_HIERARCHY;
+            }
+            else {
+                this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
+            }
+        }
+    }
 	
     private void validateInheritanceSettings() {
         if (NODETYPE_PER_CONCRETECLASS.equals(this.extendsStrategy)) {
@@ -403,8 +389,7 @@
         return superClassDescriptor;
     }
     
-    public Collection getDescendantClassDescriptors()
-    {
+    public Collection getDescendantClassDescriptors() {
     	     return this.descendantClassDescriptors;
     }
     
@@ -417,37 +402,31 @@
      * 
      * @todo : maybe we have to review this implementation to have better performance. 
      */
-    public ClassDescriptor getDescendantClassDescriptor(String nodeType)
-    {
+    public ClassDescriptor getDescendantClassDescriptor(String nodeType) {
         Iterator iterator = this.descendantClassDescriptors.iterator();
-        while (iterator.hasNext())
-        {
-        	      ClassDescriptor descendantClassDescriptor = (ClassDescriptor) iterator.next();
-        	      if (descendantClassDescriptor.getJcrNodeType().equals(nodeType))
-        	      {
-        	    	     return descendantClassDescriptor;
-        	      }
-        	      
-        	      if (descendantClassDescriptor.hasDescendants())
-        	      {
-        	    	      ClassDescriptor classDescriptor = descendantClassDescriptor.getDescendantClassDescriptor(nodeType);
-        	    	      if (classDescriptor != null)
-        	    	      {
-        	    	    	      return classDescriptor;
-        	    	      }
-        	      }
+        while (iterator.hasNext()) {
+            ClassDescriptor descendantClassDescriptor = (ClassDescriptor) iterator.next();
+  
+            if (descendantClassDescriptor.getJcrNodeType().equals(nodeType)) {
+                return descendantClassDescriptor;
+            }
+  
+            if (descendantClassDescriptor.hasDescendants()) {
+                ClassDescriptor classDescriptor = descendantClassDescriptor.getDescendantClassDescriptor(nodeType);
+                if (classDescriptor != null) {
+                    return classDescriptor;
+                }
+            }
         }
         return null;
     }
     
-    public void addDescendantClassDescriptor(ClassDescriptor classDescriptor)
-    {
+    public void addDescendantClassDescriptor(ClassDescriptor classDescriptor) {
     	     this.descendantClassDescriptors.add(classDescriptor);
     	     this.hasDescendant = true;
     }
     
-    public boolean hasDescendants()
-    {
+    public boolean hasDescendants() {
     	    return this.hasDescendant;
     }
 
@@ -457,7 +436,6 @@
     public void setSuperClassDescriptor(ClassDescriptor superClassDescriptor) {
         this.superClassDescriptor= superClassDescriptor;
         superClassDescriptor.addDescendantClassDescriptor(this);
-        
     }
 
     private Map mergeFields(Map existing, Collection superSource) {
@@ -471,9 +449,8 @@
             if (!merged.containsKey(fieldDescriptor.getFieldName())) {
                 merged.put(fieldDescriptor.getFieldName(), fieldDescriptor);
             }
-            else
-            {
-            	    log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName()
+ " -  this  field name is also defined  in the ancestor class : " + this.getSuperClass());
+            else {
+                log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName()
+ " -  this  field name is also defined  in the ancestor class : " + this.getSuperClass());
             }
         }
 
@@ -492,9 +469,8 @@
             if (!merged.containsKey(beanDescriptor.getFieldName())) {
                 merged.put(beanDescriptor.getFieldName(), beanDescriptor);
             }
-            else
-            {
-            	    log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName()
+ " -  this  field name is also defined  in the ancestor class : " + this.getSuperClass());
+            else {
+                log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName()
+ " -  this  field name is also defined  in the ancestor class : " + this.getSuperClass());
             }
         }
 
@@ -512,9 +488,8 @@
             if (!merged.containsKey(collectionDescriptor.getFieldName())) {
                 merged.put(collectionDescriptor.getFieldName(), collectionDescriptor);
             }
-            else
-            {
-            	    log.warn("Collection name conflict in " + this.className + " - field : "
+collectionDescriptor.getFieldName() + " -  this  field name is also defined  in the ancestor
class : " + this.getSuperClass());
+            else {
+                log.warn("Collection name conflict in " + this.className + " - field : "
+collectionDescriptor.getFieldName() + " -  this  field name is also defined  in the ancestor
class : " + this.getSuperClass());
             }
         }
 
@@ -522,9 +497,6 @@
     }    
     
 	public String toString() {
-		
 		return "Class Descriptor : " +  this.getClassName();
 	}
-    
-    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?rev=390621&r1=390620&r2=390621&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
Sat Apr  1 00:33:04 2006
@@ -636,15 +636,15 @@
                                         Object object,
                                         ClassDescriptor classDescriptor,
                                         Node objectNode) {
-        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors()
-                                                               .iterator();
+        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+        
         while (collectionDescriptorIterator.hasNext()) {
-            CollectionDescriptor collectionDescriptor = (CollectionDescriptor)
-                collectionDescriptorIterator.next();
+            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
             CollectionConverter collectionConverter = this.getCollectionConverter(session,
collectionDescriptor);
             Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
             ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
-            collectionConverter.insertCollection(session,objectNode,   collectionDescriptor,
manageableCollection);
+            
+            collectionConverter.insertCollection(session,objectNode, collectionDescriptor,
manageableCollection);
         }
     }
 
@@ -652,16 +652,14 @@
                                         Object object,
                                         ClassDescriptor classDescriptor,
                                         Node objectNode) {
-        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors()
-                                                               .iterator();
+        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+        
         while (collectionDescriptorIterator.hasNext()) {
-            CollectionDescriptor collectionDescriptor = (CollectionDescriptor)
-                collectionDescriptorIterator.next();
+            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
             CollectionConverter collectionConverter = this.getCollectionConverter(session,
collectionDescriptor);
-            Object collection = ReflectionUtils.getNestedProperty(object,
-                    collectionDescriptor.getFieldName());
-            ManageableCollection manageableCollection = ManageableCollectionUtil
-                .getManageableCollection(collection);
+            Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
+            ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
+            
             collectionConverter.updateCollection(session,
                                                  objectNode,
                                                  collectionDescriptor,

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=390621&r1=390620&r2=390621&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
Sat Apr  1 00:33:04 2006
@@ -1,281 +1,283 @@
-/*
- * 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
+/*
+ * 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();
+    }
+
+}

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java?rev=390621&r1=390620&r2=390621&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
Sat Apr  1 00:33:04 2006
@@ -1,125 +1,119 @@
-/*
- * 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.Iterator;
-import java.util.Map;
-
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
-import org.apache.portals.graffito.jcr.query.Filter;
-import org.apache.portals.graffito.jcr.query.Query;
-import org.apache.portals.graffito.jcr.query.QueryManager;
-
-public class QueryManagerImpl implements QueryManager
-{
-
-	private Mapper mapper;
-	private Map atomicTypeConverters;
-	public QueryManagerImpl(Mapper mapper,  Map atomicTypeConverters)
-	{
-		this.mapper = mapper;
-		this.atomicTypeConverters = atomicTypeConverters;
-	}
-	
-	public Filter createFilter(Class classQuery) 
-	{
-
-		return new FilterImpl(mapper.getClassDescriptor(classQuery), atomicTypeConverters, classQuery);
-	}
-
-	public Query createQuery(Filter filter)
-	{
-
-		return new QueryImpl(filter, mapper);
-	}
-
-	public String buildJCRExpression(Query query)
-	{
-
-		Filter filter = query.getFilter();
-		
-        // Check if the class has  an inheritance discriminator field		
-		ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass()); 
-		if (classDescriptor.hasDiscriminatorField())
-		{
-			Filter discrininatorFilter = buildDiscriminatorFilter(query,  classDescriptor);
-			 filter = filter.addAndFilter(discrininatorFilter);
-		}
-		
-		String jcrExp = "";
-		
-		// Add scope
-		if ((filter.getScope() != null && ( ! filter.getScope().equals(""))))
-		{
-			jcrExp +=  "/jcr:root" + filter.getScope() + "element(*, ";
-		}
-		else
-		{
-			jcrExp +=  "//element(*, ";
-		}
-		
-		// Add node type
-		jcrExp +=  this.getNodeType(filter) + ") ";
-
-        // Add filter criteria
-		String filterExp = ((FilterImpl)filter).getJcrExpression();
-			
-		// Build the jcr filter
-		if ((filterExp != null) && ( ! filterExp.equals("")))
-		{
-		    jcrExp += "[" + filterExp + "]";
-		}
-		
-		// Add order by
-		jcrExp += ((QueryImpl)query).getOrderByExpression();
-		
-		return jcrExp;
-		 
-	}
-
-	private Filter buildDiscriminatorFilter(Query query, ClassDescriptor classDescriptor) {
-		Filter discrininatorFilter = this.createFilter(query.getFilter().getFilterClass());
-		if ( ! classDescriptor.isAbstract())
-		{
-		    FieldDescriptor fieldDescriptor = classDescriptor.getDiscriminatorFieldDescriptor();
-		    discrininatorFilter.addEqualTo(fieldDescriptor.getFieldName(), classDescriptor.getClassName());
-		}
-		
-		if (classDescriptor.hasDescendants())
-		{
-			Iterator  descendantDescriptorIterator = classDescriptor.getDescendantClassDescriptors().iterator();
-			while (descendantDescriptorIterator.hasNext())
-			{
-				 ClassDescriptor descendantClassDescriptor = (ClassDescriptor)descendantDescriptorIterator.next();
-				 //Add subdescendant discriminator value
-				 discrininatorFilter =  discrininatorFilter.addOrFilter( this.buildDiscriminatorFilter(query,
descendantClassDescriptor));
-			}
-			
-		}
-		return discrininatorFilter;
-	}
-	
-	private String getNodeType(Filter filter)
-	{
-		ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass());
-		return classDescriptor.getJcrNodeType();
-		
-	}
-
-}
+/*
+ * 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.Iterator;
+import java.util.Map;
+
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
+import org.apache.portals.graffito.jcr.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+
+public class QueryManagerImpl implements QueryManager {
+
+    private Mapper mapper;
+    private Map atomicTypeConverters;
+
+    public QueryManagerImpl(Mapper mapper, Map atomicTypeConverters) {
+        this.mapper = mapper;
+        this.atomicTypeConverters = atomicTypeConverters;
+    }
+
+    public Filter createFilter(Class classQuery) {
+        return new FilterImpl(mapper.getClassDescriptor(classQuery),
+                              atomicTypeConverters,
+                              classQuery);
+    }
+
+    public Query createQuery(Filter filter) {
+        return new QueryImpl(filter, mapper);
+    }
+
+    public String buildJCRExpression(Query query) {
+
+        Filter filter = query.getFilter();
+
+        // Check if the class has  an inheritance discriminator field
+        ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass());
+        if (classDescriptor.hasDiscriminatorField()) {
+            Filter discrininatorFilter = buildDiscriminatorFilter(query, classDescriptor);
+            filter = filter.addAndFilter(discrininatorFilter);
+        }
+
+        String jcrExp = "";
+
+        // Add scope
+        if (((filter.getScope() != null) && (!filter.getScope().equals("")))) {
+            jcrExp += "/jcr:root" + filter.getScope() + "element(*, ";
+        }
+        else {
+            jcrExp += "//element(*, ";
+        }
+
+        // Add node type
+        jcrExp += this.getNodeType(filter) + ") ";
+
+        // Add filter criteria
+        String filterExp = ((FilterImpl) filter).getJcrExpression();
+
+        // Build the jcr filter
+        if ((filterExp != null) && (!filterExp.equals(""))) {
+            jcrExp += "[" + filterExp + "]";
+        }
+
+        // Add order by
+        jcrExp += ((QueryImpl) query).getOrderByExpression();
+
+        return jcrExp;
+
+    }
+
+    private Filter buildDiscriminatorFilter(Query query, ClassDescriptor classDescriptor)
{
+        Filter discriminatorFilter = this.createFilter(query.getFilter().getFilterClass());
+        if (!classDescriptor.isAbstract()) {
+            FieldDescriptor fieldDescriptor = classDescriptor.getDiscriminatorFieldDescriptor();
+            discriminatorFilter.addEqualTo(fieldDescriptor.getFieldName(),
+                                           classDescriptor.getClassName());
+        }
+
+        if (classDescriptor.hasDescendants()) {
+            Iterator descendantDescriptorIterator = classDescriptor.getDescendantClassDescriptors().iterator();
+            
+            while (descendantDescriptorIterator.hasNext()) {
+                ClassDescriptor descendantClassDescriptor = (ClassDescriptor) descendantDescriptorIterator.next();
+
+                //Add subdescendant discriminator value
+                discriminatorFilter = discriminatorFilter.addOrFilter(
+                        this.buildDiscriminatorFilter(query, descendantClassDescriptor));
+            }
+
+        }
+
+        return discriminatorFilter;
+    }
+
+    private String getNodeType(Filter filter) {
+        ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass());
+
+        return classDescriptor.getJcrNodeType();
+    }
+
+}



Mime
View raw message