use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.
the class RDBDocumentStore method getIfCached.
@Override
public <T extends Document> T getIfCached(Collection<T> collection, String id) {
if (collection != Collection.NODES) {
return null;
} else {
NodeDocument doc = nodesCache.getIfPresent(id);
doc = (doc != null) ? unwrap(doc) : null;
return castAsT(doc);
}
}
use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.
the class RDBDocumentStore method invalidateNodesCache.
private void invalidateNodesCache(String id, boolean remove) {
Lock lock = locks.acquire(id);
try {
if (remove) {
nodesCache.invalidate(id);
} else {
nodesCache.markChanged(id);
NodeDocument entry = nodesCache.getIfPresent(id);
if (entry != null) {
entry.markUpToDate(0);
}
}
} finally {
lock.unlock();
}
}
use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.
the class RDBDocumentStore method readDocumentCached.
private <T extends Document> Map<String, T> readDocumentCached(Collection<T> collection, Set<String> keys) {
Map<String, T> documents = new HashMap<String, T>();
if (collection == Collection.NODES) {
for (String key : keys) {
NodeDocument cached = nodesCache.getIfPresent(key);
if (cached != null && cached != NodeDocument.NULL) {
T doc = castAsT(unwrap(cached));
documents.put(doc.getId(), doc);
}
}
}
Set<String> documentsToRead = Sets.difference(keys, documents.keySet());
Map<String, T> readDocuments = readDocumentsUncached(collection, documentsToRead);
documents.putAll(readDocuments);
if (collection == Collection.NODES) {
for (T doc : readDocuments.values()) {
nodesCache.putIfAbsent((NodeDocument) doc);
}
}
return documents;
}
use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.
the class Utils method internalGetSelectedDocuments.
private static Iterable<NodeDocument> internalGetSelectedDocuments(final DocumentStore store, final String indexedProperty, final long startValue, final int batchSize) {
if (batchSize < 2) {
throw new IllegalArgumentException("batchSize must be > 1");
}
return new Iterable<NodeDocument>() {
@Override
public Iterator<NodeDocument> iterator() {
return new AbstractIterator<NodeDocument>() {
private String startId = NodeDocument.MIN_ID_VALUE;
private Iterator<NodeDocument> batch = nextBatch();
@Override
protected NodeDocument computeNext() {
// read next batch if necessary
if (!batch.hasNext()) {
batch = nextBatch();
}
NodeDocument doc;
if (batch.hasNext()) {
doc = batch.next();
// remember current id
startId = doc.getId();
} else {
doc = endOfData();
}
return doc;
}
private Iterator<NodeDocument> nextBatch() {
List<NodeDocument> result = indexedProperty == null ? store.query(Collection.NODES, startId, NodeDocument.MAX_ID_VALUE, batchSize) : store.query(Collection.NODES, startId, NodeDocument.MAX_ID_VALUE, indexedProperty, startValue, batchSize);
return result.iterator();
}
};
}
};
}
use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.
the class MemoryDocumentStore method toString.
@Override
public String toString() {
StringBuilder buff = new StringBuilder();
buff.append("Nodes:\n");
for (String p : nodes.keySet()) {
buff.append("Path: ").append(p).append('\n');
NodeDocument doc = nodes.get(p);
for (Map.Entry<String, Object> entry : doc.entrySet()) {
buff.append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
}
buff.append("\n");
}
return buff.toString();
}
Aggregations