summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-03-24 15:57:53 (EDT)
committerEike Stepper2008-03-24 15:57:53 (EDT)
commitfff4285351a1df07fd89ebc900dde7a6dafbfba0 (patch)
tree18b819f1edb038f704272f0c9ad3c82fa7511b4f
parent5a2c55b1d119816c208b5f224d5fa1d844da2160 (diff)
downloadcdo-fff4285351a1df07fd89ebc900dde7a6dafbfba0.zip
cdo-fff4285351a1df07fd89ebc900dde7a6dafbfba0.tar.gz
cdo-fff4285351a1df07fd89ebc900dde7a6dafbfba0.tar.bz2
[217117] Develop a HibernateStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217117
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java32
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java32
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManagerImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java3
5 files changed, 59 insertions, 11 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
index b4da8ce..6173f57 100644
--- a/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
@@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
org.eclipse.emf.cdo.server;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.eclipse.emf.cdo;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.eclipse.emf.cdo.tests.model1;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
+ org.eclipse.emf.cdo.tests.model2;bundle-version="[0.8.0,0.9.0)",
org.eclipse.emf.cdo.tests.mango;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.junit;visibility:=reexport
Export-Package: org.eclipse.emf.cdo.tests,
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
index 6baa148..ac9d807 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
@@ -17,6 +17,9 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.tests.model2.Model2Factory;
+import org.eclipse.emf.cdo.tests.model2.Model2Package;
+import org.eclipse.emf.cdo.tests.model2.SpecialPurchaseOrder;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.common.util.URI;
@@ -35,7 +38,7 @@ import java.io.IOException;
*/
public class PackageRegistryTest extends AbstractCDOTest
{
- public void testGeneratedPackage() throws Exception
+ public void __testGeneratedPackage() throws Exception
{
{
// Create resource in session 1
@@ -61,6 +64,33 @@ public class PackageRegistryTest extends AbstractCDOTest
}
}
+ public void testCommitTwoPackages() throws Exception
+ {
+ {
+ // Create resource in session 1
+ CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ session.getPackageRegistry().putEPackage(Model2Package.eINSTANCE);
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource res = transaction.createResource("/res");
+
+ SpecialPurchaseOrder specialPurchaseOrder = Model2Factory.eINSTANCE.createSpecialPurchaseOrder();
+ specialPurchaseOrder.setDiscountCode("12345");
+ res.getContents().add(specialPurchaseOrder);
+ transaction.commit();
+ }
+
+ // {
+ // // Load resource in session 2
+ // CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ // CDOTransaction transaction = session.openTransaction();
+ // CDOResource res = transaction.getResource("/res");
+ //
+ // Company company = (Company)res.getContents().get(0);
+ // assertEquals("Eike", company.getName());
+ // }
+ }
+
/**
* TODO Fix testDynamicPackage()
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
index 8261bb8..dbb4887 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
@@ -256,15 +256,27 @@ public final class EMFUtil
}
}
- public static String ePackageToString(EPackage ePackage)
+ public static String ePackageToString(EPackage ePackage, EPackage.Registry packageRegistry)
{
+ Resource.Factory resourceFactory = new XMIResourceFactoryImpl();
+ ResourceSetImpl resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", resourceFactory);
+ resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("*", resourceFactory);
+
+ Resource packageResource = createPackageResource(resourceSet, ePackage);
+ for (Object object : packageRegistry.values())
+ {
+ if (object != ePackage)
+ {
+ createPackageResource(resourceSet, (EPackage)object);
+ }
+ }
+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
- XMIResource resource = new XMIResourceImpl();
try
{
- resource.getContents().add(ePackage);
- resource.save(stream, null);
+ packageResource.save(stream, null);
return stream.toString(ECORE_ENCODING);
}
catch (RuntimeException ex)
@@ -275,10 +287,14 @@ public final class EMFUtil
{
throw new IORuntimeException(ex);
}
- finally
- {
- resource.getContents().clear();
- }
+ }
+
+ private static Resource createPackageResource(ResourceSetImpl resourceSet, EPackage ePackage)
+ {
+ URI uri = URI.createURI(ePackage.getNsURI());
+ Resource resource = resourceSet.createResource(uri);
+ resource.getContents().add(ePackage);
+ return resource;
}
/**
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManagerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManagerImpl.java
index 5053847..abc6bac 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManagerImpl.java
@@ -140,6 +140,6 @@ public class CDOSessionPackageManagerImpl extends CDOPackageManagerImpl implemen
protected String provideEcore(CDOPackage cdoPackage)
{
EPackage ePackage = ModelUtil.getEPackage(cdoPackage, session.getPackageRegistry());
- return EMFUtil.ePackageToString(ePackage);
+ return EMFUtil.ePackageToString(ePackage, session.getPackageRegistry());
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
index 07aba8f..749a96b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
@@ -159,7 +159,8 @@ public final class ModelUtil
// certain Ecore features (see newsgroup thread "eGenericSuperTypes" and
// EMFUtil.getPersistentFeatures()
- String ecore = EcorePackage.eINSTANCE.getNsURI().equals(packageURI) ? null : EMFUtil.ePackageToString(ePackage);
+ String ecore = EcorePackage.eINSTANCE.getNsURI().equals(packageURI) ? null : EMFUtil.ePackageToString(ePackage,
+ packageManager.getSession().getPackageRegistry());
// String ecore = EMFUtil.ePackageToString(ePackage);
CDOIDMetaRange idRange = packageManager.getSession().registerEPackage(ePackage);