summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-12 05:53:43 (EDT)
committerEike Stepper2008-04-12 05:53:43 (EDT)
commit23554de707062666397f50517d6e2e36acc5899e (patch)
tree770432677f7e29fcddf4f0e1ede87f8bd4f57bef
parent7f0567e2f8484a9bd4b0ebd8eb6f1c95673a6acf (diff)
downloadcdo-23554de707062666397f50517d6e2e36acc5899e.zip
cdo-23554de707062666397f50517d6e2e36acc5899e.tar.gz
cdo-23554de707062666397f50517d6e2e36acc5899e.tar.bz2
[226739] Default value not handle correctly
https://bugs.eclipse.org/bugs/show_bug.cgi?id=226739
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java55
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java31
2 files changed, 76 insertions, 10 deletions
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
new file mode 100644
index 0000000..d8f1ad0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AttributeTest.java
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+
+/**
+ * @author Eike Stepper
+ */
+public class AttributeTest extends AbstractCDOTest
+{
+ public void testPrimitiveDefaults() throws Exception
+ {
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Preferred Supplier");
+ assertEquals(true, supplier.isPreferred());
+
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/my/resource");
+ resource.getContents().add(supplier);
+ assertEquals(true, supplier.isPreferred());
+
+ transaction.commit();
+ assertEquals(true, supplier.isPreferred());
+
+ session.close();
+ }
+
+ {
+ CDOSession session = openModel1Session();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource("/my/resource");
+ Supplier supplier = (Supplier)resource.getContents().get(0);
+ assertEquals(true, supplier.isPreferred());
+
+ view.close();
+ session.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index d7f528b..3d31535 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
+import org.eclipse.emf.internal.cdo.util.GenUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
@@ -207,7 +208,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
for (int i = 0; i < eClass.getFeatureCount(); i++)
{
Object setting = eSettings[i];
- if (setting != null)
+ // if (setting != null)
{
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
@@ -233,16 +234,19 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
boolean isReference = cdoFeature.isReference();
if (cdoFeature.isMany())
{
- int index = 0;
- EList<Object> list = (EList<Object>)setting;
- for (Object value : list)
+ if (setting != null)
{
- if (isReference)
+ int index = 0;
+ EList<Object> list = (EList<Object>)setting;
+ for (Object value : list)
{
- value = view.convertObjectToID(value);
- }
+ if (isReference)
+ {
+ value = view.convertObjectToID(value);
+ }
- revision.add(cdoFeature, index++, value);
+ revision.add(cdoFeature, index++, value);
+ }
}
}
else
@@ -251,9 +255,16 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
setting = view.convertObjectToID(setting);
}
- else if (cdoFeature.getType() == CDOType.CUSTOM)
+ else
{
- setting = EcoreUtil.convertToString((EDataType)eFeature.getEType(), setting);
+ if (cdoFeature.getType() == CDOType.CUSTOM)
+ {
+ setting = EcoreUtil.convertToString((EDataType)eFeature.getEType(), setting);
+ }
+ else if (setting == null && GenUtil.isPrimitiveType(eFeature.getEType()))
+ {
+ setting = eFeature.getDefaultValue();
+ }
}
revision.set(cdoFeature, 0, setting);