Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 740c04f43e851f490af252d15dad992b4e270204 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (c) 2011, 2012 Eike Stepper (Berlin, 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:
 *    Caspar De Groot - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.tests.model1.SalesOrder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;

import org.eclipse.emf.ecore.EObject;

import java.util.HashSet;
import java.util.Set;

/**
 * Bug 336314 - Partial commits choke on CDOMoveFeatureDeltas
 * 
 * @author Caspar De Groot
 */
public class Bugzilla_336314_Test extends AbstractCDOTest
{
  public void test1() throws CommitException
  {
    test(new MoveIt()
    {
      public void move(SalesOrder order, OrderDetail detail)
      {
        order.getOrderDetails().remove(detail);
        order.getOrderDetails().add(detail);
      }
    });
  }

  public void test2() throws CommitException
  {
    test(new MoveIt()
    {
      public void move(SalesOrder order, OrderDetail detail)
      {
        order.getOrderDetails().move(0, 1);
      }
    });
  }

  private static interface MoveIt
  {
    void move(SalesOrder order, OrderDetail detail);
  }

  private void test(MoveIt moveIt) throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();

    assertEquals(true, getModel1Package().getOrder_OrderDetails().isOrdered());

    Model1Factory mf = getModel1Factory();
    CDOResource resource = tx.createResource(getResourcePath("test"));

    OrderDetail detailY = mf.createOrderDetail();
    detailY.setPrice(1.0f);

    OrderDetail detailZ = mf.createOrderDetail();
    detailY.setPrice(2.0f);

    SalesOrder orderX = mf.createSalesOrder();
    orderX.getOrderDetails().add(detailY);
    orderX.getOrderDetails().add(detailZ);

    resource.getContents().add(orderX);

    // We need another object to make the later commit partial
    Product1 product = mf.createProduct1();
    product.setName("abc");
    resource.getContents().add(product);

    tx.commit();

    // Remove then add back, so as to change ordering
    moveIt.move(orderX, detailY);

    // Partial commit
    Set<EObject> committables = new HashSet<EObject>(1);
    committables.add(orderX);
    tx.setCommittables(committables);

    // Make other object dirty too, so that commit becomes 'partial'
    product.setName("def");

    tx.commit();

    session.close();
  }
}

Back to the top