summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-03-02 05:03:40 (EST)
committerStefan Winkler2010-03-02 05:03:40 (EST)
commit5d27b96d5122fb2b9d339251773ff95437df19e6 (patch)
treec2320bdb1d5b5107a8fa3147538fe6fa4954cf54
parentc2c7460cb2b25c91525620e8a11e2ae5f4e275e2 (diff)
downloadcdo-5d27b96d5122fb2b9d339251773ff95437df19e6.zip
cdo-5d27b96d5122fb2b9d339251773ff95437df19e6.tar.gz
cdo-5d27b96d5122fb2b9d339251773ff95437df19e6.tar.bz2
[296020] [DB] Custom type mapping produces ClassCastException
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296020
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AutomatedTests.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java132
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DBStoreTest.java135
5 files changed, 138 insertions, 157 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 0e3eb71..5d4b302 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
@@ -34,9 +34,7 @@ import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EStructuralFeature;
import java.math.BigDecimal;
@@ -50,7 +48,7 @@ import java.util.Date;
/**
* This is a default implementation for the {@link ITypeMapping} interface which provides default behavor for all common
* types.
- *
+ *
* @author Eike Stepper
*/
public abstract class TypeMapping implements ITypeMapping
@@ -67,7 +65,7 @@ public abstract class TypeMapping implements ITypeMapping
/**
* Create a new type mapping
- *
+ *
* @param mappingStrategy
* the associated mapping strategy.
* @param feature
@@ -221,7 +219,7 @@ public abstract class TypeMapping implements ITypeMapping
/**
* Returns the SQL type of this TypeMapping. The default implementation considers the type map hold by the meta-data
* manager (@see {@link MetaDataManager#getDBType(org.eclipse.emf.ecore.EClassifier)} Subclasses may override.
- *
+ *
* @return The sql type of this TypeMapping.
*/
protected int getSqlType()
@@ -603,22 +601,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMCustom extends TypeMapping
{
- private EDataType dataType;
-
- private EFactory factory;
-
public TMCustom(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
{
super(mappingStrategy, feature, type);
- dataType = (EDataType)getFeature().getEType();
- factory = dataType.getEPackage().getEFactoryInstance();
- }
-
- @Override
- protected void doSetValue(PreparedStatement stmt, int index, Object value) throws SQLException
- {
- String svalue = factory.convertToString(dataType, value);
- stmt.setString(index, svalue);
}
@Override
@@ -630,7 +615,7 @@ public abstract class TypeMapping implements ITypeMapping
return getFeature().isUnsettable() ? CDORevisionData.NIL : null;
}
- return factory.createFromString(dataType, val);
+ return val;
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AutomatedTests.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AutomatedTests.java
index 1aca4df..d7ee111 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AutomatedTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AutomatedTests.java
@@ -24,6 +24,8 @@ public class AutomatedTests
suite.addTest(AllTestsDBHsqldb.suite());
suite.addTest(AllTestsDBHsqldbNonAudit.suite());
suite.addTest(AllTestsDBH2.suite());
+ suite.addTest(AllTestsDBH2Branching.suite());
+ suite.addTest(AllTestsDBH2Offline.suite());
suite.addTest(AllTestsDBH2NonAudit.suite());
return suite;
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
index 2f778c3..1c9cc6d 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
@@ -11,6 +11,7 @@
*/
package org.eclipse.emf.cdo.tests.db;
+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;
@@ -18,8 +19,17 @@ import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
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.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;
+
import java.util.GregorianCalendar;
/**
@@ -107,6 +117,128 @@ public class DBStoreTest extends AbstractCDOTest
assertEquals(new GregorianCalendar(2008, 11, 24, 12, 34, 56).getTime(), o.getDate());
}
+ public void testStoreCustom()
+ {
+ EPackage pkg = EMFUtil.createEPackage("customTest", "ct", "http://tests.cdo.emf.eclipse.org/customTest");
+
+ EDataType dt = EcoreFactory.eINSTANCE.createEDataType();
+ dt.setName("custom");
+ dt.setInstanceClass(Custom.class);
+ pkg.getEClassifiers().add(dt);
+
+ EClass clz = EMFUtil.createEClass(pkg, "customClass", false, false);
+ EAttribute att = EMFUtil.createEAttribute(clz, "customAtt", dt);
+
+ Custom cust1 = new Custom(2, 5);
+ Custom cust1ref = new Custom(2, 5);
+ Custom cust2 = new Custom(5, 2);
+ Custom cust2ref = new Custom(5, 2);
+
+ assertEquals(cust1ref, cust1);
+ assertEquals(cust2ref, cust2);
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+
+ {
+ EObject obj1 = EcoreUtil.create(clz);
+ EObject obj2 = EcoreUtil.create(clz);
+
+ obj1.eSet(att, cust1);
+ obj2.eSet(att, cust2);
+
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/test");
+ resource.getContents().add(obj1);
+ resource.getContents().add(obj2);
+ transaction.commit();
+ transaction.close();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(pkg);
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource("/test");
+
+ assertEquals(2, resource.getContents().size());
+
+ EObject obj1 = resource.getContents().get(0);
+ EObject obj2 = resource.getContents().get(1);
+
+ assertEquals(cust1ref, obj1.eGet(att));
+ assertEquals(cust2ref, obj2.eGet(att));
+
+ view.close();
+ session.close();
+ }
+
+ }
+
+ public static class Custom
+ {
+ private int first;
+
+ private int second;
+
+ public Custom(String emfString)
+ {
+ int sep = emfString.indexOf('!');
+ first = Integer.parseInt(emfString.substring(0, sep));
+ second = Integer.parseInt(emfString.substring(sep + 1));
+ }
+
+ public Custom(int first, int second)
+ {
+ this.first = first;
+ this.second = second;
+ }
+
+ public int getFirst()
+ {
+ return first;
+ }
+
+ public int getSecond()
+ {
+ return second;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof Custom)
+ {
+ return first == ((Custom)other).first && second == ((Custom)other).second;
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (first + 3 * second) % 65536;
+ }
+
+ // -------------------------------------------
+ // - EMF String serialization
+ @Override
+ public String toString()
+ {
+ return Integer.valueOf(first) + "!" + Integer.valueOf(second);
+ }
+
+ public static Custom valueOf(String s)
+ {
+ return new Custom(s);
+ }
+ }
+
private void storeRetrieve(String s)
{
CDOSession session = openSession();
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 6714dc8..c1e1e69 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
@@ -132,9 +132,6 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
// Specific for MEMStore
testClasses.add(MEMStoreQueryTest.class);
- // Specific for DBStore
- testClasses.add(DBStoreTest.class);
-
// Bugzilla verifications
testClasses.add(Bugzilla_241464_Test.class);
testClasses.add(Bugzilla_243310_Test.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DBStoreTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DBStoreTest.java
deleted file mode 100644
index 0b5deda..0000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DBStoreTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.tests;
-
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.tests.model1.Company;
-import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import java.util.GregorianCalendar;
-
-/**
- * @author Stefan Winkler
- */
-public class DBStoreTest extends AbstractCDOTest
-{
- // Bug 256462
- public void testInsertNull() throws Exception
- {
- CDOSession s = openSession();
- CDOTransaction t = s.openTransaction();
- CDOResource r = t.createResource("/dbStoreTest");
-
- Company c = Model1Factory.eINSTANCE.createCompany();
- c.setName(null);
- r.getContents().add(c);
-
- t.commit();
- }
-
- public void testStoreStringTrailingBackslash()
- {
- storeRetrieve("foobar\\");
- }
-
- public void testStoreStringContainingBackslash()
- {
- storeRetrieve("foo\\bar");
- }
-
- public void testStoreStringTrailingSingleQuote()
- {
- storeRetrieve("foobar'");
- }
-
- public void testStoreStringContainingSingleQuote()
- {
- storeRetrieve("foo'bar");
- }
-
- public void testStoreStringTrailingDoubleQuote()
- {
- storeRetrieve("foobar\"");
- }
-
- public void testStoreStringContainingDoubleQuote()
- {
- storeRetrieve("foo\"bar");
- }
-
- public void testStoreStringTrailingTwoSingleQuote()
- {
- storeRetrieve("foobar''");
- }
-
- public void testStoreStringContainingTwoSingleQuote()
- {
- storeRetrieve("foo''bar");
- }
-
- private void storeRetrieve(String s)
- {
- CDOSession session = openSession();
- CDOTransaction transaction = session.openTransaction();
- CDOResource resource = transaction.getOrCreateResource("/test");
-
- Company e = Model1Factory.eINSTANCE.createCompany();
- e.setName(s);
- // this escapes only the string!
- // resulting string only contains one backslash
-
- resource.getContents().add(e);
- transaction.commit();
-
- transaction.close();
- session.close();
- clearCache(getRepository().getRevisionManager());
-
- session = openSession();
- CDOView view = session.openView();
- resource = view.getResource("/test");
-
- assertEquals(1, resource.getContents().size());
- e = (Company)resource.getContents().get(0);
- assertEquals(s, e.getName());
- }
-
- // Bug 217255
- public void testStoreDate()
- {
- CDOSession session = openSession();
- CDOTransaction transaction = session.openTransaction();
- CDOResource resource = transaction.getOrCreateResource("/test");
-
- PurchaseOrder o = Model1Factory.eINSTANCE.createPurchaseOrder();
- o.setDate(new GregorianCalendar(2008, 11, 24, 12, 34, 56).getTime());
-
- resource.getContents().add(o);
- transaction.commit();
-
- transaction.close();
- session.close();
- clearCache(getRepository().getRevisionManager());
-
- session = openSession();
- CDOView view = session.openView();
- resource = view.getResource("/test");
-
- assertEquals(1, resource.getContents().size());
- o = (PurchaseOrder)resource.getContents().get(0);
- assertEquals(new GregorianCalendar(2008, 11, 24, 12, 34, 56).getTime(), o.getDate());
- }
-}