incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r331149 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/exception/ java/org/apache/portals/graffito/jcr/persistence/ java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ java/org/ap...
Date Sun, 06 Nov 2005 19:55:42 GMT
Author: clombart
Date: Sun Nov  6 11:55:27 2005
New Revision: 331149

URL: http://svn.apache.org/viewcvs?rev=331149&view=rev
Log:
* Add basic version management (GRFT-46)
* Add method isPersistence (GRFT-68) - Provided by Martin Koci

Added:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/exception/VersionException.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/Version.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/VersionIterator.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerBasicVersionningTest.java
Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/exception/VersionException.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/exception/VersionException.java?rev=331149&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/exception/VersionException.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/exception/VersionException.java Sun Nov  6 11:55:27 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * 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.exception;
+
+
+/**
+ * Occurs when it is not possible to read information on version or manage versions
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+
+public class VersionException extends JcrMappingException
+{
+
+    /**
+     * Default Constructor without information.
+     */
+    public VersionException() 
+    {
+        super();
+    }
+    
+    /**
+     * Constructor with message.
+     * 
+     * @param message the message associated to the exception
+     */
+    public VersionException(String message) 
+    {
+        super(message);
+    }
+    
+    /**
+     * Constructor with throwable object.
+     * 
+     * @param nested the associated throwable object
+     */    
+    public VersionException(Throwable nested)
+    {
+        super(nested);
+    }
+    
+    /**
+     * Constructor with message and throwable object.
+     * 
+     * @param message the message associated to the exception
+     * @param nested the associated throwable object
+     */    
+    public VersionException(String message, Throwable nested)
+    {
+        super(message, nested);
+    }
+
+}

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java Sun Nov  6 11:55:27 2005
@@ -18,8 +18,12 @@
 import java.util.Collection;
 import java.util.Iterator;
 
+import javax.jcr.version.VersionException;
+
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.version.Version;
+import org.apache.portals.graffito.jcr.version.VersionIterator;
 
 /**
  * The persistence manager encapsulates a JCR session. 
@@ -34,12 +38,22 @@
     
     /**
      * Check if an object exists
-     * @param path the JCR item path  
+     * @param path the object path 
      * @return true if the item exists
      * @throws PersistenceException when it is not possible to check if the item exist
      */
     public boolean objectExists(String path) throws PersistenceException;
 
+    
+    /**
+     * Can this persistence manager insert, update, delete, ... that type?
+     * 
+     * @param clazz class for question
+     * @return <code>true</code> if the class is persistence
+     */
+     boolean isPersistent(Class clazz);
+     
+     
     /**
      * Insert an object into the JCR repository
      * @param path the target path 
@@ -50,7 +64,7 @@
 
     /**
      * Update an object 
-     * @param path the object paht
+     * @param path the object path
      * @param object the object to update 
      * @throws PersistenceException when it is not possible to update the object
      */
@@ -67,6 +81,18 @@
     public Object getObject(Class objectClass, String path) throws PersistenceException;
 
     /**
+     * Get an object from the JCR repository 
+     * @param objectClass the object class
+     * @param path the object path
+     * @param versionNumber The desired object version number
+     * @return the object found or null
+     * 
+     * @throws PersistenceException when it is not possible to retrieve the object 
+     */
+    public Object getObject(Class objectClass, String path, String versionNumber) throws PersistenceException;
+    
+    
+    /**
      * Remove an object from a JCR repository
      * @param path the object path
      * @throws PersistenceException when it is not possible to remove the object 
@@ -111,18 +137,101 @@
      * @throws PersistenceException when it is not possible to retrieve the objects 
      */
     public Iterator getObjectIterator (Query query) throws PersistenceException;
+     
     
     /**
-     * Close the session    
-     * @throws PersistenceException when it is not possible to logout
+     * Checkout - Create a new version
+     * This is only possible if the object is based on mix:versionable node type
+     *  
+     * @param path The object path
+     * @throws VersionException when it is not possible to create a new version 
      */
