incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r290791 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java test-config/jcrmapping.xml test-config/repository.xml
Date Wed, 21 Sep 2005 18:52:49 GMT
Author: clombart
Date: Wed Sep 21 11:52:43 2005
New Revision: 290791

URL: http://svn.apache.org/viewcvs?rev=290791&view=rev
Log:
Reorganise the JCR repository used for the unit test. 

Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java
    incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr-mapping/src/test-config/repository.xml

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=290791&r1=290790&r2=290791&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
Wed Sep 21 11:52:43 2005
@@ -28,10 +28,13 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.core.jndi.RegistryHelper;
 import org.apache.jackrabbit.value.DateValue;
 import org.apache.jackrabbit.value.StringValue;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 
 /**
 * Utility class for managing JCR repositories.
@@ -41,9 +44,18 @@
 */
 public class RepositoryUtil
 {
+    
+    /** Graffito namespace prefix constant.
+     */
+    private static final String GRAFFITO_NAMESPACE_PREFIX   = "graffito";
+
+    /** Graffito namespace constant.
+     */
+    private static final String GRAFFITO_NAMESPACE          = "http://incubator.apache.org/graffito";
   
     /** Item path separator */
     public static final String PATH_SEPARATOR = "/";
     
+    private final static Log log = LogFactory.getLog(RepositoryUtil.class);  
     /**
      * Register a new repository 
      * 
@@ -63,16 +75,47 @@
             InitialContext ctx = new InitialContext(env);
 
             RegistryHelper.registerRepository(ctx, repositoryName, configFile, homeDir, true);
           
-            
+
         }
         catch (Exception e)
         {
+        	e.printStackTrace();
             throw new JcrMappingException("Impossible to register the respository : " + 
                                            repositoryName + " - config file : " + configFile,
e);
         }        
         
     }
     
+    
+    /**
+     * Unregister a repository 
+     * 
+     * @param repositoryName The repository unique name
+     * 
+     * @throws JcrMappingException when it is not possible to unregister the repository
+     */
+    public static void unRegisterRepository(String repositoryName) throws JcrMappingException
+    {
+        try
+        {
+            
+        	
+        	Hashtable env = new Hashtable();
+            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+            env.put(Context.PROVIDER_URL, "localhost");
+            InitialContext ctx = new InitialContext(env);
+
+            RegistryHelper.unregisterRepository(ctx, repositoryName);            
+
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to unregister the respository : " +

+                                           repositoryName , e);
+        }        
+        
+    }
+    
     /**
      * Get a repository
      * 
@@ -115,7 +158,8 @@
         try
         {
             Session session = repository.login(new SimpleCredentials(user, password.toCharArray()),
null);
-            
+            setupSession(session);
+           
             return session; 
             
         }
@@ -198,5 +242,46 @@
         }        
         return pathElements[pathElements.length-1];
     }
+    
+    /**
+     * Setup the session. 
+     * Until now, we check only if the Graffito namespace prefix exist in the repository
+     * 
+     */
+    private static void setupSession(Session session) throws JcrMappingException
+    {
+         try
+         {
+            String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes();
+            boolean createGraffitoNamespace = true;
+            for (int i = 0; i < jcrNamespaces.length; i++)
+            {
+                if (jcrNamespaces[i].equals(GRAFFITO_NAMESPACE_PREFIX))
+                {
+                    createGraffitoNamespace = false;
+                    log.debug("Graffito namespace exists.");
+                }
+            }
+             
+            if (createGraffitoNamespace)
+            {
+                session.getWorkspace().getNamespaceRegistry().registerNamespace(GRAFFITO_NAMESPACE_PREFIX,
GRAFFITO_NAMESPACE);
+                log.info("Successfully created graffito namespace.");
+            }
+            
+            if (session.getRootNode() != null)
+            {
+                log.info("Jcr repository setup successfull.");
+            }
+            
+
+        }
+        catch (Exception e)
+        {
+            log.error("Error while setting up the jcr repository.", e);
+            throw new JcrMappingException(e.getMessage());
+        }
+    }
+    
       
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml?rev=290791&r1=290790&r2=290791&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml Wed Sep 21 11:52:43
2005
@@ -2,7 +2,7 @@
 
 <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN"
"../dtd/graffito-jcr-mapping.dtd">
 <graffito-jcr>
-  
+    
   
     <class-descriptor
 		className="org.apache.portals.graffito.jcr.testmodel.Atomic" jcrNodeType="nt:unstructured">
@@ -18,11 +18,12 @@
 		<field-descriptor fieldName="doubleObject" jcrName="doubleObject" />
 		<field-descriptor fieldName="doublePrimitive" jcrName="doublePrimitive" />
 		<field-descriptor fieldName="inputStream" jcrName="inputStream" />
+		<field-descriptor fieldName="timestamp" jcrName="timestamp" />
 				
 	</class-descriptor>
-    
-	<class-descriptor
-		className="org.apache.portals.graffito.jcr.testmodel.Folder" jcrNodeType="nt:unstructured">
+
+   
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Folder" jcrNodeType="nt:unstructured">
 		<!-- Field-descriptor is used to map simple attributes to jcr property -->
 		<field-descriptor fieldName="name" jcrName="name" />
 		<field-descriptor fieldName="description" jcrName="description" />
@@ -59,6 +60,7 @@
 		-->
 		<collection-descriptor fieldName="collection" jcrName="collection" proxy="false" elementClassName="org.apache.portals.graffito.jcr.testmodel.C"
/>
 		<collection-descriptor fieldName="emptyCollection" jcrName="emptyCollection" proxy="false"
