summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-01-08 07:34:42 (EST)
committerStefan Winkler2009-01-08 07:34:42 (EST)
commit01eaaed429318e591fbe8496b7104d48401a39a3 (patch)
tree262e9322556335f2ee6a038d2ed93e403f5f9670
parent3586a8dca601f3941c475ff5bedc60c1ef45e89d (diff)
downloadcdo-01eaaed429318e591fbe8496b7104d48401a39a3.zip
cdo-01eaaed429318e591fbe8496b7104d48401a39a3.tar.gz
cdo-01eaaed429318e591fbe8496b7104d48401a39a3.tar.bz2
[217255] [DB] DBStore does not store Date type correctly
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217255
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DBStoreTest.java31
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java41
4 files changed, 70 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
index 04a3d9b..3084156 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
@@ -4,7 +4,7 @@
* 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:
* Eike Stepper - initial API and implementation
**************************************************************************/
@@ -212,8 +212,7 @@ public abstract class AttributeMapping extends FeatureMapping implements IAttrib
@Override
protected Object getResultSetValue(ResultSet resultSet, int column) throws SQLException
{
- // TODO Is getDate() correct?
- return resultSet.getDate(column);
+ return resultSet.getTimestamp(column);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index e6c9733..621c8f4 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -399,7 +399,7 @@ public class DBStore extends LongIDStore implements IDBStore
}
else if (type == CDOType.DATE)
{
- return DBType.DATE;
+ return DBType.TIMESTAMP;
}
else if (type == CDOType.DOUBLE || type == CDOType.DOUBLE_OBJECT)
{
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
index f25e7db..caec87b 100644
--- 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
@@ -4,7 +4,7 @@
* 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
**************************************************************************/
@@ -16,6 +16,9 @@ import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResource;
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 java.util.GregorianCalendar;
/**
* @author Stefan Winkler
@@ -102,4 +105,30 @@ public class DBStoreTest extends AbstractCDOTest
e = (Company)resource.getContents().get(0);
assertEquals(s, e.getName());
}
+
+ // Bug 217255
+ public void testStoreDate()
+ {
+ CDOSession session = openModel1Session();
+ 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 = openModel1Session();
+ 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());
+ }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
index 0c45c7a..f9ca440 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
@@ -4,12 +4,14 @@
* 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:
* Eike Stepper - initial API and implementation
**************************************************************************/
package org.eclipse.net4j.db;
+import java.util.Date;
+
/**
* @author Eike Stepper
*/
@@ -29,9 +31,40 @@ public enum DBType
CHAR(1), //
VARCHAR(12), //
LONGVARCHAR(-1, "LONG VARCHAR"), //
- DATE(91), //
- TIME(92), //
- TIMESTAMP(93), //
+ DATE(91)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ TIME(92)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ TIMESTAMP(93)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ if (value instanceof Date)
+ {
+ Date date = (Date)value;
+ builder.append("'");
+ builder.append(new java.sql.Timestamp(date.getTime()));
+ builder.append("'");
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a java.util.Date: " + value);
+ }
+ }
+ }, //
BINARY(-2)
{
@Override