-    public void logout() throws PersistenceException;
+    public void checkout(String path) throws VersionException;
+    
+    /**
+     * Checkin an object
+     * @param path the object path 
+     * @throws VersionException when it is not possible to checkin
+     */
+    public void checkin(String path) throws VersionException;
     
     /**
+     * Checkin an object and apply some labels to this new version 
+     * Within a particular object path, a given label may appear a maximum of once
+     * @param path The object path 
+     * @param versionLabels the version labels to apply to the new version 
+     * @throws VersionException when it is possible to checkin
+     */
+    public void checkin(String path, String[] versionLabels) throws VersionException;
+    
+    
+    /**
+     * Get all version labels assigned to a particular object version 
+     * @param path the object path
+     * @param versionName the object version name (1.0, ...) 
+     * @return a array of string (version labels) 
+     * @throws VersionException when it is not to get all version labels
+     */
+    public String[] getVersionLabels(String path, String versionName) throws VersionException;
+    
+    
+    /**
+     * Get all version labels assigned to all versions 
+     * @param path the object path     
+     * @return a array of string (version labels) 
+     * @throws VersionException when it is not to get all version labels
+     */
+    public String[] getAllVersionLabels(String path) throws VersionException;    
+    
+    /**
+     * Add  a new label to a particular version  
+     * @param path the object path
+     * @param versionName the object versio name (1.0, 1.1, ...) 
+     * @param versionLabel The new label to apply
+     * @throws VersionException when it is not possible to add a new version label to this version
+     */
+    public void addVersionLabel(String path, String versionName, String versionLabel) throws VersionException;   
+    
+        
+    /**
+     * Get all object versions 
+     * @param path the object path
+     * @return a version iterator
+     * @throws VersionException when it is not possible to retrieve all versions
+     */
+    public VersionIterator getAllVersions(String path) throws VersionException;
+    
+    /**
+     * Get the first object version 
+     * @param path the object path
+     * @return the first version found
+     * @throws VersionException when it is not possible to get the root version 
+     */
+    public Version getRootVersion(String path) throws VersionException;
+    
+    
+    public Version getBaseVersion(String path) throws VersionException;
+    /**
+     * Get a particular version
+     * @param path the object path
+     * @param versionName the version name
+     * @return the version found or null 
+     * @throws VersionException when it is not possible to retrieve this particular version 
+     */
+    public Version getVersion(String path, String versionName) throws VersionException;
+    
+
+    /**
      * Save all modifications made by the persistence manager
      *
      * @throws PersistenceException when it is not possible to save all pending operation into the JCR repo 
      */
-    public void save() throws PersistenceException;
+    public void save() throws PersistenceException;  
+    
+    /**
+     * Close the session    
+     * @throws PersistenceException when it is not possible to logout
+     */
+    public void logout() throws PersistenceException;
         
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java Sun Nov  6 11:55:27 2005
@@ -16,6 +16,8 @@
 
 package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -27,6 +29,8 @@
 import javax.jcr.query.QueryResult;
 
 import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
