@Override public void clear( CachedNode node ) { delegate.clear(node); }
@Override public NodeKey createNodeKey( String sourceName, String identifier ) { return delegate.createNodeKey(sourceName, identifier); }
@Override public NodeKey createNodeKeyWithIdentifier( String identifier ) { return delegate.createNodeKeyWithIdentifier(identifier); }
private CachedNode getSystemNode( SessionCache systemSession ) { CachedNode systemRoot = systemSession.getNode(systemSession.getRootKey()); ChildReference systemNodeRef = systemRoot.getChildReferences(systemSession).getChild(JcrLexicon.SYSTEM); assert systemNodeRef != null; return systemSession.getNode(systemNodeRef.getKey()); }
SessionCache systemSession = repository.createSystemSession(repository.context(), false); NodeKey systemNodeKey = getSystemNode(systemSession).getKey(); MutableCachedNode systemNode = systemSession.mutable(systemNodeKey); ChildReference federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION); MutableCachedNode federationNode = systemSession.mutable(federationNodeKey); ChildReferences federationChildRefs = federationNode.getChildReferences(systemSession); ChildReference projectionRef = federationChildRefs.getChild(ModeShapeLexicon.PROJECTION, i); NodeKey projectionRefKey = projectionRef.getKey(); CachedNode storedProjection = systemSession.getNode(projectionRefKey); String storedProjectionExternalNodeKey = storedProjection.getProperty(ModeShapeLexicon.EXTERNAL_NODE_KEY, systemSession).getFirstValue().toString(); if (storedProjectionExternalNodeKey.equals(externalNodeKey)) { federationNode.removeChild(systemSession, projectionRefKey); systemSession.destroy(projectionRefKey); systemSession.save(); break;
@Test public void shouldReturnTransientKeysAtOrBelowNodeWithRemovedChild() { NodeKey rootKey = session1.getRootKey(); MutableCachedNode root = session1.mutable(rootKey); SessionCache sessionCache = session(); NodeKey childKey = newKey("x-childA"); MutableCachedNode child = root.createChild(sessionCache, childKey, name("childA"), property("p1", "value A")); session1.destroy(child.getKey()); assertEquals(new HashSet<NodeKey>(Arrays.asList(rootKey, childKey)), session1.getChangedNodeKeysAtOrBelow(root)); } }
@Override public void removeVersionLabel( String label ) throws VersionException, RepositoryException { AbstractJcrNode versionLabels = versionLabels(); Name propName = null; try { // This throws a PNFE if the named property doesn't already exist propName = versionLabels.getProperty(label).name(); } catch (PathNotFoundException pnfe) { // This gets thrown if the label doesn't already exist throw new VersionException(JcrI18n.invalidVersionLabel.text(label, getPath())); } // Use a separate system session to remove the REFERENCE property on the 'nt:versionLabels' child node ... SessionCache system = session.createSystemCache(false); system.mutable(versionLabels.key()).removeProperty(system, propName); system.save(); }
@Override public MutableCachedNode.PermissionChanges removeACL( SessionCache cache ) { if (this.isExternal(cache)) { throw new UnsupportedOperationException(JcrI18n.aclsOnExternalNodesNotAllowed.text()); } if (hasACL(cache)) { NodeKey aclNodeKey = getChildReferences(cache).getChild(ModeShapeLexicon.ACCESS_LIST_NODE_NAME).getKey(); MutableCachedNode mutableACLNode = cache.mutable(aclNodeKey); for (ChildReference permissionRef : mutableACLNode.getChildReferences(cache)) { permissionChanges().principalRemoved(permissionRef.getName().getString()); } if (!cache.isDestroyed(aclNodeKey)) { this.removeChild(cache, aclNodeKey); cache.destroy(aclNodeKey); } removeMixin(cache, ModeShapeLexicon.ACCESS_CONTROLLABLE); } return permissionChanges(); }
Set<NodeKey> sourceKeys = sourceCache.getNodeKeysAtAndBelow(sourceNode.key()); sourceKeys = filterNodeKeysForClone(sourceKeys, sourceCache); cloneSession.aclAdded(permissions.size()); boolean isExternal = !srcKey.getSourceKey().equalsIgnoreCase(sourceCache.getRootKey().getSourceKey()); if (isExternal && session.nodeExists(srcKey) && !removeExisting) { throw new ItemExistsException(JcrI18n.itemAlreadyExistsWithUuid.text(srcKey, workspaceName, boolean hasAnyPendingChanges = !session.cache().getChangedNodeKeysAtOrBelow(cloneSessionNode.node()) .isEmpty(); if (hasAnyPendingChanges) {
@Test public void shouldReturnAllTransientNodeKeys() { NodeKey rootKey = session1.getRootKey(); MutableCachedNode root = session1.mutable(rootKey); NodeKey childAKey = root.createChild(session(), newKey("x-childA"), name("childA"), property("p1", "value A")).getKey(); NodeKey childBKey = root.createChild(session(), newKey("x-childB"), name("childB"), property("p1", "value B")).getKey(); Set<NodeKey> transientNodeKeys = session1.getChangedNodeKeys(); assertEquals(new HashSet<NodeKey>(Arrays.asList(rootKey, childAKey, childBKey)), transientNodeKeys); }
@Test public void shouldReturnTransientKeysAtOrBelowNode() { NodeKey rootKey = session1.getRootKey(); MutableCachedNode root = session1.mutable(rootKey); // root/childA MutableCachedNode childA = root.createChild(session(), newKey("x-childA"), name("childA"), property("p1", "value A")); // root/childA/childB MutableCachedNode childB = childA.createChild(session(), newKey("x-childB"), name("childB"), property("p1", "value B")); // root/childC MutableCachedNode childC = root.createChild(session(), newKey("x-childC"), name("childC"), property("p1", "value C")); assertEquals(new HashSet<NodeKey>(Arrays.asList(childA.getKey(), childB.getKey())), session1.getChangedNodeKeysAtOrBelow(childA)); assertEquals(new HashSet<NodeKey>(Arrays.asList(rootKey, childA.getKey(), childB.getKey(), childC.getKey())), session1.getChangedNodeKeysAtOrBelow(root)); assertEquals(new HashSet<NodeKey>(Arrays.asList(childC.getKey())), session1.getChangedNodeKeysAtOrBelow(childC)); }
@Override public MutableCachedNode mutable( NodeKey key ) throws NodeNotFoundException, UnsupportedOperationException { return delegate.mutable(key); }
for (int i = 0; i != 1000; ++i) { create.start(); NodeKey newKey = session1.createNodeKey(); nodeB.createChild(session(), newKey, name("newChild"), property("p1a", 344), property("p2", false)); create.stop(); session1.save(); save.stop(); total.stop(); print("Time (total): " + total.getTotalDuration()); session1.clear(); print("Time (getchild#9450): " + total.getTotalDuration()); session1.clear();
@Override public void save( Set<NodeKey> toBeSaved, SessionCache otherSession, PreSave preSaveOperation ) { delegate.save(toBeSaved, otherSession, preSaveOperation); }
/** * Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this * session's root. This method is used for reference resolving. * * @param key the node key; may be null * @return true if the node key is considered foreign, false otherwise. */ protected final boolean isForeignKey( NodeKey key ) { return isForeignKey(key, cache.getRootKey()); }
/** * Utility method to determine if the node with the specified key still exists within the transient & persisted state. * * @param key the key of the node; may not be null * @return true if the node exists, or false if it does not */ protected boolean nodeExists( NodeKey key ) { return cache.getNode(key) != null; }
protected boolean unregisterNamespace( String namespaceUri ) { MutableCachedNode namespaces = mutableNamespacesNode(); NodeKey key = keyForNamespaceUri(namespaceUri); CachedNode nsNode = system.getNode(key); if (nsNode != null) { namespaces.removeChild(system, key); system.destroy(key); return true; } return false; }
public void remove( IndexDefinition indexDefn ) { assert indexDefn != null; assert system != null; MutableCachedNode indexes = mutableIndexesNode(); final NodeKey providerKey = nodeKey(indexes.getKey(), indexDefn.getProviderName()); if (indexes.getChildReferences(system).hasChild(providerKey)) { // Find the provider node ... MutableCachedNode providerNode = system.mutable(providerKey); // And remove the index defn from the provider ... final NodeKey key = nodeKey(providerNode.getKey(), indexDefn); providerNode.removeChild(system, key); system.destroy(key); // If there are no more children under the provider, remove it, too... if (providerNode.getChildReferences(system).isEmpty()) { indexes.removeChild(system, providerKey); system.destroy(providerKey); } } }
@Test public void shouldSplitDocumentThatContainsTooManyChildReferences() throws Exception { // Create a bunch of children ... MutableCachedNode nodeB = check(session1).mutableNode("/childB"); for (int i = 0; i != 10; ++i) { NodeKey newKey = session1.createNodeKey(); nodeB.createChild(session(), newKey, name("newChild"), property("p1a", 344), property("p2", false)); } session1.save(); // Optimize the storage ... Document result = runInTransaction(() -> { NodeKey key = nodeB.getKey(); EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true); optimizer.optimizeChildrenBlocks(key, doc, 9, 5); return doc; }); print(false); print(result, true); }
/** * Determines whether this node, or any nodes below it, contain changes that depend on nodes that are outside of this node's * hierarchy. * * @param affectedNodeKeys the reference that should be assigned to the set of node keys that are at or below this node; may * be null if not needed * @return true if this node's hierarchy has nodes with changes dependent on nodes from outside the hierarchy * @throws InvalidItemStateException * @throws ItemNotFoundException * @throws RepositoryException */ protected boolean containsChangesWithExternalDependencies( AtomicReference<Set<NodeKey>> affectedNodeKeys ) throws RepositoryException { Set<NodeKey> allChanges = sessionCache().getChangedNodeKeys(); Set<NodeKey> changesAtOrBelowThis = sessionCache().getChangedNodeKeysAtOrBelow(this.node()); removeReferrerChanges(allChanges, changesAtOrBelowThis); if (affectedNodeKeys != null) affectedNodeKeys.set(changesAtOrBelowThis); return !changesAtOrBelowThis.containsAll(allChanges); }