@Override public void unregisterIndexes( String... indexNames ) throws NoSuchIndexException, RepositoryException { if (indexNames == null || indexNames.length == 0) return; // Remove the definition from the system area ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); for (String indexName : indexNames) { IndexDefinition defn = indexes.getIndexDefinitions().get(indexName); if (defn == null) { throw new NoSuchIndexException(JcrI18n.indexDoesNotExist.text(indexName, repository.name())); } system.remove(defn); } system.save(); // Refresh the immutable snapshot ... this.indexes = readIndexDefinitions(); }
/** * Refresh the node types from the stored representation. * * @return true if there was at least one node type found, or false if there were none */ protected boolean refreshFromSystem() { this.nodeTypesLock.writeLock().lock(); try { // Re-read and re-register all of the node types ... SessionCache systemCache = repository.createSystemSession(context, true); SystemContent system = new SystemContent(systemCache); Collection<NodeTypeDefinition> nodeTypes = system.readAllNodeTypes(); if (nodeTypes.isEmpty()) return false; registerNodeTypes(nodeTypes, false, false, false); return true; } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); return false; } finally { this.nodeTypesLock.writeLock().unlock(); } }
@Test public void shouldUnregisterNamespace() { Map<String, String> urisByPrefix = new HashMap<String, String>(); String uri = "http://foo.bar"; String prefix = "foobar"; urisByPrefix.put(prefix, uri); system.registerNamespaces(urisByPrefix); assertTrue(system.unregisterNamespace(uri)); assertNull(system.readNamespacePrefix(uri, false)); } }
protected void store( IndexDefinition indexDefn, boolean updateExisting ) { MutableCachedNode indexesNode = mutableIndexesNode(); store(indexDefn, indexesNode, updateExisting); }
/** * Stores the node type in the system area under <code>/jcr:system/jcr:nodeTypes</code>. * <p> * The stored content will contain a node with a primary type of <code>nt:nodeType</code> and a name that corresponds to the * node type's name. All other properties and child nodes for the newly created node are added in a manner consistent with the * guidance provided in section 6.7.22 of the JCR 1.0 specification and section 4.7.24 of the JCR 2.0 specification where * possible. * </p> * * @param nodeType the node type to write; may not be null * @param updateExisting a boolean flag denoting whether the new node type definition should be overwrite an existing node * type definition */ public void store( JcrNodeType nodeType, boolean updateExisting ) { MutableCachedNode nodeTypesNode = mutableNodeTypesNode(); store(nodeType, nodeTypesNode, updateExisting); }
public boolean hasVersionHistory( NodeKey versionableNodeKey ) { return cache().getNode(versionHistoryNodeKeyFor(versionableNodeKey)) != null; }
SystemContent system = new SystemContent(systemCache); CachedNode locks = system.locksNode(); MutableCachedNode mutableLocks = null; Set<NodeKey> corruptedLocks = new HashSet<>(); if (node == null) { if (mutableLocks == null) { mutableLocks = system.mutableLocksNode(); system.save(); for (Iterator<Map.Entry<NodeKey, ModeShapeLock>> locksIterator = locksByNodeKey.entrySet().iterator(); locksIterator.hasNext();) {
@SuppressWarnings( "deprecation" ) private void updateLocks( RunningState repository ) { try { SessionCache systemSession = repository.createSystemSession(repository.context(), false); SystemContent systemContent = new SystemContent(systemSession); CachedNode locksNode = systemContent.locksNode(); if (locksNode == null) { return; } ChildReferences childReferences = locksNode.getChildReferences(systemSession); if (childReferences.isEmpty()) { return; } for (ChildReference ref : childReferences) { MutableCachedNode lockNode = systemSession.mutable(ref.getKey()); // remove properties that belong to the old (invalid) node type lockNode.removeProperty(systemSession, ModeShapeLexicon.LOCKED_KEY); lockNode.removeProperty(systemSession, ModeShapeLexicon.SESSION_SCOPE); lockNode.removeProperty(systemSession, ModeShapeLexicon.IS_DEEP); } systemContent.save(); } catch (Exception e) { LOGGER.error(e, JcrI18n.upgrade3_6_0CannotUpdateLocks, e.getMessage()); } }
if (persist) { SessionCache systemCache = repository.createSystemSession(context, false); system = new SystemContent(systemCache); if (system != null) system.store(nodeType, true); if (system != null) system.save();
SystemContent systemContent = new SystemContent(systemSession); CachedNode locksNode = systemContent.locksNode(); ChildReferences childReferences = locksNode.getChildReferences(systemSession); if (childReferences.isEmpty()) { if (expirationDate.isBefore(now)) { systemContent.removeLock(lock);
/** * Register a set of namespaces. * * @param namespaceUrisByPrefix the map of new namespace URIs by their prefix */ public void register( Map<String, String> namespaceUrisByPrefix ) { if (namespaceUrisByPrefix == null || namespaceUrisByPrefix.isEmpty()) return; final Lock lock = this.namespacesLock.writeLock(); try { lock.lock(); SystemContent systemContent = systemContent(false); systemContent.registerNamespaces(namespaceUrisByPrefix); systemContent.save(); for (Map.Entry<String, String> entry : namespaceUrisByPrefix.entrySet()) { String prefix = entry.getKey().trim(); String uri = entry.getValue().trim(); if (prefix.length() == 0) continue; this.cache.register(prefix, uri); } } finally { lock.unlock(); } }
SystemContent systemContent = new SystemContent(systemCache); Map<NodeKey, NodeKey> baseVersionKeys = this.baseVersionKeys.get(); Map<NodeKey, NodeKey> originalVersionKeys = this.originalVersionKeys.get(); try { cache().save(systemContent.cache(), new JcrPreSave(systemContent, baseVersionKeys, originalVersionKeys, aclChangesCount())); clearState();
private void initializeVersionHistoryFor( AbstractJcrNode node, NodeKey historyKey, SessionCache cache ) throws RepositoryException { SystemContent content = new SystemContent(session.createSystemCache(false)); CachedNode cachedNode = node.node(); Name primaryTypeName = cachedNode.getPrimaryType(cache); Set<Name> mixinTypeNames = cachedNode.getMixinTypes(cache); NodeKey versionedKey = cachedNode.getKey(); Path versionHistoryPath = versionHistoryPathFor(versionedKey); DateTime now = session().dateFactory().create(); content.initializeVersionStorage(versionedKey, historyKey, null, primaryTypeName, mixinTypeNames, versionHistoryPath, null, now); content.save(); }
/** * Updates the underlying repository directly (i.e., outside the scope of the {@link Session}) to mark the token for the given * lock as being held (or not held) by some {@link Session}. Note that this method does not identify <i>which</i> (if any) * session holds the token for the lock, just that <i>some</i> session holds the token for the lock. * * @param session the session on behalf of which the lock operation is being performed * @param lockToken the lock token for which the "held" status should be modified; may not be null * @param value the new value * @return true if the lock "held" status was successfully changed to the desired value, or false otherwise * @throws LockException if there is no such lock with the supplied token */ boolean setHeldBySession( JcrSession session, String lockToken, boolean value ) throws LockException { assert lockToken != null; // Create a system session to remove the locks ... final ExecutionContext context = session.context(); SessionCache systemSession = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemSession); // Mark the session as held/unheld ... if (!system.changeLockHeldBySession(lockToken, value)) { return false; } // Now save the session ... system.save(); return true; }
final NodeKey providerKey = nodeKey(indexes.getKey(), indexDefn.getProviderName()); if (indexes.getChildReferences(system).hasChild(providerKey)) { final NodeKey key = nodeKey(indexes.getKey(), indexDefn); MutableCachedNode indexNode = null; Set<NodeKey> existingChildKeys = null; Property prop = createProperty(entry.getKey(), entry.getValue()); if (prop != null) properties.add(prop); NodeKey columnDefnKey = store(indexNode, columnDefn); if (existingChildKeys != null) existingChildKeys.remove(columnDefnKey);
SystemContent systemContent = new SystemContent(system); systemContent.unregisterNodeTypes(removedNodeTypes.toArray(new JcrNodeType[removedNodeTypes.size()])); systemContent.save();
SystemContent system = new SystemContent(systemSession); NodeKey nodeKey = node.getKey(); NodeKey lockKey = generateLockKey(system.locksKey(), nodeKey); String token = generateLockToken(); ModeShapeLock lock = new ModeShapeLock(nodeKey, lockKey, session.workspaceName(), owner, token, isDeep, isSessionScoped, system.storeLock(lock);
SystemContent systemContent = new SystemContent(systemSession); MutableCachedNode systemNode = systemContent.mutableSystemNode(); systemNode.removeProperty(systemSession, ModeShapeLexicon.ACL_COUNT); systemSession.save(); SystemContent systemContent = new SystemContent(systemSession); MutableCachedNode systemNode = systemContent.mutableSystemNode(); Property aclCountProp = systemNode.getProperty(ModeShapeLexicon.ACL_COUNT, systemSession); assertNotNull("ACL count property not found after upgrade", aclCountProp); SystemContent systemContent = new SystemContent(systemSession); CachedNode systemNode = systemContent.systemNode(); Property aclCountProp = systemNode.getProperty(ModeShapeLexicon.ACL_COUNT, systemSession); assertNotNull("ACL count property not found after upgrade", aclCountProp);
public NodeKey nodeTypesKey() { if (nodeTypesKey == null) { // This is idempotent, so no need to lock CachedNode systemNode = systemNode(); ChildReference nodeTypesRef = systemNode.getChildReferences(system).getChild(JcrLexicon.NODE_TYPES); nodeTypesKey = nodeTypesRef.getKey(); } return nodeTypesKey; }
SystemContent systemContent = new SystemContent(systemSession); MutableCachedNode systemNode = systemContent.mutableSystemNode(); systemNode.setProperty(systemSession, context.getPropertyFactory().create(ModeShapeLexicon.ACL_COUNT, nodesWithAccessControl)); systemSession.save();