elementClassName="org.apache.portals.graffito.jcr.testmodel.C" />
+		
 	</class-descriptor>
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.B"  jcrNodeType="nt:unstructured">
@@ -74,4 +76,31 @@
 		<field-descriptor fieldName="name" jcrName="graffito:name" />
 	</class-descriptor>
 
+
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="nt:unstructured">
+		<field-descriptor fieldName="title" jcrName="title" />
+		<collection-descriptor fieldName="paragraphs" proxy="false" 
+		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.Paragraph"

+		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl"
/>
+	</class-descriptor>
+
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph">
+		<field-descriptor fieldName="text" jcrName="graffito:text" />
+	</class-descriptor>
+
+
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Main"
jcrNodeType="nt:unstructured">
+		<field-descriptor fieldName="text" jcrName="text" />
+		<collection-descriptor fieldName="elements" proxy="false" 
+		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.Element"

+		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl"

+		                       collectionClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.HashMapElement"
/>
+		                       
+	</class-descriptor>
+
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element"
jcrNodeType="graffito:element">
+		<field-descriptor fieldName="id" jcrName="graffito:id" />
+		<field-descriptor fieldName="text" jcrName="graffito:text" />
+	</class-descriptor>
 </graffito-jcr>
+ 
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr-mapping/src/test-config/repository.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-config/repository.xml?rev=290791&r1=290790&r2=290791&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/repository.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/repository.xml Wed Sep 21 11:52:43
2005
@@ -111,7 +111,7 @@
         (used by the QueryHandler); the class attribute specifies the
         FQN of the class implementing the QueryHandler interface.
     -->
-    <!ELEMENT SearchIndex (param*,FileSystem)>
+    <!ELEMENT SearchIndex (param*,FileSystem?)>
     <!ATTLIST SearchIndex
       class CDATA #REQUIRED>
 
@@ -131,7 +131,8 @@
         (e.g. registered namespaces, custom node types, etc.)
     -->
     <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-        <param name="path" value="${rep.home}/../../src/test-config/repository-test"/>
+        <param name="path" value="${rep.home}/repository"/>
+        
     </FileSystem>
 
     <!--
@@ -164,36 +165,72 @@
         <!--
             virtual file system of the workspace:
             class: FQN of class implementing the FileSystem interface
-        
+        -->
         <FileSystem class="com.day.jackrabbit.fs.cq.CQFileSystem">
             <param name="path" value="${wsp.home}/wspStore.dat"/>
             <param name="autoRepair" value="false"/>
             <param name="blockSize" value="128"/>
             <param name="autoSync" value="false"/>
         </FileSystem>
-        -->
-
+        <!--
         <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
             <param name="path" value="${wsp.home}"/>
         </FileSystem>
-        
+        -->
         <!--
             persistence manager of the workspace:
             class: FQN of class implementing the PersistenceManager interface
         -->
-       
+        <!--
         <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager"/>
-        
+        -->
+        <!--
+        <PersistenceManager class="org.apache.jackrabbit.core.state.mem.InMemPersistenceManager">
+            <param name="initialCapacity" value="100000"/>
+            <param name="loadFactor" value="0.3"/>
+            <param name="persistent" value="true"/>
+        </PersistenceManager>
+        -->
+        <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager"/>
+        <!--
+            Search index and the file system it uses.
+            class: FQN of class implementing the QueryHandler interface
+
+            If required by the QueryHandler implementation, one may configure
+            a FileSystem that the handler may use.
+
+            Supported parameters for lucene search index:
+            - path: location of the index. This parameter is mandatory!
+            - useCompoundFile: advises lucene to use compound files for the index files
+            - minMergeDocs: minimum number of nodes in an index until segments are merged
+            - volatileIdleTime: idle time in seconds until the volatile index is
+              moved to persistent index even though minMergeDocs is not reached.
+            - maxMergeDocs: maximum number of nodes in segments that will be merged
+            - mergeFactor: determines how often segment indices are merged
+            - bufferSize: maximum number of documents that are held in a pending
+              queue until added to the index
+            - cacheSize: size of the document number cache. This cache maps
+              uuids to lucene document numbers
+            - forceConsistencyCheck: runs a consistency check on every startup. If
+              false, a consistency check is only performed when the search index
+              detects a prior forced shutdown.
+            - autoRepair: errors detected by a consistency check are automatically
+              repaired. If false, errors are only written to the log.
+
+            Note: all parameters (except path) in this SearchIndex config are default
+            values and can be omitted.
+        -->
         <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+            <param name="path" value="${wsp.home}/index"/>
             <param name="useCompoundFile" value="true"/>
-            <param name="minMergeDocs" value="1000"/>
+            <param name="minMergeDocs" value="100"/>
+            <param name="volatileIdleTime" value="3"/>
             <param name="maxMergeDocs" value="100000"/>
             <param name="mergeFactor" value="10"/>
             <param name="bufferSize" value="10"/>
-
-            <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-                <param name="path" value="${wsp.home}/index"/>
-            </FileSystem>
+            <param name="cacheSize" value="1000"/>
+            <param name="forceConsistencyCheck" value="false"/>
+            <param name="autoRepair" value="true"/>
         </SearchIndex>
     </Workspace>
 
@@ -204,18 +241,19 @@
         <!--
             Configures the filesystem to use for versioning for the respective
             persistence manager
-        
+        -->
         <FileSystem class="com.day.jackrabbit.fs.cq.CQFileSystem">
             <param name="path" value="${rep.home}/version/version.dat"/>
             <param name="autoRepair" value="false"/>
             <param name="blockSize" value="128"/>
             <param name="autoSync" value="false"/>
         </FileSystem>
-         -->
-        
+    
+        <!--
             <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
                 <param name="path" value="${rep.home}/version"/>
             </FileSystem>
+        -->
         
         <!--
             Configures the perisistence manager to be used for persisting version state.



Mime
View raw message