private static boolean hasReferences(IndexStoreStrategy refStore, NodeState root, NodeState definition, String name, String key) { return definition.hasChildNode(name) && refStore.count(root, definition, of(key), 1) > 0; }
@Override public boolean hasChildNode(@NotNull String name) { assert base != null; NodeState child = nodes.get(name); if (child != null) { return child.exists(); } else { return base.hasChildNode(name); } }
private static boolean hasReferences(IndexStoreStrategy refStore, NodeState root, NodeState definition, String name, String key) { return definition.hasChildNode(name) && refStore.count(root, definition, of(key), 1) > 0; }
List<String> getSyncIndexPaths() { List<String> indexPaths = new ArrayList<>(); NodeState root = nodeStore.getRoot(); for (String indexPath : indexPathService.getIndexPaths()) { NodeState idx = getNode(root, indexPath); if (TYPE_LUCENE.equals(idx.getString(TYPE_PROPERTY_NAME)) && idx.hasChildNode(PROPERTY_INDEX)) { indexPaths.add(indexPath); } } return indexPaths; }
@Override public void contentChanged( @NotNull NodeState root, @NotNull CommitInfo info) { if (root.getChildNode("test").hasChildNode("newNode")) { observedRoot.set(checkNotNull(root)); latch.countDown(); } } });
@Override public boolean hasChildNode(@NotNull String name) { if (!state.hasChildNode(name)) { return false; } else if (treePermission.canReadAll()) { return true; } else { NodeState child = state.getChildNode(name); return treePermission.getChildPermission(name, child).canRead(); } }
@NotNull @Override public RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { if (state.hasChildNode(failOnName)) { throw new IOException("Encountered node with name " + failOnName); } return delegate.writeNode(state, stableIdBytes); }
@Override public Validator getRootValidator( NodeState before, NodeState after, CommitInfo info) { boolean initPhase = !before.hasChildNode(JCR_SYSTEM); return new NameValidator(after .getChildNode(JCR_SYSTEM) .getChildNode(REP_NAMESPACES), initPhase); }
@Override public InputStream openResource(String resource) throws IOException { if (state.hasChildNode(resource)){ return ConfigUtil.getBlob(state.getChildNode(resource), resource).getNewStream(); } return delegate.openResource(resource); }
static boolean hasAsyncIndexerRun(NodeState root, String indexPath, NodeState defnNodeState) { boolean hasAsyncNode = root.hasChildNode(ASYNC); String asyncLaneName = getAsyncLaneName(defnNodeState, indexPath, defnNodeState.getProperty(ASYNC_PROPERTY_NAME)); if (asyncLaneName != null) { return hasAsyncNode && root.getChildNode(ASYNC).hasProperty(asyncLaneName); } else { // useful only for tests - basically non-async index defs which don't rely on /:async // hence either readers are there (and this method doesn't come into play during open) // OR there is no cycle (where we return false correctly) return false; } }
@Override public InputStream openResource(String resource) throws IOException { if (state.hasChildNode(resource)){ return ConfigUtil.getBlob(state.getChildNode(resource), resource).getNewStream(); } return delegate.openResource(resource); }
static boolean hasAsyncIndexerRun(NodeState root, String indexPath, NodeState defnNodeState) { boolean hasAsyncNode = root.hasChildNode(ASYNC); String asyncLaneName = getAsyncLaneName(defnNodeState, indexPath, defnNodeState.getProperty(ASYNC_PROPERTY_NAME)); if (asyncLaneName != null) { return hasAsyncNode && root.getChildNode(ASYNC).hasProperty(asyncLaneName); } else { // useful only for tests - basically non-async index defs which don't rely on /:async // hence either readers are there (and this method doesn't come into play during open) // OR there is no cycle (where we return false correctly) return false; } }
@Test public void shouldExposeTarName() { Backend backend = mock(Backend.class); when(backend.tarExists("t")).thenReturn(true); NodeState n = new StoreNode(backend); assertTrue(n.hasChildNode("t")); assertTrue(n.getChildNode("t").exists()); }
@Test public void shouldExposeCommitHandle() { Backend backend = mock(Backend.class); when(backend.commitExists("h")).thenReturn(true); NodeState n = new JournalNode(backend); assertTrue(n.hasChildNode("h")); assertTrue(n.getChildNode("h").exists()); }
@Test public void shouldNotExposeNonExistingTarName() { NodeState n = new StoreNode(mock(Backend.class)); assertFalse(n.hasChildNode("t")); assertFalse(n.getChildNode("t").exists()); }
@Test public void shouldNotExposeNonExistingSegmentId() { NodeState n = new TarNode(mock(Backend.class), "t"); assertFalse(n.hasChildNode("s")); assertFalse(n.getChildNode("s").exists()); }
@Test public void shouldNotExposeNonExistingHandle() { NodeState n = new JournalNode(mock(Backend.class)); assertFalse(n.hasChildNode("h")); assertFalse(n.getChildNode("h").exists()); }
@Test public void removeNodeInRootStore() throws Exception { NodeBuilder builder = store.getRoot().builder(); builder.getChildNode("apps").remove(); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertFalse("Node must be removed from the composite store", store.getRoot().hasChildNode("apps")); assertFalse("Node must be removed from the owning (root) store", globalStore.getRoot().hasChildNode("apps")); }
@Test @Ignore("Test ignored, since only the default store is writeable") public void moveNodeBetweenStores() throws Exception { NodeBuilder builder = store.getRoot().builder(); NodeBuilder src = builder.child("src"); NodeBuilder dst = builder.child("tmp"); boolean result = src.moveTo(dst, "src"); assertTrue("move result should be success", result); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertFalse("/src must no longer exist", store.getRoot().hasChildNode("src")); assertTrue("/tmp/src must exist (composite store)", store.getRoot().getChildNode("tmp").hasChildNode("src")); }
@Test public void builderBasedOnRootStoreChildNode() throws Exception { NodeBuilder builder = store.getRoot().builder(); NodeBuilder appsBuilder = builder.getChildNode("apps"); appsBuilder.removeProperty("prop"); appsBuilder.setChildNode("child1"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertFalse("Node apps must have no properties (composite store)", store.getRoot().getChildNode("apps").hasProperty("prop")); assertFalse("Node apps must have no properties (root store)", globalStore.getRoot().getChildNode("apps").hasProperty("prop")); assertTrue("Node /apps/child1 must exist (composite store)", store.getRoot().getChildNode("apps").hasChildNode("child1")); assertTrue("Node /apps/child1 must exist (root store)", globalStore.getRoot().getChildNode("apps").hasChildNode("child1")); }