[dna-commits] DNA SVN: r1379 - in trunk: dna-jcr/src/test/java/org/jboss/dna/jcr and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue Dec 1 22:24:39 EST 2009


Author: rhauch
Date: 2009-12-01 22:24:38 -0500 (Tue, 01 Dec 2009)
New Revision: 1379

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
   trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicModel.java
Log:
DNA-566 I created a package-level static final boolean WORKSPACES_SHARE_SYSTEM_BRANCH flag that may be changed to false when debugging so that the federated connector is not used.  As stated above, this has implications for some connectors, and definitely cannot be changed in production without having some potentially serious deviations from JCR spec behavior with respect to the '/jcr:system' branch.  However, it is very useful while debugging certain situations.

I added a new unit test to check that the flag is 'true', and this should always pass (except when debugging).  This helps ensure that the value is not accidentally committed to SVN with a value of 'false'.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2009-12-02 03:10:41 UTC (rev 1378)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2009-12-02 03:24:38 UTC (rev 1379)
@@ -104,6 +104,16 @@
 public class JcrRepository implements Repository {
 
     /**
+     * A flag that controls whether the repository uses a shared repository (or workspace) for the "/jcr:system" content in all of
+     * the workspaces. In production, this needs to be "true" for proper JCR functionality, but in some debugging cases it can be
+     * set to false to simplify the architecture by removing the federated connector layer.
+     * <p>
+     * This should be changed to 'false' only in advanced situations, and never for production.
+     * </p>
+     */
+    static final boolean WORKSPACES_SHARE_SYSTEM_BRANCH = true;
+
+    /**
      * The available options for the {@code JcrRepository}.
      */
     public enum Option {
@@ -405,23 +415,28 @@
             ioe.printStackTrace();
             throw new IllegalStateException("Could not access node type definition files", ioe);
         }
-        if (Boolean.valueOf(this.options.get(Option.PROJECT_NODE_TYPES))) {
-            // Note that the node types are written directly to the system workspace.
-            Path parentOfTypeNodes = pathFactory.create(systemPath, JcrLexicon.NODE_TYPES);
-            this.repositoryTypeManager.projectOnto(systemGraph, parentOfTypeNodes);
-        }
+        if (WORKSPACES_SHARE_SYSTEM_BRANCH) {
+            if (Boolean.valueOf(this.options.get(Option.PROJECT_NODE_TYPES))) {
+                // Note that the node types are written directly to the system workspace.
+                Path parentOfTypeNodes = pathFactory.create(systemPath, JcrLexicon.NODE_TYPES);
+                this.repositoryTypeManager.projectOnto(systemGraph, parentOfTypeNodes);
+            }
 
-        // Create the projection for the system repository ...
-        ProjectionParser projectionParser = ProjectionParser.getInstance();
-        String rule = "/jcr:system => /jcr:system";
-        Projection.Rule[] systemProjectionRules = projectionParser.rulesFromString(this.executionContext, rule);
-        this.systemSourceProjection = new Projection(systemSourceName, systemWorkspaceName, true, systemProjectionRules);
+            // Create the projection for the system repository ...
+            ProjectionParser projectionParser = ProjectionParser.getInstance();
+            String rule = "/jcr:system => /jcr:system";
+            Projection.Rule[] systemProjectionRules = projectionParser.rulesFromString(this.executionContext, rule);
+            this.systemSourceProjection = new Projection(systemSourceName, systemWorkspaceName, true, systemProjectionRules);
 
-        // Define the federated repository source. Use the same name as the repository, since this federated source
-        // will not be in the connection factory ...
-        this.federatedSource = new FederatedRepositorySource();
-        this.federatedSource.setName("JCR " + repositorySourceName);
-        this.federatedSource.initialize(new FederatedRepositoryContext(this.connectionFactory));
+            // Define the federated repository source. Use the same name as the repository, since this federated source
+            // will not be in the connection factory ...
+            this.federatedSource = new FederatedRepositorySource();
+            this.federatedSource.setName("JCR " + repositorySourceName);
+            this.federatedSource.initialize(new FederatedRepositoryContext(this.connectionFactory));
+        } else {
+            this.federatedSource = null;
+            this.systemSourceProjection = null;
+        }
 
         this.lockManagers = new ConcurrentHashMap<String, WorkspaceLockManager>();
         this.locksPath = pathFactory.create(pathFactory.createRootPath(), JcrLexicon.SYSTEM, DnaLexicon.LOCKS);
@@ -468,7 +483,15 @@
 
     Graph createWorkspaceGraph( String workspaceName,
                                 ExecutionContext workspaceContext ) {
-        Graph graph = Graph.create(this.federatedSource, workspaceContext);
+        Graph graph = null;
+        if (WORKSPACES_SHARE_SYSTEM_BRANCH) {
+            // Connect via the federated source ...
+            assert this.federatedSource != null;
+            graph = Graph.create(this.federatedSource, workspaceContext);
+        } else {
+            // Otherwise, just create a graph directly to the connection factory ...
+            graph = Graph.create(this.sourceName, this.connectionFactory, workspaceContext);
+        }
         graph.useWorkspace(workspaceName);
         return graph;
     }
@@ -671,8 +694,10 @@
                 // Verify that the workspace exists (or can be created) ...
                 Set<String> workspaces = graph.getWorkspaces();
                 if (!workspaces.contains(workspaceName)) {
-                    // Make sure there isn't a federated workspace ...
-                    this.federatedSource.removeWorkspace(workspaceName);
+                    if (this.federatedSource != null) {
+                        // Make sure there isn't a federated workspace ...
+                        this.federatedSource.removeWorkspace(workspaceName);
+                    }
                     // Per JCR 1.0 6.1.1, if the workspaceName is not recognized, a NoSuchWorkspaceException is thrown
                     throw new NoSuchWorkspaceException(JcrI18n.workspaceNameIsInvalid.text(sourceName, workspaceName));
                 }
@@ -686,16 +711,25 @@
             }
         }
 
