Skip to main content
summaryrefslogtreecommitdiffstats
blob: 86532e447b04c3ab8d63a8533c4c594472b317dd (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
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2004 - 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.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
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.Company;
import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;

import org.eclipse.emf.internal.cdo.transaction.CDOSavepointImpl;

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

import java.util.Date;

/**
 * Bug 294859 - Deltas for local changes to objects in CONFLICT state, are not added to tx
 *
 * @author Caspar De Groot
 */
public class Bugzilla_294859_Test extends AbstractCDOTest
{
  private static String RESOURCE_NAME = "/r1";

  public void test() throws CommitException
  {
    CDOSession session = openSession();
    session.options().setPassiveUpdateEnabled(false);

    CDOTransaction tx = session.openTransaction();

    // Do NOT use a conflict resolver

    CDOResource r1 = tx.createResource(getResourcePath(RESOURCE_NAME));

    Company company1 = getModel1Factory().createCompany();
    Company company2 = getModel1Factory().createCompany();
    PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder();
    company1.getPurchaseOrders().add(purchaseOrder);
    r1.getContents().add(company1);
    r1.getContents().add(company2);
    tx.commit();

    // Touch the purchaseOrder
    purchaseOrder.setDate(new Date(1000L));

    doSecondSession();

    // Convenience
    CDOObject cdoPurchaseOrder = CDOUtil.getCDOObject(purchaseOrder);

    // The purchaseOrder was touched in both this and 2nd session;
    // we refresh now go cause a conflict
    session.refresh();
    assertEquals(true, cdoPurchaseOrder.cdoState() == CDOState.CONFLICT);

    // Touch it again
    purchaseOrder.setDate(new Date(3000L));

    // Verify that the delta representing the LAST LOCAL change is in the TX
    //
    CDOSavepointImpl savepoint = (CDOSavepointImpl)((InternalCDOTransaction)tx).getLastSavepoint();
    CDORevisionDelta revDelta = savepoint.getRevisionDeltas2().get(cdoPurchaseOrder.cdoID());
    assertNotNull(revDelta);
    assertEquals(true, revDelta.getFeatureDeltas().size() == 1);
    CDOFeatureDelta featDelta = revDelta.getFeatureDeltas().get(0);
    EAttribute eAttr = getModel1Factory().getModel1Package().getPurchaseOrder_Date();
    assertEquals(true, featDelta instanceof CDOSetFeatureDelta);
    CDOSetFeatureDelta setFeatDelta = (CDOSetFeatureDelta)featDelta;
    assertSame(eAttr, setFeatDelta.getFeature());
    assertSame(CDOFeatureDelta.Type.SET, setFeatDelta.getType());
    assertEquals(new Date(3000L), setFeatDelta.getValue());

    try
    {
      tx.commit();
      fail("CommitException expected");
    }
    catch (CommitException expected)
    {
      // Correct
    }

    tx.close();
    session.close();
  }

  private void doSecondSession() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();
    CDOResource r1 = tx.getResource(getResourcePath(RESOURCE_NAME));
    Company c = (Company)r1.getContents().get(0);

    // Touch the purchaseOrder
    c.getPurchaseOrders().get(0).setDate(new Date(2000L));

    tx.commit();
    tx.close();
    session.close();
  }
}

Back to the top