summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-06-10 09:29:32 (EDT)
committerStefan Winkler2009-06-10 09:29:32 (EDT)
commit7d9522cad1a9f92d05a9114339433c3009b9fa85 (patch)
treeb420194b267001a925786099a5437499963539a5
parent07234dc1fada8a6dd9a9f49e9ebf7e6e1fb5ea71 (diff)
downloadcdo-7d9522cad1a9f92d05a9114339433c3009b9fa85.zip
cdo-7d9522cad1a9f92d05a9114339433c3009b9fa85.tar.gz
cdo-7d9522cad1a9f92d05a9114339433c3009b9fa85.tar.bz2
[275303] [DB] DBStore does not handle BIG_INTEGER and BIG_DECIMAL
https://bugs.eclipse.org/bugs/show_bug.cgi?id=275303 (NULL value handling had been missed)
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java113
2 files changed, 129 insertions, 2 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 a7d6e46..619fd0e 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
@@ -424,7 +424,14 @@ public abstract class TypeMapping implements ITypeMapping
@Override
protected Object getResultSetValue(ResultSet resultSet, int column) throws SQLException
{
- return new BigInteger(resultSet.getString(column));
+ String val = resultSet.getString(column);
+
+ if (resultSet.wasNull())
+ {
+ return null;
+ }
+
+ return new BigInteger(val);
}
@Override
@@ -447,7 +454,14 @@ public abstract class TypeMapping implements ITypeMapping
@Override
protected Object getResultSetValue(ResultSet resultSet, int column) throws SQLException
{
- return new BigDecimal(resultSet.getString(column));
+ String val = resultSet.getString(column);
+
+ if (resultSet.wasNull())
+ {
+ return null;
+ }
+
+ return new BigDecimal(val);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java
index 0697650..9c4f354 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java
@@ -133,6 +133,76 @@ public class AttributeTest extends AbstractCDOTest
}
}
+ public void testByteArrayEmpty() throws Exception
+ {
+ byte saveByteArray[] = new byte[0];
+
+ {
+ EPackage packageBytes = createDynamicEPackageWithByte();
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(packageBytes);
+ CDOTransaction transaction = session.openTransaction();
+
+ EClass eClass = (EClass)packageBytes.getEClassifier("GenOfByteArray");
+ EObject genOfByteArray = packageBytes.getEFactoryInstance().create(eClass);
+ genOfByteArray.eSet(genOfByteArray.eClass().getEStructuralFeature("bytes"), saveByteArray);
+
+ CDOResource resource = transaction.createResource("/my/resource");
+ resource.getContents().add(genOfByteArray);
+
+ transaction.commit();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openModel1Session();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource("/my/resource");
+ EObject genOfByteArray = resource.getContents().get(0);
+ byte storeByteArray[] = (byte[])genOfByteArray.eGet(genOfByteArray.eClass().getEStructuralFeature("bytes"));
+ assertEquals(0, storeByteArray.length);
+ view.close();
+ session.close();
+ }
+ }
+
+ public void testByteArrayNull() throws Exception
+ {
+ byte saveByteArray[] = null;
+
+ {
+ EPackage packageBytes = createDynamicEPackageWithByte();
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(packageBytes);
+ CDOTransaction transaction = session.openTransaction();
+
+ EClass eClass = (EClass)packageBytes.getEClassifier("GenOfByteArray");
+ EObject genOfByteArray = packageBytes.getEFactoryInstance().create(eClass);
+ genOfByteArray.eSet(genOfByteArray.eClass().getEStructuralFeature("bytes"), saveByteArray);
+
+ CDOResource resource = transaction.createResource("/my/resource");
+ resource.getContents().add(genOfByteArray);
+
+ transaction.commit();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openModel1Session();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource("/my/resource");
+ EObject genOfByteArray = resource.getContents().get(0);
+ byte storeByteArray[] = (byte[])genOfByteArray.eGet(genOfByteArray.eClass().getEStructuralFeature("bytes"));
+ assertNull(storeByteArray);
+ view.close();
+ session.close();
+ }
+ }
+
public void testBigDecimalAndBigInteger() throws Exception
{
BigDecimal bigDecimal = new BigDecimal(10);
@@ -180,6 +250,49 @@ public class AttributeTest extends AbstractCDOTest
}
}
+ public void testBigDecimalAndBigIntegerNull() throws Exception
+ {
+ BigDecimal bigDecimal = null;
+ BigInteger bigInteger = null;
+
+ {
+ EPackage ePackage = createDynamicEPackageBigIntegerAndBigDecimal();
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(ePackage);
+ CDOTransaction transaction = session.openTransaction();
+
+ EClass eClass = (EClass)ePackage.getEClassifier("Gen");
+ EStructuralFeature bigDecimalFeature = eClass.getEStructuralFeature("bigDecimal");
+ EStructuralFeature bigIntegerFeature = eClass.getEStructuralFeature("bigInteger");
+
+ EObject gen = ePackage.getEFactoryInstance().create(eClass);
+ gen.eSet(bigDecimalFeature, bigDecimal);
+ gen.eSet(bigIntegerFeature, bigInteger);
+
+ CDOResource resource = transaction.createResource("/my/resource");
+ resource.getContents().add(gen);
+
+ transaction.commit();
+ session.close();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession session = openSession();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource("/my/resource");
+ EObject gen = resource.getContents().get(0);
+ BigDecimal bigDecimalStore = (BigDecimal)gen.eGet(gen.eClass().getEStructuralFeature("bigDecimal"));
+ BigInteger bigIntegerStore = (BigInteger)gen.eGet(gen.eClass().getEStructuralFeature("bigInteger"));
+ assertNull(bigDecimalStore);
+ assertNull(bigIntegerStore);
+
+ view.close();
+ session.close();
+ }
+ }
+
private EPackage createDynamicEPackageWithByte()
{
final EcoreFactory efactory = EcoreFactory.eINSTANCE;