Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-08-11 11:24:13 +0000
committerEike Stepper2008-08-11 11:24:13 +0000
commit7673dd215cf345a7569d4f8628842567c7dda450 (patch)
tree44d2e9fd4451a177519769c7228abdaa8ebf93bd
parent5abef58c4a5449d9bbceea307bcfa52370febd5b (diff)
downloadcdo-7673dd215cf345a7569d4f8628842567c7dda450.tar.gz
cdo-7673dd215cf345a7569d4f8628842567c7dda450.tar.xz
cdo-7673dd215cf345a7569d4f8628842567c7dda450.zip
[243720] [Hibernate] Create HibernateStoreFactory
https://bugs.eclipse.org/bugs/show_bug.cgi?id=243720
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml27
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProvider.java (renamed from plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java)31
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProviderFactory.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java34
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoUtil.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/build.properties3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/plugin.xml12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/schema/mappingProviderFactories.exsd109
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java (renamed from plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateFileMappingProvider.java)31
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java62
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java46
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java42
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java64
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOAutomaticPackageRefTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOPackageRefTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HbStoreRepositoryProvider.java2
21 files changed, 517 insertions, 65 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
index f434453dd6..a0ab2f02b7 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
@@ -42,6 +42,7 @@ public final class CDODBUtil
store.setMappingStrategy(mappingStrategy);
store.setDbAdapter(dbAdapter);
store.setDbConnectionProvider(dbConnectionProvider);
+ mappingStrategy.setStore(store);
return store;
}
@@ -56,7 +57,6 @@ public final class CDODBUtil
*
* @see #createHorizontalMappingStrategy()
*/
-
public static IMappingStrategy createMappingStrategy(String type)
{
IExtensionRegistry registry = Platform.getExtensionRegistry();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
index d073c97929..db6460c008 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
@@ -14,7 +14,6 @@ import org.eclipse.emf.cdo.internal.server.RepositoryConfigurator;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreFactory;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.net4j.db.DBUtil;
@@ -51,9 +50,7 @@ public class DBStoreFactory implements IStoreFactory
IDBAdapter dbAdapter = getDBAdapter(storeConfig);
DataSource dataSource = getDataSource(storeConfig);
IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);
- IDBStore store = CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider);
- mappingStrategy.setStore(store);
- return store;
+ return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider);
}
private IMappingStrategy getMappingStrategy(Element storeConfig)
@@ -61,7 +58,7 @@ public class DBStoreFactory implements IStoreFactory
NodeList mappingStrategyConfigs = storeConfig.getElementsByTagName("mappingStrategy");
if (mappingStrategyConfigs.getLength() != 1)
{
- throw new IllegalStateException("Exactly one mappingStrategy must be configured for DB store");
+ throw new IllegalStateException("Exactly one mapping strategy must be configured for DB store");
}
Element mappingStrategyConfig = (Element)mappingStrategyConfigs.item(0);
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
index f9f1113cfa..7a63178dc0 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
@@ -10,4 +10,8 @@ Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)",
org.eclipse.emf.cdo.server.hibernate;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Import-Package: org.eclipse.emf.teneo.hibernate.cdo,
org.hibernate.cfg
-Export-Package: org.eclipse.emf.cdo.server.hibernate.teneo;version="2.0.0"
+Export-Package: org.eclipse.emf.cdo.server.hibernate.internal.teneo;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate,org.eclipse.emf.cdo.tests.hibernate.client",
+ org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate,org.eclipse.emf.cdo.tests.hibernate.client",
+ org.eclipse.emf.cdo.server.hibernate.teneo;version="2.0.0"
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM$Activator
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties
index fe8d7f10f7..1058de4abd 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties
@@ -5,4 +5,5 @@ bin.includes = META-INF/,\
copyright.txt,\
epl-v10.html,\
license.html,\
- plugin.properties
+ plugin.properties,\
+ plugin.xml
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml
new file mode 100644
index 0000000000..81fefe82a4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.3"?>
+<!--
+ <copyright>
+
+ 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
+
+ </copyright>
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.emf.cdo.server.hibernate.mappingProviderFactories">
+ <mappingProviderFactory
+ class="org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProviderFactory"
+ type="teneo"/>
+ </extension>
+
+</plugin>
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/internal/teneo/TeneoHibernateMappingProvider.java
index b456a3291f..6e5c573c44 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/internal/teneo/TeneoHibernateMappingProvider.java
@@ -9,14 +9,13 @@
* Martin Taal - initial API and implementation
* Eike Stepper - http://bugs.eclipse.org/238300
**************************************************************************/
-package org.eclipse.emf.cdo.server.hibernate.teneo;
+package org.eclipse.emf.cdo.server.hibernate.internal.teneo;
import org.eclipse.emf.cdo.common.model.CDOPackage;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
+import org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateMappingProvider;
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.net4j.util.WrappedException;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -45,11 +44,19 @@ import java.util.Properties;
* @author Martin Taal
* @author Eike Stepper
*/
-public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
+public class TeneoHibernateMappingProvider extends HibernateMappingProvider
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TeneoHibernateMappingProvider.class);
- private IHibernateStore hibernateStore;
+ public TeneoHibernateMappingProvider()
+ {
+ }
+
+ @Override
+ public HibernateStore getHibernateStore()
+ {
+ return (HibernateStore)super.getHibernateStore();
+ }
public void addMapping(Configuration configuration)
{
@@ -84,7 +91,7 @@ public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
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 : ((HibernateStore)hibernateStore).getPackageHandler().getCDOPackages())
+ for (CDOPackage cdoPackage : getHibernateStore().getPackageHandler().getCDOPackages())
{
if (TRACER.isEnabled())
{
@@ -149,14 +156,4 @@ public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
resolveSubPackages(subEPackage, result);
}
}
-
- public IHibernateStore getHibernateStore()
- {
- return hibernateStore;
- }
-
- public void setHibernateStore(IHibernateStore hibernateStore)
- {
- this.hibernateStore = hibernateStore;
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProviderFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProviderFactory.java
new file mode 100644
index 0000000000..865d4b0b60
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProviderFactory.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.hibernate.internal.teneo;
+
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+
+import org.w3c.dom.Element;
+
+/**
+ * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class TeneoHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory
+{
+ public static final String TYPE = "teneo";
+
+ public TeneoHibernateMappingProviderFactory()
+ {
+ }
+
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ public TeneoHibernateMappingProvider create(Element config)
+ {
+ return new TeneoHibernateMappingProvider();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java
new file mode 100644
index 0000000000..5b84ae58cc
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java
@@ -0,0 +1,34 @@
+package org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server.hibernate.teneo"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoUtil.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoUtil.java
new file mode 100644
index 0000000000..9d11caea8e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoUtil.java
@@ -0,0 +1,30 @@
+/***************************************************************************
+ * 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.server.hibernate.teneo;
+
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public final class TeneoUtil
+{
+ private TeneoUtil()
+ {
+ }
+
+ public static IHibernateMappingProvider createMappingProvider()
+ {
+ return new TeneoHibernateMappingProvider();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/build.properties b/plugins/org.eclipse.emf.cdo.server.hibernate/build.properties
index d936599c9b..8e73fbd4d7 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/build.properties
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/build.properties
@@ -24,4 +24,5 @@ bin.includes = META-INF/,\
about.ini,\
about.mappings,\
about.properties,\
- modeling32.png
+ modeling32.png,\
+ schema/
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/plugin.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/plugin.xml
index fa269f23cf..dc15ee9f36 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/plugin.xml
@@ -17,12 +17,20 @@
<plugin>
+ <extension-point id="mappingProviderFactories" name="Hibernate Mapping Provider Factories" schema="schema/mappingProviderFactories.exsd"/>
+
<extension
point="org.eclipse.emf.cdo.server.storeFactories">
<storeFactory
class="org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreFactory"
- storeType="hibernate">
- </storeFactory>
+ storeType="hibernate"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.emf.cdo.server.hibernate.mappingProviderFactories">
+ <mappingProviderFactory
+ class="org.eclipse.emf.cdo.server.internal.hibernate.FileHibernateMappingProviderFactory"
+ type="file"/>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/schema/mappingProviderFactories.exsd b/plugins/org.eclipse.emf.cdo.server.hibernate/schema/mappingProviderFactories.exsd
new file mode 100644
index 0000000000..607ef46da2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/schema/mappingProviderFactories.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.cdo.server.hibernate" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.emf.cdo.server.hibernate" id="mappingProviderFactories" name="Hibernate Mapping Provider Factories"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="mappingProviderFactory" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="mappingProviderFactory">
+ <complexType>
+ <attribute name="type" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider$Factory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java
index 2b1ec7df41..9a453b780d 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.cdo.server.hibernate;
import org.hibernate.cfg.Configuration;
+import org.w3c.dom.Element;
/**
* A mappingprovider adds a hibernate mapping to a hibernate configuration object.
@@ -19,9 +20,31 @@ import org.hibernate.cfg.Configuration;
*/
public interface IHibernateMappingProvider
{
- /** Adds a mapping to a configuration object */
+ /**
+ * Adds a mapping to a configuration object
+ */
public void addMapping(Configuration configuration);
- /** Sets the Store in the mapping provider, is called before addMapping. */
+ /**
+ * Sets the Store in the mapping provider, is called before addMapping.
+ */
public void setHibernateStore(IHibernateStore hibernateStore);
+
+ /**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+ public interface Factory
+ {
+ /**
+ * Returns the type of the mapping providers this factory can create.
+ */
+ public String getType();
+
+ /**
+ * Creates a Hibernate mapping provider from the given element of the <code>cdo-server.xml</code> configuration
+ * file.
+ */
+ public IHibernateMappingProvider create(Element config);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateFileMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java
index f1853b3b0f..4c10311784 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateFileMappingProvider.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java
@@ -10,8 +10,6 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.hibernate;
-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.net4j.util.WrappedException;
@@ -27,32 +25,20 @@ import java.io.InputStream;
*
* @author Martin Taal
*/
-public class HibernateFileMappingProvider implements IHibernateMappingProvider
+public class FileHibernateMappingProvider extends HibernateMappingProvider
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HibernateFileMappingProvider.class);
-
- private IHibernateStore hibernateStore;
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, FileHibernateMappingProvider.class);
private final String[] mappingFileLocations;
- public HibernateFileMappingProvider(String location)
- {
- this(new String[] { location });
- }
-
- public HibernateFileMappingProvider(String[] locations)
- {
- mappingFileLocations = locations;
- }
-
- public IHibernateStore getHibernateStore()
+ public FileHibernateMappingProvider(String... mappingFileLocations)
{
- return hibernateStore;
- }
+ if (mappingFileLocations == null || mappingFileLocations.length == 0)
+ {
+ throw new IllegalArgumentException("mappingFileLocations");
+ }
- public void setHibernateStore(IHibernateStore hibernateStore)
- {
- this.hibernateStore = hibernateStore;
+ this.mappingFileLocations = mappingFileLocations;
}
public void addMapping(Configuration configuration)
@@ -70,6 +56,7 @@ public class HibernateFileMappingProvider implements IHibernateMappingProvider
}
InputStream is = null;
+
try
{
// MT.Question: the mapping file is in a dependent plugin but when using the OM.BUNDLE
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java
new file mode 100644
index 0000000000..3b99c9baed
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * 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;
+
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+
+import org.eclipse.net4j.util.StringUtil;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
+ *
+ * @author Martin Taal
+ */
+public class FileHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory
+{
+ public static final String TYPE = "file";
+
+ public FileHibernateMappingProviderFactory()
+ {
+ }
+
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ public FileHibernateMappingProvider create(Element config)
+ {
+ List<String> locations = new ArrayList<String>();
+ NodeList mappingFileConfigs = config.getElementsByTagName("mappingFile");
+ for (int i = 0; i < mappingFileConfigs.getLength(); i++)
+ {
+ Element mappingFile = (Element)mappingFileConfigs.item(i);
+ String location = mappingFile.getAttribute("location");
+ if (!StringUtil.isEmpty(location))
+ {
+ locations.add(location);
+ }
+ }
+
+ if (locations.isEmpty())
+ {
+ throw new IllegalStateException("No mapping file configured for file mapping provider");
+ }
+
+ return new FileHibernateMappingProvider(locations.toArray(new String[locations.size()]));
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java
new file mode 100644
index 0000000000..c497454434
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.internal.hibernate;
+
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class HibernateMappingProvider implements IHibernateMappingProvider
+{
+ private IHibernateStore hibernateStore;
+
+ public HibernateMappingProvider()
+ {
+ }
+
+ /**
+ * @return the hibernate store, never null.
+ * @throws IllegalStateException
+ * if the hibernate store is null.
+ */
+ public IHibernateStore getHibernateStore()
+ {
+ if (hibernateStore == null)
+ {
+ throw new IllegalStateException("hibernateStore is null");
+ }
+
+ return hibernateStore;
+ }
+
+ public void setHibernateStore(IHibernateStore hibernateStore)
+ {
+ this.hibernateStore = hibernateStore;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java
index 6cda2111c7..ff1fb4005d 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java
@@ -10,10 +10,12 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.hibernate;
-import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreFactory;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* @author Eike Stepper
@@ -29,15 +31,35 @@ public class HibernateStoreFactory implements IStoreFactory
return HibernateStore.TYPE;
}
- public IStore createStore(Element storeConfig)
+ public IHibernateStore createStore(Element storeConfig)
{
- throw new UnsupportedOperationException(); // TODO Implement me
- // IMappingStrategy mappingStrategy = getMappingStrategy(storeConfig);
- // IDBAdapter dbAdapter = getDBAdapter(storeConfig);
- // DataSource dataSource = getDataSource(storeConfig);
- // IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);
- // HibernateStore store = new HibernateStore(mappingStrategy, dbAdapter, connectionProvider);
- // mappingStrategy.setStore(store);
- // return store;
+ IHibernateMappingProvider mappingProvider = getMappingProvider(storeConfig);
+ return HibernateUtil.getInstance().createStore(mappingProvider);
+ }
+
+ private IHibernateMappingProvider getMappingProvider(Element storeConfig)
+ {
+ NodeList mappingProviderConfigs = storeConfig.getElementsByTagName("mappingProvider");
+ if (mappingProviderConfigs.getLength() != 1)
+ {
+ throw new IllegalStateException("Exactly one mapping provider must be configured for Hibernate store");
+ }
+
+ Element mappingProviderConfig = (Element)mappingProviderConfigs.item(0);
+ String mappingProviderType = mappingProviderConfig.getAttribute("type");
+ IHibernateMappingProvider.Factory factory = HibernateUtil.getInstance().createMappingProviderFactory(
+ mappingProviderType);
+ if (factory == null)
+ {
+ throw new IllegalArgumentException("Unknown mapping provider type: " + mappingProviderType);
+ }
+
+ IHibernateMappingProvider mappingProvider = factory.create(mappingProviderConfig);
+ if (mappingProvider == null)
+ {
+ throw new IllegalArgumentException("No mapping provider created: " + mappingProviderType);
+ }
+
+ return mappingProvider;
}
}
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 eeca53c470..5dca5b282d 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
@@ -15,9 +15,20 @@ import org.eclipse.emf.cdo.common.id.CDOIDTemp;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.StoreUtil;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate;
+import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.WrappedException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
import org.hibernate.Session;
import java.util.Map;
@@ -28,6 +39,8 @@ import java.util.Properties;
*/
public class HibernateUtil
{
+ private static final String EXT_POINT = "mappingProviderFactories";
+
private static HibernateUtil instance = new HibernateUtil();
/**
@@ -50,6 +63,57 @@ public class HibernateUtil
/**
* @since 2.0
*/
+ public IHibernateStore createStore(IHibernateMappingProvider mappingProvider)
+ {
+ HibernateStore store = new HibernateStore(mappingProvider);
+ mappingProvider.setHibernateStore(store);
+ return store;
+ }
+
+ /**
+ * Can only be used when Eclipse is running. In standalone scenarios create the mapping strategy instance by directly
+ * calling the constructor of the mapping strategy class.
+ *
+ * @see #createFileMappingProvider(String...)
+ * @since 2.0
+ */
+ public IHibernateMappingProvider.Factory createMappingProviderFactory(String type)
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT);
+ for (final IConfigurationElement element : elements)
+ {
+ if ("mappingProviderFactory".equals(element.getName()))
+ {
+ String typeAttr = element.getAttribute("type");
+ if (ObjectUtil.equals(typeAttr, type))
+ {
+ try
+ {
+ return (IHibernateMappingProvider.Factory)element.createExecutableExtension("class");
+ }
+ catch (CoreException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IHibernateMappingProvider createFileMappingProvider(String... locations)
+ {
+ return new FileHibernateMappingProvider(locations);
+ }
+
+ /**
+ * @since 2.0
+ */
public Session getHibernateSession()
{
final HibernateStoreReader storeReader = (HibernateStoreReader)StoreUtil.getReader();
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOAutomaticPackageRefTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOAutomaticPackageRefTest.java
index a8fbff5fe9..9ad8d78226 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOAutomaticPackageRefTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOAutomaticPackageRefTest.java
@@ -7,7 +7,7 @@ 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.hibernate.teneo.TeneoHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
import org.eclipse.emf.cdo.util.CDOUtil;
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOPackageRefTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOPackageRefTest.java
index 51eea8623d..151963c954 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOPackageRefTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/CDOPackageRefTest.java
@@ -7,7 +7,7 @@ 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.hibernate.teneo.TeneoHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
import org.eclipse.emf.cdo.util.CDOUtil;
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 aef36e8454..a23946620b 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
@@ -15,7 +15,7 @@ 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.hibernate.IHibernateMappingProvider;
-import org.eclipse.emf.cdo.server.hibernate.teneo.TeneoHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
import org.eclipse.emf.cdo.tests.StoreRepositoryProvider;

Back to the top