Search in sources :

Example 6 with ConflictHook

use of org.apache.jackrabbit.oak.plugins.commit.ConflictHook in project jackrabbit-oak by apache.

the class Oak method with.

/**
     * Associates the given conflict handler with the repository to be created.
     *
     * @param conflictHandler conflict handler
     * @return this builder
     */
@Nonnull
public Oak with(@Nonnull ConflictHandler conflictHandler) {
    checkNotNull(conflictHandler);
    withEditorHook();
    commitHooks.add(new ConflictHook(conflictHandler));
    return this;
}
Also used : ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) Nonnull(javax.annotation.Nonnull)

Example 7 with ConflictHook

use of org.apache.jackrabbit.oak.plugins.commit.ConflictHook in project jackrabbit-oak by apache.

the class NodeStoreDiffTest method diffWithConflict.

@Test
public void diffWithConflict() throws Exception {
    //Last rev on /var would be 1-0-1
    createNodes("/var/a", "/var/b/b1");
    //1. Dummy commits to bump the version no
    createNodes("/fake/b");
    createNodes("/fake/c");
    //Root rev = 3-0-1
    //Root rev = 3-0-1
    //2. Create a node under /var/a but hold on commit
    NodeBuilder b1 = ns.getRoot().builder();
    createNodes(b1, "/var/a/a1");
    //3. Remove a node under /var/b and commit it
    NodeBuilder b2 = ns.getRoot().builder();
    b2.child("var").child("b").child("b1").remove();
    merge(b2);
    //4. Now merge and commit the changes in b1 and include conflict hooks
    //For now exception would be thrown
    ns.merge(b1, new CompositeHook(new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider())), CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test)

Example 8 with ConflictHook

use of org.apache.jackrabbit.oak.plugins.commit.ConflictHook in project jackrabbit-oak by apache.

the class NodeStoreTest method addExistingNodeJCRLastModified.

@Test
public void addExistingNodeJCRLastModified() throws CommitFailedException {
    CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder b2 = store.getRoot().builder();
    Calendar calendar = Calendar.getInstance();
    b1.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    calendar.add(Calendar.MINUTE, 1);
    b2.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    b1.setChildNode("conflict");
    b2.setChildNode("conflict");
    store.merge(b1, hook, CommitInfo.EMPTY);
    store.merge(b2, hook, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Calendar(java.util.Calendar) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Aggregations

ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)8 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)7 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)4 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)4 Test (org.junit.Test)4 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 Calendar (java.util.Calendar)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)2 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2 Nonnull (javax.annotation.Nonnull)1