You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2018/10/17 18:22:19 UTC
[sling-whiteboard] branch master updated (1f2238f -> c979af9)
This is an automated email from the ASF dual-hosted git repository.
jeb pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.
from 1f2238f initial commits
new 58ab5ed adding commit
new c979af9 added recursive deletion
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/sling/mvresource/impl/MvResource.java | 8 ++--
.../mvresource/impl/MvStoreResourceProvider.java | 48 ++++++++++++++++++----
2 files changed, 44 insertions(+), 12 deletions(-)
[sling-whiteboard] 01/02: adding commit
Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 58ab5ed5514b35ec6550454f238eee9f0d0678dc
Author: JE Bailey <ja...@sas.com>
AuthorDate: Wed Oct 17 11:14:08 2018 -0400
adding commit
---
.../src/main/java/org/apache/sling/mvresource/impl/MvResource.java | 2 --
.../org/apache/sling/mvresource/impl/MvStoreResourceProvider.java | 7 +++++++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
index e708ce9..6addbd4 100644
--- a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
+++ b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.mvresource.impl;
-import java.util.Map;
-
import org.apache.sling.api.resource.AbstractResource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
diff --git a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
index 66717ce..2c7c666 100644
--- a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
+++ b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
@@ -120,6 +120,7 @@ public class MvStoreResourceProvider extends ResourceProvider<Object> implements
newChildren[children.length] = child;
parentResource.put(parent, newChildren);
MVMap<String, Object> data = store.openMap(path);
+
data.putAll(properties);
store.commit();
return new MvResource(ctx.getResourceResolver(), path, data);
@@ -142,6 +143,12 @@ public class MvStoreResourceProvider extends ResourceProvider<Object> implements
}
@Override
+ public void commit(ResolveContext<Object> ctx) throws PersistenceException {
+ LOG.info("COMMIT {} ", ctx.getProviderState());
+ store.commit();
+ }
+
+ @Override
public void delete(ResolveContext<Object> ctx, Resource resource) throws PersistenceException {
LOG.info("DELETE {} ", resource.getName());
if (!(resource instanceof MVMap)) {
[sling-whiteboard] 02/02: added recursive deletion
Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit c979af9539a3e55f5b919d4f976c3c49e6472a46
Author: JE Bailey <ja...@sas.com>
AuthorDate: Wed Oct 17 14:21:53 2018 -0400
added recursive deletion
---
.../apache/sling/mvresource/impl/MvResource.java | 6 ++-
.../mvresource/impl/MvStoreResourceProvider.java | 43 +++++++++++++++++-----
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
index 6addbd4..5d031fc 100644
--- a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
+++ b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvResource.java
@@ -48,7 +48,11 @@ public class MvResource extends AbstractResource {
if (properties.isEmpty()) {
return null;
}
- return (String) properties.get("sling:resourceType");
+ String type = (String) properties.get("sling:resourceType");
+ if (type == null) {
+ type = (String) properties.get("jcr:primaryType");
+ }
+ return type;
}
@Override
diff --git a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
index 2c7c666..e468365 100644
--- a/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
+++ b/mvresourceprovider/src/main/java/org/apache/sling/mvresource/impl/MvStoreResourceProvider.java
@@ -20,7 +20,9 @@ package org.apache.sling.mvresource.impl;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Deque;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -113,16 +115,13 @@ public class MvStoreResourceProvider extends ResourceProvider<Object> implements
LOG.info("CREATE {} ", path);
try {
String parent = parentPath(path);
- String child = currentName(path);
MVMap<String, String[]> parentResource = store.openMap("_children");
String[] children = parentResource.getOrDefault(parent, new String[] {});
String[] newChildren = Arrays.copyOf(children, children.length + 1);
- newChildren[children.length] = child;
+ newChildren[children.length] = path;
parentResource.put(parent, newChildren);
MVMap<String, Object> data = store.openMap(path);
-
data.putAll(properties);
- store.commit();
return new MvResource(ctx.getResourceResolver(), path, data);
} catch (Exception e) {
LOG.error("Error occured in creation {}", e);
@@ -131,7 +130,7 @@ public class MvStoreResourceProvider extends ResourceProvider<Object> implements
}
- private String currentName(String path) {
+ public String currentName(String path) {
LOG.info("CURRENT NAME {} ", path);
int index = path.lastIndexOf('/');
return path.substring(index + 1, path.length());
@@ -151,12 +150,36 @@ public class MvStoreResourceProvider extends ResourceProvider<Object> implements
@Override
public void delete(ResolveContext<Object> ctx, Resource resource) throws PersistenceException {
LOG.info("DELETE {} ", resource.getName());
- if (!(resource instanceof MVMap)) {
- throw new PersistenceException();
+ if (!(resource instanceof MvResource)) {
+ throw new PersistenceException("can not delete resource of type" + resource.getClass());
}
- MVMap<String, Object> map = ((MvResource) resource).getMVMap();
- store.removeMap(map);
- store.commit();
+ MVMap<String, String[]> parentResource = store.openMap("_children");
+ String parentPath = parentPath(resource.getPath());
+ String[] childNames = parentResource.get(parentPath);
+ String[] newChildren = new String[childNames.length - 1];
+ int newIndex = 0;
+ for (int index = 0; index < childNames.length ; ++index) {
+ if (!childNames[index].equals(resource.getName())) {
+ newChildren[newIndex++] = childNames[index];
+ }
+ }
+ parentResource.put(parentPath, newChildren);
+ Deque<String> resourceToDelete = new LinkedList<>();
+ resourceToDelete.add(resource.getPath());
+ deleteDescendents(parentResource, resourceToDelete);
+ }
+
+ private void deleteDescendents(MVMap<String, String[]> parentMap, Deque<String> pathsToDelete ) {
+ if (pathsToDelete.isEmpty()) {
+ return;
+ }
+ String currentPath = pathsToDelete.pop();
+ String[] children = parentMap.getOrDefault(currentPath, new String[] {});
+ store.removeMap(store.openMap(currentPath));
+ for (int i = 0; i < children.length ; ++i) {
+ pathsToDelete.add(children[i]);
+ }
+ deleteDescendents(parentMap,pathsToDelete);
}
@Override