Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2010-05-31 16:41:33 +0000
committerMartin Taal2010-05-31 16:41:33 +0000
commite19dfda4bec40a841ed788893205c82d1cc7969b (patch)
tree79580fc61de30ebf36023f55467e9d434cf4eecb /plugins/org.eclipse.emf.cdo.server.hibernate
parent29e265de1e1b8a9f638482de47cce2c01a5d71c7 (diff)
downloadcdo-e19dfda4bec40a841ed788893205c82d1cc7969b.tar.gz
cdo-e19dfda4bec40a841ed788893205c82d1cc7969b.tar.xz
cdo-e19dfda4bec40a841ed788893205c82d1cc7969b.zip
fixes issue [303280] [Hibernate] set/get defaultvalue in case value is null and there is a defaultvalue
fixes issue [315067] [Hibernate] Store version in a non-version property, disable/remove Hibernate optimistic locking fixes issue [313539] [Hibernate] NonUniqueObjectException when saving a model with cyclical references
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumIntegerType.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumStringType.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java26
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java11
14 files changed, 185 insertions, 114 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
index c58f470318..d95369318c 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
@@ -24,9 +24,9 @@
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
+ <property name="e_version" column="e_version" type="java.lang.Integer" access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler">
+ <meta attribute="version">true</meta>
+ </property>
<property name="resourceID" type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
<column name="resource_id"/>
</property>
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java
index b865613862..3aaaff5ddc 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java
@@ -57,78 +57,71 @@ public class HibernateQueryHandler implements IQueryHandler
// so all db access uses the same session.
final Session session = hibernateStoreAccessor.getHibernateSession();
- try
- {
- // create the query
- final Query query = session.createQuery(info.getQueryString());
+ // create the query
+ final Query query = session.createQuery(info.getQueryString());
- // get the parameters with some parameter conversion
- int firstResult = -1;
- for (String key : info.getParameters().keySet())
+ // get the parameters with some parameter conversion
+ int firstResult = -1;
+ for (String key : info.getParameters().keySet())
+ {
+ if (key.toLowerCase().equals(FIRST_RESULT.toLowerCase()))
{
- if (key.toLowerCase().equals(FIRST_RESULT.toLowerCase()))
- {
- final Object o = info.getParameters().get(key);
- if (o != null)
- {
- try
- {
- firstResult = (Integer)o;
- }
- catch (ClassCastException e)
- {
- throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$
- + " class " + o.getClass().getName()); //$NON-NLS-1$
- }
- }
- }
- else
+ final Object o = info.getParameters().get(key);
+ if (o != null)
{
- // in case the parameter is a CDOID get the object from the db
- final Object param = info.getParameters().get(key);
- if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param))
+ try
{
- final CDOID cdoID = (CDOID)param;
- final String entityName = HibernateUtil.getInstance().getEntityName(cdoID);
- final Serializable idValue = HibernateUtil.getInstance().getIdValue(cdoID);
- final CDORevision revision = (CDORevision)session.get(entityName, idValue);
- query.setEntity(key, revision);
- hibernateStoreAccessor.addToRevisionCache(revision);
+ firstResult = (Integer)o;
}
- else
+ catch (ClassCastException e)
{
- query.setParameter(key, param);
+ throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$
+ + " class " + o.getClass().getName()); //$NON-NLS-1$
}
}
}
-
- // set the first result
- if (firstResult > -1)
- {
- query.setFirstResult(firstResult);
- }
-
- // the max result
- if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS)
- {
- query.setMaxResults(info.getMaxResults());
- }
-
- // and go for the query
- // future extension: support iterate, scroll through a parameter
- for (Object o : query.list())
+ else
{
- final boolean addOneMore = context.addResult(o);
- hibernateStoreAccessor.addToRevisionCache(o);
- if (!addOneMore)
+ // in case the parameter is a CDOID get the object from the db
+ final Object param = info.getParameters().get(key);
+ if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param))
+ {
+ final CDOID cdoID = (CDOID)param;
+ final String entityName = HibernateUtil.getInstance().getEntityName(cdoID);
+ final Serializable idValue = HibernateUtil.getInstance().getIdValue(cdoID);
+ final CDORevision revision = (CDORevision)session.get(entityName, idValue);
+ query.setEntity(key, revision);
+ hibernateStoreAccessor.addToRevisionCache(revision);
+ }
+ else
{
- return;
+ query.setParameter(key, param);
}
}
}
- finally
+
+ // set the first result
+ if (firstResult > -1)
{
- hibernateStoreAccessor.endHibernateSession();
+ query.setFirstResult(firstResult);
+ }
+
+ // the max result
+ if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS)
+ {
+ query.setMaxResults(info.getMaxResults());
+ }
+
+ // and go for the query
+ // future extension: support iterate, scroll through a parameter
+ for (Object o : query.list())
+ {
+ final boolean addOneMore = context.addResult(o);
+ hibernateStoreAccessor.addToRevisionCache(o);
+ if (!addOneMore)
+ {
+ return;
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
index db4df5f2fb..bb3e338a4c 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
@@ -439,6 +439,7 @@ public class HibernateStore extends Store implements IHibernateStore
if (mappingProvider != null)
{
mappingProvider.setHibernateStore(this);
+ // System.err.println(mappingProvider.getMapping());
hibernateConfiguration.addXML(mappingProvider.getMapping());
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
index 47ea719aa8..1c7984bc32 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionData;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.common.revision.cache.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
@@ -438,9 +439,15 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
final EStructuralFeature feature = revision.getEClass().getEStructuralFeature(NAME_EFEATURE_NAME);
if (feature != null)
{
- String revisionName = (String)revision.data().get(feature, 0);
- boolean match = exactMatch || revisionName == null || name == null ? ObjectUtil.equals(revisionName, name)
- : revisionName.startsWith(name);
+ Object value = revision.data().get(feature, 0);
+ if (value == CDORevisionData.NIL)
+ {
+ value = null;
+ }
+
+ final String revisionName = (String)value;
+ final boolean match = exactMatch || revisionName == null || name == null ? ObjectUtil
+ .equals(revisionName, name) : revisionName.startsWith(name);
if (match && !context.addResource(revision.getID()))
{
@@ -519,17 +526,6 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
final Session session = getNewHibernateSession();
session.setFlushMode(FlushMode.MANUAL);
- // first decrease the version for all dirty objects
- // hibernate will increase it again
- for (CDORevision revision : context.getDirtyObjects())
- {
- if (revision instanceof InternalCDORevision)
- {
- InternalCDORevision internalRevision = (InternalCDORevision)revision;
- internalRevision.setVersion(internalRevision.getVersion() - 1);
- }
- }
-
// order is 1) insert, 2) update and then delete
// this order is the most stable! Do not change it without testing
@@ -563,7 +559,7 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
for (CDORevision revision : context.getDirtyObjects())
{
final String entityName = HibernateUtil.getInstance().getEntityName(revision.getID());
- session.saveOrUpdate(entityName, revision);
+ session.merge(entityName, revision);
if (TRACER.isEnabled())
{
TRACER.trace("Updated Object " + revision.getEClass().getName() + " id: " + revision.getID()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -701,8 +697,8 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
throw new UnsupportedOperationException();
}
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID,
- long fromCommitTime, long toCommitTime) throws IOException
+ public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
+ throws IOException
{
throw new UnsupportedOperationException();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java
index 5379abec6d..e6f821aaae 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java
@@ -359,10 +359,10 @@ public class HibernateUtil
{
final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext();
InternalCDORevision revision;
- if ((revision = commitContext.getDirtyObject(id)) != null)
- {
- return revision;
- }
+ // if ((revision = commitContext.getDirtyObject(id)) != null)
+ // {
+ // return revision;
+ // }
if ((revision = commitContext.getNewObject(id)) != null)
{
@@ -531,7 +531,7 @@ public class HibernateUtil
{
// TODO: not the nicest check but we know that only these are supported
// by the hibernatestore
- return cdoID instanceof CDOClassifierRef.Provider;
+ return cdoID instanceof CDOClassifierRef.Provider || cdoID instanceof CDOIDExternal;
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumIntegerType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumIntegerType.java
index bfcd51280d..5341f01387 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumIntegerType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumIntegerType.java
@@ -68,9 +68,7 @@ public class CDOENumIntegerType extends CDOENumStringType
{
if (value == null)
{
- // an enum can not be null
- st.setInt(index, ((Enumerator)getEEnum().getDefaultValue()).getValue());
- // st.setNull(index, Types.INTEGER);
+ st.setNull(index, Types.INTEGER);
}
if (value instanceof Integer)
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumStringType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumStringType.java
index 9c3fdaefbc..008088f7a8 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumStringType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOENumStringType.java
@@ -167,9 +167,8 @@ public class CDOENumStringType implements UserType, ParameterizedType
{
if (value == null)
{
- // don't support null value for enums, they must always be set anyway
- st.setString(index, ((Enumerator)getEEnum().getDefaultValue()).getLiteral());
- // st.setNull(index, Types.VARCHAR);
+ // st.setString(index, ((Enumerator)getEEnum().getDefaultValue()).getLiteral());
+ st.setNull(index, Types.VARCHAR);
}
else
{
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java
index 15737e26fe..7660cd4a6f 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java
@@ -31,7 +31,7 @@ import org.hibernate.collection.PersistentCollection;
// - cdo does not have direct java references but stores cdoids in the list while hibernate expects real java object
// references.
// - cdo uses a moveablearraylist and not the standard arraylist
-//
+//
// The solution:
// - never return null when hibernate asks for the current value of the manyreference, always
// return a MoveableArrayList so that hibernate uses that as the delegate, set the MoveableArrayList
@@ -58,6 +58,15 @@ public class CDOManyAttributeGetter extends CDOPropertyGetter
InternalCDORevision revision = (InternalCDORevision)target;
CDOList list = revision.getList(getEStructuralFeature(), 10);
+ if (list instanceof WrappedHibernateList)
+ {
+ final Object delegate = ((WrappedHibernateList)list).getDelegate();
+ if (delegate instanceof PersistentCollection)
+ {
+ return delegate;
+ }
+ }
+
// Wrap the moveablearraylist
HibernateMoveableListWrapper wrapper = new HibernateMoveableListWrapper();
wrapper.setDelegate(list);
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java
index 44b19dca92..eb0283bdbe 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java
@@ -31,7 +31,7 @@ import org.hibernate.collection.PersistentCollection;
// - cdo does not have direct java references but stores cdoids in the list while hibernate expects real java object
// references.
// - cdo uses a moveablearraylist and not the standard arraylist
-//
+//
// The solution:
// - never return null when hibernate asks for the current value of the manyreference, always
// return a MoveableArrayList so that hibernate uses that as the delegate, set the MoveableArrayList
@@ -58,6 +58,15 @@ public class CDOManyReferenceGetter extends CDOPropertyGetter
InternalCDORevision revision = (InternalCDORevision)target;
CDOList list = revision.getList(getEStructuralFeature(), 10);
+ if (list instanceof WrappedHibernateList)
+ {
+ final Object delegate = ((WrappedHibernateList)list).getDelegate();
+ if (delegate instanceof PersistentCollection)
+ {
+ return delegate;
+ }
+ }
+
// Wrap the moveablearraylist
HibernateMoveableListWrapper wrapper = new HibernateMoveableListWrapper();
wrapper.setDelegate(list);
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java
index 5d03b4d220..9e930c2a0c 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionData;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionPropertyAccessor.CDORevisionSetter;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EEnum;
import org.hibernate.HibernateException;
@@ -62,20 +63,44 @@ public class CDOPropertyGetter extends CDOPropertyHandler implements Getter
public Object get(Object target) throws HibernateException
{
InternalCDORevision revision = (InternalCDORevision)target;
- final Object value = revision.getValue(getEStructuralFeature());
- if (value == null)
+ Object value = revision.getValue(getEStructuralFeature());
+ if (value == CDORevisionData.NIL)
{
+ // explicitly set to null
return null;
}
- if (value == CDORevisionData.NIL)
+ if (value == null)
{
- return null;
+ if (getEStructuralFeature().getDefaultValue() == null)
+ {
+ return null;
+ }
+
+ if (getEStructuralFeature().isUnsettable())
+ {
+ return null;
+ }
+
+ if (isEEnum)
+ {
+ // handle it a few lines lower
+ value = getEStructuralFeature().getDefaultValue();
+ }
+ else
+ {
+ return getEStructuralFeature().getDefaultValue();
+ }
}
// hibernate sees eenums, CDO sees int
if (isEEnum)
{
+ if (value instanceof Enumerator)
+ {
+ return value;
+ }
+
return eEnum.getEEnumLiteral((Integer)value);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java
index 09a3a24c31..83c56a8d5b 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java
@@ -11,9 +11,11 @@
*/
package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+import org.eclipse.emf.cdo.common.revision.CDORevisionData;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionPropertyAccessor.CDORevisionSetter;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -93,10 +95,32 @@ public class CDOPropertySetter extends CDOPropertyHandler implements Setter
else
{
// hibernate sees enums, cdo sees int's
- if (value instanceof EEnumLiteral)
+ if (value instanceof Enumerator)
+ {
+ revision.setValue(getEStructuralFeature(), ((Enumerator)value).getValue());
+ }
+ else if (value instanceof EEnumLiteral)
{
revision.setValue(getEStructuralFeature(), ((EEnumLiteral)value).getValue());
}
+ else if (value == null)
+ {
+ final Object defaultValue = getEStructuralFeature().getDefaultValue();
+ if (defaultValue == null)
+ {
+ revision.setValue(getEStructuralFeature(), null);
+ }
+ else if (getEStructuralFeature().isUnsettable())
+ {
+ revision.setValue(getEStructuralFeature(), null);
+ }
+ else
+ {
+ // there was a default value so was explicitly set to null
+ // otherwise the default value would be in the db
+ revision.setValue(getEStructuralFeature(), CDORevisionData.NIL);
+ }
+ }
else
{
revision.setValue(getEStructuralFeature(), value);
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java
index 1a6b4061be..6be7c58c81 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java
@@ -253,7 +253,7 @@ public class CDORevisionTuplizer extends AbstractEntityTuplizer
{
return new CDOIDPropertyGetter(this, mappedProperty.getName());
}
- else if (mappedProperty == mappedEntity.getVersion())
+ else if (mappedProperty.getMetaAttribute("version") != null)
{
return new CDOVersionPropertyGetter(this, mappedProperty.getName());
}
@@ -302,7 +302,7 @@ public class CDORevisionTuplizer extends AbstractEntityTuplizer
return new CDOIDPropertySetter(this, mappedProperty.getName());
}
- if (mappedProperty == mappedEntity.getVersion())
+ if (mappedProperty.getMetaAttribute("version") != null)
{
return new CDOVersionPropertySetter(this, mappedProperty.getName());
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java
index 679961cabb..1f2829fdea 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java
@@ -142,23 +142,29 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
return result;
}
- protected CDOID getCDOID(Object o)
+ protected Object getValue(Object o)
{
if (o instanceof CDOIDMeta || o instanceof CDOIDExternal)
{
- return (CDOID)o;
+ return o;
+ }
+
+ // can happen for primitive typed lists
+ if (!(o instanceof CDORevision))
+ {
+ return o;
}
CDORevision cdoRevision = (CDORevision)o;
return cdoRevision.getID();
}
- protected List<CDOID> getCDOIDs(Collection<?> c)
+ protected List<Object> getValues(Collection<?> c)
{
- List<CDOID> newC = new ArrayList<CDOID>();
+ List<Object> newC = new ArrayList<Object>();
for (Object o : c)
{
- newC.add(getCDOID(o));
+ newC.add(getValue(o));
}
return newC;
@@ -166,22 +172,22 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public void add(int index, Object element)
{
- getDelegate().add(index, getCDOID(element));
+ getDelegate().add(index, getValue(element));
}
public boolean add(Object o)
{
- return getDelegate().add(getCDOID(o));
+ return getDelegate().add(getValue(o));
}
public boolean addAll(Collection<? extends Object> c)
{
- return getDelegate().addAll(getCDOIDs(c));
+ return getDelegate().addAll(getValues(c));
}
public boolean addAll(int index, Collection<? extends Object> c)
{
- return getDelegate().addAll(index, getCDOIDs(c));
+ return getDelegate().addAll(index, getValues(c));
}
public void clear()
@@ -191,12 +197,12 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public boolean contains(Object o)
{
- return getDelegate().contains(getCDOID(o));
+ return getDelegate().contains(getValue(o));
}
public boolean containsAll(Collection<?> c)
{
- return getDelegate().containsAll(getCDOIDs(c));
+ return getDelegate().containsAll(getValues(c));
}
public Object get(int index)
@@ -206,7 +212,7 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public int indexOf(Object o)
{
- return getDelegate().indexOf(getCDOID(o));
+ return getDelegate().indexOf(getValue(o));
}
public boolean isEmpty()
@@ -221,7 +227,7 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public int lastIndexOf(Object o)
{
- return getDelegate().lastIndexOf(getCDOID(o));
+ return getDelegate().lastIndexOf(getValue(o));
}
public ListIterator<Object> listIterator()
@@ -241,22 +247,22 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public boolean remove(Object o)
{
- return getDelegate().remove(getCDOID(o));
+ return getDelegate().remove(getValue(o));
}
public boolean removeAll(Collection<?> c)
{
- return getDelegate().removeAll(getCDOIDs(c));
+ return getDelegate().removeAll(getValues(c));
}
public boolean retainAll(Collection<?> c)
{
- return getDelegate().retainAll(getCDOIDs(c));
+ return getDelegate().retainAll(getValues(c));
}
public Object set(int index, Object element)
{
- return getDelegate().set(index, getCDOID(element));
+ return getDelegate().set(index, getValue(element));
}
public int size()
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java
index 24d8eef948..29956343eb 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java
@@ -44,6 +44,17 @@ public class PersistableListHolder
public void putListMapping(Object target, EStructuralFeature feature, PersistentCollection collection)
{
Key key = new Key(target, feature);
+ final PersistentCollection currentCachedValue = getListMapping(target, feature);
+ if (currentCachedValue == collection)
+ {
+ return;
+ }
+
+ if (currentCachedValue != null)
+ {
+ throw new IllegalStateException("There is already a list mapping present");
+ }
+
getListMapping().put(key, collection);
if (TRACER.isEnabled())
{

Back to the top