Package org.apache.jackrabbit.mongomk.impl.model

Examples of org.apache.jackrabbit.mongomk.impl.model.MongoCommit


        }

        DBObject query = qb.get();
        DBObject fields = new BasicDBObject(MongoCommit.KEY_REVISION_ID, 1);
        DBObject orderBy = new BasicDBObject(MongoCommit.KEY_REVISION_ID, -1);
        MongoCommit commit = (MongoCommit)collection.findOne(query, fields, orderBy);
        return commit != null? commit.getRevisionId() : headRevisionId;
    }
View Full Code Here


        this.pathDepth = PathUtils.getDepth(this.path);
    }

    @Override
    public String execute() throws Exception {
        MongoCommit fromCommit = new FetchCommitAction(
                nodeStore, fromRevision).execute();
        MongoCommit toCommit = new FetchCommitAction(
                nodeStore, toRevision).execute();
        FetchNodesActionNew action = new FetchNodesActionNew(
                nodeStore, path, 0, fromRevision);
        action.setBranchId(fromCommit.getBranchId());
        NodeImpl fromNode = MongoNode.toNode(action.execute().get(path));
        action = new FetchNodesActionNew(
                nodeStore, path, 0, toRevision);
        action.setBranchId(toCommit.getBranchId());
        NodeImpl toNode = MongoNode.toNode(action.execute().get(path));

        String diff = "";
        if (!fromNode.getRevisionId().equals(toNode.getRevisionId())) {
            // diff of node at given path
View Full Code Here

        // FetchCommitsAction because that action does not leverage the
        // commit cache in NodeStore. Retrieving each commit individually
        // results in good cache hit ratios when the revision range is recent
        // and not too big.
        List<MongoCommit> commits = new ArrayList<MongoCommit>();
        MongoCommit fromCommit = c1.getRevisionId() < c2.getRevisionId() ? c1 : c2;
        MongoCommit toCommit = c1.getRevisionId() < c2.getRevisionId() ? c2 : c1;
        Long revision = toCommit.getBaseRevisionId();
        commits.add(toCommit);
        while (revision != null && revision > fromCommit.getRevisionId()) {
            MongoCommit c = new FetchCommitAction(nodeStore, revision).execute();
            commits.add(c);
            revision = c.getBaseRevisionId();
        }
        commits.add(fromCommit);
        return commits;
    }
View Full Code Here

    @Test
    public void revisionId() throws Exception {
        FetchCommitsAction action = new FetchCommitsAction(getNodeStore());
        List<MongoCommit> commits = action.execute();
        MongoCommit commit0 = commits.get(0);

        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
        scenario.create();
        commits = action.execute();
        MongoCommit commit1 = commits.get(0);
        assertTrue(commit0.getRevisionId() < commit1.getRevisionId());

        int numberOfChildren = 3;
        scenario.addChildrenToA(numberOfChildren);
        commits = action.execute();
        MongoCommit commit2 = commits.get(0);
        assertTrue(commit1.getRevisionId() < commit2.getRevisionId());
    }
View Full Code Here

    @Test
    public void time() throws Exception {
        FetchCommitsAction action = new FetchCommitsAction(getNodeStore());
        List<MongoCommit> commits = action.execute();
        MongoCommit commit0 = commits.get(0);

        Thread.sleep(1000);

        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
        scenario.create();
        commits = action.execute();
        MongoCommit commit1 = commits.get(0);
        assertTrue(commit0.getTimestamp() < commit1.getTimestamp());

        Thread.sleep(1000);

        int numberOfChildren = 3;
        scenario.addChildrenToA(numberOfChildren);
        commits = action.execute();
        MongoCommit commit2 = commits.get(0);
        assertTrue(commit1.getTimestamp() < commit2.getTimestamp());
    }
View Full Code Here

        action.includeBranchCommits(false);

        List<MongoCommit> commits = action.execute();
        List<MongoCommit> history = new ArrayList<MongoCommit>();
        for (int i = commits.size() - 1; i >= 0; i--) {
            MongoCommit commit = commits.get(i);
            if (commit.getTimestamp() >= since) {
                if (MongoUtil.isFiltered(path)) {
                    try {
                        String diff = new DiffBuilder(
                                MongoUtil.wrap(getNode("/", commit.getBaseRevisionId())),
                                MongoUtil.wrap(getNode("/", commit.getRevisionId())),
                                "/", -1, new SimpleMongoNodeStore(), path).build();
                        if (!diff.isEmpty()) {
                            history.add(commit);
                        }
                    } catch (Exception e) {
                        throw new MicroKernelException(e);
                    }
                } else {
                    history.add(commit);
                }
            }
        }

        JsopBuilder buff = new JsopBuilder().array();
        for (MongoCommit commit : history) {
            buff.object()
            .key("id").value(MongoUtil.fromMongoRepresentation(commit.getRevisionId()))
            .key("ts").value(commit.getTimestamp())
            .key("msg").value(commit.getMessage())
            .endObject();
        }
        return buff.endArray().toString();
    }
