summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-02-25 03:20:40 (EST)
committerStefan Winkler2010-02-25 03:20:40 (EST)
commit29f021f94cb806774b0f6c3e35910b855604d3bc (patch)
tree5b1cdfb1d73aa9692ea8e26ce284933eb40fa890
parenteb712c49a908f82c8dcae83549e36daeb131bd00 (diff)
downloadcdo-29f021f94cb806774b0f6c3e35910b855604d3bc.zip
cdo-29f021f94cb806774b0f6c3e35910b855604d3bc.tar.gz
cdo-29f021f94cb806774b0f6c3e35910b855604d3bc.tar.bz2
[301300] Wrong implementation of eIsSet()
https://bugs.eclipse.org/bugs/show_bug.cgi?id=301300
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java69
1 files changed, 64 insertions, 5 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 4ed3c27..0e3eb71 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
@@ -32,6 +32,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBType;
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;
@@ -49,11 +50,13 @@ 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
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TypeMapping.class);
+
private IMappingStrategy mappingStrategy;
private EStructuralFeature feature;
@@ -64,7 +67,7 @@ public abstract class TypeMapping implements ITypeMapping
/**
* Create a new type mapping
- *
+ *
* @param mappingStrategy
* the associated mapping strategy.
* @param feature
@@ -100,10 +103,36 @@ public abstract class TypeMapping implements ITypeMapping
public final void setValue(PreparedStatement stmt, int index, Object value) throws SQLException
{
- if (value == null || value == CDORevisionData.NIL)
+ if (value == CDORevisionData.NIL)
{
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("TypeMapping for {0}: converting Revision.NIL to DB-null", feature.getName()); //$NON-NLS-1$
+ }
+
stmt.setNull(index, getSqlType());
}
+ else if (value == null)
+ {
+ if (feature.isMany() || feature.getDefaultValue() == null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("TypeMapping for {0}: writing Revision.null as DB.null", feature.getName()); //$NON-NLS-1$
+ }
+
+ stmt.setNull(index, getSqlType());
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("TypeMapping for {0}: converting Revision.null to default value", feature.getName()); //$NON-NLS-1$
+ }
+
+ setDefaultValue(stmt, index);
+ }
+ }
else
{
doSetValue(stmt, index, value);
@@ -143,7 +172,37 @@ public abstract class TypeMapping implements ITypeMapping
Object value = getResultSetValue(resultSet);
if (resultSet.wasNull())
{
- value = feature.isUnsettable() ? CDORevisionData.NIL : null;
+ if (feature.isMany())
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("TypeMapping for {0}: read db.null - setting Revision.null", feature.getName()); //$NON-NLS-1$
+ }
+
+ value = null;
+ }
+ else
+ {
+ if (feature.getDefaultValue() == null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format(
+ "TypeMapping for {0}: read db.null - setting Revision.null, because of default", feature.getName()); //$NON-NLS-1$
+ }
+
+ value = null;
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("TypeMapping for {0}: read db.null - setting Revision.NIL", feature.getName()); //$NON-NLS-1$
+ }
+
+ value = CDORevisionData.NIL;
+ }
+ }
}
return value;
@@ -162,7 +221,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()