Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-02-02 11:47:40 +0000
committerEike Stepper2008-02-02 11:47:40 +0000
commita9c20f406c68c1f9b93d658173128cc81dcf7525 (patch)
treee8a401f1a774c4cd514979924d9ed3d2c4918e76
parente4bd8b54e23068e6bbd2a48aeaf86561c280021a (diff)
downloadcdo-a9c20f406c68c1f9b93d658173128cc81dcf7525.tar.gz
cdo-a9c20f406c68c1f9b93d658173128cc81dcf7525.tar.xz
cdo-a9c20f406c68c1f9b93d658173128cc81dcf7525.zip
[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/HibernateTest.java115
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java8
3 files changed, 123 insertions, 1 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 2eaf09859a..c74c605232 100644
--- a/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
org.eclipse.net4j.jvm;bundle-version="0.8.0";resolution:=optional,
org.eclipse.net4j.tcp;bundle-version="[0.8.0,0.9.0)";resolution:=optional,
org.eclipse.emf.cdo.server;bundle-version="[0.8.0,0.9.0)",
+ org.eclipse.emf.cdo.server.hibernate;bundle-version="[0.8.0,0.9.0)";resolution:=optional,
org.eclipse.emf.cdo;bundle-version="[0.8.0,0.9.0)",
org.eclipse.emf.cdo.tests.model1;bundle-version="[0.8.0,0.9.0)",
org.eclipse.emf.cdo.tests.mango;bundle-version="[0.8.0,0.9.0)",
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/HibernateTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/HibernateTest.java
new file mode 100644
index 0000000000..25df8717ac
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/HibernateTest.java
@@ -0,0 +1,115 @@
+/***************************************************************************
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.server.CDOServerUtil;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.server.IRepository.Props;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.tests.model1.Product;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+
+import org.hibernate.cfg.Configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class HibernateTest
+{
+ private static final String REPOSITORY_NAME = "repo1";
+
+ public static void main(String[] args)
+ {
+ // Turn on tracing
+ OMPlatform.INSTANCE.setDebugging(true);
+
+ // Prepare the standalone infra structure (not needed when running inside Eclipse)
+ IManagedContainer container = ContainerUtil.createContainer(); // Create a wiring container
+ Net4jUtil.prepareContainer(container); // Prepare the Net4j kernel
+ JVMUtil.prepareContainer(container); // Prepare the JVM transport
+ CDOServerUtil.prepareContainer(container); // Prepare the CDO server
+ CDOUtil.prepareContainer(container, false); // Prepare the CDO client
+
+ // Start the transport and create a repository
+ JVMUtil.getAcceptor(container, "default"); // Start the JVM transport
+ CDOServerUtil.addRepository(container, createRepository()); // Start a CDO respository
+
+ // Establish a communications connection and open a session with the repository
+ IConnector connector = JVMUtil.getConnector(container, "default"); // Open a JVM connection
+ CDOSession session = CDOUtil.openSession(connector, REPOSITORY_NAME, true);// Open a CDO session
+ session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);// Not needed after first commit!!!
+
+ CDOTransaction transaction = session.openTransaction();// Open a CDO transaction
+ Resource resource = transaction.createResource("/my/big/resource");// Create a new EMF resource
+
+ // Work normally with the EMF resource
+ EObject inputModel = getInputModel();
+ resource.getContents().add(inputModel);
+ transaction.commit();
+ session.close();
+ connector.disconnect();
+ }
+
+ private static IRepository createRepository()
+ {
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(Props.PROP_SUPPORTING_AUDITS, "false");
+ props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "true");
+ props.put(Props.PROP_VERIFYING_REVISIONS, "false");
+ props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
+ props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
+ return CDOServerUtil.createRepository(REPOSITORY_NAME, createStore(), props);
+ }
+
+ private static IStore createStore()
+ {
+ Configuration configuration = new Configuration();
+ return new HibernateStore(configuration);
+ }
+
+ private static EObject getInputModel()
+ {
+ Category cat1 = Model1Factory.eINSTANCE.createCategory();
+ cat1.setName("CAT1");
+ Category cat2 = Model1Factory.eINSTANCE.createCategory();
+ cat2.setName("CAT2");
+ cat1.getCategories().add(cat2);
+ Product p1 = Model1Factory.eINSTANCE.createProduct();
+ p1.setName("P1");
+ cat1.getProducts().add(p1);
+ Product p2 = Model1Factory.eINSTANCE.createProduct();
+ p2.setName("P2");
+ cat1.getProducts().add(p2);
+ Product p3 = Model1Factory.eINSTANCE.createProduct();
+ p3.setName("P3");
+ cat2.getProducts().add(p3);
+ return cat1;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
index ad37f33874..96cff115aa 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
@@ -209,7 +209,13 @@ public abstract class AbstractBundle implements OMBundle
public InputStream getInputStream(String path) throws IOException
{
- URL url = new URL(getBaseURL().toString() + ".options"); //$NON-NLS-1$
+ String base = getBaseURL().toString();
+ if (!path.startsWith("/"))
+ {
+ base += "/";
+ }
+
+ URL url = new URL(base + path);
return url.openStream();
}

Back to the top