-        synchronized (this.federatedSource) {
-            if (!this.federatedSource.hasWorkspace(workspaceName)) {
-                // Add the workspace to the federated source ...
-                ProjectionParser projectionParser = ProjectionParser.getInstance();
-                Projection.Rule[] mirrorRules = projectionParser.rulesFromString(this.executionContext, "/ => /");
-                List<Projection> projections = new ArrayList<Projection>(2);
-                projections.add(new Projection(sourceName, workspaceName, false, mirrorRules));
-                projections.add(this.systemSourceProjection);
-                this.federatedSource.addWorkspace(workspaceName, projections, isDefault);
+        if (WORKSPACES_SHARE_SYSTEM_BRANCH) {
+            assert this.federatedSource != null;
+            assert this.systemSourceProjection != null;
+            synchronized (this.federatedSource) {
+                if (!this.federatedSource.hasWorkspace(workspaceName)) {
+                    // Add the workspace to the federated source ...
+                    ProjectionParser projectionParser = ProjectionParser.getInstance();
+                    Projection.Rule[] mirrorRules = projectionParser.rulesFromString(this.executionContext, "/ => /");
+                    List<Projection> projections = new ArrayList<Projection>(2);
+                    projections.add(new Projection(sourceName, workspaceName, false, mirrorRules));
+                    projections.add(this.systemSourceProjection);
+                    this.federatedSource.addWorkspace(workspaceName, projections, isDefault);
+                }
             }
+        } else {
+            // We're not sharing a '/jcr:system' branch, so we need to make sure there is one in the source.
+            // Note that this doesn't always work with some connectors (e.g., the FileSystem or SVN connectors)
+            // that don't allow arbitrary nodes.
+            initializeSystemContent(graph);
         }
 
         // Create the workspace, which will create its own session ...

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java	2009-12-02 03:10:41 UTC (rev 1378)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java	2009-12-02 03:24:38 UTC (rev 1379)
@@ -135,6 +135,12 @@
     }
 
     @Test
+    public void shouldFailIfWorkspacesSharingSystemBranchConstantIsFalse() {
+        // Check that the debugging flag is ALWAYS set to true...
+        assertThat(JcrRepository.WORKSPACES_SHARE_SYSTEM_BRANCH, is(true));
+    }
+
+    @Test
     public void shouldAllowNullDescriptors() {
         new JcrRepository(context, connectionFactory, sourceName, null, null);
     }

Modified: trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicModel.java
===================================================================
--- trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicModel.java	2009-12-02 03:10:41 UTC (rev 1378)
+++ trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicModel.java	2009-12-02 03:24:38 UTC (rev 1379)
@@ -128,11 +128,11 @@
     public RepositoryConnection createConnection( JpaSource source ) {
         RepositoryContext repositoryContext = source.getRepositoryContext();
         Observer observer = repositoryContext != null ? repositoryContext.getObserver() : null;
-        return new BasicJpaConnection(getName(), observer, source.getCachePolicy(), source.getEntityManagers(),
-                                 source.getRootUuid(),
-                                 source.getDefaultWorkspaceName(), source.getPredefinedWorkspaceNames(),
-                                 source.getLargeValueSizeInBytes(), source.isCreatingWorkspacesAllowed(),
-                                 source.isCompressData(), source.isReferentialIntegrityEnforced());
+        return new BasicJpaConnection(source.getName(), observer, source.getCachePolicy(), source.getEntityManagers(),
+                                      source.getRootUuid(), source.getDefaultWorkspaceName(),
+                                      source.getPredefinedWorkspaceNames(), source.getLargeValueSizeInBytes(),
+                                      source.isCreatingWorkspacesAllowed(), source.isCompressData(),
+                                      source.isReferentialIntegrityEnforced());
     }
 
 }



More information about the dna-commits mailing list