Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 226cbd067308976f7af6d9d33528638d043b8545 (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
/*
 * Copyright (c) 2013 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:
 *    Martin Taal - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.hibernate;

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.transaction.CDOTransaction;

/**
 * @author Michael Taal
 */
public class HibernateBugzilla_416530_Test extends AbstractCDOTest
{

  // @Override
  // public void doSetUp() throws Exception
  // {
  // org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1);
  // org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1);
  // super.doSetUp();
  // }
  //
  // @Override
  // public void doTearDown() throws Exception
  // {
  // org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0);
  // org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0);
  // super.doTearDown();
  // }

  public void testCreatePersist() throws Exception
  {
    // step 1: create initial objects and add to resource
    {
      final CDOSession session = openSession();
      final CDOTransaction transaction = session.openTransaction();
      // get/create a resource
      CDOResource resource = transaction.createResource(getResourcePath("/test1"));

      // clear any previous data
      resource.getContents().clear();

      for (int i = 0; i < 100; i++)
      {
        final Company address = getModel1Factory().createCompany();
        address.setCity("test"); //$NON-NLS-1$
        String addressName = "name " + System.currentTimeMillis(); //$NON-NLS-1$
        address.setName(addressName);
        address.setStreet("test"); //$NON-NLS-1$
        resource.getContents().add(address);
      }

      transaction.commit();
    }

    // step 2: create one additional object and add to resource
    // observations: for each object in the resource, the following add will cause a select for each of that object
    {
      final CDOSession session = openSession();
      final CDOTransaction transaction = session.openTransaction();
      // get/create a resource
      CDOResource resource = transaction.getResource(getResourcePath("/test1"));

      {
        final Company address = getModel1Factory().createCompany();
        address.setCity("test"); //$NON-NLS-1$
        String addressName = "name " + System.currentTimeMillis(); //$NON-NLS-1$
        address.setName(addressName);
        address.setStreet("test"); //$NON-NLS-1$
        resource.getContents().add(address);
      }

      transaction.commit();
    }
  }
}

Back to the top