Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 308895 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java (+6 lines)
Lines 633-637 Link Here
633
633
634
      return val;
634
      return val;
635
    }
635
    }
636
637
    @Override
638
    public void setDefaultValue(PreparedStatement stmt, int index) throws SQLException
639
    {
640
      setValue(stmt, index, getFeature().getDefaultValueLiteral());
641
    }
636
  }
642
  }
637
}
643
}
(-)src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java (+2 lines)
Lines 69-74 Link Here
69
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303466_Test;
69
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303466_Test;
70
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
70
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
71
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306710_Test;
71
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306710_Test;
72
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_308895_Test;
72
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
73
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
73
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
74
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
74
75
Lines 198-203 Link Here
198
    testClasses.add(Bugzilla_303466_Test.class);
199
    testClasses.add(Bugzilla_303466_Test.class);
199
    testClasses.add(Bugzilla_303807_Test.class);
200
    testClasses.add(Bugzilla_303807_Test.class);
200
    testClasses.add(Bugzilla_306710_Test.class);
201
    testClasses.add(Bugzilla_306710_Test.class);
202
    testClasses.add(Bugzilla_308895_Test.class);
201
203
202
    // TODO testClasses.add(NonCDOResourceTest.class);
204
    // TODO testClasses.add(NonCDOResourceTest.class);
203
    // TODO testClasses.add(GeneratedEcoreTest.class);
205
    // TODO testClasses.add(GeneratedEcoreTest.class);
(-)src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_308895_Test.java (+240 lines)
Added Link Here
1
package org.eclipse.emf.cdo.tests.bugzilla;
2
3
import org.eclipse.emf.cdo.common.model.EMFUtil;
4
import org.eclipse.emf.cdo.eresource.CDOResource;
5
import org.eclipse.emf.cdo.session.CDOSession;
6
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
7
import org.eclipse.emf.cdo.transaction.CDOTransaction;
8
import org.eclipse.emf.cdo.util.CDOUtil;
9
import org.eclipse.emf.cdo.view.CDOView;
10
11
import org.eclipse.emf.ecore.EAttribute;
12
import org.eclipse.emf.ecore.EClass;
13
import org.eclipse.emf.ecore.EDataType;
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.EPackage;
16
import org.eclipse.emf.ecore.EcoreFactory;
17
import org.eclipse.emf.ecore.util.EcoreUtil;
18
19
/**
20
 * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
21
 * All rights reserved. This program and the accompanying materials
22
 * are made available under the terms of the Eclipse Public License v1.0
23
 * which accompanies this distribution, and is available at
24
 * http://www.eclipse.org/legal/epl-v10.html
25
 * 
26
 * Contributors:
27
 *    Stefan Winkler - initial API and implementation
28
 */
29
30
/**
31
 * @author Stefan Winkler
32
 */
