@Override protected NodeKey createTargetKeyFor( NodeKey sourceKey, NodeKey parentKeyInTarget, String preferredKey ) { // Reuse the same source and identifier, but a different workspace ... return !StringUtil.isBlank(preferredKey) ? new NodeKey(preferredKey) : parentKeyInTarget.withId(sourceKey.getIdentifier()); }
protected String getIdentifier( CachedNode node, NodeKey workspaceRootKey ) { NodeKey key = node.getKey(); if (!key.getSourceKey().equals(workspaceRootKey.getSourceKey())) { // return the whole thing ... return key.toString(); } // return just the identifier part ... return key.getIdentifier(); }
public NodeKey withRandomId() { return new NodeKey(getSourceKey(), getWorkspaceKey(), UUID.randomUUID().toString()); }
public NodeKey withWorkspaceKeyAndId( String workspaceKey, String identifier ) { return new NodeKey(getSourceKey(), workspaceKey, identifier); }
protected final NodeKey lockedNodeKeyFromLockKey( NodeKey key ) { // The identifier of the lock key contains "mode:lock-" followed by the full key of the locked node ... String identifier = key.getIdentifier(); return new NodeKey(identifier.substring(KEY_OFFSET)); }
protected final Path correspondingNodePath( String workspaceName ) throws NoSuchWorkspaceException, ItemNotFoundException, RepositoryException { assert workspaceName != null; NamespaceRegistry namespaces = this.context().getNamespaceRegistry(); // Find the closest ancestor (including this node) that is referenceable ... AbstractJcrNode referenceableRoot = this; while (!referenceableRoot.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) { referenceableRoot = referenceableRoot.getParent(); } // Find the relative path from the nearest referenceable node to this node (or null if this node is referenceable) ... Path relativePath = path().equals(referenceableRoot.path()) ? null : path().relativeTo(referenceableRoot.path()); NodeKey key = referenceableRoot.key(); // if the we're looking for a system node, we need to use the system ws name, which is repository-wide String systemWsKey = session.getRepository().systemWorkspaceKey(); String workspaceKey = systemWsKey.equals(key.getWorkspaceKey()) ? systemWsKey : NodeKey.keyForWorkspaceName(workspaceName); NodeKey nodeKey = new NodeKey(key.getSourceKey(), workspaceKey, key.getIdentifier()); return session.getPathForCorrespondingNode(workspaceName, nodeKey, relativePath); }
/** * @param key the key for the node that could not be locked */ public LockFailureException( NodeKey key ) { super(key.toString()); this.key = key; }
String sourceKey = NodeKey.keyForSourceName(sourceName); String workspaceKey = NodeKey.keyForWorkspaceName(workspaceName); NodeKey rootKey = new NodeKey(sourceKey, workspaceKey, rootId);
private WorkspaceCache initializeCacheForWorkspace(String name, WorkspaceCache systemWorkspaceCache) { String workspaceKey = NodeKey.keyForWorkspaceName(name); NodeKey rootKey = new NodeKey(sourceKey, workspaceKey, rootNodeId); context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.ROOT), null, null); String rootKeyString = rootKey.toString(); trans.setProperty(rootDoc, context.getPropertyFactory().create(JcrLexicon.UUID, rootKeyString), null, null); childInfo.setNumber(DocumentTranslator.COUNT, 1); EditableDocument systemDoc = documentStore.edit(RepositoryCache.this.systemKey.toString(), false); assert systemDoc != null; String parent = systemDoc.getString(DocumentTranslator.PARENT);
@Override public NodeKey deserialize( DataInput in, int available ) throws IOException { String keyStr = in.readUTF(); return new NodeKey(keyStr); }
protected boolean shouldProcessSourceKey( NodeKey sourceKey ) { return !sourceKey.equals(sourceCache.getRootKey()) && !sourceKey.getWorkspaceKey().equalsIgnoreCase(systemWorkspaceKey); } }
/** * Returns a string representing a node's identifier, based on whether the node is foreign or not. * * @param key the node key; may be null * @param rootKey the key of the root node in the workspace; may not be null * @return the identifier for the node; never null * @see javax.jcr.Node#getIdentifier() */ public static String nodeIdentifier( NodeKey key, NodeKey rootKey ) { return isForeignKey(key, rootKey) ? key.toString() : key.getIdentifier(); }
private final NodeKey nodeKey( NodeKey prototype, String providerName ) { return prototype.withId("/jcr:system/mode:indexes/" + providerName); }
@Override public NodeKey getParentKeyInAnyWorkspace( NodeCache cache ) { WorkspaceCache wsCache = workspaceCache(cache); return wsCache.translator().getParentKey(document(), key.getWorkspaceKey(), key.getWorkspaceKey()); }
@Override public Reference create( String value ) { if (value == null) return null; NodeKey key = JcrSession.createNodeKeyFromIdentifier(value, rootKey); boolean isForeign = !(key.getSourceKey().equals(rootKey.getSourceKey()) && key.getWorkspaceKey() .equals(rootKey.getWorkspaceKey())); return new NodeKeyReference(key, weak, isForeign, simple); }
@Override public NodeKey create( String value ) throws ValueFormatException { if (NodeKey.isValidFormat(value)) { return new NodeKey(value); } throw new ValueFormatException(value, PropertyType.OBJECT, "Unable to convert " + value.getClass() + " to a NodeKey"); }
private final NodeKey nodeKey( NodeKey indexDefnKey, IndexColumnDefinition defn ) { String id = strings.create(strings.create(defn.getPropertyName())); return indexDefnKey.withId(indexDefnKey.getIdentifier() + id); }
String workspaceKey = NodeKey.keyForWorkspaceName(workspaceName); boolean commitRequired = false; updateIndexesStatus(workspaceName, IndexManager.IndexStatus.ENABLED, IndexManager.IndexStatus.REINDEXING); if (!workspaceKey.equals(nodeKey.getWorkspaceKey())) {
@Test public void shouldNotSplitDocumentWithChildReferenceBlocksThatAreAlreadyTooSmall() throws Exception { NodeKey key = new NodeKey("source1works1-childB"); transactions().begin(); EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true); EditableArray children = doc.getArray(DocumentTranslator.CHILDREN); String nextBlock = doc.getDocument(DocumentTranslator.CHILDREN_INFO).getString(DocumentTranslator.NEXT_BLOCK); boolean changed = optimizer.splitChildren(key, doc, children, 100, 50, true, nextBlock); transactions().commit(); assertThat(changed, is(false)); }