summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2008-04-24 07:47:08 (EDT)
committerMartin Taal2008-04-24 07:47:08 (EDT)
commit6b4a347ec29e546bf7ea6722d48df5d3529acddc (patch)
tree7e1fb4d5afabe31f633e3d53a57e90a42d888e8d
parent1661dcf1226ce8aaa2012c51542c3af8b358f0ac (diff)
downloadcdo-6b4a347ec29e546bf7ea6722d48df5d3529acddc.zip
cdo-6b4a347ec29e546bf7ea6722d48df5d3529acddc.tar.gz
cdo-6b4a347ec29e546bf7ea6722d48df5d3529acddc.tar.bz2
[228403]
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java35
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml4
-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/HibernatePackageHandler.java133
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreReader.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreWriter.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOFeatureReferenceTypePropertyHandler.java95
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java129
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTests.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernatePackageRegistryTest.java82
20 files changed, 617 insertions, 141 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java
index 2c09abc..fa6c648 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java
@@ -21,10 +21,12 @@ import org.eclipse.net4j.util.WrappedException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
import org.eclipse.emf.teneo.hibernate.cdo.CDOHelper;
import org.hibernate.cfg.Configuration;
@@ -62,25 +64,28 @@ public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
public String generateMapping()
{
TRACER.trace("Generating Hibernate Mapping");
- final List<String> models = new ArrayList<String>();
- for (CDOPackage cdoPackage : getHibernateStore().getPackageHandler().getCDOPackages())
- {
- TRACER.trace("Using cdoPackage : " + cdoPackage.getName() + " - " + cdoPackage.getPackageURI());
- models.add(cdoPackage.getEcore());
- }
final Properties properties = HibernateUtil.getInstance().getPropertiesFromStore(getHibernateStore());
// TODO: handle nested package structures
final List<EPackage> epacks = new ArrayList<EPackage>();
final ResourceSet rs = new ResourceSetImpl();
- rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
- for (String ecoreStr : models)
+ rs.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
+ rs.getPackageRegistry().put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
+ rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new EcoreResourceFactoryImpl());
+ for (CDOPackage cdoPackage : getHibernateStore().getPackageHandler().getCDOPackages())
{
+ TRACER.trace("Using cdoPackage : " + cdoPackage.getName() + " - " + cdoPackage.getPackageURI());
+ final String ecoreStr = cdoPackage.getEcore();
+ if (ecoreStr == null)
+ {
+ // happens at initialization time
+ continue;
+ }
// this assumes that the (default) encoding is the same on both the client and
// server
final ByteArrayInputStream bis = new ByteArrayInputStream(ecoreStr.getBytes());
// fool the resourceset by passing a fake uri
- final URI epackageURI = URI.createURI("epackage.ecore");
+ final URI epackageURI = URI.createURI(cdoPackage.getPackageURI());
final Resource resource = rs.createResource(epackageURI);
try
{
@@ -104,10 +109,20 @@ public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
return CDOHelper.getInstance().generateMapping(ePackageArray, properties);
}
+ // this will check the global package registry and read the epackages from
+ // there if the epackage is already present there
protected List<EPackage> resolveSubPackages(EPackage epack)
{
final List<EPackage> epacks = new ArrayList<EPackage>();
- epacks.add(epack);
+ if (EPackage.Registry.INSTANCE.get(epack.getNsURI()) != null)
+ {
+ epacks.add((EPackage)EPackage.Registry.INSTANCE.get(epack.getNsURI()));
+ }
+ else
+ {
+ epacks.add(epack);
+ }
+
for (EPackage subEPackage : epack.getESubpackages())
{
epacks.addAll(resolveSubPackages(subEPackage));
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF
index 2c6dcd9..1893666 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
+ org.eclipse.emf.cdo;bundle-version="0.8.0",
org.eclipse.emf.cdo.server;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.eclipse.emf.cdo.server.hibernate.libraries;bundle-version="0.8.0",
org.eclipse.emf.cdo.server.hibernate.id;bundle-version="0.8.0"
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
index 3a8f2ea..4144776 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
@@ -63,7 +63,9 @@
<property name="featureID" column="feature" type="int" not-null="true" />
<property name="type" type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOTypeUserType"
not-null="false" />
- <many-to-one name="referenceType" class="CDOClassImpl" column="reftype" not-null="false" cascade="persist, merge, save-update, evict, replicate, lock, refresh"/>
+ <many-to-one name="referenceType" class="CDOClassImpl" column="reftype" not-null="false"
+ cascade="persist, merge, save-update, evict, replicate, lock, refresh"
+ access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOFeatureReferenceTypePropertyHandler"/>
<property name="many" type="boolean" not-null="true" />
<property name="containment" type="boolean" not-null="false" />
</joined-subclass>
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 2f67dcf..f369963 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
@@ -6,12 +6,12 @@
<meta attribute="epackage">http://www.eclipse.org/emf/CDO/resource/1.0.0</meta>
<tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
<tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
- <id type="long" name="e_id" column="e_id">
+ <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticIdPropertyHandler">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version">
+ <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="path" type="string" not-null="true" length="255" />
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
index a992033..cef9321 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
@@ -11,13 +11,14 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.hibernate;
-import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOClass;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOFeature;
import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.server.IStoreWriter.CommitContext;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
@@ -29,6 +30,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
+import org.hibernate.criterion.Expression;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import java.io.InputStream;
@@ -58,8 +60,6 @@ public class HibernatePackageHandler
private Collection<CDOPackageInfo> cdoPackageInfos = null;
- private Collection<CDOPackage> cdoPackages = null;
-
private HibernateStore hibernateStore;
/**
@@ -70,9 +70,38 @@ public class HibernatePackageHandler
hibernateStore = store;
}
+ public List<CDOPackage> getCDOPackages()
+ {
+ final List<CDOPackage> cdoPackages = new ArrayList<CDOPackage>();
+ if (HibernateThreadContext.isCommitContextSet())
+ {
+ final CommitContext cc = HibernateThreadContext.getCommitContext();
+ if (cc instanceof org.eclipse.emf.cdo.internal.server.Transaction)
+ {
+ final org.eclipse.emf.cdo.internal.server.Transaction tx = (org.eclipse.emf.cdo.internal.server.Transaction)cc;
+ for (CDOPackage cdoPackage : tx.getNewPackages())
+ {
+ cdoPackages.add(cdoPackage);
+ }
+ }
+ }
+ for (CDOPackage cdoPackage : hibernateStore.getRepository().getPackageManager().getPackages())
+ {
+ cdoPackages.add(cdoPackage);
+ }
+ for (CDOPackage cdoPackage : cdoPackages)
+ {
+ // force resolve
+ if (cdoPackage.getClassCount() == 0)
+ {
+ TRACER.trace("Returning " + cdoPackage.getPackageURI());
+ }
+ }
+ return cdoPackages;
+ }
+
public void writePackages(CDOPackage... cdoPackages)
{
- readPackages();
TRACER.trace("Persisting new CDOPackages");
final Session session = getSessionFactory().openSession();
final Transaction tx = session.beginTransaction();
@@ -112,17 +141,20 @@ public class HibernatePackageHandler
protected boolean cdoPackageExistsAndIsUnchanged(CDOPackage newCDOPackage)
{
- final CDOPackage currentCDOPackage = getCDOPackage(newCDOPackage.getPackageURI());
- if (currentCDOPackage == null)
+ final CDOPackage[] cdoPackages = hibernateStore.getRepository().getPackageManager().getPackages();
+ for (CDOPackage cdoPackage : cdoPackages)
{
- return false;
+ if (cdoPackage.getClassCount() > 0 && cdoPackage.getPackageURI().compareTo(newCDOPackage.getPackageURI()) == 0)
+ {
+ return cdoPackage.getEcore().compareTo(newCDOPackage.getEcore()) == 0;
+ }
}
- return currentCDOPackage.getEcore().compareTo(newCDOPackage.getEcore()) == 0;
+
+ return false;
}
public void writePackage(CDOPackage cdoPackage)
{
- readPackages();
if (cdoPackageExistsAndIsUnchanged(cdoPackage))
{
OM.LOG.warn("CDOPackage " + cdoPackage.getPackageURI() + " already exists not persisting it again!");
@@ -151,41 +183,64 @@ public class HibernatePackageHandler
hibernateStore.reInitialize();
}
- public CDOPackage getCDOPackage(String uri)
- {
- readPackages();
- TRACER.trace("Getting CDOPackage using uri: " + uri);
- for (CDOPackage cdoPackage : cdoPackages)
- {
- if (cdoPackage.getPackageURI().compareTo(uri) == 0)
- {
- TRACER.trace("CDOPackage found");
- return cdoPackage;
- }
- }
- TRACER.trace("CDOPackage NOT found");
- return null;
- }
-
public Collection<CDOPackageInfo> getCDOPackageInfos()
{
- readPackages();
+ readPackageInfos();
return cdoPackageInfos;
}
- public Collection<CDOPackage> getCDOPackages()
+ protected void readPackage(CDOPackage cdoPackage)
{
- readPackages();
- return cdoPackages;
+ if (cdoPackage.getClassCount() > 0)
+ { // already initialized go away
+ return;
+ }
+
+ TRACER.trace("Reading CDOPackage with uri " + cdoPackage.getPackageURI() + " from db");
+ Session session = getSessionFactory().openSession();
+ try
+ {
+ Criteria criteria = session.createCriteria(CDOPackage.class);
+ criteria.add(Expression.eq("packageURI", cdoPackage.getPackageURI()));
+ List<?> list = criteria.list();
+ if (list.size() != 1)
+ {
+ throw new IllegalArgumentException("CDOPackage with uri " + cdoPackage.getPackageURI()
+ + " not present in the db");
+ }
+ TRACER.trace("Found " + list.size() + " CDOPackages in DB");
+
+ final CDOPackage dbPackage = (CDOPackage)list.get(0);
+ TRACER.trace("Read CDOPackage: " + cdoPackage.getName());
+ ((InternalCDOPackage)cdoPackage).setServerInfo(dbPackage.getServerInfo());
+ ((InternalCDOPackage)cdoPackage).setName(dbPackage.getName());
+ ((InternalCDOPackage)cdoPackage).setEcore(dbPackage.getEcore());
+ ((InternalCDOPackage)cdoPackage).setMetaIDRange(cdoPackage.getMetaIDRange());
+
+ final List<CDOClass> cdoClasses = new ArrayList<CDOClass>();
+ for (CDOClass cdoClass : dbPackage.getClasses())
+ {
+ cdoClasses.add(cdoClass);
+ for (CDOFeature cdoFeature : cdoClass.getFeatures())
+ {
+ ((InternalCDOFeature)cdoFeature).setContainingClass(cdoClass);
+ }
+ }
+ ((CDOPackageImpl)cdoPackage).setClasses(cdoClasses);
+ }
+ finally
+ {
+ session.close();
+ }
+ TRACER.trace("Finished reading CDOPackages");
}
- protected void readPackages()
+ protected void readPackageInfos()
{
if (cdoPackageInfos == null || cdoPackageInfos.size() == 0)
{
TRACER.trace("Reading CDOPackages from db");
Collection<CDOPackageInfo> result = new ArrayList<CDOPackageInfo>();
- Collection<CDOPackage> resultPackages = new ArrayList<CDOPackage>();
Session session = getSessionFactory().openSession();
try
{
@@ -199,21 +254,8 @@ public class HibernatePackageHandler
result.add(new CDOPackageInfo(cdoPackage.getPackageURI(), cdoPackage.isDynamic(),
cdoPackage.getMetaIDRange(), cdoPackage.getParentURI()));
((InternalCDOPackage)cdoPackage).setPackageManager(hibernateStore.getRepository().getPackageManager());
- resultPackages.add(cdoPackage);
-
- // repair something
- // TODO: set this in the mapping with a bi-directional relation
- for (CDOClass cdoClass : cdoPackage.getClasses())
- {
- ((InternalCDOClass)cdoClass).setContainingPackage(cdoPackage);
- for (CDOFeature cdoFeature : cdoClass.getFeatures())
- {
- ((InternalCDOFeature)cdoFeature).setContainingClass(cdoClass);
- }
- }
- }
- cdoPackages = resultPackages;
+ }
cdoPackageInfos = result;
}
finally
@@ -255,7 +297,6 @@ public class HibernatePackageHandler
public void reset()
{
cdoPackageInfos = null;
- cdoPackages = null;
}
protected void doActivate()
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 b2ef584..725014f 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
@@ -22,6 +22,7 @@ import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOInterceptor;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.WrappedException;
@@ -29,7 +30,6 @@ import org.eclipse.net4j.util.io.IOUtil;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
-import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import java.io.InputStream;
@@ -93,6 +93,8 @@ public class HibernateStore extends Store implements IHibernateStore
try
{
+ initConfiguration();
+
hibernateSessionFactory = hibernateConfiguration.buildSessionFactory();
}
finally
@@ -201,9 +203,6 @@ public class HibernateStore extends Store implements IHibernateStore
// Activate the package store
packageHandler.doActivate();
-
- initConfiguration();
- initSchema();
}
@Override
@@ -238,8 +237,6 @@ public class HibernateStore extends Store implements IHibernateStore
}
hibernateSessionFactory = null;
}
- initConfiguration();
- initSchema();
}
protected void initConfiguration()
@@ -269,6 +266,8 @@ public class HibernateStore extends Store implements IHibernateStore
in = OM.BUNDLE.getInputStream("mappings/resource.hbm.xml");
hibernateConfiguration.addInputStream(in);
+ hibernateConfiguration.setInterceptor(new CDOInterceptor());
+
hibernateConfiguration.setProperties(HibernateUtil.getInstance().getPropertiesFromStore(this));
}
catch (Exception ex)
@@ -281,16 +280,6 @@ public class HibernateStore extends Store implements IHibernateStore
}
}
- protected void initSchema()
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Updating db schema for HibernateStore");
- }
-
- new SchemaUpdate(hibernateConfiguration).execute(true, true);
- }
-
public static HibernateStore getCurrentHibernateStore()
{
return currentHibernateStore.get();
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreReader.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreReader.java
index 96ead98..24e3f75 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreReader.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreReader.java
@@ -11,18 +11,11 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.hibernate;
-import org.eclipse.emf.cdo.internal.protocol.model.CDOClassProxy;
-import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOClass;
-import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOFeature;
-import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOPackage;
import org.eclipse.emf.cdo.protocol.id.CDOID;
-import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.cdo.protocol.model.CDOModelUtil;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOPackageInfo;
-import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.protocol.model.resource.CDOResourceClass;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.server.ISession;
@@ -86,56 +79,7 @@ public class HibernateStoreReader extends HibernateStoreAccessor implements IHib
public void readPackage(CDOPackage cdoPackage)
{
- final CDOPackage dbPackage = getStore().getPackageHandler().getCDOPackage(cdoPackage.getPackageURI());
- ((InternalCDOPackage)cdoPackage).setServerInfo(dbPackage.getServerInfo());
- ((InternalCDOPackage)cdoPackage).setName(dbPackage.getName());
- ((InternalCDOPackage)cdoPackage).setEcore(dbPackage.getEcore());
-
- ((InternalCDOPackage)cdoPackage).setMetaIDRange(cdoPackage.getMetaIDRange());
- copyCDOClasses(dbPackage, cdoPackage);
- }
-
- protected void copyCDOClasses(CDOPackage dbPackage, CDOPackage cdoPackage)
- {
- for (CDOClass dbCDOClass : dbPackage.getClasses())
- {
- final CDOClass cdoClass = CDOModelUtil.createClass(cdoPackage, dbCDOClass.getClassifierID(),
- dbCDOClass.getName(), dbCDOClass.isAbstract());
- ((InternalCDOClass)cdoClass).setServerInfo(dbCDOClass.getServerInfo());
- ((InternalCDOPackage)cdoPackage).addClass(cdoClass);
- for (CDOClass dbSuperCDOClass : dbCDOClass.getSuperTypes())
- {
- ((InternalCDOClass)cdoClass).addSuperType(CDOModelUtil.createClassRef(dbSuperCDOClass.getContainingPackage()
- .getPackageURI(), dbSuperCDOClass.getClassifierID()));
- }
-
- for (CDOFeature dbCDOFeature : dbCDOClass.getFeatures())
- {
- int featureID = dbCDOFeature.getFeatureID();
- String name = dbCDOFeature.getName();
- CDOType type = dbCDOFeature.getType();
- boolean many = dbCDOFeature.isMany();
-
- CDOFeature feature;
- if (type == CDOType.OBJECT)
- {
- String packageURI = dbCDOFeature.getReferenceType().getContainingPackage().getPackageURI();
- int classifierID = dbCDOFeature.getReferenceType().getClassifierID();
- boolean containment = dbCDOFeature.isContainment();
- CDOClassRef classRef = CDOModelUtil.createClassRef(packageURI, classifierID);
- CDOClassProxy referenceType = new CDOClassProxy(classRef, cdoClass.getPackageManager());
- feature = CDOModelUtil.createReference(cdoClass, featureID, name, referenceType, many, containment);
- }
- else
- {
- feature = CDOModelUtil.createAttribute(cdoClass, featureID, name, type, many);
- }
-
- ((InternalCDOFeature)feature).setServerInfo(dbCDOFeature.getServerInfo());
- ((InternalCDOClass)cdoClass).addFeature(feature);
- }
- }
- ;
+ getStore().getPackageHandler().readPackage(cdoPackage);
}
public Collection<CDOPackageInfo> readPackageInfos()
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreWriter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreWriter.java
index 03c18f5..e9406e0 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreWriter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreWriter.java
@@ -48,6 +48,7 @@ public class HibernateStoreWriter extends HibernateStoreReader implements IHiber
{
TRACER.trace("Committing transaction");
}
+ HibernateThreadContext.setCommitContext(context);
writePackages(context.getNewPackages());
@@ -55,7 +56,6 @@ public class HibernateStoreWriter extends HibernateStoreReader implements IHiber
{
// start with fresh hibernate session
final Session session = getHibernateSession();
- HibernateThreadContext.setCommitContext(context);
session.setFlushMode(FlushMode.COMMIT);
session.beginTransaction();
for (Object o : context.getNewObjects())
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java
index 06b89a0..174f55f 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java
@@ -72,6 +72,11 @@ public class HibernateThreadContext
return result;
}
+ public static boolean isCommitContextSet()
+ {
+ return commitContext.get() != null;
+ }
+
public static void setCommitContext(CommitContext newCommitContext)
{
if (newCommitContext != null && commitContext.get() != null)
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 08de25c..8cf8a07 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
@@ -10,7 +10,9 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.hibernate;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.internal.protocol.id.CDOIDNullImpl;
+import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
import org.eclipse.emf.cdo.protocol.id.CDOID;
import org.eclipse.emf.cdo.protocol.id.CDOIDTemp;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
@@ -86,6 +88,20 @@ public class HibernateUtil
return (CDOIDHibernate)cdoRevision.getID();
}
+ public InternalCDORevision getCDORevision(Object target)
+ {
+ final InternalCDORevision revision;
+ if (target instanceof CDOObject)
+ {
+ revision = (InternalCDORevision)((CDOObject)target).cdoRevision();
+ }
+ else
+ {
+ revision = (InternalCDORevision)target;
+ }
+ return revision;
+ }
+
/**
* Gets a current object, first checks the new and dirty objects from the commitcontent. Otherwise reads it from the
* session.
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOFeatureReferenceTypePropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOFeatureReferenceTypePropertyHandler.java
new file mode 100644
index 0000000..cddd3aa
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOFeatureReferenceTypePropertyHandler.java
@@ -0,0 +1,95 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) 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
+ * </copyright>
+ *
+ * $Id: CDOFeatureReferenceTypePropertyHandler.java,v 1.1 2008-04-24 11:47:07 mtaal Exp $
+ */
+
+package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.model.CDOType;
+
+import org.hibernate.HibernateException;
+import org.hibernate.PropertyNotFoundException;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.property.Getter;
+import org.hibernate.property.PropertyAccessor;
+import org.hibernate.property.Setter;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Is only used for synthetic id's.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+@SuppressWarnings("unchecked")
+public class CDOFeatureReferenceTypePropertyHandler implements Getter, Setter, PropertyAccessor
+{
+ private static final long serialVersionUID = 4707601844087591747L;
+
+ public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Object get(Object owner) throws HibernateException
+ {
+ final CDOFeature cdoFeature = (CDOFeature)owner;
+ if (cdoFeature.getType() != CDOType.OBJECT)
+ {
+ return null;
+ }
+ return cdoFeature.getReferenceType();
+ }
+
+ public Object getForInsert(Object arg0, Map arg1, SessionImplementor arg2) throws HibernateException
+ {
+ return get(arg0);
+ }
+
+ public Method getMethod()
+ {
+ return null;
+ }
+
+ public String getMethodName()
+ {
+ return null;
+ }
+
+ public Class getReturnType()
+ {
+ return null;
+ }
+
+ public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException
+ {
+ final CDOFeatureImpl cdoFeature = (CDOFeatureImpl)target;
+ if (cdoFeature.getType() != CDOType.OBJECT)
+ {
+ return;
+ }
+ cdoFeature.setReferenceType((CDOClass)value);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java
index 3f06276..1ab47d1 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java
@@ -52,6 +52,10 @@ public class CDOIDMetaRangeUserType implements UserType
public Object deepCopy(Object value)
{
+ if (value == null)
+ {
+ return null;
+ }
final CDOIDMetaRange cdoRange = (CDOIDMetaRange)value;
final CDOIDMeta newCdoIDMeta = new CDOIDMetaImpl(((CDOIDMetaImpl)cdoRange.getLowerBound()).getLongValue());
return new CDOIDMetaRangeImpl(newCdoIDMeta, cdoRange.size());
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java
index 57e5edd..33d5e29 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java
@@ -67,6 +67,10 @@ public class CDOIDPropertySetter extends CDOPropertySetter
throw new IllegalStateException("Current id and new id are different " + value + "/" + hbCDOID.getId());
}
}
+ if (!isVirtualProperty())
+ {
+ super.set(target, value, factory);
+ }
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java
new file mode 100644
index 0000000..1ed448c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Springsite B.V. 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.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
+
+import org.hibernate.EmptyInterceptor;
+
+/**
+ * Resolves entitynames, todo: use entityname strategy!
+ *
+ * @author Martin Taal
+ */
+public class CDOInterceptor extends EmptyInterceptor
+{
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getEntityName(Object object)
+ {
+ if (object instanceof CDOObject)
+ {
+ return ((CDOObject)object).cdoClass().getName();
+ }
+ final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(object);
+ return revision.getCDOClass().getName();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java
index b6a1307..b5e7f9c 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java
@@ -13,10 +13,10 @@ package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.revision.CDORevisionUtil;
-import org.eclipse.emf.cdo.server.IPackageManager;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IRevisionManager;
import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.Instantiator;
@@ -37,8 +37,8 @@ public class CDORevisionInstantiator implements Instantiator
public CDORevisionInstantiator(CDORevisionTuplizer tuplizer, PersistentClass mappingInfo)
{
cdoClass = tuplizer.getCDOClass();
- IPackageManager packageManager = (IPackageManager)cdoClass.getPackageManager();
- IRepository repository = packageManager.getRepository();
+ final HibernateStore hbStore = HibernateStore.getCurrentHibernateStore();
+ IRepository repository = hbStore.getRepository();
revisionManager = repository.getRevisionManager();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java
new file mode 100644
index 0000000..432e3da
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java
@@ -0,0 +1,129 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) 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
+ * </copyright>
+ *
+ * $Id: CDOSyntheticIdPropertyHandler.java,v 1.1 2008-04-24 11:47:07 mtaal Exp $
+ */
+
+package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.protocol.id.CDOID;
+import org.eclipse.emf.cdo.protocol.id.CDOIDTemp;
+import org.eclipse.emf.cdo.server.IStoreWriter.CommitContext;
+import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate;
+import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
+
+import org.hibernate.HibernateException;
+import org.hibernate.PropertyNotFoundException;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.property.Getter;
+import org.hibernate.property.PropertyAccessor;
+import org.hibernate.property.Setter;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Is only used for synthetic id's.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+@SuppressWarnings("unchecked")
+public class CDOSyntheticIdPropertyHandler implements Getter, Setter, PropertyAccessor
+{
+ private static final long serialVersionUID = 4707601844087591747L;
+
+ public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Object get(Object owner) throws HibernateException
+ {
+ final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(owner);
+ if (revision == null)
+ {
+ return null;
+ }
+ if (!(revision.getID() instanceof CDOIDHibernate))
+ {
+ return null;
+ }
+
+ final CDOIDHibernate cdoID = (CDOIDHibernate)revision.getID();
+ return cdoID.getId();
+ }
+
+ public Object getForInsert(Object arg0, Map arg1, SessionImplementor arg2) throws HibernateException
+ {
+ return get(arg0);
+ }
+
+ public Method getMethod()
+ {
+ return null;
+ }
+
+ public String getMethodName()
+ {
+ return null;
+ }
+
+ public Class getReturnType()
+ {
+ return null;
+ }
+
+ public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException
+ {
+ if (value == null)
+ {
+ return;
+ }
+
+ final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(target);
+ final CDOID cdoID = revision.getID();
+ if (cdoID == null)
+ {
+ final CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value,
+ revision.getCDOClass().getName());
+ revision.setID(newCDOID);
+ }
+ else if (cdoID instanceof CDOIDTemp)
+ {
+ final CommitContext commitContext = HibernateThreadContext.getCommitContext();
+ final CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value,
+ revision.getCDOClass().getName());
+ revision.setID(newCDOID);
+ commitContext.addIDMapping((CDOIDTemp)cdoID, newCDOID);
+ }
+ else
+ {
+ final CDOIDHibernate hbCDOID = (CDOIDHibernate)revision.getID();
+ if (!hbCDOID.getId().equals(value))
+ {
+ throw new IllegalStateException("Current id and new id are different " + value + "/" + hbCDOID.getId());
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java
new file mode 100644
index 0000000..81339e3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java
@@ -0,0 +1,107 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) 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
+ * </copyright>
+ *
+ * $Id: CDOSyntheticVersionPropertyHandler.java,v 1.1 2008-04-24 11:47:07 mtaal Exp $
+ */
+
+package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
+
+import org.hibernate.HibernateException;
+import org.hibernate.PropertyNotFoundException;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.property.Getter;
+import org.hibernate.property.PropertyAccessor;
+import org.hibernate.property.Setter;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Reads the version from the internal version cache.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+@SuppressWarnings("unchecked")
+public class CDOSyntheticVersionPropertyHandler implements Getter, Setter, PropertyAccessor
+{
+ /**
+ * Generated Serial Version ID
+ */
+ private static final long serialVersionUID = -7004553329654520847L;
+
+ public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException
+ {
+ return this;
+ }
+
+ public Object get(Object owner) throws HibernateException
+ {
+ final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(owner);
+ if (revision == null)
+ {
+ return null;
+ }
+ return revision.getVersion();
+ }
+
+ /**
+ * Reads the version from the versioncache
+ */
+ public Object getForInsert(Object owner, Map mergeMap, SessionImplementor session) throws HibernateException
+ {
+ return get(owner);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.hibernate.property.Getter#getMethod()
+ */
+ public Method getMethod()
+ {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.hibernate.property.Getter#getMethodName()
+ */
+ public String getMethodName()
+ {
+ return null;
+ }
+
+ /** Returns Integer.class */
+ public Class getReturnType()
+ {
+ return Integer.class;
+ }
+
+ /** Sets the version in the internal version cache */
+ public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException
+ {
+ final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(target);
+ revision.setVersion(((Number)value).intValue());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTests.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTests.java
index d9cdf41..2532da4 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTests.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.tests.InitialTest;
import org.eclipse.emf.cdo.tests.InvalidationTest;
import org.eclipse.emf.cdo.tests.MangoTest;
import org.eclipse.emf.cdo.tests.NoLegacyTest;
-import org.eclipse.emf.cdo.tests.PackageRegistryTest;
import org.eclipse.emf.cdo.tests.ResourceTest;
import org.eclipse.emf.cdo.tests.RevisionDeltaTest;
import org.eclipse.emf.cdo.tests.RevisionHolderTest;
@@ -40,8 +39,10 @@ public class AllTests
StoreRepositoryProvider.setInstance(HbStoreRepositoryProvider.getInstance());
TestSuite suite = new TestSuite("Tests for CDO using Hibernate");
+ suite.addTestSuite(HibernatePackageRegistryTest.class);
+
+ suite.addTestSuite(ContainmentTest.class);
suite.addTestSuite(RevisionDeltaTest.class);
- suite.addTestSuite(HbTransactionDeadLockTest.class);
suite.addTestSuite(RollbackTest.class);
suite.addTestSuite(StateMachineTest.class);
suite.addTestSuite(RevisionHolderTest.class);
@@ -51,11 +52,10 @@ public class AllTests
suite.addTestSuite(NoLegacyTest.class);
suite.addTestSuite(ResourceTest.class);
suite.addTestSuite(InvalidationTest.class);
- suite.addTestSuite(ContainmentTest.class);
suite.addTestSuite(InitialTest.class);
suite.addTestSuite(ViewTest.class);
suite.addTestSuite(IndexReconstructionTest.class);
- suite.addTestSuite(PackageRegistryTest.class);
+ suite.addTestSuite(HbTransactionDeadLockTest.class);
// These fail for standard cdo >>>
// suite.addTestSuite(DymamicEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java
index bfdac10..03ebd4b 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java
@@ -32,6 +32,8 @@ import java.util.Properties;
*/
public class HbStoreRepositoryProvider extends StoreRepositoryProvider
{
+ public static final String MAPPING_FILE = "mappingfile";
+
private static HbStoreRepositoryProvider instance = new HbStoreRepositoryProvider();
public static HbStoreRepositoryProvider getInstance()
@@ -86,7 +88,7 @@ public class HbStoreRepositoryProvider extends StoreRepositoryProvider
{
IHibernateMappingProvider mappingProvider = new TeneoHibernateMappingProvider();
// return new HibernateStore(props, mappingProvider);
- // IHibernateMappingProvider mappingProvider = new HibernateFileMappingProvider("/mappings/product.hbm.xml");
+ // IHibernateMappingProvider mappingProvider = new CDOInterceptor("/mappings/product.hbm.xml");
return new HibernateStore(mappingProvider);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernatePackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernatePackageRegistryTest.java
new file mode 100644
index 0000000..ea83c9b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernatePackageRegistryTest.java
@@ -0,0 +1,82 @@
+/***************************************************************************
+ * 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests.hibernate;
+
+import org.eclipse.emf.cdo.tests.PackageRegistryTest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Overrides the real testclass because it needs some specific create-drop settings for specific testcases. This is not
+ * the nicest way of doing this but it is short and easy to understand.
+ */
+public class HibernatePackageRegistryTest extends PackageRegistryTest
+{
+
+ private String hbm2ddlValue = null;
+
+ // allows a testcase to pass specific properties
+ @Override
+ protected Map<String, String> getTestProperties()
+ {
+ final Map<String, String> testProperties = new HashMap<String, String>();
+ if (getHbm2ddlValue() != null)
+ {
+ testProperties.put("hibernate.hbm2ddl.auto", getHbm2ddlValue());
+ }
+ return testProperties;
+ }
+
+ @Override
+ // this testcase can't handle create-drop because in the middle of the
+ // testcase a new package is written to the db
+ public void testCommitUnrelatedPackage() throws Exception
+ {
+ setHbm2ddlValue("update");
+ // this needs to be extra because in doSetup it is unknown which testcase is being run
+ doTearDown();
+ doSetUp();
+ try
+ {
+ super.testCommitUnrelatedPackage();
+ }
+ finally
+ {
+ setHbm2ddlValue(null);
+ }
+ }
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ System.err.println("Called dosetup");
+ super.doSetUp();
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ System.err.println("Called doteardown");
+ super.doTearDown();
+ }
+
+ public String getHbm2ddlValue()
+ {
+ return hbm2ddlValue;
+ }
+
+ public void setHbm2ddlValue(String hbm2ddlValue)
+ {
+ this.hbm2ddlValue = hbm2ddlValue;
+ }
+}