@@ -34,6 +38,7 @@
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
 
 /** 
  * Collection Mapping/convertion based on node type.
@@ -66,6 +71,8 @@
 public class NTCollectionConverterImpl extends AbstractCollectionConverterImpl
 {
 
+	private final static Log log = LogFactory.getLog(NTCollectionConverterImpl.class);
+	
     private static final String COLLECTION_ELEMENT_NAME = "collection-element";
 
     /**
@@ -144,13 +151,13 @@
             
             if (collection == null)
             {
-                this.deleteCollectionItems(session, parentNode.getPath(), elementClassDescriptor.getJcrNodeType());
+                this.deleteCollectionItems(session, parentNode, elementClassDescriptor.getJcrNodeType());
                 return;
             }
 
             if (!elementClassDescriptor.hasIdField())
             {
-               this.deleteCollectionItems(session, parentNode.getPath(), elementClassDescriptor.getJcrNodeType());
+               this.deleteCollectionItems(session, parentNode, elementClassDescriptor.getJcrNodeType());
             }
             
             Iterator collectionIterator = collection.getIterator();
@@ -196,10 +203,10 @@
             // Delete JCR nodes that are not present in the collection
             if (elementClassDescriptor.hasIdField())
             {
-                NodeIterator nodeIterator = this.getCollectionNodes(session, parentNode.getPath(), elementClassDescriptor.getJcrNodeType());
+                Iterator nodeIterator = this.getCollectionNodes(session, parentNode, elementClassDescriptor.getJcrNodeType()).iterator();
                 while (nodeIterator.hasNext())
                 {
-                    Node child = nodeIterator.nextNode();
+                    Node child = (Node) nodeIterator.next();
                     if (! updatedItems.containsKey(child.getName()))
                     {
                         child.remove();
@@ -224,13 +231,14 @@
         {
             ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor(Class.forName(collectionDescriptor
                     .getElementClassName()));                        
-            NodeIterator children = this.getCollectionNodes(session, parentNode.getPath(), elementClassDescriptor.getJcrNodeType());
+            Iterator children = this.getCollectionNodes(session, parentNode, elementClassDescriptor.getJcrNodeType()).iterator();
 
             ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
 
             while (children.hasNext())
             {
-                Node itemNode = children.nextNode();
+                Node itemNode = (Node) children.next();
+                log.debug("Collection node found : " + itemNode.getPath());
                 Object item = objectConverter.getObject(session, Class.forName(collectionDescriptor.getElementClassName()),
                         itemNode.getPath());
                 collection.addObject(item);
@@ -245,20 +253,56 @@
         }
     }
 
-    private NodeIterator getCollectionNodes (Session session, String parentNodePath, String itemNodeType) throws Exception
+    private Collection getCollectionNodes (Session session, Node parentNode, String itemNodeType) throws Exception
     {
-           Query query =  session.getWorkspace().getQueryManager().createQuery("/jcr:root" + parentNodePath + "//element(*," + itemNodeType + ")", Query.XPATH);
-           QueryResult queryResult = query.execute();
-           return queryResult.getNodes();
+    	  
+           ArrayList collectionNodes = new ArrayList();
+
+           // TODO : review this workaround used to support version nodes  
+           // Searching on the version storage has some bugs => loop on all child noded and check the property jcr:frozenPrimaryType
+           // I have to investigate in more detail what's happen exactly  
+    	   if (! parentNode.getPath().startsWith("/jcr:system/jcr:versionStorage"))
+    	   {               
+               NodeIterator nodeIterator = parentNode.getNodes();
+               while (nodeIterator.hasNext())
+               {        	   
+            	   Node child = nodeIterator.nextNode();
+
+            	   if (child.isNodeType(itemNodeType))
+            	   {
+                       collectionNodes.add(child);
+            	   }
+               }    		   
+    	   }
+    	   else
+    	   {
+    		                  
+               NodeIterator nodeIterator = parentNode.getNodes();
+               while (nodeIterator.hasNext())
+               {        	   
+            	   Node child = nodeIterator.nextNode();
+
+            	   if (child.getProperty("jcr:frozenPrimaryType").getString().equals(itemNodeType))
+            	   {
+                       collectionNodes.add(child);
+            	   }
+               } 
+    		   
+    	   }
+    	   
+           return collectionNodes;
+           
     }
     
-    private void deleteCollectionItems(Session session, String parentNodePath, String itemNodeType) throws Exception
+    private void deleteCollectionItems(Session session, Node parentNode, String itemNodeType) throws Exception
     {
-           NodeIterator nodeIterator = this.getCollectionNodes(session, parentNodePath, itemNodeType); 
+           Iterator nodeIterator = this.getCollectionNodes(session, parentNode, itemNodeType).iterator(); 
            while (nodeIterator.hasNext())
            {
-               Node node = nodeIterator.nextNode();
+               Node node = (Node) nodeIterator.next();
                node.remove();
            }
     }
+    
+    
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Sun Nov  6 11:55:27 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2004 The Apache Software Foundation.
+ * Copyright 2000-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,16 +26,21 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionHistory;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.exception.VersionException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
 import org.apache.portals.graffito.jcr.query.Query;
 import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.version.Version;
+import org.apache.portals.graffito.jcr.version.VersionIterator;
 
 /** 
  * 
@@ -52,19 +57,18 @@
 	 */
 	private final static Log log = LogFactory.getLog(PersistenceManagerImpl.class);
 
-
 	/** 
 	 * JCR session.
 	 */
 	protected Session session;
 
+	protected Mapper mapper;
 
 	/**
 	 * The Graffito query manager
 	 */
 	protected QueryManager queryManager;
 
-	 
 	/**
 	 * Object Converter
 	 */
@@ -81,17 +85,17 @@
 	 */
 	public PersistenceManagerImpl(Mapper mapper, Map atomicTypeConverters, QueryManager queryManager, Session session)
 	{
-			this.session = session;
-			this.objectConverter = new ObjectConverterImpl(mapper, atomicTypeConverters);
-			this.queryManager = queryManager;
+		this.mapper = mapper;
+		this.session = session;
+		this.objectConverter = new ObjectConverterImpl(mapper, atomicTypeConverters);
+		this.queryManager = queryManager;
 	}
 
