Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2008-11-01 18:12:35 -0400
committerMartin Taal2008-11-01 18:12:35 -0400
commitc7995acfe4e92fbbec426c8eadcc537d52b34626 (patch)
tree9fda8529ea89f0b84b38af02d411f452b4e3b926
parent5bd42bae1db1571624a841ceb0b39dad54b56c29 (diff)
downloadcdo-c7995acfe4e92fbbec426c8eadcc537d52b34626.tar.gz
cdo-c7995acfe4e92fbbec426c8eadcc537d52b34626.tar.xz
cdo-c7995acfe4e92fbbec426c8eadcc537d52b34626.zip
Solved resourcetest and other issues
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java123
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java5
3 files changed, 66 insertions, 67 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 77f946f262..4825332287 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
@@ -28,13 +28,12 @@
<column name="name" unique-key="resourcepath"/>
</property>
<many-to-one name="folder" entity-name="CDOResourceFolder"
- column="folderid" />
+ column="folderid" update="false" insert="false" />
<subclass entity-name="CDOResourceFolder" abstract="false"
lazy="false" discriminator-value="cdoresourcefolder">
<meta attribute="eclassName">CDOResourceFolder</meta>
<meta attribute="epackage">http://www.eclipse.org/emf/CDO/resource/2.0.0</meta>
- <list name="nodes" lazy="true" cascade="all"
- inverse="true">
+ <list name="nodes" lazy="true" cascade="merge, persist, save-update, refresh, lock, evict, replicate">
<key column="folderid" />
<list-index />
<one-to-many entity-name="CDOResourceNode" />
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 a69f5f30a0..0aeb4a9ed0 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
@@ -115,6 +115,38 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
}
/**
+ * Commits the session
+ *
+ * @since 2.0
+ */
+ public void commitRollbackHibernateSession()
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Commiting hibernate session");
+ }
+
+ if (isErrorOccured())
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Rolling back hb transaction");
+ }
+
+ hibernateSession.getTransaction().rollback();
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Committing hb transaction");
+ }
+
+ hibernateSession.getTransaction().commit();
+ }
+ }
+
+ /**
* commits/rollbacks and closes the session
*
* @since 2.0
@@ -130,24 +162,7 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
{
try
{
- if (isErrorOccured())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Rolling back hb transaction");
- }
-
- hibernateSession.getTransaction().rollback();
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Committing hb transaction");
- }
-
- hibernateSession.getTransaction().commit();
- }
+ commitRollbackHibernateSession();
}
finally
{
@@ -324,27 +339,40 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
*/
public void commit()
{
- // Do nothing
+ commitRollbackHibernateSession();
+ HibernateThreadContext.setCommitContext(null);
}
@Override
public void write(CommitContext context)
{
- if (TRACER.isEnabled())
+ HibernateThreadContext.setCommitContext(context);
+ if (context.getNewPackages().length > 0)
{
- TRACER.trace("Committing transaction");
+ writePackages(context.getNewPackages());
}
-
- HibernateThreadContext.setCommitContext(context);
- writePackages(context.getNewPackages());
- boolean err = true;
-
try
{
// start with fresh hibernate session
final Session session = getHibernateSession();
session.setFlushMode(FlushMode.MANUAL);
+ // first repair the version for all dirty objects
+ for (CDORevision cdoRevision : context.getDirtyObjects())
+ {
+ if (cdoRevision instanceof InternalCDORevision)
+ {
+ ((InternalCDORevision)cdoRevision).setVersion(cdoRevision.getVersion() - 1);
+ }
+ }
+
+ // delete all objects
+ for (CDOID cdoID : context.getDetachedObjects())
+ {
+ final CDORevision revision = HibernateUtil.getInstance().getCDORevision(cdoID);
+ session.delete(revision);
+ }
+
final List<CDORevision> cdoRevisions = Arrays.asList(context.getNewObjects());
// keep track for which cdoRevisions the container id needs to be repaired afterwards
@@ -369,18 +397,9 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
}
}
- // first repair the version for all dirty objects
- for (CDORevision cdoRevision : context.getDirtyObjects())
- {
- if (cdoRevision instanceof InternalCDORevision)
- {
- ((InternalCDORevision)cdoRevision).setVersion(cdoRevision.getVersion() - 1);
- }
- }
-
for (CDORevision cdoRevision : context.getDirtyObjects())
{
- session.update(HibernateUtil.getInstance().getEntityName(cdoRevision), cdoRevision);
+ session.merge(HibernateUtil.getInstance().getEntityName(cdoRevision), cdoRevision);
if (TRACER.isEnabled())
{
TRACER.trace("Updated Object " + cdoRevision.getCDOClass().getName() + " id: " + cdoRevision.getID());
@@ -411,35 +430,13 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
session.flush();
- // does the commit
- endHibernateSession();
- err = false;
}
catch (Exception e)
{
OM.LOG.error(e);
throw WrappedException.wrap(e);
}
- finally
- {
- if (err)
- {
- setErrorOccured(true);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Clearing used hibernate session");
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Applying id mappings");
- }
-
- context.applyIDMappings();
- HibernateThreadContext.setCommitContext(null);
- }
+ context.applyIDMappings();
}
@Override
@@ -452,11 +449,9 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
@Override
protected void rollback(CommitContext context)
{
- // Don't do anything as the real action is done at commit (which does not happen now)
- if (TRACER.isEnabled())
- {
- TRACER.trace("Rollbacked called");
- }
+ setErrorOccured(true);
+ endHibernateSession();
+ HibernateThreadContext.setCommitContext(null);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java
index 87d1a6c24e..65ddb2093e 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java
@@ -34,6 +34,11 @@ public class CDOManyReferenceSetter extends CDOPropertySetter
public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException
{
// Do some checking
+ if (value instanceof HibernateMoveableListWrapper)
+ {
+ super.set(target, ((HibernateMoveableListWrapper)value).getDelegate(), factory);
+ return;
+ }
if (!(value instanceof PersistentList))
{
throw new IllegalArgumentException("Value is not a persistentlist but a " + value.getClass().getName());

Back to the top