The JPA connector's implementation of CloneBranchRequest is not correct when cloning from another workspace. This is used in the JCR API in the 'Node.update(String workspaceName)' method as well as the 'Workspace.clone( String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting )'.
The problem appears to be that the removeExisting behavior only works by comparing exact UUIDs, whereas the removeExisting behavior (for clone) really should apply only to the specified path. Yes, any existing nodes with the same UUIDs should be removed, but certainly if 'removeExisting' is true any existing node at the desired location for the clone should be removed as well.
This was discovered because the TCK tests are failing when they're run against a repository using the JPA connector (both against HSQLDB and PostgreSQL):
JpaRepositoryTckTest
Tests for jpa(read-write)
org.apache.jackrabbit.test.api.NodeTest
testUpdate(org.apache.jackrabbit.test.api.NodeTest)
java.lang.IllegalArgumentException: The last segment of the actual location of </{}testroot/{}node1[2] && [
uuid = c3863875-6422-46ee-b47f-5a12547e27d8]> does not have the requested child segment {}node1
at org.jboss.dna.graph.request.CloneBranchRequest.setActualLocations(CloneBranchRequest.java:199)
at org.jboss.dna.connector.store.jpa.model.basic.BasicRequestProcessor.process(BasicRequestProcessor.java:1672)
at org.jboss.dna.graph.request.processor.RequestProcessor.process(RequestProcessor.java:261)
at org.jboss.dna.graph.request.processor.RequestProcessor.process(RequestProcessor.java:298)
at org.jboss.dna.graph.request.processor.RequestProcessor.process(RequestProcessor.java:219)
at org.jboss.dna.connector.store.jpa.JpaConnection.execute(JpaConnection.java:150)
at org.jboss.dna.graph.connector.federation.ForkRequestProcessor$Channel$3.call(ForkRequestProcessor.java:318)
at org.jboss.dna.graph.connector.federation.ForkRequestProcessor$Channel$3.call(ForkRequestProcessor.java:308)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
org.apache.jackrabbit.test.api.WorkspaceCloneReferenceableTest
testCloneNodesRemoveExistingTrue(org.apache.jackrabbit.test.api.WorkspaceCloneReferenceableTest)
junit.framework.AssertionFailedError: null
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertFalse(Assert.java:34)
at junit.framework.Assert.assertFalse(Assert.java:41)
at org.apache.jackrabbit.test.api.WorkspaceCloneReferenceableTest.testCloneNodesRemoveExistingTrue(WorkspaceCloneReferenceableTest.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at org.apache.jackrabbit.test.AbstractJCRTest.run(AbstractJCRTest.java:406)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)