Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2013-09-09 17:34:02 -0400
committerMartin Taal2013-09-09 17:34:02 -0400
commit41ff69f9649f9f6431643f0f9680124fd1659c22 (patch)
treeb8c9b7f14a9d3322dd572f75b3de79d7ce30dae7
parentfec6dc9ed61d94ffd0fc7a43ab605f63d04c2868 (diff)
downloadcdo-41ff69f9649f9f6431643f0f9680124fd1659c22.tar.gz
cdo-41ff69f9649f9f6431643f0f9680124fd1659c22.tar.xz
cdo-41ff69f9649f9f6431643f0f9680124fd1659c22.zip
[416530] - [Hibernate] Performance issues
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java37
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java106
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java81
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDAnyUserType.java86
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeGetter.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java64
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_416530_Test.java86
14 files changed, 449 insertions, 105 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
index fa91ddef6e..e0a6853826 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
@@ -56,6 +56,7 @@ import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap.Entry;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
+import java.awt.List;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Map;
@@ -81,16 +82,19 @@ public abstract class BaseCDORevision extends AbstractCDORevision
private static final byte SET_NOT_NULL_OPCODE = 2;
+ private static final byte PERMISSION_MASK = 0x03;
+
/**
* private static final byte READ_PERMISSION_FLAG = 0x01;
*
* private static final byte WRITE_PERMISSION_FLAG = 0x02;
*/
+
private static final byte FROZEN_FLAG = 0x04;
private static final byte UNCHUNKED_FLAG = 0x08;
- private static final byte PERMISSION_MASK = 0x03;
+ private static final byte LIST_PRESERVING_FLAG = 0x10;
private CDOID id;
@@ -565,7 +569,14 @@ public abstract class BaseCDORevision extends AbstractCDORevision
public void clear(EStructuralFeature feature)
{
- setValue(feature, null);
+ if (feature.isMany() && (flags & LIST_PRESERVING_FLAG) != 0)
+ {
+ getList(feature).clear();
+ }
+ else
+ {
+ setValue(feature, null);
+ }
}
public Object move(EStructuralFeature feature, int targetIndex, int sourceIndex)
@@ -593,7 +604,14 @@ public abstract class BaseCDORevision extends AbstractCDORevision
public void unset(EStructuralFeature feature)
{
- setValue(feature, null);
+ if (feature.isMany() && (flags & LIST_PRESERVING_FLAG) != 0)
+ {
+ getList(feature).clear();
+ }
+ else
+ {
+ setValue(feature, null);
+ }
}
/**
@@ -753,6 +771,19 @@ public abstract class BaseCDORevision extends AbstractCDORevision
}
/**
+ * The default behavior of a {@link BaseCDORevision} on a {@link #clear(EStructuralFeature)} and {@link #unset(EStructuralFeature)} methods is to set the efeature's value to null (discarding the value itself, a List). By calling this {@link #setListPreservingFlag()} method the default behavior is changed, instead of setting the efeature's value to null, the {@link List#clear()} method is called on the efeature's list instance.
+ *
+ * On purpose private to prevent api changes.
+ *
+ * @since 4.2
+ */
+ @SuppressWarnings("unused")
+ private void setListPreservingFlag()
+ {
+ flags |= LIST_PRESERVING_FLAG;
+ }
+
+ /**
* @since 4.1
*/
public void freeze()
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 d92d57c1ed..54e8c25548 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
@@ -63,10 +63,10 @@
<column name="`cdoresource_e_id`" not-null="true" unique="false"/>
</key>
<list-index column="`cdoresourcecontents_idx`"/>
- <many-to-any id-type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDAnyUserType" meta-type="string">
+ <element type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDAnyUserType">
<column not-null="false" unique="false" name="`contents_type`"/>
<column not-null="false" unique="false" name="`contents_id`"/>
- </many-to-any>
+ </element>
</list>
</subclass>
<subclass entity-name="CDOTextResource" abstract="false" lazy="false" extends="CDOResourceNode" discriminator-value="CDOTextResource">
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 226e0a7cca..c227b97424 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
@@ -36,6 +36,7 @@ import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreAccessor;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionProxyHibernate;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.PersistableListHolder;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.WrappedHibernateList;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
@@ -879,26 +880,6 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
// decrement version, hibernate will increment it
decrementVersions(context);
- // now check the versions and store the hibernate revision to repair
- // versions later on. The versions can be updated when inserting new objects
- // this will result in a version difference when the object gets merged
- // this repair is done just before the merge
- final Map<CDOID, InternalCDORevision> existingRevisions = CDOIDUtil.createMap();
- for (InternalCDORevision revision : context.getDirtyObjects())
- {
- final String entityName = HibernateUtil.getInstance().getEntityName(revision.getID());
- final Serializable idValue = HibernateUtil.getInstance().getIdValue(revision.getID());
- final InternalCDORevision cdoRevision = (InternalCDORevision)session.get(entityName, idValue);
- if (cdoRevision != null)
- {
- if (cdoRevision.getVersion() != revision.getVersion())
- {
- throw new IllegalStateException("Revision " + cdoRevision + " was already updated by another transaction");
- }
- existingRevisions.put(revision.getID(), cdoRevision);
- }
- }
-
// order is 1) insert, 2) update and then delete
// this order is the most stable! Do not change it without testing
@@ -908,6 +889,14 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
final List<InternalCDORevision> repairResourceIDs = new ArrayList<InternalCDORevision>();
for (InternalCDORevision revision : context.getNewObjects())
{
+ if (revision instanceof CDORevisionProxyHibernate)
+ {
+ ((CDORevisionProxyHibernate)revision).setListPreservingFlag();
+ }
+ else
+ {
+ HibernateUtil.getInstance().callSetListPreservingMethod(revision);
+ }
// keep track for which cdoRevisions the container id needs to be repaired afterwards
final CDOID containerID = (CDOID)revision.getContainerID();
if (containerID instanceof CDOIDTemp && !containerID.isNull())
@@ -925,33 +914,78 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
session.saveOrUpdate(entityName, revision);
}
- for (InternalCDORevision revision : context.getDirtyObjects())
+ // now apply all the changes
+ if (context.getDirtyObjectDeltas() != null)
{
- final String entityName = HibernateUtil.getInstance().getEntityName(revision.getID());
- final InternalCDORevision existingRevision = existingRevisions.get(revision.getID());
- if (existingRevision != null)
+ for (InternalCDORevisionDelta delta : context.getDirtyObjectDeltas())
{
- revision.setVersion(existingRevision.getVersion());
+ final String entityName = HibernateUtil.getInstance().getEntityName(delta.getID());
+ final Serializable idValue = HibernateUtil.getInstance().getIdValue(delta.getID());
+ final InternalCDORevision cdoRevision = (InternalCDORevision)session.get(entityName, idValue);
+ if (cdoRevision instanceof CDORevisionProxyHibernate)
+ {
+ ((CDORevisionProxyHibernate)cdoRevision).setListPreservingFlag();
+ }
+ else
+ {
+ HibernateUtil.getInstance().callSetListPreservingMethod(cdoRevision);
+ }
+ delta.apply(cdoRevision);
}
+ }
- final InternalCDORevision cdoRevision = (InternalCDORevision)session.merge(entityName, revision);
- if (getStore().isAuditing() && cdoRevision.getVersion() == revision.getVersion())
+ // preserve old behavior for the hibernate raw commit
+ if (context instanceof HibernateRawCommitContext)
+ {
+ // now check the versions and store the hibernate revision to repair
+ // versions later on. The versions can be updated when inserting new objects
+ // this will result in a version difference when the object gets merged
+ // this repair is done just before the merge
+ final Map<CDOID, InternalCDORevision> existingRevisions = CDOIDUtil.createMap();
+ for (InternalCDORevision revision : context.getDirtyObjects())
{
- // do a direct update of the version in the db to get it in sync with
- // hibernate, a special case, hibernate does not send the change back, do it ourselves
- // only needs to be done in case of auditing
- cdoRevision.setVersion(cdoRevision.getVersion() + 1);
+ final String entityName = HibernateUtil.getInstance().getEntityName(revision.getID());
+ final Serializable idValue = HibernateUtil.getInstance().getIdValue(revision.getID());
+ final InternalCDORevision cdoRevision = (InternalCDORevision)session.get(entityName, idValue);
+ if (cdoRevision != null)
+ {
+ if (cdoRevision.getVersion() != revision.getVersion())
+ {
+ throw new IllegalStateException("Revision " + cdoRevision + " was already updated by another transaction");
+ }
+ existingRevisions.put(revision.getID(), cdoRevision);
+ }
}
- if (TRACER.isEnabled())
+ for (InternalCDORevision revision : context.getDirtyObjects())
{
- TRACER.trace("Updated Object " + revision.getEClass().getName() + " id: " + revision.getID()); //$NON-NLS-1$ //$NON-NLS-2$
+ final String entityName = HibernateUtil.getInstance().getEntityName(revision.getID());
+ final InternalCDORevision existingRevision = existingRevisions.get(revision.getID());
+ if (existingRevision != null)
+ {
+ revision.setVersion(existingRevision.getVersion());
+ }
+
+ final InternalCDORevision cdoRevision = (InternalCDORevision)session.merge(entityName, revision);
+ if (getStore().isAuditing() && cdoRevision.getVersion() == revision.getVersion())
+ {
+ // do a direct update of the version in the db to get it in sync with
+ // hibernate, a special case, hibernate does not send the change back, do it ourselves
+ // only needs to be done in case of auditing
+ cdoRevision.setVersion(cdoRevision.getVersion() + 1);
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Updated Object " + revision.getEClass().getName() + " id: " + revision.getID()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
}
- // and increment the versions again so that the objects are cached correctly
- // note that this is needed because above a merge is done and not a
- // saveupdate, so hibernate does not update the version back in the revision
+ // and increment the versions stored in the context
+ // note that this is needed because above the cdorevision read from the db
+ // is updated and its version gets incremented, and not the revision currently
+ // in the cache
incrementVersions(context);
session.flush();
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 ff096ac048..3d3fa683e3 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
@@ -20,12 +20,15 @@ import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+import org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -55,6 +58,7 @@ import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.Serializable;
+import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
@@ -114,16 +118,40 @@ public class HibernateUtil
// Local copy of the datatype factory
private DatatypeFactory dataTypeFactory;
+ private static Method setListPreservingFlag_Method;
+
public HibernateUtil()
{
try
{
+ setListPreservingFlag_Method = BaseCDORevision.class.getDeclaredMethod("setListPreservingFlag");
+ setListPreservingFlag_Method.setAccessible(true);
dataTypeFactory = DatatypeFactory.newInstance();
}
catch (DatatypeConfigurationException ex)
{
throw new IllegalStateException("Exception ", ex);
}
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void callSetListPreservingMethod(Object o)
+ {
+ if (!(o instanceof BaseCDORevision))
+ {
+ return;
+ }
+ try
+ {
+ setListPreservingFlag_Method.invoke(o);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
public DatatypeFactory getDataTypeFactory()
@@ -137,6 +165,26 @@ public class HibernateUtil
}
/**
+ * @return true if the efeature is {@link CDOResource#getContents()} efeature.
+ */
+ public boolean isCDOResourceContents(EStructuralFeature eFeature)
+ {
+ if (!eFeature.getEContainingClass().getEPackage().getNsURI().equals(EresourcePackage.eNS_URI))
+ {
+ return false;
+ }
+ if (!eFeature.getEContainingClass().getName().equals(EresourcePackage.eINSTANCE.getCDOResource().getName()))
+ {
+ return false;
+ }
+ if (!eFeature.getName().equals(EresourcePackage.eINSTANCE.getCDOResource_Contents().getName()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Uses the repository package repository to find the EClass of the identified by the CDOClassifierRef.
*
* @param classifierRef
@@ -340,7 +388,7 @@ public class HibernateUtil
@Deprecated
public String getEntityName(CDORevision revision)
{
- return HibernateThreadContext.getCurrentStoreAccessor().getStore().getEntityName(revision.getEClass());
+ return getEntityName((Object)revision);
}
/**
@@ -676,7 +724,8 @@ public class HibernateUtil
*/
public String getEntityName(CDOID id)
{
- final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(id);
+ final CDOID localId = resolvePossibleTempId(id);
+ final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(localId);
if (classifierRef == null)
{
throw new IllegalArgumentException("This CDOID type of " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$
@@ -687,6 +736,34 @@ public class HibernateUtil
}
/**
+ * If the passed in id is a temp id, resolve it against the {@link HibernateThreadContext#getCommitContext()}
+ */
+ public CDOID resolvePossibleTempId(CDOID cdoId)
+ {
+ if (!(cdoId instanceof CDOIDTemp))
+ {
+ return cdoId;
+ }
+ if (HibernateThreadContext.isCommitContextSet())
+ {
+ final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext();
+
+ final CDOID newID = commitContext.getCommitContext().getIDMappings().get(cdoId);
+ if (newID != null)
+ {
+ return newID;
+ }
+
+ InternalCDORevision revision;
+ if ((revision = commitContext.getNewObject(cdoId)) != null)
+ {
+ return revision.getID();
+ }
+ }
+ return cdoId;
+ }
+
+ /**
* Create a {@link XMLGregorianCalendar} from a {@link Date} instance.
*/
public XMLGregorianCalendar getXMLGregorianCalendarDate(Date date, boolean dateTime)
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDAnyUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDAnyUserType.java
index 93ae413717..42d0b2f65f 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDAnyUserType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDAnyUserType.java
@@ -12,9 +12,18 @@
package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDExternal;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.emf.ecore.EClass;
+
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.usertype.UserType;
@@ -32,10 +41,12 @@ import java.util.HashMap;
*/
public class CDOIDAnyUserType implements UserType
{
- private static final int[] SQL_TYPES = { Types.VARCHAR };
+ private static final int[] SQL_TYPES = { Types.VARCHAR, Types.VARCHAR };
private static final String SEPARATOR = "__;__"; //$NON-NLS-1$
+ private static final String EXTERNAL = "EXTERNAL"; //$NON-NLS-1$
+
/** Constructor by id */
private final HashMap<String, Constructor<?>> constructors = new HashMap<String, Constructor<?>>();
@@ -81,32 +92,83 @@ public class CDOIDAnyUserType implements UserType
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
throws SQLException
{
- final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
+ final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[1], sessionImplementor);
if (rs.wasNull())
{
return null;
}
-
- final int end1 = value.indexOf(SEPARATOR);
- final int start2 = end1 + SEPARATOR.length();
-
- final String idStr = value.substring(0, end1);
- final String idClassName = value.substring(start2);
- final Serializable id = getId(idStr, idClassName);
- return id;
+ final String entityName = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
+ return deserializeId(entityName, value);
}
public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor sessionImplementor)
throws SQLException
{
- if (value == null || value instanceof CDOID && ((CDOID)value).isNull())
+ final String entityName;
+ final CDOID localValue;
+ if (value instanceof CDORevision)
+ {
+ final CDORevision cdoRevision = (CDORevision)value;
+ localValue = cdoRevision.getID();
+ // cast to object to use correct method from hibernate util
+ entityName = HibernateUtil.getInstance().getEntityName((Object)cdoRevision);
+ }
+ else if (value instanceof CDOID)
+ {
+ localValue = (CDOID)value;
+ entityName = HibernateUtil.getInstance().getEntityName(localValue);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Type " + value + " not supported here");
+ }
+
+ // the first column is there for backward compatibility, fill it with nulls..
+ final String strValue = serializeId(localValue);
+ if (strValue == null)
{
statement.setNull(index, Types.VARCHAR);
+ statement.setNull(index + 1, Types.VARCHAR);
}
else
{
- statement.setString(index, value.toString() + SEPARATOR + value.getClass().getName());
+ statement.setString(index, entityName);
+ statement.setString(index + 1, strValue);
+ }
+ }
+
+ protected String serializeId(CDOID id)
+ {
+ final CDOID cdoID = HibernateUtil.getInstance().resolvePossibleTempId(id);
+ if (cdoID == null || cdoID.isNull())
+ {
+ return null;
+ }
+ if (cdoID.getType() == CDOID.Type.EXTERNAL_OBJECT)
+ {
+ return EXTERNAL + SEPARATOR + ((CDOIDExternal)cdoID).getURI();
+ }
+ final Serializable idValue = HibernateUtil.getInstance().getIdValue(cdoID);
+ return idValue + SEPARATOR + idValue.getClass().getName();
+ }
+
+ protected CDOID deserializeId(String entityName, String value)
+ {
+ final int end1 = value.indexOf(SEPARATOR);
+ final int start2 = end1 + SEPARATOR.length();
+
+ final String idStr = value.substring(0, end1);
+ final String idClassName = value.substring(start2);
+
+ if (EXTERNAL.equals(entityName))
+ {
+ return CDOIDUtil.createExternal(idStr);
}
+
+ final Serializable idValue = getId(idStr, idClassName);
+ final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
+ final EClass eClass = accessor.getStore().getEClass(entityName);
+ return HibernateUtil.getInstance().createCDOID(new CDOClassifierRef(eClass), idValue);
}
public Serializable disassemble(Object value)
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 c627dff34f..54b7985eb0 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
@@ -75,6 +75,7 @@ public class CDOManyAttributeGetter extends CDOPropertyGetter
// Wrap the moveablearraylist
HibernateMoveableListWrapper wrapper = new HibernateMoveableListWrapper();
+ wrapper.setEFeature(getEStructuralFeature());
wrapper.setDelegate(list);
// And return it
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 d8697ff74a..bbc5868716 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
@@ -75,6 +75,7 @@ public class CDOManyReferenceGetter extends CDOPropertyGetter
// Wrap the moveablearraylist
HibernateMoveableListWrapper wrapper = new HibernateMoveableListWrapper();
+ wrapper.setEFeature(getEStructuralFeature());
wrapper.setDelegate(list);
// And return it
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java
index 2817c1dbed..8ce10a8483 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
import org.eclipse.emf.cdo.spi.common.revision.DelegatingCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -47,6 +48,11 @@ public class CDORevisionProxyHibernate extends DelegatingCDORevision implements
return li;
}
+ public void setListPreservingFlag()
+ {
+ HibernateUtil.getInstance().callSetListPreservingMethod(getDelegate());
+ }
+
public Object writeReplace()
{
return this;
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 ab28d690da..0539cf85d2 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
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -221,9 +222,13 @@ public class CDORevisionTuplizer extends AbstractEntityTuplizer
}
else
{
-
EStructuralFeature feature = getEClass().getEStructuralFeature(mappedProperty.getName());
- if (feature instanceof EReference && feature.isMany())
+ if (feature instanceof EReference && feature.isMany()
+ && HibernateUtil.getInstance().isCDOResourceContents(feature))
+ {
+ getter = new CDOManyAttributeGetter(this, mappedProperty.getName());
+ }
+ else if (feature instanceof EReference && feature.isMany())
{
getter = new CDOManyReferenceGetter(this, mappedProperty.getName());
}
@@ -270,9 +275,7 @@ public class CDORevisionTuplizer extends AbstractEntityTuplizer
{
setter = new CDOVersionPropertySetter(this, mappedProperty.getName());
}
- else
-
- if (mappedProperty.getName().compareTo(CDOHibernateConstants.RESOURCE_PROPERTY) == 0)
+ else if (mappedProperty.getName().compareTo(CDOHibernateConstants.RESOURCE_PROPERTY) == 0)
{
setter = new CDOResourceIDSetter(this, mappedProperty.getName());
}
@@ -287,7 +290,12 @@ public class CDORevisionTuplizer extends AbstractEntityTuplizer
else
{
EStructuralFeature feature = getEClass().getEStructuralFeature(mappedProperty.getName());
- if (feature instanceof EReference && feature.isMany())
+ if (feature instanceof EReference && feature.isMany()
+ && HibernateUtil.getInstance().isCDOResourceContents(feature))
+ {
+ setter = new CDOManyAttributeSetter(this, mappedProperty.getName());
+ }
+ else if (feature instanceof EReference && feature.isMany())
{
setter = new CDOManyReferenceSetter(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 a4894077ba..faac8a942d 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
@@ -19,6 +19,9 @@ import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
import org.eclipse.net4j.util.collection.MoveableList;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -36,6 +39,10 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
{
private List<Object> delegate;
+ private EStructuralFeature eFeature;
+
+ private boolean resolveCDOID;
+
public HibernateMoveableListWrapper()
{
}
@@ -120,14 +127,12 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
{
return o;
}
-
- // is already resolved
- if (!(o instanceof CDOID))
+ else if (resolveCDOID && o instanceof CDOID)
{
- return o;
+ return HibernateUtil.getInstance().getCDORevision((CDOID)o);
}
- return HibernateUtil.getInstance().getCDORevision((CDOID)o);
+ return o;
}
protected List<Object> getObjects(List<?> ids)
@@ -220,7 +225,7 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public Iterator<Object> iterator()
{
- return new CDOHibernateIterator(getDelegate().iterator());
+ return new CDOHibernateIterator(getDelegate().iterator(), resolveCDOID);
}
public int lastIndexOf(Object o)
@@ -230,12 +235,12 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public ListIterator<Object> listIterator()
{
- return new CDOHibernateListIterator(getDelegate().listIterator());
+ return new CDOHibernateListIterator(getDelegate().listIterator(), resolveCDOID);
}
public ListIterator<Object> listIterator(int index)
{
- return new CDOHibernateListIterator(getDelegate().listIterator(index));
+ return new CDOHibernateListIterator(getDelegate().listIterator(index), resolveCDOID);
}
public Object remove(int index)
@@ -297,13 +302,27 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
return a;
}
+ EStructuralFeature getEFeature()
+ {
+ return eFeature;
+ }
+
+ void setEFeature(EStructuralFeature eFeature)
+ {
+ this.eFeature = eFeature;
+ resolveCDOID = !HibernateUtil.getInstance().isCDOResourceContents(eFeature) && eFeature instanceof EReference;
+ }
+
private static final class CDOHibernateIterator implements Iterator<Object>
{
private final Iterator<?> delegate;
- public CDOHibernateIterator(Iterator<?> delegate)
+ private final boolean resolveCDOID;
+
+ public CDOHibernateIterator(Iterator<?> delegate, boolean resolveCDOID)
{
this.delegate = delegate;
+ this.resolveCDOID = resolveCDOID;
}
public boolean hasNext()
@@ -318,7 +337,7 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
{
return o;
}
- else if (o instanceof CDOID)
+ else if (resolveCDOID && o instanceof CDOID)
{
return HibernateUtil.getInstance().getCDORevision((CDOID)o);
}
@@ -336,9 +355,12 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
{
private final ListIterator<Object> delegate;
- public CDOHibernateListIterator(ListIterator<Object> delegate)
+ private final boolean resolveCDOID;
+
+ public CDOHibernateListIterator(ListIterator<Object> delegate, boolean resolveCDOID)
{
this.delegate = delegate;
+ this.resolveCDOID = resolveCDOID;
}
public void add(Object o)
@@ -359,7 +381,7 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
public Object next()
{
Object o = delegate.next();
- if (o instanceof CDOID)
+ if (resolveCDOID && o instanceof CDOID)
{
return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next());
}
@@ -398,4 +420,5 @@ public class HibernateMoveableListWrapper implements MoveableList<Object>
delegate.set(HibernateUtil.getInstance().getCDOID(o));
}
}
+
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java
index 09d547a24d..9d9d562f81 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java
@@ -12,6 +12,7 @@
package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDExternal;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.revision.CDOListFactory;
@@ -26,7 +27,6 @@ import org.eclipse.emf.cdo.spi.common.revision.CDOReferenceAdjuster;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EReference;
@@ -67,6 +67,8 @@ public class WrappedHibernateList implements InternalCDOList
private int currentListChunk = -1;
+ private boolean resolveCDOID;
+
public WrappedHibernateList(InternalCDORevision owner, EStructuralFeature eFeature)
{
this.owner = owner;
@@ -76,6 +78,7 @@ public class WrappedHibernateList implements InternalCDOList
{
currentListChunk = accessor.getCurrentListChunk();
}
+ resolveCDOID = !HibernateUtil.getInstance().isCDOResourceContents(eFeature) && eFeature instanceof EReference;
}
public void move(int newPosition, Object object)
@@ -165,13 +168,6 @@ public class WrappedHibernateList implements InternalCDOList
{
list.add(type.copyValue(get(i)));
}
-
- if (classifier instanceof EClass)
- {
- WrappedHibernateList wrapped = new WrappedHibernateList(owner, eFeature);
- wrapped.setDelegate(list);
- return wrapped;
- }
return list;
}
@@ -278,7 +274,7 @@ public class WrappedHibernateList implements InternalCDOList
return result;
}
- protected Object getCDOValue(Object o)
+ protected Object xgetCDOValue(Object o)
{
if (o instanceof CDOID)
{
@@ -294,12 +290,27 @@ public class WrappedHibernateList implements InternalCDOList
return o;
}
- protected List<Object> getCDOValues(Collection<?> c)
+ protected Object getHibernateValue(Object o)
+ {
+ if (o instanceof CDOIDExternal)
+ {
+ return o;
+ }
+
+ if (o instanceof CDOID && resolveCDOID)
+ {
+ return HibernateUtil.getInstance().getCDORevision((CDOID)o);
+ }
+
+ return o;
+ }
+
+ protected List<Object> getHibernateValues(Collection<?> c)
{
List<Object> newC = new ArrayList<Object>();
for (Object o : c)
{
- newC.add(getCDOValue(o));
+ newC.add(getHibernateValue(o));
}
return newC;
@@ -308,25 +319,25 @@ public class WrappedHibernateList implements InternalCDOList
public void add(int index, Object element)
{
checkFrozen();
- getDelegate().add(index, getCDOValue(element));
+ getDelegate().add(index, getHibernateValue(element));
}
public boolean add(Object o)
{
checkFrozen();
- return getDelegate().add(getCDOValue(o));
+ return getDelegate().add(getHibernateValue(o));
}
public boolean addAll(Collection<? extends Object> c)
{
checkFrozen();
- return getDelegate().addAll(getCDOValues(c));
+ return getDelegate().addAll(getHibernateValues(c));
}
public boolean addAll(int index, Collection<? extends Object> c)
{
checkFrozen();
- return getDelegate().addAll(index, getCDOValues(c));
+ return getDelegate().addAll(index, getHibernateValues(c));
}
public void clear()
@@ -337,12 +348,12 @@ public class WrappedHibernateList implements InternalCDOList
public boolean contains(Object o)
{
- return getDelegate().contains(getCDOValue(o));
+ return getDelegate().contains(getHibernateValue(o));
}
public boolean containsAll(Collection<?> c)
{
- return getDelegate().containsAll(getCDOValues(c));
+ return getDelegate().containsAll(getHibernateValues(c));
}
public Object get(int index)
@@ -423,7 +434,7 @@ public class WrappedHibernateList implements InternalCDOList
public int indexOf(Object o)
{
- return getDelegate().indexOf(getCDOValue(o));
+ return getDelegate().indexOf(getHibernateValue(o));
}
public boolean isEmpty()
@@ -438,7 +449,7 @@ public class WrappedHibernateList implements InternalCDOList
public int lastIndexOf(Object o)
{
- return getDelegate().lastIndexOf(getCDOValue(o));
+ return getDelegate().lastIndexOf(getHibernateValue(o));
}
public ListIterator<Object> listIterator()
@@ -460,18 +471,18 @@ public class WrappedHibernateList implements InternalCDOList
public boolean remove(Object o)
{
checkFrozen();
- return getDelegate().remove(getCDOValue(o));
+ return getDelegate().remove(getHibernateValue(o));
}
public boolean removeAll(Collection<?> c)
{
checkFrozen();
- return getDelegate().removeAll(getCDOValues(c));
+ return getDelegate().removeAll(getHibernateValues(c));
}
public boolean retainAll(Collection<?> c)
{
- return getDelegate().retainAll(getCDOValues(c));
+ return getDelegate().retainAll(getHibernateValues(c));
}
public Object set(int index, Object element)
@@ -483,12 +494,7 @@ public class WrappedHibernateList implements InternalCDOList
return null;
}
- if (element instanceof CDOID)
- {
- return getDelegate().set(index, element);
- }
-
- return getDelegate().set(index, getCDOValue(element));
+ return getDelegate().set(index, getHibernateValue(element));
}
public int size()
@@ -655,7 +661,7 @@ public class WrappedHibernateList implements InternalCDOList
public void setWithoutFrozenCheck(int i, Object value)
{
- getDelegate().set(i, value);
+ getDelegate().set(i, getHibernateValue(value));
}
CDORevision getOwner()
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties
index 1ecf9eb2a7..07c2a90744 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties
@@ -29,7 +29,7 @@ hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
# EXAMPLE SETTING FOR MYSQL DATABASE. UNCOMMENT AND EDIT TO USE.
#
#hibernate.connection.driver_class=com.mysql.jdbc.Driver
-#hibernate.connection.url=jdbc:mysql://localhost:3306/cdohibernate
+#hibernate.connection.url=jdbc:mysql://localhost:3306/cdohibernate2
#hibernate.connection.username=root
#hibernate.connection.password=root
#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
index cf375525d3..e27b9b4d4b 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
@@ -83,17 +83,24 @@ public class AllTestsHibernate extends AllConfigs
protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario)
{
// testClasses.clear();
- // testClasses.add(HibernateQueryTest.class);
+ // testClasses.add(HibernateBugzilla_380987_Test.class);
+ // testClasses.add(HibernateBugzilla_362270c_Test.class);
// if (true)
// {
// return;
// }
+ // TODO: find out why this does not work for non-auditing
+ if (scenario.getCapabilities().contains(IRepositoryConfig.CAPABILITY_AUDITING))
+ {
+ testClasses.add(HibernateBugzilla_380987_Test.class);
+ }
+
testClasses.add(HibernateChunkingTest.class);
testClasses.add(Hibernate_Failure_Test.class);
testClasses.add(Hibernate_Export_Test.class);
testClasses.add(HibernateBugzilla_381013_Test.class);
- testClasses.add(HibernateBugzilla_380987_Test.class);
+
testClasses.add(HibernateBugzilla_392653_Test.class);
testClasses.add(HibernateBugzilla_387752_Test.class);
testClasses.add(HibernateBugzilla_387752_True_Test.class);
@@ -138,6 +145,8 @@ public class AllTestsHibernate extends AllConfigs
testClasses.add(HibernateBugzilla_398057_Test.class);
testClasses.add(HibernateBugzilla_397682_Test.class);
+ testClasses.add(HibernateBugzilla_416530_Test.class);
+
if (scenario.getCapabilities().contains(IRepositoryConfig.CAPABILITY_AUDITING))
{
// need to add additional auditing annotations
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_416530_Test.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_416530_Test.java
new file mode 100644
index 0000000000..226cbd0673
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_416530_Test.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2013 Eike Stepper (Berlin, Germany) and others.
+ * 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:
+ * Martin Taal - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.hibernate;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+/**
+ * @author Michael Taal
+ */
+public class HibernateBugzilla_416530_Test extends AbstractCDOTest
+{
+
+ // @Override
+ // public void doSetUp() throws Exception
+ // {
+ // org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1);
+ // org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1);
+ // super.doSetUp();
+ // }
+ //
+ // @Override
+ // public void doTearDown() throws Exception
+ // {
+ // org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0);
+ // org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0);
+ // super.doTearDown();
+ // }
+
+ public void testCreatePersist() throws Exception
+ {
+ // step 1: create initial objects and add to resource
+ {
+ final CDOSession session = openSession();
+ final CDOTransaction transaction = session.openTransaction();
+ // get/create a resource
+ CDOResource resource = transaction.createResource(getResourcePath("/test1"));
+
+ // clear any previous data
+ resource.getContents().clear();
+
+ for (int i = 0; i < 100; i++)
+ {
+ final Company address = getModel1Factory().createCompany();
+ address.setCity("test"); //$NON-NLS-1$
+ String addressName = "name " + System.currentTimeMillis(); //$NON-NLS-1$
+ address.setName(addressName);
+ address.setStreet("test"); //$NON-NLS-1$
+ resource.getContents().add(address);
+ }
+
+ transaction.commit();
+ }
+
+ // step 2: create one additional object and add to resource
+ // observations: for each object in the resource, the following add will cause a select for each of that object
+ {
+ final CDOSession session = openSession();
+ final CDOTransaction transaction = session.openTransaction();
+ // get/create a resource
+ CDOResource resource = transaction.getResource(getResourcePath("/test1"));
+
+ {
+ final Company address = getModel1Factory().createCompany();
+ address.setCity("test"); //$NON-NLS-1$
+ String addressName = "name " + System.currentTimeMillis(); //$NON-NLS-1$
+ address.setName(addressName);
+ address.setStreet("test"); //$NON-NLS-1$
+ resource.getContents().add(address);
+ }
+
+ transaction.commit();
+ }
+ }
+}

Back to the top