public void validate() throws RepositoryException { int totalCount = 0, changedCount = 0; Node derivatesFolder = session.getNode(DERIVATIVES_PATH); Query query = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM hippo:derived", Query.SQL); QueryResult result = query.execute(); for (Node node : new NodeIterable(result.getNodes())) { ++totalCount; if (compute(derivatesFolder, node)) { ++changedCount; if ((changedCount % LocalHippoRepository.batchThreshold) == 0) { session.save(); } } } log.warn("Validated " + totalCount + " nodes, and reset " + changedCount + " nodes"); session.save(); }
/** * Persists pending changes. logs events to the HippoEventBus and if <code>hstManager</code> is not <code>null</code> * also invalidates the hstMananger * Note that this static method is synchronized as multiple thread should not try to lock nodes simultaneously * @param session * @throws javax.jcr.RepositoryException * @throws IllegalStateException in case some nodes already got locked by another user */ public synchronized static void persistChanges(final HippoSession session) throws RepositoryException, IllegalStateException { try { if (!session.hasPendingChanges()) { return; } // try acquiring locks : If does not succeed, an IllegalStateException is thrown tryLocks(session); StringBuilder buffer = new StringBuilder("User made changes at (and possibly below): "); appendPendingChangesFromNodeToBuffer(session, buffer, ","); session.save(); //only log when the save is successful logEvent("write-changes", session.getUserID(), buffer.toString()); } catch (IllegalStateException e) { session.refresh(false); log.warn("Cannot save changes :", e); } }