View Full Code Here

            toRevision = MongoUtil.toMongoRepresentation(toRevisionId);
        }

        List<MongoCommit> commits = getCommits(fromRevision, toRevision);

        MongoCommit toCommit = extractCommit(commits, toRevision);
        MongoCommit fromCommit;
        if (toRevision == fromRevision) {
            fromCommit = toCommit;
        } else {
            fromCommit = extractCommit(commits, fromRevision);
        }

        if (fromCommit != null && fromCommit.getBranchId() != null) {
            if (!fromCommit.getBranchId().equals(toCommit.getBranchId())) {
                throw new MicroKernelException("Inconsistent range specified: fromRevision denotes a private branch while toRevision denotes a head or another private branch");
            }
        }

        if (fromCommit != null && fromCommit.getTimestamp() > toCommit.getTimestamp()) {
            // negative range, return empty journal
            return "[]";
        }

        JsopBuilder commitBuff = new JsopBuilder().array();
        // Iterate over commits in chronological order, starting with oldest commit
        for (int i = commits.size() - 1; i >= 0; i--) {
            MongoCommit commit = commits.get(i);

            String diff = commit.getDiff();
            if (MongoUtil.isFiltered(path)) {
                try {
                    diff = new DiffBuilder(
                            MongoUtil.wrap(getNode("/", commit.getBaseRevisionId())),
                            MongoUtil.wrap(getNode("/", commit.getRevisionId())),
                            "/", -1, new SimpleMongoNodeStore(), path).build();
                    if (diff.isEmpty()) {
                        continue;
                    }
                } catch (Exception e) {
                    throw new MicroKernelException(e);
                }
            }
            commitBuff.object()
            .key("id").value(MongoUtil.fromMongoRepresentation(commit.getRevisionId()))
            .key("ts").value(commit.getTimestamp())
            .key("msg").value(commit.getMessage());
            if (commit.getBranchId() != null) {
                commitBuff.key("branchRootId").value(commit.getBranchId().toString());
            }
            commitBuff.key("changes").value(diff).endObject();
        }
        return commitBuff.endArray().toString();
    }
View Full Code Here

                .and(MongoCommit.KEY_BASE_REVISION_ID).is(baseRevisionId)
                .and(MongoCommit.KEY_REVISION_ID).greaterThan(0L)
                .and(MongoCommit.KEY_REVISION_ID).notEquals(revisionId);
        DBObject query = queryBuilder.get();
        DBCollection collection = nodeStore.getCommitCollection();
        MongoCommit conflictingCommit = (MongoCommit)collection.findOne(query);
        for (String affectedPath : conflictingCommit.getAffectedPaths()) {
            if (affectedPaths.contains(affectedPath)) {
                return true;
            }
        }
        return false;
View Full Code Here

        if (baseRevisionId == null) {
            return;
        }

        FetchCommitAction action = new FetchCommitAction(nodeStore, baseRevisionId);
        MongoCommit commit = action.execute();
        branchId = commit.getBranchId();
    }
View Full Code Here

                .and(MongoCommit.KEY_BASE_REVISION_ID).is(baseRevisionId)
                .and(MongoCommit.KEY_REVISION_ID).greaterThan(0L)
                .and(MongoCommit.KEY_REVISION_ID).notEquals(revisionId);
        DBObject query = queryBuilder.get();
        DBCollection collection = nodeStore.getCommitCollection();
        MongoCommit conflictingCommit = (MongoCommit)collection.findOne(query);
        for (String affectedPath : conflictingCommit.getAffectedPaths()) {
            if (affectedPaths.contains(affectedPath)) {
                return true;
            }
        }
        return false;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.mongomk.impl.model.MongoCommit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.