Skip to content

Instantly share code, notes, and snippets.

@trekawek
Created September 22, 2016 12:35
Show Gist options
  • Save trekawek/b112c3bb6d823dd81a5a5aacc313687e to your computer and use it in GitHub Desktop.
Save trekawek/b112c3bb6d823dd81a5a5aacc313687e to your computer and use it in GitHub Desktop.
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
index fb1c991..5c317eb 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
@@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.memory;
+import static com.google.common.collect.Maps.newHashMap;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
@@ -34,7 +35,7 @@ import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
/**
* Basic in-memory node state implementation.
*/
-class MemoryNodeState extends AbstractNodeState {
+public class MemoryNodeState extends AbstractNodeState {
private final Map<String, PropertyState> properties;
@@ -173,4 +174,21 @@ class MemoryNodeState extends AbstractNodeState {
return true;
}
+ public static MemoryNodeState toMemoryNodeStore(NodeState state) {
+ if (state instanceof MemoryNodeState) {
+ return (MemoryNodeState) state;
+ }
+
+ Map<String, PropertyState> properties = newHashMap();
+ for (PropertyState property : state.getProperties()) {
+ properties.put(property.getName(), property);
+ }
+
+ Map<String, NodeState> nodes = newHashMap();
+ for (ChildNodeEntry child : state.getChildNodeEntries()) {
+ nodes.put(child.getName(), child.getNodeState());
+ }
+
+ return new MemoryNodeState(properties, nodes);
+ }
}
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
index 6b4ca4e..51dca08 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
@@ -22,6 +22,8 @@ import static org.apache.jackrabbit.oak.api.Type.NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState.toMemoryNodeStore;
+import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.squeeze;
import static org.apache.jackrabbit.oak.plugins.version.VersionConstants.REP_VERSIONSTORAGE;
import com.google.common.collect.ImmutableList;
@@ -32,7 +34,6 @@ import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
-import org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState;
import org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider;
import org.apache.jackrabbit.oak.plugins.name.Namespaces;
import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
@@ -58,7 +59,7 @@ public class InitialContent implements RepositoryInitializer, NodeTypeConstants
private static NodeState createInitialContent() {
NodeBuilder builder = EMPTY_NODE.builder();
new InitialContent().initialize(builder);
- return ModifiedNodeState.squeeze(builder.getNodeState());
+ return squeeze(builder.getNodeState());
}
/**
@@ -115,7 +116,7 @@ public class InitialContent implements RepositoryInitializer, NodeTypeConstants
}
// squeeze node state before it is passed to store (OAK-2411)
- NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
+ NodeState base = toMemoryNodeStore(squeeze(builder.getNodeState()));
NodeStore store = new MemoryNodeStore(base);
NodeTypeRegistry.registerBuiltIn(RootFactory.createSystemRoot(
store, new EditorHook(new CompositeEditorProvider(
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
index eb523fe..e673081 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
@@ -23,7 +23,6 @@ import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
-import org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState;
import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
import org.apache.jackrabbit.oak.plugins.tree.RootFactory;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
@@ -35,6 +34,9 @@ import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState.toMemoryNodeStore;
+import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.squeeze;
+
/**
* {@code RepositoryInitializer} that asserts the existence and node type of
* the /jcr:system/jcr:privileges node that is used to store privilege definitions.
@@ -55,7 +57,7 @@ class PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants
privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME);
// squeeze node state before it is passed to store (OAK-2411)
- NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
+ NodeState base = toMemoryNodeStore(squeeze(builder.getNodeState()));
NodeStore store = new MemoryNodeStore(base);
try {
Root systemRoot = RootFactory.createSystemRoot(store, null, null, null, null, null);
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
index 895eb2d..24b6222 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
-import org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState;
import org.apache.jackrabbit.oak.plugins.tree.RootFactory;
import org.apache.jackrabbit.oak.query.QueryEngineSettings;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
@@ -48,6 +47,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState.toMemoryNodeStore;
+import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.squeeze;
/**
* Creates initial set of users to be present in a given workspace. This
@@ -91,7 +92,7 @@ class UserInitializer implements WorkspaceInitializer, UserConstants {
@Override
public void initialize(NodeBuilder builder, String workspaceName) {
// squeeze node state before it is passed to store (OAK-2411)
- NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
+ NodeState base = toMemoryNodeStore(squeeze(builder.getNodeState()));
MemoryNodeStore store = new MemoryNodeStore(base);
Root root = RootFactory.createSystemRoot(store, EmptyHook.INSTANCE, workspaceName,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment