Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a342635220a3e34b4fc5f8ab686d124fee844b9 (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
/*
 * Copyright (c) 2011 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
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.model4.RefSingleNonContained;
import org.eclipse.emf.cdo.tests.model4.SingleNonContainedElement;
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.cdo.util.CommitIntegrityException;

import org.eclipse.emf.internal.cdo.util.CommitIntegrityCheck;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.spi.cdo.CDOStore;
import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @author Eike Stepper
 */
public class Bugzilla_352832_Test extends AbstractCDOTest
{

  public void testNewSingle() throws CommitException
  {
    CDOSession session1 = openSession();
    CDOTransaction transaction1 = session1.openTransaction();
    CDOResource resource = transaction1.createResource(getResourcePath("test"));
    SingleNonContainedElement singleNonContainedElement = getModel4Factory().createSingleNonContainedElement();
    RefSingleNonContained refSingleNonContained = getModel4Factory().createRefSingleNonContained();
    resource.getContents().add(singleNonContainedElement);
    resource.getContents().add(refSingleNonContained);
    transaction1.commit();

    // STEP 1 Setting parent feature to point REF
    CDORevision cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement).cdoRevision();
    // here is real Java NULL
    assertEquals(null,
        cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
    singleNonContainedElement.setParent(refSingleNonContained);
    transaction1.setCommittables(
        new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement, refSingleNonContained })));
    checkPartialCommitIntegrity((InternalCDOTransaction)transaction1);
    transaction1.commit();

    // STEP 2 Setting parent feature to point NULL
    CDOSession session2 = openSession();
    InternalCDOTransaction transaction2 = (InternalCDOTransaction)session2.openTransaction();
    SingleNonContainedElement singleNonContainedElement2 = (SingleNonContainedElement)CDOUtil
        .getEObject(transaction2.getObject(CDOUtil.getCDOObject(singleNonContainedElement).cdoID()));
    RefSingleNonContained refSingleNonContained2 = singleNonContainedElement2.getParent();
    singleNonContainedElement2.setParent(null);
    cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement2).cdoRevision();
    // here is real Java NULL after setting
    assertEquals(null,
        cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
    transaction2.setCommittables(
        new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement2, refSingleNonContained2 })));
    checkPartialCommitIntegrity(transaction2);
    transaction2.commit();
    session2.close();

    // STEP 3 Setting parent feature to point REF
    session2 = openSession();
    transaction2 = (InternalCDOTransaction)session2.openTransaction();
    singleNonContainedElement2 = (SingleNonContainedElement)CDOUtil
        .getEObject(transaction2.getObject(CDOUtil.getCDOObject(singleNonContainedElement).cdoID()));
    refSingleNonContained2 = (RefSingleNonContained)CDOUtil
        .getEObject(transaction2.getObject(CDOUtil.getCDOObject(refSingleNonContained).cdoID()));

    cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement2).cdoRevision();
    // from server loaded revision has CDO NULL ID, which has meaning of the same Java NULL. Identical situation when in
    // STEP 1
    assertEquals(CDOID.NULL,
        cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
    singleNonContainedElement2.setParent(refSingleNonContained2);
    transaction2.setCommittables(
        new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement2, refSingleNonContained2 })));
    checkPartialCommitIntegrity(transaction2);
    transaction2.commit();

    session2.close();
  }

  private void checkPartialCommitIntegrity(InternalCDOTransaction tx) throws CommitIntegrityException
  {
    InternalCDOCommitContext ctx = tx.createCommitContext();
    new CommitIntegrityCheck(ctx, CommitIntegrityCheck.Style.EXCEPTION_FAST).check();

  }
}

Back to the top