Author: rhauch
Date: 2009-07-21 16:53:05 -0400 (Tue, 21 Jul 2009)
New Revision: 1123
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
Log:
DNA-392 All sessions in a repository should share the same /jcr:system content
Changed how the JcrSession and JcrWorkspace objects are instantiated to move all content
initialization code into the JcrRepository class. Creating JcrSession and JcrWorkspace
objects is not much faster, though there still is a single verify workspace request issued
against the source (even though this is still done within the JcrRepository instance, the
JcrWorkspace creates its own graph, which requires issuing this request). Changed a
number of test cases to reflect the new behavior.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-07-21
19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-07-21
20:53:05 UTC (rev 1123)
@@ -126,10 +126,6 @@
this.workspaceRegistry = workspaceRegistry;
this.session = session;
- // Add the built-ins, ensuring we overwrite any badly-initialized values ...
- for (Map.Entry<String, String> builtIn :
STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
- this.registry.register(builtIn.getKey(), builtIn.getValue());
- }
assert this.behavior != null;
assert this.registry != null;
assert this.workspaceRegistry != null;
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-07-21 19:14:15
UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-07-21 20:53:05
UTC (rev 1123)
@@ -299,6 +299,11 @@
this.persistentRegistry = new GraphNamespaceRegistry(systemGraph, namespacesPath,
uriProperty, namespaceType);
this.executionContext = executionContext.with(persistentRegistry);
+ // Add the built-ins, ensuring we overwrite any badly-initialized values ...
+ for (Map.Entry<String, String> builtIn :
JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
+ this.persistentRegistry.register(builtIn.getKey(), builtIn.getValue());
+ }
+
// Set up the repository type manager ...
try {
this.repositoryTypeManager = new
RepositoryNodeTypeManager(this.executionContext);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-21 19:14:15 UTC
(rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-21 20:53:05 UTC
(rev 1123)
@@ -156,7 +156,7 @@
this.rootPath =
this.executionContext.getValueFactories().getPathFactory().createRootPath();
// Set up the graph to use for this session (which uses the session's
namespace registry and context) ...
- this.graph = repository.createWorkspaceGraph(workspace.getName());
+ this.graph = workspace.graph();
this.cache = new SessionCache(this);
this.isLive = true;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-21 19:14:15
UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-21 20:53:05
UTC (rev 1123)
@@ -188,6 +188,10 @@
}
+ final Graph graph() {
+ return this.graph;
+ }
+
final String getSourceName() {
return this.repository.getRepositorySourceName();
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-07-21
19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-07-21
20:53:05 UTC (rev 1123)
@@ -96,6 +96,11 @@
graph.create("/jcr:system/dna:namespaces").and();
graph.set("jcr:primaryType").on("/jcr:system/dna:namespaces").to(DnaLexicon.NAMESPACES);
+ // Add the built-ins, ensuring we overwrite any badly-initialized values ...
+ for (Map.Entry<String, String> builtIn :
JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
+ context.getNamespaceRegistry().register(builtIn.getKey(),
builtIn.getValue());
+ }
+
initializeContent();
// Stub out the connection factory ...
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java 2009-07-21
19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java 2009-07-21
20:53:05 UTC (rev 1123)
@@ -94,29 +94,6 @@
}
}
- @Test
- public void shouldBeInitializedWithNamespacesDefinedByTheJcrSpecification() throws
Exception {
- // Don't use the constants, since this needs to check that the actual values
are correct
- assertThatNamespaceIsRegistered("jcr",
"http://www.jcp.org/jcr/1.0");
- assertThatNamespaceIsRegistered("nt",
"http://www.jcp.org/jcr/nt/1.0");
- assertThatNamespaceIsRegistered("mix",
"http://www.jcp.org/jcr/mix/1.0");
- assertThatNamespaceIsRegistered("xml",
"http://www.w3.org/XML/1998/namespace");
- assertThatNamespaceIsRegistered("", "");
- }
-
- @Test
- public void shouldBeInitializedWithNamespacesDefinedByTheJcrApiJavaDoc() throws
Exception {
- // Don't use the constants, since this needs to check that the actual values
are correct
- assertThatNamespaceIsRegistered("sv",
"http://www.jcp.org/jcr/sv/1.0");
- assertThatNamespaceIsRegistered("xmlns",
"http://www.w3.org/2000/xmlns/");
- }
-
- @Test
- public void shouldBeInitializedWithNamespacesSpecificToDna() throws Exception {
- // Don't use the constants, since this needs to check that the actual values
are correct
- assertThatNamespaceIsRegistered("dna",
"http://www.jboss.org/dna/1.0");
- }
-
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowRegisteringNullPrefix() throws Exception {
registry.registerNamespace("foo", null);
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-07-21
19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-07-21
20:53:05 UTC (rev 1123)
@@ -323,6 +323,33 @@
}
}
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesNeedeByDna() throws Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values
are correct
+ assertThat(session.getNamespaceURI("dna"),
is("http://www.jboss.org/dna/1.0"));
+ assertThat(session.getNamespaceURI("dnaint"),
is("http://www.jboss.org/dna/internal/1.0"));
+ }
+
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesDefinedByTheJcrSpecification() throws
Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values
are correct
+ assertThat(session.getNamespaceURI("dna"),
is("http://www.jboss.org/dna/1.0"));
+ assertThat(session.getNamespaceURI("jcr"),
is("http://www.jcp.org/jcr/1.0"));
+ assertThat(session.getNamespaceURI("mix"),
is("http://www.jcp.org/jcr/mix/1.0"));
+ assertThat(session.getNamespaceURI("nt"),
is("http://www.jcp.org/jcr/nt/1.0"));
+ assertThat(session.getNamespaceURI(""), is(""));
+ }
+
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesDefinedByTheJcrApiJavaDoc() throws
Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values
are correct
+ assertThat(session.getNamespaceURI("sv"),
is("http://www.jcp.org/jcr/sv/1.0"));
+ assertThat(session.getNamespaceURI("xmlns"),
is("http://www.w3.org/2000/xmlns/"));
+ }
+
protected JcrSession createSession() throws Exception {
LoginContext login = new LoginContext("dna-jcr", new
UserPasswordCallbackHandler("superuser", "superuser".toCharArray()));
login.login();