incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r291714 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/persistence/ java/org/apache/portals/graffito/jcr/persistence/impl/ java/org/apache/portals/graffito/jcr/query/ java/org/apache/portals/graffito/jc...
Date Mon, 26 Sep 2005 19:10:35 GMT
Author: clombart
Date: Mon Sep 26 12:10:22 2005
New Revision: 291714

URL: http://svn.apache.org/viewcvs?rev=291714&view=rev
Log:
Continue my work on the Query service. This is not yet finished. 
The PersistenceManagerQueryTest contains a good API example.

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/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java

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=291714&r1=291713&r2=291714&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
Mon Sep 26 12:10:22 2005
@@ -15,7 +15,10 @@
  */
 package org.apache.portals.graffito.jcr.persistence;
 
+import java.util.Collection;
+
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.query.Query;
 
 /**
  * The persistence manager encapsulate a JCR session. 
@@ -68,6 +71,14 @@
      */
     public void remove(String path) throws JcrMappingException;
     
+    
+    /**
+     * Retrieve some pojo objects matching to a query     
+     * @param query The Graffito Query object used to seach the objects
+     * @return a collection of object found
+     * 
+     */
+    public Collection getObjects(Query query) throws JcrMappingException;
     
     /**
      * Close the JCR session    

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=291714&r1=291713&r2=291714&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
Mon Sep 26 12:10:22 2005
@@ -15,11 +15,19 @@
  */
 package org.apache.portals.graffito.jcr.persistence.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import javax.jcr.Item;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -29,6 +37,7 @@
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterFactory;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.query.Query;
 
 /** Interface that specifies howto interact with a jcr repository (JCR broker).
  * 
@@ -39,185 +48,204 @@
  */
 public class PersistenceManagerImpl implements PersistenceManager
 {
-    /** Logger.
-     */
-    private final static Log log = LogFactory.getLog(PersistenceManagerImpl.class);    
-    
-   
-    /** 
-     * Jackrabbit jcr repository.
-     */
-    private Repository repository;
-    
-    /** Jackrabbit jcr session.
-     */
-    private Session session;
-           
-    /**
-     * The Mapper component
-     */
-    private Mapper mapper; 
-
-    /**
-     * The Atomic Type Converter Factory
-     */
-    private AtomicTypeConverterFactory atomicTypeConverterFactory;
-    
-    /**
-     * Object Converter
-     */
-    private ObjectConverter objectConverter;
-    
-
-
-    /**
-     * Contructor for setting up a session to interact with a jcr repository. 
-     * 
-     * @param mapper the Mapper component
-     * @param repository The JCR repository reference
-     * @param session The JCR Session
-     * 
-     * @throws JcrMappingException when it is impossible to create the PersistenceManager
-     */
-    public PersistenceManagerImpl(Mapper mapper, Repository repository, Session session)
throws JcrMappingException
-    {
-       try
-       {
-        this.mapper = mapper;
-        this.repository = repository;
-        this.session = session;
-        this.atomicTypeConverterFactory = AtomicTypeConverterFactory.getInstance(session.getValueFactory());
-        this.objectConverter = new ObjectConverter(mapper, atomicTypeConverterFactory); 
              
-       }
-       catch(Exception e)
-       {
-           throw new JcrMappingException("Impossible to create the persistenceManager", e);
-       }
-    }
-    
-        
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.session.JcrSession#getObject(java.lang.Class,
java.lang.String)
-     */
-    public Object getObject(Class pojoClass, String path) throws JcrMappingException
-    {   
-        try
-        {
-            if (!session.itemExists(path))
-            {
-                return null;
-            }                      
-
-        }
-        catch (Exception e)
-        {
-            throw new JcrMappingException("Impossible to get the object at " + path, e);
-        }    
-        
-        return objectConverter.getObject(session, pojoClass, path);
-                
-    }
-    
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.String,
java.lang.Object)
-     */
-    public void insert(String path, Object object)  throws JcrMappingException
-    {
-        try
-        {
-            if (session.itemExists(path))
-            {
-                throw new JcrMappingException("Path already exists : " + path);
-            }
-        }
-        catch (RepositoryException e)
-        {
-            throw new JcrMappingException("Impossible to insert the object at " + path, e);
-        }
-        
-        
-        objectConverter.insert(session, path, object);
-        
-    }
-
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.String,
java.lang.Object)
-     */
-    public void update(String path, Object object)  throws JcrMappingException
-    {
-        try
-        {
-            if (! session.itemExists(path))
-            {
-                throw new JcrMappingException("Path is not existing : " + path);
-            }
-        }
-        catch (RepositoryException e)
-        {
-            throw new JcrMappingException("Impossible to update", e);
-        }
-        
-        objectConverter.update(session, path, object);  
-    }
-        
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.String)
-     */
-    public void remove(String path) throws JcrMappingException
-    {
-    
-        try
-        {
-            Item item = session.getItem(path);
-            Node parent = item.getParent();
-            item.remove();
-            parent.save();
-        }
-        catch (RepositoryException e)
-        {
-            throw new JcrMappingException("Impossible to remove the object at " + path);
-        }
-    }
-    
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#itemExists(java.lang.String)
-     */
-    public boolean itemExists(String path) throws JcrMappingException
-    {
-        try
-        {
-            return session.itemExists(path);
-        }
-        catch (RepositoryException e)
-        {
-            throw new JcrMappingException("Impossible to check if the object exist", e);
-        }
-    }
-
-
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#logout()
-     */
-    public void logout() throws JcrMappingException
-    {
-        try 
-        {
-           session.save();
-           session.logout();
-        }
-        catch (Exception e)
-        {
-            throw new JcrMappingException("Impossible to logout", e);
-        }
-    }
-
-    
-    
-  
+	/** Logger.
+	 */
+	private final static Log log = LogFactory.getLog(PersistenceManagerImpl.class);
+
+	/** 
+	 * Jackrabbit jcr repository.
+	 */
+	private Repository repository;
+
+	/** Jackrabbit jcr session.
+	 */
+	private Session session;
+
+	/**
+	 * The Mapper component
+	 */
+	private Mapper mapper;
+
+	org.apache.portals.graffito.jcr.query.QueryManager queryManager;
+
+	/**
+	 * The Atomic Type Converter Factory
+	 */
+	private AtomicTypeConverterFactory atomicTypeConverterFactory;
+
+	/**
+	 * Object Converter
+	 */
+	private ObjectConverter objectConverter;
+
+	/**
+	 * Contructor for setting up a session to interact with a jcr repository. 
+	 * 
+	 * @param mapper the Mapper component
+	 * @param repository The JCR repository reference
+	 * @param session The JCR Session
+	 * 
+	 * @throws JcrMappingException when it is impossible to create the PersistenceManager
+	 */
+	public PersistenceManagerImpl(Mapper mapper, org.apache.portals.graffito.jcr.query.QueryManager
queryManager, Repository repository, Session session) throws JcrMappingException
+	{
+		try
+		{
+			this.mapper = mapper;
+			this.repository = repository;
+			this.session = session;
+			this.atomicTypeConverterFactory = AtomicTypeConverterFactory.getInstance(session.getValueFactory());
+			this.objectConverter = new ObjectConverter(mapper, atomicTypeConverterFactory);
+			this.queryManager = queryManager;
+		}
+		catch (Exception e)
+		{
+			throw new JcrMappingException("Impossible to create the persistenceManager", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.session.JcrSession#getObject(java.lang.Class, java.lang.String)
+	 */
+	public Object getObject(Class pojoClass, String path) throws JcrMappingException
+	{
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				return null;
+			}
+
+		}
+		catch (Exception e)
+		{
+			throw new JcrMappingException("Impossible to get the object at " + path, e);
+		}
+
+		return objectConverter.getObject(session, pojoClass, path);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.String,
java.lang.Object)
+	 */
+	public void insert(String path, Object object) throws JcrMappingException
+	{
+		try
+		{
+			if (session.itemExists(path))
+			{
+				throw new JcrMappingException("Path already exists : " + path);
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new JcrMappingException("Impossible to insert the object at " + path, e);
+		}
+
+		objectConverter.insert(session, path, object);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.String,
java.lang.Object)
+	 */
+	public void update(String path, Object object) throws JcrMappingException
+	{
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				throw new JcrMappingException("Path is not existing : " + path);
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new JcrMappingException("Impossible to update", e);
+		}
+
+		objectConverter.update(session, path, object);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.String)
+	 */
+	public void remove(String path) throws JcrMappingException
+	{
+
+		try
+		{
+			Item item = session.getItem(path);
+			Node parent = item.getParent();
+			item.remove();
+			parent.save();
+		}
+		catch (RepositoryException e)
+		{
+			throw new JcrMappingException("Impossible to remove the object at " + path);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#itemExists(java.lang.String)
+	 */
+	public boolean itemExists(String path) throws JcrMappingException
+	{
+		try
+		{
+			return session.itemExists(path);
+		}
+		catch (RepositoryException e)
+		{
+			throw new JcrMappingException("Impossible to check if the object exist", e);
+		}
+	}
+
+	public Collection getObjects(Query query) throws JcrMappingException
+	{
+		try
+		{
+
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression,
javax.jcr.query.Query.XPATH);
+			QueryResult queryResult = jcrQuery.execute();
+			NodeIterator nodeIterator = queryResult.getNodes();
+
+			ArrayList result = new ArrayList();
+			while (nodeIterator.hasNext())
+			{
+				Node node = nodeIterator.nextNode();
+				result.add(objectConverter.getObject(session, query.getFilter().getFilterClass(), node.getPath()));
+			}
+
+			return result;
+		}
+		catch (RepositoryException e)
+		{
+			throw new JcrMappingException("Impossible to get the object collection", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#logout()
+	 */
+	public void logout() throws JcrMappingException
+	{
+		try
+		{
+			session.save();
+			session.logout();
+		}
+		catch (Exception e)
+		{
+			throw new JcrMappingException("Impossible to logout", e);
+		}
+	}
+
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java?rev=291714&r1=291713&r2=291714&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
Mon Sep 26 12:10:22 2005
@@ -64,17 +64,11 @@
 
 	public void addGreaterThan(String arg0, Object arg1);
 
-	public void addIn(String attribute, Collection values);
-
 	public void addLessOrEqualThan(String arg0, Object arg1);
 
 	public void addLike(String arg0, Object arg1);
 
-	public abstract void addNotBetween(String arg0, Object arg1, Object arg2);
-
 	public void addNotEqualTo(String arg0, Object arg1);
-
-	public void addNotLike(String arg0, Object arg1);
 
 	public void addNotNull(String arg0);
 

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java?rev=291714&r1=291713&r2=291714&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
Mon Sep 26 12:10:22 2005
@@ -19,6 +19,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
@@ -40,6 +41,9 @@
 	
 	private Mapper mapper;
 	private ClassDescriptor classDescriptor;
+	
+	
+	private String orJcrExpression; 
 		
 	
 	public FilterImpl(Mapper mapper, Class clazz) throws JcrMappingException
@@ -53,8 +57,7 @@
 	
 	
 	public Class getFilterClass()
-	{
-		
+	{		
 		return claszz;
 	}
 
@@ -82,6 +85,8 @@
 	 */
 	public void addContains(String fullTextSearch)
 	{
+		String jcrExpression = "jcr:contains(., '" + fullTextSearch + "')";
+		jcrExpressions.add(jcrExpression);
 	}
 
 	/**
@@ -89,6 +94,10 @@
 	 */
 	public void addBetween(String fieldAttributeName, Object value1, Object value2)
 	{
+		String jcrExpression =  "( @" + this.getJcrFieldName(fieldAttributeName) + " >= " +
this.getStringValue(value1) + 
+		                        " and " + this.getJcrFieldName(fieldAttributeName) + " <= "
+ this.getStringValue(value2) +  ")";
+		jcrExpressions.add(jcrExpression) ;		
+
 	}
 
 	/**
@@ -116,55 +125,50 @@
 	 */
 	public void addGreaterThan(String fieldAttributeName, Object value)
 	{
+		String jcrExpression =  "@" + this.getJcrFieldName(fieldAttributeName) + " > " + this.getStringValue(value);
+		jcrExpressions.add(jcrExpression);	
+		
 	}
 
-	/**
-	 * @see org.apache.portals.graffito.jcr.query.Filter#addIn(java.lang.String, java.util.Collection)
-	 */
-	public void addIn(String fieldAttributeName, Collection values)
-	{
-	}
 
 	/**
 	 * @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String,
java.lang.Object)
 	 */
-	public void addLessOrEqualThan(String fieldAttributeName, Object arg1)
+	public void addLessOrEqualThan(String fieldAttributeName, Object value)
 	{
+		String jcrExpression =  "@" + this.getJcrFieldName(fieldAttributeName) + " <= " + this.getStringValue(value);
+		jcrExpressions.add(jcrExpression);	
+		
 	}
 
 	/**
 	 * @see org.apache.portals.graffito.jcr.query.Filter#addLike(java.lang.Object, java.lang.Object)
 	 */
-	public void addLike(String fieldAttributeName, Object arg1)
+	public void addLike(String fieldAttributeName, Object value)
 	{
+		String jcrExpression = "jcr:like(" + "@" + this.getJcrFieldName(fieldAttributeName) + ",
'" + value + "')";
+		jcrExpressions.add(jcrExpression);
 	}
 
-	/**
-	 * @see org.apache.portals.graffito.jcr.query.Filter#addNotBetween(java.lang.String, java.lang.Object,
java.lang.Object)
-	 */
-	public void addNotBetween(String fieldAttributeName, Object value1, Object value2)
-	{
-	}
 
 	/**
 	 * @see org.apache.portals.graffito.jcr.query.Filter#addNotEqualTo(java.lang.String, java.lang.Object)
 	 */
 	public void addNotEqualTo(String fieldAttributeName, Object value)
 	{
+		String jcrExpression =  "@" + this.getJcrFieldName(fieldAttributeName) + " != " + this.getStringValue(value);
+		jcrExpressions.add(jcrExpression);			
 	}
 
-	/**
-	 * @see org.apache.portals.graffito.jcr.query.Filter#addNotLike(java.lang.String, java.lang.Object)
-	 */
-	public void addNotLike(String fieldAttributeName, Object value)
-	{
-	}
 
 	/**
 	 * @see org.apache.portals.graffito.jcr.query.Filter#addNotNull(java.lang.String)
 	 */
-	public void addNotNull(String arg0)
+	public void addNotNull(String fieldAttributeName)
 	{
+		String jcrExpression =  "@" + this.getJcrFieldName(fieldAttributeName);
+		jcrExpressions.add(jcrExpression);			
+		
 	}
 
 	/**
@@ -172,6 +176,9 @@
 	 */
 	public void addIsNull(String fieldAttributeName)
 	{
+		String jcrExpression =  "not(@" + this.getJcrFieldName(fieldAttributeName)+")";
+		jcrExpressions.add(jcrExpression);			
+		
 	}
 
 	/**
@@ -179,6 +186,9 @@
 	 */
 	public void addOrFilter(Filter filter)
 	{
+		
+		orJcrExpression  = ((FilterImpl)filter).getJcrExpression();
+	
 	}
 
 	public void addJCRExpression(String jcrExpression)
@@ -205,9 +215,40 @@
 		}
 	}
 	
-	public Collection getJcrExpressions()
+	public String  getJcrExpression()
+	{
+		if (orJcrExpression == null || orJcrExpression.equals(""))
+		{
+			return buildJcrExpression();	
+		}
+		else
+		{
+			return "(" + buildJcrExpression() + ") or (" +  this.orJcrExpression + ")";
+		}
+		
+	}
+	
+	private String buildJcrExpression()
 	{
-		return jcrExpressions;
+		   int count = 1;
+		   String jcrExp = "";
+		   
+		   jcrExp += "["; 
+		   Iterator criteriaIterator =  jcrExpressions.iterator();
+		   while (criteriaIterator.hasNext())
+		   {
+			   if (count > 1)
+			   {
+				   jcrExp += " and ";
+			   }
+			   jcrExp += (String) criteriaIterator.next();
+			   count++;
+			   
+		   }
+		   jcrExp += "]"; 
+		   
+		   return jcrExp;
+		
 	}
 	
 	

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java?rev=291714&r1=291713&r2=291714&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
Mon Sep 26 12:10:22 2005
@@ -48,25 +48,7 @@
 		jcrExp += "//element(*, "  + this.getNodeType(filter) + ")";
 
         // Add filter criteria
-		if (((FilterImpl)filter).getJcrExpressions().size() > 0)
-		{
-		   int count = 1;
-		   
-		   jcrExp += "["; 
-		   Iterator criteriaIterator =  ((FilterImpl)filter).getJcrExpressions().iterator();
-		   while (criteriaIterator.hasNext())
-		   {
-			   if (count > 1)
-			   {
-				   jcrExp += " and ";
-			   }
-			   jcrExp += (String) criteriaIterator.next();
-			   count++;
-			   
-		   }
-		   jcrExp += "]"; 
-		}
-		
+		jcrExp += ((FilterImpl)filter).getJcrExpression();
 		
 		return jcrExp;
 		 

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=291714&r1=291713&r2=291714&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Mon Sep 26 12:10:22 2005
@@ -16,11 +16,23 @@
  */
 package org.apache.portals.graffito.jcr;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
 
 
 import junit.framework.TestCase;
@@ -76,9 +88,10 @@
         DigesterMapperImpl mapper = new DigesterMapperImpl("./src/test-config/jcrmapping.xml");
         Repository repository = RepositoryUtil.getRepository("repositoryTest");
         
-        session = RepositoryUtil.login(repository, "superuser", "superuser");        
-        persistenceManager = new PersistenceManagerImpl(mapper, repository, session);
+        session = RepositoryUtil.login(repository, "superuser", "superuser");
         queryManager = new QueryManagerImpl(mapper);
+        persistenceManager = new PersistenceManagerImpl(mapper, queryManager, repository,
session);
+        
         
         
         
@@ -115,11 +128,30 @@
 			BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(filePath));  
     
 			ContentHandler handler = new org.apache.xml.serialize.XMLSerializer(os, null).asContentHandler();
 			    session.exportDocumentView(nodePath, handler, skipBinary, noRecurse);
+			os.flush();
+			os.close();    
 		} catch (Exception e) 
 		{
 			System.out.println("Impossible to export the content from : " + nodePath);
 			e.printStackTrace();
 		}
+    }
+    
+    public void importDocument(String filePath, String nodePath)
+    {
+    	try
+		{
+			BufferedInputStream is = new BufferedInputStream(new FileInputStream(filePath));
+			session.importXML(nodePath, is, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+			session.save();		
+			is.close();
+		}
+		catch (Exception e)
+		{
+			System.out.println("Impossible to import the content from : " + nodePath);
+			e.printStackTrace();
+		}
+		
     }
     
     protected Session getSession()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java?rev=291714&r1=291713&r2=291714&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
Mon Sep 26 12:10:22 2005
@@ -16,16 +16,21 @@
  */
 package org.apache.portals.graffito.jcr.query.impl;
 
+import java.util.ArrayList;
+
 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.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.query.Filter;
 import org.apache.portals.graffito.jcr.query.Query;
 import org.apache.portals.graffito.jcr.query.QueryManager;
 import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
 
 
 /**
@@ -52,7 +57,7 @@
         return new TestSuite(QueryManagerTest.class);
     }
 
-    public void testClassA()
+    public void testBuildExpression1()
     {
 
     	try
@@ -67,6 +72,32 @@
     	      String jcrExpression = queryManager.buildJCRExpression(query);
     	      assertNotNull("jcrExpression is null", jcrExpression);
     	      assertTrue("Invalid JcrExpression", jcrExpression.equals("/jcr:root/test//element(*,
graffito:C)[@graffito:name = 'a test value' and @graffito:id = 1]"));
+    	      
+    	      
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    public void testBuildExpression2()
+    {
+
+    	try
+    	{
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(C.class);
+    	      filter.addEqualTo("name", "a test value");
+    	      filter.addEqualTo("id", new Integer(1));    	      
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      String jcrExpression = queryManager.buildJCRExpression(query);
+    	      assertNotNull("jcrExpression is null", jcrExpression);
+    	      assertTrue("Invalid JcrExpression", jcrExpression.equals("//element(*, graffito:C)[@graffito:name
= 'a test value' and @graffito:id = 1]"));
     	      
     	      
             



Mime
View raw message