Search in sources :

Example 6 with NoSqlData

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);
        }
    });
}
Also used : NoSqlData(org.apache.sling.nosql.generic.adapter.NoSqlData) Pattern(java.util.regex.Pattern)

Example 7 with NoSqlData

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);
    }
}
Also used : NoSqlData(org.apache.sling.nosql.generic.adapter.NoSqlData)

Example 8 with NoSqlData

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();
}
Also used : NoSqlData(org.apache.sling.nosql.generic.adapter.NoSqlData) Pattern(java.util.regex.Pattern) Resource(org.apache.sling.api.resource.Resource) TreeMap(java.util.TreeMap)

Example 9 with NoSqlData

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();
}
Also used : NoSqlData(org.apache.sling.nosql.generic.adapter.NoSqlData) ArrayList(java.util.ArrayList) Document(org.bson.Document)

Aggregations

NoSqlData (org.apache.sling.nosql.generic.adapter.NoSqlData)9 Pattern (java.util.regex.Pattern)3 Bucket (com.couchbase.client.java.Bucket)2 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 JsonDocument (com.couchbase.client.java.document.JsonDocument)1 N1qlQuery (com.couchbase.client.java.query.N1qlQuery)1 N1qlQueryResult (com.couchbase.client.java.query.N1qlQueryResult)1 N1qlQueryRow (com.couchbase.client.java.query.N1qlQueryRow)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 SortedMap (java.util.SortedMap)1 Resource (org.apache.sling.api.resource.Resource)1