-  
 	/**
 	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String)
 	 */
-	public Object getObject(Class pojoClass, String path)
+	public Object getObject(Class objectClass, String path)
 	{
 		try
 		{
@@ -106,32 +110,57 @@
 			throw new PersistenceException("Impossible to get the object at " + path, e);
 		}
 
-		return objectConverter.getObject(session, pojoClass, path);
+		return objectConverter.getObject(session, objectClass, path);
+
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String, java.lang.String)
+	 */
+	public Object getObject(Class objectClass, String path, String versionName) throws PersistenceException
+	{
+		String pathVersion = null;
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				return null;
+			}
+
+			Version version = this.getVersion(path, versionName);
+			pathVersion = version.getPath() + "/jcr:frozenNode";
 
+		}
+		catch (Exception e)
+		{
+			throw new PersistenceException("Impossible to get the object at " + path + " - version :" + versionName, e);
+		}
+
+		return objectConverter.getObject(session, objectClass, pathVersion);
 	}
 
 	/**
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.String, java.lang.Object)
 	 */
-	public void insert(String path, Object object) 
+	public void insert(String path, Object object)
 	{
 		try
 		{
 			if (session.itemExists(path))
 			{
 				Item item = session.getItem(path);
-			    if (item.isNode())
-			    {			    	
-			    	if ( ! ((Node)item).getDefinition().allowsSameNameSiblings())
-			    	{
-			    		throw new PersistenceException("Path already exists and it is not supporting the same name sibling : " + path);
-			    	}
-			    }
-			    else
-			    {			    
-			    	throw new PersistenceException("Path already exists and it is a property : " + path);
-			    }
-				
+				if (item.isNode())
+				{
+					if (!((Node) item).getDefinition().allowsSameNameSiblings())
+					{
+						throw new PersistenceException("Path already exists and it is not supporting the same name sibling : " + path);
+					}
+				}
+				else
+				{
+					throw new PersistenceException("Path already exists and it is a property : " + path);
+				}
+
 			}
 		}
 		catch (RepositoryException e)
@@ -146,7 +175,7 @@
 	/**
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.String, java.lang.Object)
 	 */
-	public void update(String path, Object object) 
+	public void update(String path, Object object)
 	{
 		try
 		{
@@ -167,21 +196,20 @@
 	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.String)
 	 */
-	public void remove(String path) 
+	public void remove(String path)
 	{
 
 		try
 		{
-			Item item = session.getItem(path);			
+			Item item = session.getItem(path);
 			item.remove();
-		
+
 		}
 		catch (RepositoryException e)
 		{
 			throw new PersistenceException("Impossible to remove the object at " + path);
 		}
 	}
-	
 
 	/**
 	 * 
@@ -194,12 +222,12 @@
 
 			String jcrExpression = this.queryManager.buildJCRExpression(query);
 			log.debug("Remove Objects with expression : " + jcrExpression);
-						
+
 			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression, javax.jcr.query.Query.XPATH);
 			QueryResult queryResult = jcrQuery.execute();
 			NodeIterator nodeIterator = queryResult.getNodes();
-            ArrayList nodes = new ArrayList();
-            
+			ArrayList nodes = new ArrayList();
+
 			while (nodeIterator.hasNext())
 			{
 				Node node = nodeIterator.nextNode();
@@ -208,21 +236,20 @@
 				// So, we add the node found in a collection to remove them after
 				nodes.add(node);
 			}
-			
+
 			// Remove all collection nodes
-            for(int i = 0; i < nodes.size(); i++)
-            {
-                Node node = (Node) nodes.get(i);
-                node.remove();
-            }
-			
+			for (int i = 0; i < nodes.size(); i++)
+			{
+				Node node = (Node) nodes.get(i);
+				node.remove();
+			}
+
 		}
 		catch (RepositoryException e)
 		{
 			throw new PersistenceException("Impossible to get the object collection", e);
 		}
-		
-		
+
 	}
 
 	/**
@@ -244,30 +271,45 @@
 
 	/**
 	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#isPersistent(java.lang.Class)
+	 */
+	public boolean isPersistent(final Class clazz)
+	{
+		boolean isPersistent = false;
+		ClassDescriptor classDescriptor = mapper.getClassDescriptor(clazz);
+		if (classDescriptor != null)
+		{
+			isPersistent = true;
+		}
+		return isPersistent;
+	}
+
+	/**
+	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(org.apache.portals.graffito.jcr.query.Query)
 	 */
-	public Object getObject(Query query) 
+	public Object getObject(Query query)
 	{
-		
+
 		try
 		{
 
 			String jcrExpression = this.queryManager.buildJCRExpression(query);
 			log.debug("Get Object with expression : " + jcrExpression);
-						
+
 			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression, javax.jcr.query.Query.XPATH);
 			QueryResult queryResult = jcrQuery.execute();
 			NodeIterator nodeIterator = queryResult.getNodes();
 
-            if (nodeIterator.getSize() > 1)
-            {
-            	throw new PersistenceException("Impossible to get the object - the query returns more than one object");
-            }
-            
-			Object object = null; 
-            if (nodeIterator.hasNext())
+			if (nodeIterator.getSize() > 1)
 			{
-				Node node = nodeIterator.nextNode();				
+				throw new PersistenceException("Impossible to get the object - the query returns more than one object");
+			}
+
+			Object object = null;
+			if (nodeIterator.hasNext())
+			{
+				Node node = nodeIterator.nextNode();
 				object = objectConverter.getObject(session, query.getFilter().getFilterClass(), node.getPath());
 			}
 
@@ -284,14 +326,14 @@
 	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObjects(org.apache.portals.graffito.jcr.query.Query)
 	 */
-	public Collection getObjects(Query query) 
+	public Collection getObjects(Query query)
 	{
 		try
 		{
 
 			String jcrExpression = this.queryManager.buildJCRExpression(query);
 			log.debug("Get Objects with expression : " + jcrExpression);
-						
+
 			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression, javax.jcr.query.Query.XPATH);
 			QueryResult queryResult = jcrQuery.execute();
 			NodeIterator nodeIterator = queryResult.getNodes();
@@ -316,26 +358,256 @@
 	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObjectIterator(org.apache.portals.graffito.jcr.query.Query)
 	 */
-	public Iterator getObjectIterator(Query query) 
+	public Iterator getObjectIterator(Query query)
 	{
 		try
 		{
 
 			String jcrExpression = this.queryManager.buildJCRExpression(query);
 			log.debug("Get Object with expression : " + jcrExpression);
-						
+
 			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression, javax.jcr.query.Query.XPATH);
 			QueryResult queryResult = jcrQuery.execute();
 			NodeIterator nodeIterator = queryResult.getNodes();
 			return new ObjectIterator(nodeIterator, query.getFilter().getFilterClass(), this.objectConverter, this.session);
-			
+
 		}
 		catch (RepositoryException e)
 		{
 			throw new PersistenceException("Impossible to get the object collection", e);
 		}
-	}	
-	
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkin(java.lang.String)
+	 */
+	public void checkin(String path)
+	{
+		this.checkin(path, null);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkin(java.lang.String, java.lang.String[])
+	 */
+	public void checkin(String path, String[] versionLabels)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+			javax.jcr.version.Version newVersion = node.checkin();
+
+			if (versionLabels != null)
+			{
+				VersionHistory versionHistory = node.getVersionHistory();
+				for (int i = 0; i < versionLabels.length; i++)
+				{
+					versionHistory.addVersionLabel(newVersion.getName(), versionLabels[i], false);
+				}
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException("Impossible to checkin the object " + path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkout(java.lang.String)
+	 */
+	public void checkout(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			node.checkout();
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException("Impossible to checkout the object " + path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#addVersionLabel(java.lang.String, java.lang.String, java.lang.String)
+	 */
+	public void addVersionLabel(String path, String versionName, String versionLabel)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			history.addVersionLabel(versionName, versionLabel, false);
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException("Impossible to add a new version label to  " + path + " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getVersion(java.lang.String, java.lang.String)
+	 */
+	public Version getVersion(String path, String versionName)
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+
+			return new Version(history.getVersion(versionName));
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the version : " + path + " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getVersionLabels(java.lang.String, java.lang.String)
+	 */
+	public String[] getVersionLabels(String path, String versionName)
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			javax.jcr.version.Version version = history.getVersion(versionName);
+			return history.getVersionLabels(version);
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the version labels : " + path + " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getAllVersionLabels(java.lang.String)
+	 */
+	public String[] getAllVersionLabels(String path) throws javax.jcr.version.VersionException
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			return history.getVersionLabels();
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the all version labels : " + path, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getAllVersions(java.lang.String)
+	 */
+	public VersionIterator getAllVersions(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			return new VersionIterator(history.getAllVersions());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to checkin the object " + path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getRootVersion(java.lang.String)
+	 */
+	public Version getRootVersion(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+
+			return new Version(history.getRootVersion());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the root version  for the object " + path, e);
+		}
+
+	}
+
+	public Version getBaseVersion(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path + "is not versionable");
+			}
+
+			return new Version(node.getBaseVersion());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the base version for the object " + path, e);
+		}
+
+	}
+
 	/**
 	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#logout()
@@ -352,7 +624,6 @@
 			throw new PersistenceException("Impossible to logout", e);
 		}
 	}
-	
 
 	/**
 	 * 
@@ -362,20 +633,20 @@
 	{
 		try
 		{
-		    session.save();
+			session.save();
 		}
-		catch(Exception e)
+		catch (Exception e)
 		{
 			throw new PersistenceException("Impossible to save", e);
 		}
 	}
-	
+
 	/**
 	 * @return The JCR Session
 	 */
 	public Session getSession()
 	{
 		return this.session;
-	}	
+	}
 
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java Sun Nov  6 11:55:27 2005
@@ -26,6 +26,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.jackrabbit.core.util.ISO9075;
+import org.apache.jackrabbit.util.Text;
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.exception.RepositoryException;
 
@@ -273,6 +275,25 @@
             log.error("Error while setting up the jcr repository.", e);
             throw new RepositoryException(e.getMessage());
         }
+    }
+
+    /**
+     * Encode a path 
+     * @TODO : drop Jackrabbit dependency
+     * 
+     * @param path the path to encode
+     * @return the encoded path 
+     * 
+     */
+    public static String encodePath(String path)
+    {
+    	String[] pathElements = Text.explode(path, '/');
+    	for (int i=0;i<pathElements.length;i++)
+    	{
+    		pathElements[i] = ISO9075.encode(pathElements[i]);
+    	}
+    	return "/" + Text.implode(pathElements, "/");
+    	
     }
     
       

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/Version.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/Version.java?rev=331149&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/Version.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/Version.java Sun Nov  6 11:55:27 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * 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.version;
+
+import java.util.Calendar;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.portals.graffito.jcr.exception.VersionException;
+
+/**
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * 
+ */
+public class Version
+{
+
+	private javax.jcr.version.Version version;
+
+	public Version(javax.jcr.version.Version version)
+	{
+		this.version = version;
+	}
+
+	public Calendar getCreated()
+	{
+		try
+		{
+			return version.getCreated();
+		}
+		catch (RepositoryException e)
+		{
+
+			throw new VersionException("Error while retrieving the version creation date", e);
+		}
+	}
+
+	public String getUuid()
+	{
+		try
+		{
+			return version.getUUID();
+		}
+		catch (RepositoryException e)
+		{
+
+			throw new VersionException("Error while retrieving the version UUID", e);
+		}
+	}
+
+	public String getPath()
+	{
+		try
+		{
+			return version.getPath();
+		}
+		catch (RepositoryException e)
+		{
+
+			throw new VersionException("Error while retrieving the version path", e);
+		}
+	}
+
+	public String getName()
+	{
+		try
+		{
+			return version.getName();
+			
+		}
+		catch (RepositoryException e)
+		{
+
+			throw new VersionException("Error while retrieving the version path", e);
+		}
+	}	
+	
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/VersionIterator.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/VersionIterator.java?rev=331149&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/VersionIterator.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/version/VersionIterator.java Sun Nov  6 11:55:27 2005
@@ -0,0 +1,88 @@
+/*
+ * 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.version;
+
+import java.util.Iterator;
+
+import javax.jcr.version.Version;
+
+
+/**
+ * VersionIterator is a wrapper class for JCR VersionIterator
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class VersionIterator implements Iterator
+{
+
+	private javax.jcr.version.VersionIterator versionIterator;
+	
+	public VersionIterator(javax.jcr.version.VersionIterator versionIterator)
+	{
+		this.versionIterator = versionIterator;
+	}
+
+	/**
+	 * 
+	 * @see java.util.Iterator#hasNext()
+	 */
+	public boolean hasNext()
+	{
+		return versionIterator.hasNext();
+	}
+
+	/**
+	 * 
+	 * @see java.util.Iterator#next()
+	 */
+	public Object next() 
+	{
+
+		try
+		{
+			Version version =  versionIterator.nextVersion();
+			return new org.apache.portals.graffito.jcr.version.Version(version);
+		}
+		catch (Exception e)
+		{
+           return null;			
+		}
+
+	}
+
+	/**
+	 * 
+	 * @return the versionIterator size
+	 */
+	public long getSize()
+	{
+	   return versionIterator.getSize();	
+	}
+	
+	/**
+	 * 
+	 * @see java.util.Iterator#remove()
+	 */
+	public void remove()
+	{
+		versionIterator.remove();
+		
+	}
+
+}

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerBasicVersionningTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerBasicVersionningTest.java?rev=331149&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerBasicVersionningTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerBasicVersionningTest.java Sun Nov  6 11:55:27 2005
@@ -0,0 +1,155 @@
+package org.apache.portals.graffito.jcr.persistence.impl;
+
+
+import java.util.Date;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+import org.apache.portals.graffito.jcr.version.Version;
+import org.apache.portals.graffito.jcr.version.VersionIterator;
+
+/**
+ * Test Query on atomic fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerBasicVersionningTest extends TestBase
+{
+	private final static Log log = LogFactory.getLog(PersistenceManagerBasicVersionningTest.class);
+	private Date date = new Date();
+	
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerBasicVersionningTest(String testName) throws Exception
+	{
+		super(testName);
+		
+	}
+
+	public static Test suite()
+	{
+		// All methods starting with "test" will be executed in the test suite.
+		return new TestSuite(PersistenceManagerBasicVersionningTest.class);
+	}
+
+    public void tearDown() throws Exception
+    {
+    	PersistenceManager persistenceManager = getPersistenceManager();
+	    persistenceManager.remove("/page");
+    	persistenceManager.save();
+       
+        super.tearDown();
+    }	
+
+	public void testSimpleVersion()
+	{
+		     PersistenceManager persistenceManager = getPersistenceManager();
+             try
+             {
+            	 
+            	 Page page = new Page();
+            	 page.setTitle("Page Title");            	 
+            	 page.addParagraph(new Paragraph("para1"));
+            	 page.addParagraph(new Paragraph("para2"));
+            	 persistenceManager.insert("/page", page);
+            	 persistenceManager.save();
+            	 
+                 
+            	 page.addParagraph(new Paragraph("para3"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update("/page", page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page");
+            	 
+            	 page.addParagraph(new Paragraph("para4"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update("/page", page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page");            	 
+
+            	 VersionIterator versionIterator = persistenceManager.getAllVersions("/page");
+            	 assertNotNull("VersionIterator is null", versionIterator);
+            	 assertTrue("Invalid number of versions found", versionIterator.getSize() == 3);
+            	 
+            	 while (versionIterator.hasNext())
+            	 {
+            		 Version version = (Version) versionIterator.next();
+            		 log.info("version found : " + version.getPath() + " - " +  version.getCreated().getTime());
+            		 
+            	 }
+            	 
+            	 Version baseVersion = persistenceManager.getBaseVersion("/page");
+            	 System.out.println("Base version : " + baseVersion.getName());
+
+            	 Version rootVersion = persistenceManager.getRootVersion("/page");
+            	 System.out.println("Root version : " + rootVersion.getName());
+            	 //this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage", true, false);
+            	             	
+            	 //Get the object matching to the first version 
+            	 Page page1 = (Page) persistenceManager.getObject(Page.class, "/page", "1.0");
+            	 assertNotNull("version 1.0 object is null", page1);
+            	 assertTrue("Invalid number of paragraph found in the root version", page1.getParagraphs().size() == 3);
+
+             }
+             catch(Exception e)
+             {
+            	 e.printStackTrace();
+            	 fail();
+            	 
+             }
+	}
+
+	
+	public void testVersionLabels()
+	{
+		     PersistenceManager persistenceManager = getPersistenceManager();
+             try
+             {
+            	 
+            	 Page page = new Page();
+            	 page.setTitle("Page Title");            	 
+            	 page.addParagraph(new Paragraph("para1"));
+            	 page.addParagraph(new Paragraph("para2"));
+            	 persistenceManager.insert("/page", page);
+            	 persistenceManager.save();
+            	 
+                 
+            	 page.addParagraph(new Paragraph("para3"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update("/page", page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page", new String[] {"A", "B"});
+            	 
+            	 page.addParagraph(new Paragraph("para4"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update("/page", page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page", new String[] {"C", "D"});         	 
+
+            	 String[] allLabels = persistenceManager.getAllVersionLabels("/page");
+            	 assertTrue("Incorrect number of labels", allLabels.length == 4);
+
+            	 String[] versionLabels = persistenceManager.getVersionLabels("/page", "1.1");
+            	 assertTrue("Incorrect number of labels", versionLabels.length == 2);
+            	 assertTrue("Incorrect label", versionLabels[0].equals("C") || versionLabels[0].equals("D"));
+            	 assertTrue("Incorrect label", versionLabels[1].equals("C") || versionLabels[0].equals("D"));
+            	
+
+             }
+             catch(Exception e)
+             {
+            	 e.printStackTrace();
+            	 fail(); 
+             }
+	}
+	
+}
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java Sun Nov  6 11:55:27 2005
@@ -92,22 +92,15 @@
     	try
     	{
     		
-    		  // No scope    		  
-    	      QueryManager queryManager = this.getQueryManager();
-    	      Filter filter = queryManager.createFilter(Paragraph.class);    
-    	      
-    	      Query query = queryManager.createQuery(filter);    	      
+              	      
     	      PersistenceManager persistenceManager = this.getPersistenceManager();
-    	      Collection result = persistenceManager.getObjects(query);
-    	      assertTrue("Invalid number of objects - should be = 16", result.size() == 16);
-
     	      // Search on subtree (test/node1)
-    	      queryManager = this.getQueryManager();
-    	      filter = queryManager.createFilter(Paragraph.class);    
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);    
     	      filter.setScope("/test/node1//");
-    	      query = queryManager.createQuery(filter);    	      
+    	      Query query = queryManager.createQuery(filter);    	      
     	      persistenceManager = this.getPersistenceManager();
-    	      result = persistenceManager.getObjects(query);
+    	      Collection result = persistenceManager.getObjects(query);
     	      assertTrue("Invalid number of objects - should be = 8", result.size() == 8);
     	      
     	      

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java Sun Nov  6 11:55:27 2005
@@ -18,11 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.Session;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -34,7 +29,6 @@
 import org.apache.portals.graffito.jcr.testmodel.A;
 import org.apache.portals.graffito.jcr.testmodel.B;
 import org.apache.portals.graffito.jcr.testmodel.C;
-import org.apache.portals.graffito.jcr.testmodel.Folder;
 
 /**
  * Test JcrSession
@@ -66,8 +60,11 @@
      */
     public void tearDown() throws Exception
     {
-    	getPersistenceManager().remove("/test");
-    	getPersistenceManager().save();
+    	if (getPersistenceManager().objectExists("/test"))
+    	{
+    	   getPersistenceManager().remove("/test");
+    	   getPersistenceManager().save();
+    	}
         super.tearDown();
     }
     
@@ -154,6 +151,13 @@
             fail("Exception occurs during the unit test : " + e);
         }
         
+    }
+    
+    public void testIsPersistent()
+    {    
+    	PersistenceManager persistenceManager = getPersistenceManager();
+    	assertTrue("Class A is not persistent ", persistenceManager.isPersistent(A.class));
+    	assertFalse("Class String is  persistent - hum ? ", persistenceManager.isPersistent(String.class));
     }
     
 

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java?rev=331149&r1=331148&r2=331149&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java Sun Nov  6 11:55:27 2005
@@ -167,5 +167,15 @@
             e.printStackTrace();
             fail("Unable to find the repository : " + e);
         }
-    }    
+    }   
+    
+    public void testEncodePath()
+    {
+         String encodedPath = RepositoryUtil.encodePath("/files/test/1.0");
+         assertTrue("Incorrect encoded path", encodedPath.equals("/files/test/_x0031_.0"));
+
+         encodedPath = RepositoryUtil.encodePath("/files/test/12aa/b/34/rrr/1.0");
+         assertTrue("Incorrect encoded path", encodedPath.equals("/files/test/_x0031_2aa/b/_x0033_4/rrr/_x0031_.0"));
+
+    }
 }



Mime
View raw message