Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4670bffb0ce282ca207bf9b3ba452f62faec2e75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (c) 2012 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Ronald Krijgsheld - initial API and implementation
 */
package org.eclipse.emf.cdo.tests;

import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOObjectHandler;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.emf.spi.cdo.InternalCDOTransaction;

/**
 * @author Ronald Krijgsheld
 */
public class Test368331 extends AbstractCDOTest
{
  public void testDetach() throws CommitException
  {
    final CDOSession session = openSession();
    InternalCDOTransaction tx1 = (InternalCDOTransaction)session.openTransaction();
    final CDOResource resourceA = tx1.createResource(getResourcePath("/test1"));
    Company c = createCompanyWithCategories(resourceA);
    tx1.commit();

    tx1.addObjectHandler(new CDOObjectHandler()
    {
      public void objectStateChanged(CDOView view, CDOObject object, CDOState oldState, CDOState newState)
      {
        if (object instanceof Company && newState == CDOState.TRANSIENT)
        {
          Company c = (Company)object;
          c.getCategories().clear();
        }
      }
    });

    resourceA.getContents().remove(c);
  }

  private Company createCompanyWithCategories(final CDOResource resourceA)
  {
    final Company companyA = getModel1Factory().createCompany();
    resourceA.getContents().add(companyA);
    for (int i = 0; i < 10; i++)
    {
      Category c = getModel1Factory().createCategory();
      companyA.getCategories().add(c);
    }
    return companyA;
  }
}

Back to the top