private final SystemContent systemContent( boolean readOnly ) { SessionCache systemCache = repository.createSystemSession(context, readOnly); return new SystemContent(systemCache); }
private final SystemContent systemContent( boolean readOnly ) { SessionCache systemCache = repository.createSystemSession(context, readOnly); return new SystemContent(systemCache); }
/** * 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(); } }
/** * 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(); } }
/** * 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() { Lock lock = this.namespacesLock.writeLock(); try { lock.lock(); // Re-read and re-register all of the namespaces ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<Namespace> namespaces = system.readAllNamespaces(); if (namespaces.isEmpty()) return false; this.cache.clear(); this.cache.register(namespaces); } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); } finally { lock.unlock(); } return true; }
/** * 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() { Lock lock = this.namespacesLock.writeLock(); try { lock.lock(); // Re-read and re-register all of the namespaces ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<Namespace> namespaces = system.readAllNamespaces(); if (namespaces.isEmpty()) return false; this.cache.clear(); this.cache.register(namespaces); } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); } finally { lock.unlock(); } return true; }
public JcrVersionManager( JcrSession session ) { super(); this.session = session; versionStoragePath = absolutePath(JcrLexicon.SYSTEM, JcrLexicon.VERSION_STORAGE); ExecutionContext context = session.context(); versionHistoryPathAlgorithm = new HiearchicalPathAlgorithm(versionStoragePath, context); readableSystem = new SystemContent(this.session.cache()); }
public JcrVersionManager( JcrSession session ) { super(); this.session = session; versionStoragePath = absolutePath(JcrLexicon.SYSTEM, JcrLexicon.VERSION_STORAGE); ExecutionContext context = session.context(); versionHistoryPathAlgorithm = new HiearchicalPathAlgorithm(versionStoragePath, context); readableSystem = new SystemContent(this.session.cache()); }
protected RepositoryIndexes readIndexDefinitions() { // There were at least some changes ... NodeTypes nodeTypes = repository.nodeTypeManager().getNodeTypes(); try { // Read the affected index definitions ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<IndexDefinition> indexDefns = system.readAllIndexDefinitions(providers.keySet()); this.indexes = new Indexes(context, indexDefns, nodeTypes); return this.indexes; } catch (WorkspaceNotFoundException e) { // This happens occasionally when shutting down ... } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingIndexDefinitions, repository.name()); } return indexes; }
/** * 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; }
protected RepositoryIndexes readIndexDefinitions() { // There were at least some changes ... NodeTypes nodeTypes = repository.nodeTypeManager().getNodeTypes(); try { // Read the affected index definitions ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<IndexDefinition> indexDefns = system.readAllIndexDefinitions(providers.keySet()); this.indexes = new Indexes(context, indexDefns, nodeTypes); return this.indexes; } catch (WorkspaceNotFoundException e) { // This happens occasionally when shutting down ... } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingIndexDefinitions, repository.name()); } return indexes; }
@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(); }
@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(); }
@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()); } }
@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()); } }
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(); }
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(); }
private void unlock( JcrSession session, Iterable<ModeShapeLock> locks ) { if (locks == null) return; // Create a system session to remove the locks ... final ExecutionContext context = session.context(); SessionCache systemSession = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemSession); // And create a separate session cache to change the locked nodes ... SessionCache lockingSession = session.spawnSessionCache(false); // Remove the locks ... for (ModeShapeLock lock : locks) { system.removeLock(lock); NodeKey lockedNodeKey = lock.getLockedNodeKey(); if (session.cache().getNode(lockedNodeKey) == null) { // the node on which the lock was placed, has been removed continue; } MutableCachedNode lockedNode = lockingSession.mutable(lockedNodeKey); lockedNode.removeProperty(lockingSession, JcrLexicon.LOCK_IS_DEEP); lockedNode.removeProperty(lockingSession, JcrLexicon.LOCK_OWNER); lockedNode.unlock(); } // Now save the two sessions ... // save the system session first so that the system change is reflected first in the ws caches systemSession.save(lockingSession, null); }
private void unlock( JcrSession session, Iterable<ModeShapeLock> locks ) { if (locks == null) return; // Create a system session to remove the locks ... final ExecutionContext context = session.context(); SessionCache systemSession = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemSession); // And create a separate session cache to change the locked nodes ... SessionCache lockingSession = session.spawnSessionCache(false); // Remove the locks ... for (ModeShapeLock lock : locks) { system.removeLock(lock); NodeKey lockedNodeKey = lock.getLockedNodeKey(); if (session.cache().getNode(lockedNodeKey) == null) { // the node on which the lock was placed, has been removed continue; } MutableCachedNode lockedNode = lockingSession.mutable(lockedNodeKey); lockedNode.removeProperty(lockingSession, JcrLexicon.LOCK_IS_DEEP); lockedNode.removeProperty(lockingSession, JcrLexicon.LOCK_OWNER); lockedNode.unlock(); } // Now save the two sessions ... // save the system session first so that the system change is reflected first in the ws caches systemSession.save(lockingSession, null); }
@Before public void beforeEach() throws Exception { config = new RepositoryConfiguration("repoName").with(new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); SessionCache systemCache = repository.createSystemSession(repository.runningState().context(), false); system = new SystemContent(systemCache); }