33
public class Bugzilla_308895_Test extends AbstractCDOTest
34
{
35
  private EPackage pkg;
36
37
  private EClass cls;
38
39
  private EAttribute att;
40
41
  @Override
42
  public void setUp() throws Exception
43
  {
44
    super.setUp();
45
46
    pkg = EMFUtil.createEPackage("customTest", "ct", "http://cdo.emf.eclipse.org/customTest.ecore");
47
    EDataType custom = EcoreFactory.eINSTANCE.createEDataType();
48
    custom.setInstanceClass(CustomType.class);
49
    custom.setName("CustomType");
50
51
    pkg.getEClassifiers().add(custom);
52
53
    cls = EMFUtil.createEClass(pkg, "Foobar", false, false);
54
    att = EMFUtil.createEAttribute(cls, "att", custom);
55
56
    CDOUtil.prepareDynamicEPackage(pkg);
57
  }
58
59
  public void testCustomRegular()
60
  {
61
    EObject obj = EcoreUtil.create(cls);
62
    obj.eSet(att, new CustomType(23, 42));
63
64
    {
65
      CDOSession session = openSession();
66
      session.getPackageRegistry().putEPackage(pkg);
67
      CDOTransaction tx = session.openTransaction();
68
      CDOResource res = tx.createResource("/test");
69
      res.getContents().add(obj);
70
      tx.commit();
71
      tx.close();
72
      session.close();
73
    }
74
75
    clearCache(getRepository().getRevisionManager());
76
77
    {
78
      CDOSession session = openSession();
79
      session.getPackageRegistry().putEPackage(pkg);
80
      CDOView v = session.openView();
81
      CDOResource res = v.getResource("/test");
82
      EObject persistent = res.getContents().get(0);
83
84
      CustomType pCustom = (CustomType)persistent.eGet(att);
85
      assertEquals(23, pCustom.getA());
86
      assertEquals(42, pCustom.getB());
87
88
      v.close();
89
      session.close();
90
    }
91
  }
92
93
  public void testCustomDefaultLiteral()
94
  {
95
    // valid default literal
96
    att.setDefaultValueLiteral("1;2");
97
98
    EObject obj = EcoreUtil.create(cls);
99
    obj.eUnset(att);
100
101
    {
102
      CDOSession session = openSession();
103
      session.getPackageRegistry().putEPackage(pkg);
104
      CDOTransaction tx = session.openTransaction();
105
      CDOResource res = tx.createResource("/test");
106
      res.getContents().add(obj);
107
      tx.commit();
108
      tx.close();
109
      session.close();
110
    }
111
112
    clearCache(getRepository().getRevisionManager());
113
114
    {
115
      CDOSession session = openSession();
116
      session.getPackageRegistry().putEPackage(pkg);
117
      CDOView v = session.openView();
118
      CDOResource res = v.getResource("/test");
119
      EObject persistent = res.getContents().get(0);
120
121
      CustomType pCustom = (CustomType)persistent.eGet(att);
122
      assertEquals(1, pCustom.getA());
123
      assertEquals(2, pCustom.getB());
124
125
      v.close();
126
      session.close();
127
    }
128
  }
129
130
  public void testCustomDefaultDefault()
131
  {
132
    // no default literal is set
133
    EObject obj = EcoreUtil.create(cls);
134
135
    {
136
      CDOSession session = openSession();
137
      session.getPackageRegistry().putEPackage(pkg);
138
      CDOTransaction tx = session.openTransaction();
139
      CDOResource res = tx.createResource("/test");
140
      res.getContents().add(obj);
141
      tx.commit();
142
      tx.close();
143
      session.close();
144
    }
145
146
    clearCache(getRepository().getRevisionManager());
147
148
    {
149
      CDOSession session = openSession();
150
      session.getPackageRegistry().putEPackage(pkg);
151
      CDOView v = session.openView();
152
      CDOResource res = v.getResource("/test");
153
      EObject persistent = res.getContents().get(0);
154
155
      CustomType pCustom = (CustomType)persistent.eGet(att);
156
      assertNull(pCustom);
157
158
      v.close();
159
      session.close();
160
    }
161
  }
162
163
  public void testCustomDefaultInvalidLiteral()
164
  {
165
    // invalid default literal
166
    att.setDefaultValueLiteral("1;2;3");
167
168
    EObject obj = EcoreUtil.create(cls);
169
170
    {
171
      CDOSession session = openSession();
172
      session.getPackageRegistry().putEPackage(pkg);
173
      CDOTransaction tx = session.openTransaction();
174
      CDOResource res = tx.createResource("/test");
175
      res.getContents().add(obj);
176
      tx.commit();
177
      tx.close();
178
      session.close();
179
    }
180
181
    clearCache(getRepository().getRevisionManager());
182
183
    {
184
      CDOSession session = openSession();
185
      session.getPackageRegistry().putEPackage(pkg);
186
      CDOView v = session.openView();
187
      CDOResource res = v.getResource("/test");
188
      EObject persistent = res.getContents().get(0);
189
190
      CustomType pCustom = (CustomType)persistent.eGet(att);
191
      assertNull(pCustom);
192
193
      v.close();
194
      session.close();
195
    }
196
  }
197
198
  public static class CustomType
199
  {
200
    private int a = 0;
201
202
    private int b = 0;
203
204
    public CustomType(int _a, int _b)
205
    {
206
      a = _a;
207
      b = _b;
208
    }
209
210
    public CustomType(String literal)
211
    {
212
      String[] values = literal.split(";");
213
      if (values.length != 2)
214
      {
215
        throw new RuntimeException("Error: only 2 values allowed");
216
      }
217
      else
218
      {
219
        a = Integer.valueOf(values[0]);
220
        b = Integer.valueOf(values[1]);
221
      }
222
    }
223
224
    @Override
225
    public String toString()
226
    {
227
      return a + ";" + b;
228
    }
229
230
    public int getA()
231
    {
232
      return a;
233
    }
234
235
    public int getB()
236
    {
237
      return b;
238
    }
239
  }
240
}

Return to bug 308895