use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method childNodeEntries.
@Test
public void childNodeEntries() throws Exception {
final AtomicInteger counter = new AtomicInteger();
DocumentStore docStore = new MemoryDocumentStore() {
@Nonnull
@Override
public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
counter.incrementAndGet();
return super.query(collection, fromKey, toKey, limit);
}
};
DocumentNodeStore store = builderProvider.newBuilder().setDocumentStore(docStore).getNodeStore();
NodeBuilder root = store.getRoot().builder();
for (int i = 0; i < 10; i++) {
root.child("node-" + i);
}
store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
counter.set(0);
// the commit and not use a query on the document store (OAK-1322)
for (ChildNodeEntry e : store.getRoot().getChildNodeEntries()) {
e.getNodeState();
}
assertEquals(0, counter.get());
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class TypePredicate method isOrderable.
@Nonnull
public static TypePredicate isOrderable(@Nonnull NodeState root) {
Set<String> orderable = newHashSet();
NodeState types = checkNotNull(root).getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
for (ChildNodeEntry entry : types.getChildNodeEntries()) {
NodeState type = entry.getNodeState();
if (type.getBoolean(JCR_HASORDERABLECHILDNODES)) {
orderable.add(entry.getName());
}
}
return new TypePredicate(root, orderable);
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method isEmptyHistory.
/**
* Checks whether the passed node history hasn't been modified since its
* creation. It means that: (1) there's just one version, called jcr:rootVersion
* and (2) there are no custom labels.
*
* @param versionHistory to test
* @return {@code true} if the version history hasn't been changed yet
*/
private boolean isEmptyHistory(NodeState versionHistory) {
for (ChildNodeEntry entry : versionHistory.getChildNodeEntries()) {
String name = entry.getName();
NodeState node = entry.getNodeState();
if (!JCR_ROOTVERSION.equals(name) && isVersion.apply(node)) {
// a checked-in version
return false;
}
}
NodeState labels = versionHistory.getChildNode(JCR_VERSIONLABELS);
for (PropertyState prop : labels.getProperties()) {
if (prop.getType() == Type.REFERENCE) {
// custom label
return false;
}
}
return true;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class NodeStoreTree method filterNodeStates.
private static void filterNodeStates(Set<UUID> uuids, List<String> paths, NodeState state, String path, ExplorerBackend store) {
Set<String> localPaths = newTreeSet();
for (PropertyState ps : state.getProperties()) {
if (store.isPersisted(ps)) {
String recordId = store.getRecordId(ps);
UUID id = store.getSegmentId(ps);
if (uuids.contains(id)) {
if (ps.getType().tag() == STRING) {
String val = "";
if (ps.count() > 0) {
// only shows the first value, do we need more?
val = displayString(ps.getValue(Type.STRING, 0));
}
localPaths.add(path + ps.getName() + " = " + val + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
} else {
localPaths.add(path + ps + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
}
}
if (ps.getType().tag() == BINARY) {
// look for extra segment references
for (int i = 0; i < ps.count(); i++) {
Blob b = ps.getValue(Type.BINARY, i);
for (Entry<UUID, String> e : store.getBulkSegmentIds(b).entrySet()) {
if (!e.getKey().equals(id) && uuids.contains(e.getKey())) {
localPaths.add(path + ps + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
}
}
}
}
}
}
String stateId = store.getRecordId(state);
if (uuids.contains(store.getSegmentId(state))) {
localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
}
String templateId = store.getTemplateRecordId(state);
if (uuids.contains(store.getTemplateSegmentId(state))) {
localPaths.add(path + "[Template@" + templateId + "]");
}
paths.addAll(localPaths);
for (ChildNodeEntry ce : state.getChildNodeEntries()) {
filterNodeStates(uuids, paths, ce.getNodeState(), path + ce.getName() + "/", store);
}
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class ModifiedNodeState method squeeze.
/**
* "Squeezes" {@link ModifiedNodeState} instances into equivalent
* {@link MemoryNodeState}s. Other kinds of states are returned as-is.
*/
public static NodeState squeeze(NodeState state) {
if (state instanceof ModifiedNodeState) {
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(), squeeze(child.getNodeState()));
}
state = new MemoryNodeState(properties, nodes);
}
return state;
}
Aggregations