Java Code Examples for javax.jcr.Session#refresh()

The following examples show how to use javax.jcr.Session#refresh() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Importer.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
public void applyMemberships(Session session) {
    if (memberships.isEmpty()) {
        return;
    }
    if (opts.isDryRun()) {
        track("Dry run: Would apply merged group memberships...", "");
    } else {
        track("Applying merged group memberships...", "");
    }
    for (String id: memberships.keySet()) {
        String[] members = memberships.get(id);
        String authPath = userManagement.getAuthorizablePath(session, id);
        if (authPath != null) {
            if (!opts.isDryRun()) {
                userManagement.addMembers(session, id, members);
            }
            track("U", String.format("%s", authPath));
        }
    }
    try {
        session.save();
    } catch (RepositoryException e) {
        log.error("Error while updating memberships.", e);
        try {
            session.refresh(false);
        } catch (RepositoryException e1) {
            // ignore
        }
    }
    memberships.clear();
}
 
Example 2
Source File: AutoSave.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * saves the changes under the given node and resets the counter
 * @param session the session to save. can be {@code null}
 * @throws RepositoryException if an error occurs.
 */
public void save(@Nullable Session session) throws RepositoryException {
    if (threshold == Integer.MAX_VALUE) {
        log.trace("Save disabled.");
        return;
    }
    int diff = numModified - lastSave;
    log.debug("Threshold of {} reached. {} approx {} transient changes. {} unresolved", new Object[]{
            threshold,
            dryRun ? "dry run, reverting" : "saving",
            diff,
            missingMandatory.size()
    });
    if (tracker != null) {
        if (dryRun) {
            tracker.track("reverting approx " + diff + " nodes... (dry run)", "");
        } else {
            tracker.track("saving approx " + diff + " nodes...", "");
        }
    }
    if (session != null) {
        if (debugFailEach > 0 && debugSaveCount > 0 && debugSaveCount%debugFailEach == 0) {
            String msg = String.format("Debugging provoked failure after %s saves.", debugSaveCount);
            log.error(msg);
            throw new RepositoryException(msg);
        }

        if (dryRun) {
            session.refresh(false);
        } else {
            try {
                session.save();
                debugSaveCount++;
            } catch (RepositoryException e) {
                log.error("error during auto save - retrying after refresh...");
                session.refresh(true);
                session.save();
                debugSaveCount++;
            }
        }
    }
    lastSave = numModified;
}