summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-05-09 08:03:45 (EDT)
committerStefan Winkler2010-05-09 08:03:45 (EDT)
commit6605672b3999349618580344b52a38a21d5a099b (patch)
tree978b66e71a1a558fe23e86dff27ed92c5863d882
parent5c71c914579283e4a52e5cd4f6dedff2c1b02e7c (diff)
downloadcdo-6605672b3999349618580344b52a38a21d5a099b.zip
cdo-6605672b3999349618580344b52a38a21d5a099b.tar.gz
cdo-6605672b3999349618580344b52a38a21d5a099b.tar.bz2
[308895] [DB] Saving a default value of a custom type throws NotSerializableException
https://bugs.eclipse.org/bugs/show_bug.cgi?id=308895
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_308895_Test.java240
3 files changed, 248 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
index c7629cf..697aa8c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
@@ -682,5 +682,11 @@ public abstract class TypeMapping implements ITypeMapping
return val;
}
+
+ @Override
+ public void setDefaultValue(PreparedStatement stmt, int index) throws SQLException
+ {
+ setValue(stmt, index, getFeature().getDefaultValueLiteral());
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
index 9269a6a..b440940 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
@@ -69,6 +69,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_302233_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303466_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306710_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_308895_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -198,6 +199,7 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_303466_Test.class);
testClasses.add(Bugzilla_303807_Test.class);
testClasses.add(Bugzilla_306710_Test.class);
+ testClasses.add(Bugzilla_308895_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_308895_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_308895_Test.java
new file mode 100644
index 0000000..2a26483
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_308895_Test.java
@@ -0,0 +1,240 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+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.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * Copyright (c) 2004 - 2010 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:
+ * Stefan Winkler - initial API and implementation
+ */
+
+/**
+ * @author Stefan Winkler
+ */
+public class Bugzilla_308895_Test extends AbstractCDOTest
+{
+ private EPackage pkg;
+
+ private EClass cls;
+
+ private EAttribute att;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ pkg = EMFUtil.createEPackage("customTest", "ct", "http://cdo.emf.eclipse.org/customTest.ecore");
+ EDataType custom = EcoreFactory.eINSTANCE.createEDataType();
+ custom.setInstanceClass(CustomType.class);
+ custom.setName("CustomType");
+
+ pkg.getEClassifiers().add(custom);
+
+ cls = EMFUtil.createEClass(pkg, "Foobar", false, false);
+ att = EMFUtil.createEAttribute(cls, "att", custom);
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+ }
+
+ public void testCustomRegular()
+ {
+ EObject obj = EcoreUtil.create(cls);
+ obj.eSet(att, new CustomType(23, 42));
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView v = session.openView();
+ CDOResource res = v.getResource("/test");
+ EObject persistent = res.getContents().get(0);
+
+ CustomType pCustom = (CustomType)persistent.eGet(att);
+ assertEquals(23, pCustom.getA());
+ assertEquals(42, pCustom.getB());
+
+ v.close();
+ session.close();
+ }
+ }
+
+ public void testCustomDefaultLiteral()
+ {
+ // valid default literal
+ att.setDefaultValueLiteral("1;2");
+
+ EObject obj = EcoreUtil.create(cls);
+ obj.eUnset(att);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView v = session.openView();
+ CDOResource res = v.getResource("/test");
+ EObject persistent = res.getContents().get(0);
+
+ CustomType pCustom = (CustomType)persistent.eGet(att);
+ assertEquals(1, pCustom.getA());
+ assertEquals(2, pCustom.getB());
+
+ v.close();
+ session.close();
+ }
+ }
+
+ public void testCustomDefaultDefault()
+ {
+ // no default literal is set
+ EObject obj = EcoreUtil.create(cls);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView v = session.openView();
+ CDOResource res = v.getResource("/test");
+ EObject persistent = res.getContents().get(0);
+
+ CustomType pCustom = (CustomType)persistent.eGet(att);
+ assertNull(pCustom);
+
+ v.close();
+ session.close();
+ }
+ }
+
+ public void testCustomDefaultInvalidLiteral()
+ {
+ // invalid default literal
+ att.setDefaultValueLiteral("1;2;3");
+
+ EObject obj = EcoreUtil.create(cls);
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction tx = session.openTransaction();
+ CDOResource res = tx.createResource("/test");
+ res.getContents().add(obj);
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView v = session.openView();
+ CDOResource res = v.getResource("/test");
+ EObject persistent = res.getContents().get(0);
+
+ CustomType pCustom = (CustomType)persistent.eGet(att);
+ assertNull(pCustom);
+
+ v.close();
+ session.close();
+ }
+ }
+
+ public static class CustomType
+ {
+ private int a = 0;
+
+ private int b = 0;
+
+ public CustomType(int _a, int _b)
+ {
+ a = _a;
+ b = _b;
+ }
+
+ public CustomType(String literal)
+ {
+ String[] values = literal.split(";");
+ if (values.length != 2)
+ {
+ throw new RuntimeException("Error: only 2 values allowed");
+ }
+ else
+ {
+ a = Integer.valueOf(values[0]);
+ b = Integer.valueOf(values[1]);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return a + ";" + b;
+ }
+
+ public int getA()
+ {
+ return a;
+ }
+
+ public int getB()
+ {
+ return b;
+ }
+ }
+}