use of org.apache.sling.nosql.generic.adapter.NoSqlData in project sling by apache.
the class SimpleNoSqlAdapter method getChildren.
public Iterator<NoSqlData> getChildren(String parentPath) {
Iterator<String> keys = store.keySet().iterator();
final Pattern childKeyPattern = PathUtil.getChildPathPattern(parentPath);
Iterator<String> childKeys = Iterators.filter(keys, new Predicate<String>() {
public boolean apply(String path) {
return childKeyPattern.matcher(path).matches();
}
});
return Iterators.transform(childKeys, new Function<String, NoSqlData>() {
public NoSqlData apply(String path) {
return get(path);
}
});
}
use of org.apache.sling.nosql.generic.adapter.NoSqlData in project sling by apache.
the class NoSqlResourceProvider method commit.
public void commit(ResourceResolver resolver) throws PersistenceException {
try {
for (String path : deletedResources) {
adapter.deleteRecursive(path);
notifyRemoved(path);
}
for (NoSqlData item : changedResources.values()) {
boolean created = adapter.store(item);
if (created) {
notifyAdded(item.getPath());
} else {
notifyUpdated(item.getPath());
}
}
} finally {
this.revert(resolver);
}
}
use of org.apache.sling.nosql.generic.adapter.NoSqlData in project sling by apache.
the class NoSqlResourceProvider method listChildren.
public Iterator<Resource> listChildren(Resource parent) {
// use map to consolidate data from adapter minus deleted plus changed resources
// always sorty result alphabetically to have a consistent ordering - the nosql data source does not support ordering
SortedMap<String, Resource> children = new TreeMap<String, Resource>();
Iterator<NoSqlData> fromAdapter = adapter.getChildren(parent.getPath());
while (fromAdapter.hasNext()) {
NoSqlData item = fromAdapter.next();
if (isDeleted(item.getPath()) || changedResources.containsKey(item.getPath())) {
continue;
}
children.put(item.getPath(), new NoSqlResource(item, parent.getResourceResolver(), this));
}
Pattern childPathPattern = PathUtil.getChildPathPattern(parent.getPath());
for (NoSqlData item : changedResources.values()) {
if (childPathPattern.matcher(item.getPath()).matches()) {
children.put(item.getPath(), new NoSqlResource(item, parent.getResourceResolver(), this));
}
}
return children.values().iterator();
}
use of org.apache.sling.nosql.generic.adapter.NoSqlData in project sling by apache.
the class MongoDBNoSqlAdapter method getChildren.
@Override
public Iterator<NoSqlData> getChildren(String parentPath) {
List<NoSqlData> children = new ArrayList<>();
FindIterable<Document> result = collection.find(Filters.eq(PN_PARENT_PATH, parentPath));
try (MongoCursor<Document> envelopes = result.iterator()) {
while (envelopes.hasNext()) {
Document envelope = envelopes.next();
String path = envelope.get(PN_PATH, String.class);
Document data = envelope.get(PN_DATA, Document.class);
children.add(new NoSqlData(path, data, MultiValueMode.LISTS));
}
}
return children.iterator();
}
Aggregations