Maybe I confused the issue with the way I had coded it. I want to add a
reference to the 'department' object in the two disconnected DataGraphs.
I was calling DataObject.detach to remove the container reference. The
test case will fail with the same exception if you comment out the
detach.
I am not removing objects, I am adding objects. At the end of the test
case I would have expected to see companyA to have 1 department and
companyB to have 2 departments. The only way we are able to work around
this is by making a copy of the object as follows:
for (Iterator iter = departments_A.iterator(); iter.hasNext();) {
DataObject department_A = (DataObject) iter.next();
departments_B.add(CopyHelper.INSTANCE.copy(department_A));
}
This is the failing test code fragment:
for (Iterator iter = departments_A.iterator(); iter.hasNext();) {
DataObject department_A = (DataObject) iter.next();
departments_B.add(department_A);
}
I hope this clarifies the use case and question.
-----Original Message-----
From: Frank Budinsky [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 20, 2007 11:54 AM
To: [email protected]
Subject: Re: ConcurrentModificationException Disconnected DataGraphs
Murtaza,
This is just a standard Java programming issue. You can't remove objects
in a List while you have an active Iterator, unless you use
Iterator.remove().
In your example, instead of this:
department_A.detach();
you would need to call:
iter.remove();
to remove the department from the list and inform the Iterator of the
change.
Frank
"Murtaza Goga" <[EMAIL PROTECTED]> wrote on 03/20/2007
11:24:34
AM:
> We have two disconnected DataGraphs and when we add DataObjects from
one
> DataGraph into the other (with or without 'detach' being called) we
are
> observe ConcurrentModificationExceptions. I have pasted a simple test
> case below which adds a 'department' from one company into another.
> This test case will error out with the above exception. The
company.xsd
> is from the Tuscany M3 RC1 build.
>
>
>
> Can someone explain this behavior and what should be the recommended
> usage pattern?
>
>
>
> /**
>
> * @see junit.framework.TestCase#setUp()
>
> */
>
> @Override
>
> protected void setUp() throws Exception {
>
> XSDHelper.INSTANCE.define(ClassLoader
>
> .getSystemResourceAsStream("company.xsd"), null);
>
> }
>
>
>
> /**
>
> * Test list usage.
>
> */
>
> public void test01Concurrency() {
>
> DataGraph dataGraph_A = createCompanyDataGraph(1);
>
> DataGraph dataGraph_B = createCompanyDataGraph(1);
>
>
>
> List departments_A =
> dataGraph_A.getRootObject().getList("departments");
>
> List departments_B =
> dataGraph_B.getRootObject().getList("departments");
>
> for (Iterator iter = departments_A.iterator(); iter.hasNext();) {
>
> DataObject department_A = (DataObject) iter.next();
>
> department_A.detach(); // Does not matter if this call is made
or
> not
>
> departments_B.add(department_A);
>
> }
>
> }
>
>
>
> /**
>
> * Creates the company datagraph.
>
> * @param departmentsToCreate the number of departments to create.
>
> * @return the DataGraph.
>
> */
>
> private DataGraph createCompanyDataGraph(int departmentsToCreate) {
>
> DataGraph dataGraph = SDOUtil.createDataGraph();
>
> dataGraph.createRootObject("company.xsd", "CompanyType");
>
> for (int i = 0; i < departmentsToCreate; i++) {
>
> dataGraph.getRootObject().createDataObject("departments",
> "company.xsd",
>
> "DepartmentType");
>
> }
>
> return dataGraph;
>
> }
>
>
>
> Thanks,
>
> Murtaza.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]