summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2008-03-13 03:09:17 (EDT)
committerMartin Taal2008-03-13 03:09:17 (EDT)
commitc927a309b7877b352ecaeed0190a6f630b000d76 (patch)
treeb31c7706b2992ddea642187f8a96358f061e0f5e
parenteda66b5aa9b701ac34b5ee1c839a24367ad8530d (diff)
downloadcdo-c927a309b7877b352ecaeed0190a6f630b000d76.zip
cdo-c927a309b7877b352ecaeed0190a6f630b000d76.tar.gz
cdo-c927a309b7877b352ecaeed0190a6f630b000d76.tar.bz2
Implemented specific hibernate id types and changed mapping of hibernate id
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/.settings/org.eclipse.pde.core.prefs3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingContext.java104
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOTeneoException.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/TeneoHibernateMappingProvider.java108
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/product.hbm.xml218
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateMappingProvider.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateStore.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateFileMappingProvider.java87
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java46
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java57
14 files changed, 223 insertions, 470 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/.settings/org.eclipse.pde.core.prefs b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..e03b596
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,3 @@
+#Mon Mar 03 10:59:33 CET 2008
+eclipse.preferences.version=1
+resolve.requirebundle=false
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 d63d16b..4556252 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
@@ -4,10 +4,11 @@ Bundle-SymbolicName: org.eclipse.emf.cdo.server.hibernate.teneo;singleton:=true
Bundle-Name: %pluginName
Bundle-Version: 0.8.0.qualifier
Bundle-Vendor: %providerName
+Eclipse-BuddyPolicy: dependent
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)";visibility:=reexport,
+Require-Bundle: org.eclipse.emf.cdo.protocol;bundle-version="0.8.0",
+ org.eclipse.emf.teneo.hibernate.mapper;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.eclipse.emf.cdo.server.hibernate;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
- org.eclipse.emf.teneo;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
- org.eclipse.emf.teneo.annotations;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
- org.eclipse.emf.teneo.hibernate.mapper;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
+ org.eclipse.emf.ecore.xmi;bundle-version="2.4.0"
Export-Package: org.eclipse.emf.cdo.server.hibernate.teneo
+Import-Package: org.hibernate.cfg
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 34d2e4d..cf30ba7 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/build.properties
@@ -2,3 +2,4 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
+jars.extra.classpath = platform:/plugin/org.eclipse.emf.cdo.server.hibernate.libraries/lib/hibernate3.jar
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingContext.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingContext.java
deleted file mode 100644
index e4155c9..0000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingContext.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
-import org.eclipse.emf.teneo.hibernate.mapper.MappingContext;
-import org.eclipse.emf.teneo.simpledom.Element;
-
-/**
- * Mapping context for CDO. It provides cdo classes as propertyhandler etc.
- *
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- */
-public class CDOMappingContext extends MappingContext
-{
-
- /** Add a tuplizer element or not */
- @Override
- public void addTuplizerElement(Element entityElement, PAnnotatedEClass aclass)
- {
- Element tuplizerElement = new Element("tuplizer").addAttribute("entity-mode", "dynamic-map").addAttribute("class",
- "org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer");
- entityElement.add(0, tuplizerElement);
- tuplizerElement = new Element("tuplizer").addAttribute("entity-mode", "pojo").addAttribute("class",
- "org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer");
- entityElement.add(0, tuplizerElement);
- }
-
- @Override
- public String getComponentPropertyHandlerName()
- {
- return super.getComponentPropertyHandlerName();
- }
-
- @Override
- public String getIdPropertyHandlerName()
- {
- return null;
- }
-
- @Override
- public String getPropertyHandlerName()
- {
- return super.getPropertyHandlerName();
- }
-
- @Override
- public String getVersionPropertyHandlerName()
- {
- return null;
- }
-
- @Override
- public String getEnumUserType()
- {
- return super.getEnumUserType();
- }
-
- @Override
- public String getEnumIntegerUserType()
- {
- return super.getEnumIntegerUserType();
- }
-
- @Override
- public String getSyntheticIdPropertyHandlerName()
- {
- return super.getSyntheticIdPropertyHandlerName();
- }
-
- @Override
- public String getSyntheticVersionPropertyHandlerName()
- {
- return super.getSyntheticVersionPropertyHandlerName();
- }
-
- @Override
- public String getDynamicEnumUserType()
- {
- return super.getDynamicEnumIntegerUserType();
- }
-
- @Override
- public String getDynamicEnumIntegerUserType()
- {
- return super.getDynamicEnumIntegerUserType();
- }
-
- @Override
- public String getDefaultUserType()
- {
- return super.getDefaultUserType();
- }
-
- @Override
- public String getXSDDateUserType()
- {
- return super.getXSDDateUserType();
- }
-
- @Override
- public String getXSDDateTimeUserType()
- {
- return super.getXSDDateTimeUserType();
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOTeneoException.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOTeneoException.java
deleted file mode 100644
index 9bde9e2..0000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOTeneoException.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/***************************************************************************
- * 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:
- * Martin Taal - initial API and implementation
- **************************************************************************/
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-/**
- * Simple runtimeexception.
- *
- * @author Martin Taal
- */
-public class CDOTeneoException extends RuntimeException
-{
-
- private static final long serialVersionUID = 1L;
-
- public CDOTeneoException(String msg, Throwable cause)
- {
- super(msg, cause);
- }
-}
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 65a07bb..0eb32c4 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
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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
@@ -10,7 +10,14 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.hibernate.teneo;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
+import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
+import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
@@ -18,84 +25,82 @@ 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.teneo.extension.ExtensionManager;
-import org.eclipse.emf.teneo.extension.ExtensionManagerFactory;
-import org.eclipse.emf.teneo.extension.ExtensionUtil;
-import org.eclipse.emf.teneo.hibernate.mapper.MappingContext;
-import org.eclipse.emf.teneo.hibernate.mapper.MappingUtil;
+import org.eclipse.emf.teneo.hibernate.cdo.CDOHelper;
+
+import org.hibernate.cfg.Configuration;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
/**
- * Handles different cases of input modes: the modelObjects can be a collection of String (containing an ecore model) or
- * EPackage objects.
+ * Uses the ecore string in the cdoPackages of the store to generate a mapping.
*
* @author Martin Taal
*/
public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TeneoHibernateMappingProvider.class);
+
+ private IHibernateStore hibernateStore;
+
+ public void addMapping(Configuration configuration)
+ {
+ final String mapping = generateMapping();
+ TRACER.trace("Generated hibernate mapping:");
+ TRACER.trace(mapping);
+ configuration.addXML(mapping);
+ TRACER.trace("Added mapping to configuration");
+ }
+
// the passed modelObjects collection is defined as a collection of Objects
// to prevent binary dependency on emf.
- public String provideMapping(Collection<Object> modelObjects, Properties properties)
+ 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 (Object o : modelObjects)
+ for (String ecoreStr : models)
{
- if (o instanceof EPackage)
+ // 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 Resource resource = rs.createResource(epackageURI);
+ try
{
- epacks.addAll(resolveSubPackages((EPackage)o));
- }
- else
- { // assume a String read from it
- final String ecoreStr = (String)o;
- // 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 Resource resource = rs.createResource(epackageURI);
- try
- {
- resource.load(bis, Collections.EMPTY_MAP);
+ resource.load(bis, Collections.EMPTY_MAP);
- // now the toplevel content should be EPackage
- for (Object contentObject : resource.getContents())
- {
- epacks.addAll(resolveSubPackages((EPackage)contentObject));
- }
- }
- catch (Exception e)
+ // now the toplevel content should be EPackage
+ for (Object contentObject : resource.getContents())
{
- throw new CDOTeneoException("Exception when loading: " + ecoreStr, e);
+ epacks.addAll(resolveSubPackages((EPackage)contentObject));
}
}
+ catch (Exception e)
+ {
+ throw WrappedException.wrap(e);
+ }
}
// translate the list of EPackages to an array
final EPackage[] ePackageArray = epacks.toArray(new EPackage[epacks.size()]);
- // register the custom cdo extensions
- final ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create();
- registerCDOExtensions(extensionManager);
-
- // and go for it!
- return MappingUtil.generateMapping(ePackageArray, properties, extensionManager);
- }
-
- public void registerCDOExtensions(ExtensionManager extensionManager)
- {
- MappingUtil.registerHbExtensions(extensionManager);
- extensionManager.registerExtension(ExtensionUtil.createExtension(MappingContext.class, CDOMappingContext.class,
- false));
+ return CDOHelper.getInstance().generateMapping(ePackageArray, properties);
}
protected List<EPackage> resolveSubPackages(EPackage epack)
@@ -109,4 +114,13 @@ public class TeneoHibernateMappingProvider implements IHibernateMappingProvider
return epacks;
}
+ public IHibernateStore getHibernateStore()
+ {
+ return hibernateStore;
+ }
+
+ public void setHibernateStore(IHibernateStore hibernateStore)
+ {
+ this.hibernateStore = hibernateStore;
+ }
}
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 461da4c..2c6dcd9 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
@@ -11,7 +11,8 @@ 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.server;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
- org.eclipse.emf.cdo.server.hibernate.id;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"
Export-Package: org.eclipse.emf.cdo.server.hibernate,
org.eclipse.emf.cdo.server.internal.hibernate,
org.eclipse.emf.cdo.server.internal.hibernate.bundle,
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/product.hbm.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/product.hbm.xml
deleted file mode 100644
index 174d68a..0000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/product.hbm.xml
+++ /dev/null
@@ -1,218 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping auto-import="false">
- <class entity-name="Address" abstract="false" lazy="false" discriminator-value="Address" table="`address`">
- <meta attribute="eclassName">Address</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
- <meta attribute="syntheticId">true</meta>
- <generator class="native"/>
- </id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
- <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
- <column not-null="false" unique="false" name="`name`"/>
- </property>
- <property name="street" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
- <column not-null="false" unique="false" name="`street`"/>
- </property>
- <property name="city" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
- <column not-null="false" unique="false" name="`city`"/>
- </property>
- </class>
- <subclass entity-name="Company" abstract="false" lazy="false" extends="Address" discriminator-value="Company">
- <meta attribute="eclassName">Company</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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"/>
- <list name="categories" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="company_categories">
- <column name="`company_categories_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`company_categories_idx`"/>
- <one-to-many entity-name="Category"/>
- </list>
- <list name="suppliers" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="company_suppliers">
- <column name="`company_suppliers_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`company_suppliers_idx`"/>
- <one-to-many entity-name="Supplier"/>
- </list>
- <list name="customers" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="company_customers">
- <column name="`company_customers_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`company_customers_idx`"/>
- <one-to-many entity-name="Customer"/>
- </list>
- <list name="purchaseOrders" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="company_purchaseorders">
- <column name="`company_purchaseorders_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`company_purchaseorders_idx`"/>
- <one-to-many entity-name="PurchaseOrder"/>
- </list>
- <list name="salesOrders" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="company_salesorders">
- <column name="`company_salesorders_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`company_salesorders_idx`"/>
- <one-to-many entity-name="SalesOrder"/>
- </list>
- </subclass>
- <subclass entity-name="Supplier" abstract="false" lazy="false" extends="Address" discriminator-value="Supplier">
- <meta attribute="eclassName">Supplier</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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"/>
- <list name="purchaseOrders" lazy="true">
- <key update="true">
- <column name="`purchaseorder_supplier_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`supplier_purchaseorders_idx`"/>
- <one-to-many entity-name="PurchaseOrder"/>
- </list>
- </subclass>
- <subclass entity-name="Customer" abstract="false" lazy="false" extends="Address" discriminator-value="Customer">
- <meta attribute="eclassName">Customer</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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"/>
- <list name="salesOrders" lazy="true">
- <key update="true">
- <column name="`salesorder_customer_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`customer_salesorders_idx`"/>
- <one-to-many entity-name="SalesOrder"/>
- </list>
- </subclass>
- <class entity-name="Order" abstract="false" lazy="false" discriminator-value="Order" table="`order`">
- <meta attribute="eclassName">Order</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
- <meta attribute="syntheticId">true</meta>
- <generator class="native"/>
- </id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
- <list name="orderDetails" lazy="true" cascade="all,delete-orphan">
- <key update="true">
- <column name="`orderdetail_order_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`order_orderdetails_idx`"/>
- <one-to-many entity-name="OrderDetail"/>
- </list>
- </class>
- <class entity-name="OrderDetail" abstract="false" lazy="false" discriminator-value="OrderDetail" table="`orderdetail`">
- <meta attribute="eclassName">OrderDetail</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
- <meta attribute="syntheticId">true</meta>
- <generator class="native"/>
- </id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
- <many-to-one name="order" entity-name="Order" foreign-key="orderdetail_order" lazy="false" insert="false" update="false" not-null="false">
- <column not-null="false" unique="false" name="`orderdetail_order_e_id`"/>
- </many-to-one>
- <many-to-one name="product" entity-name="Product" foreign-key="orderdetail_product" lazy="false" insert="false" update="false" not-null="false">
- <column not-null="false" unique="false" name="`orderdetail_product_e_id`"/>
- </many-to-one>
- <property name="price" lazy="false" insert="true" update="true" not-null="false" unique="false" type="float">
- <column not-null="false" unique="false" name="`price`"/>
- </property>
- </class>
- <subclass entity-name="PurchaseOrder" abstract="false" lazy="false" extends="Order" discriminator-value="PurchaseOrder">
- <meta attribute="eclassName">PurchaseOrder</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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"/>
- <property name="date" lazy="false" insert="true" update="true" not-null="false" unique="false" type="timestamp">
- <column not-null="false" unique="false" name="`date`"/>
- </property>
- <many-to-one name="supplier" entity-name="Supplier" foreign-key="purchaseorder_supplier" lazy="false" insert="false" update="false" not-null="false">
- <column not-null="false" unique="false" name="`purchaseorder_supplier_e_id`"/>
- </many-to-one>
- </subclass>
- <subclass entity-name="SalesOrder" abstract="false" lazy="false" extends="Order" discriminator-value="SalesOrder">
- <meta attribute="eclassName">SalesOrder</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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"/>
- <property name="id" lazy="false" insert="true" update="true" not-null="false" unique="false" type="int">
- <column not-null="false" unique="false" name="`id`"/>
- </property>
- <many-to-one name="customer" entity-name="Customer" foreign-key="salesorder_customer" lazy="false" insert="false" update="false" not-null="false">
- <column not-null="false" unique="false" name="`salesorder_customer_e_id`"/>
- </many-to-one>
- </subclass>
- <class entity-name="Category" abstract="false" lazy="false" discriminator-value="Category" table="`category`">
- <meta attribute="eclassName">Category</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
- <meta attribute="syntheticId">true</meta>
- <generator class="native"/>
- </id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
- <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
- <column not-null="false" unique="false" name="`name`"/>
- </property>
- <list name="categories" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="category_categories">
- <column name="`category_categories_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`category_categories_idx`"/>
- <one-to-many entity-name="Category"/>
- </list>
- <list name="products" lazy="true" cascade="all,delete-orphan">
- <key update="true" foreign-key="category_products">
- <column name="`category_products_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`category_products_idx`"/>
- <one-to-many entity-name="Product"/>
- </list>
- </class>
- <class entity-name="Product" abstract="false" lazy="false" discriminator-value="Product" table="`product`">
- <meta attribute="eclassName">Product</meta>
- <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/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" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
- <meta attribute="syntheticId">true</meta>
- <generator class="native"/>
- </id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
- <meta attribute="syntheticVersion">true</meta>
- </version>
- <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
- <column not-null="false" unique="false" name="`name`"/>
- </property>
- <list name="orderDetails" lazy="true">
- <key update="true">
- <column name="`orderdetail_product_e_id`" not-null="false" unique="false"/>
- </key>
- <list-index column="`product_orderdetails_idx`"/>
- <one-to-many entity-name="OrderDetail"/>
- </list>
- </class>
-</hibernate-mapping>
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 3b538de..cf897fa 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
@@ -10,20 +10,19 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.hibernate;
-import java.util.Collection;
-import java.util.Properties;
+import org.hibernate.cfg.Configuration;
/**
- * Provides or generates a hibernate mapping on the basis of a set of EPackages and properties. An example of a
- * hibernate mapping provider is Teneo, another provider can read the mapping from a hbm file based on the file location
- * passed as a property.
+ * A mappingprovider adds a hibernate mapping to a hibernate configuration object.
*
* @author Martin Taal
*/
public interface IHibernateMappingProvider
{
- // the passed modelObjects collection is defined as a collection of Objects
- // to prevent binary dependency on emf.
- public String provideMapping(Collection<Object> modelObjects, Properties properties);
+ /** Adds a mapping to a configuration object */
+ public void addMapping(Configuration configuration);
+
+ /** Sets the Store in the mapping provider, is called before addMapping. */
+ public void setHibernateStore(IHibernateStore hibernateStore);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateStore.java
index 3f0766c..3f270d6 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/hibernate/IHibernateStore.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.hibernate;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IView;
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernatePackageHandler;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
@@ -29,4 +30,6 @@ public interface IHibernateStore extends IStore
public IHibernateStoreReader getReader(ISession session);
public IHibernateStoreWriter getWriter(IView view);
+
+ public HibernatePackageHandler getPackageHandler();
}
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/HibernateFileMappingProvider.java
new file mode 100644
index 0000000..1076bc3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateFileMappingProvider.java
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * 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.emf.cdo.server.hibernate.IHibernateStore;
+import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import org.hibernate.cfg.Configuration;
+
+import java.io.InputStream;
+
+/**
+ * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
+ *
+ * @author Martin Taal
+ */
+public class HibernateFileMappingProvider implements IHibernateMappingProvider
+{
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HibernateFileMappingProvider.class);
+
+ private IHibernateStore hibernateStore;
+
+ private final String[] mappingFileLocations;
+
+ public HibernateFileMappingProvider(String location)
+ {
+ this(new String[] { location });
+ }
+
+ public HibernateFileMappingProvider(String[] locations)
+ {
+ mappingFileLocations = locations;
+ }
+
+ public void addMapping(Configuration configuration)
+ {
+ TRACER.trace("Adding hibernate mapping from location(s):");
+ for (String location : mappingFileLocations)
+ {
+ TRACER.trace(location);
+ InputStream is = null;
+ try
+ {
+ // MT.Question: the mapping file is in a dependent plugin but when using the OM.BUNDLE
+ // it tries to find it in this plugin and I get:
+ // filenotfound:
+ // /home/mtaal/mydata/dev/workspaces/nextspace/org.eclipse.emf.cdo.server.hibernate/mappings/product.hbm.xml
+ // I have set Eclipse-BuddyPolicy to dependent
+ // is = OM.BUNDLE.getInputStream(location);
+ is = getClass().getResourceAsStream(location);
+ configuration.addInputStream(is);
+ }
+ catch (Exception e)
+ {
+ throw WrappedException.wrap(e);
+ }
+ finally
+ {
+ IOUtil.close(is);
+ }
+ }
+ }
+
+ public IHibernateStore getHibernateStore()
+ {
+ 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/HibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
index 3746a2b..b2ef584 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
@@ -16,7 +16,6 @@ import org.eclipse.emf.cdo.internal.server.Store;
import org.eclipse.emf.cdo.protocol.id.CDOIDLibraryDescriptor;
import org.eclipse.emf.cdo.protocol.id.CDOIDLibraryProvider;
import org.eclipse.emf.cdo.protocol.id.CDOIDObjectFactory;
-import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
@@ -33,8 +32,6 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
/**
* @author Eike Stepper
@@ -256,44 +253,12 @@ public class HibernateStore extends Store implements IHibernateStore
try
{
- final Collection<CDOPackage> cdoPackages = getPackageHandler().getCDOPackages();
- final Collection<Object> ecoreStrs = new ArrayList<Object>();
-
hibernateConfiguration = new Configuration();
- final String mapping;
-
- if (cdoPackages.size() > 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Mapping ecore to hibernate for CDOPackages:");
- }
-
- for (CDOPackage cdoPackage : cdoPackages)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("adding ecore for CDOPackage " + cdoPackage.getPackageURI());
- }
-
- ecoreStrs.add(cdoPackage.getEcore());
- }
- // DISABLED to prevent teneo dependency
- // mapping = mappingProvider.provideMapping(ecoreStrs, properties);
- // TRACER.trace(mapping);
- // System.err.println(mapping);
- mapping = null;
- in = OM.BUNDLE.getInputStream("mappings/product.hbm.xml");
- hibernateConfiguration.addInputStream(in);
- }
- else
+ if (mappingProvider != null)
{
- mapping = null;
- if (TRACER.isEnabled())
- {
- TRACER.trace("No CDOPackages found, ecore not mapped to hibernate");
- }
+ mappingProvider.setHibernateStore(this);
+ mappingProvider.addMapping(hibernateConfiguration);
}
if (TRACER.isEnabled())
@@ -303,11 +268,6 @@ public class HibernateStore extends Store implements IHibernateStore
in = OM.BUNDLE.getInputStream("mappings/resource.hbm.xml");
hibernateConfiguration.addInputStream(in);
- if (mapping != null)
- {
- TRACER.trace("Adding generated mapping to configuration");
- hibernateConfiguration.addXML(mapping);
- }
hibernateConfiguration.setProperties(HibernateUtil.getInstance().getPropertiesFromStore(this));
}
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 a754b61..57e5edd 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
@@ -15,7 +15,7 @@ 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.CDOIDHibernateImpl;
+import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext;
import org.hibernate.HibernateException;
@@ -47,17 +47,15 @@ public class CDOIDPropertySetter extends CDOPropertySetter
final CDOID cdoID = revision.getID();
if (cdoID == null)
{
- final CDOIDHibernate newCDOID = new CDOIDHibernateImpl();
- newCDOID.setId((Serializable)value);
- newCDOID.setEntityName(revision.getCDOClass().getName());
+ 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 = new CDOIDHibernateImpl();
- newCDOID.setId((Serializable)value);
- newCDOID.setEntityName(revision.getCDOClass().getName());
+ final CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value,
+ revision.getCDOClass().getName());
revision.setID(newCDOID);
commitContext.addIDMapping((CDOIDTemp)cdoID, newCDOID);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java
index 75e6ef8..1ba56a6 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java
@@ -14,17 +14,21 @@ import org.eclipse.emf.cdo.protocol.id.CDOID;
import org.eclipse.emf.cdo.protocol.id.CDOIDTemp;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate;
-import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateImpl;
+import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
+import org.eclipse.net4j.util.WrappedException;
+
import org.hibernate.Hibernate;
import org.hibernate.usertype.UserType;
import java.io.Serializable;
+import java.lang.reflect.Constructor;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.HashMap;
/**
* Persists a CDOID in the DB.
@@ -32,9 +36,12 @@ import java.sql.Types;
public class CDOIDUserType implements UserType
{
/**
- * Second varchar is just for informational purposes
+ * 1) entityname, 2) id, 3) id class name
*/
- private static final int[] SQL_TYPES = { Types.VARCHAR, Types.VARCHAR, Types.VARBINARY };
+ private static final int[] SQL_TYPES = { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR };
+
+ /** Constructor by id */
+ private final HashMap<String, Constructor<?>> constructors = new HashMap<String, Constructor<?>>();
public CDOIDUserType()
{
@@ -78,15 +85,22 @@ public class CDOIDUserType implements UserType
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException
{
final String entityName = (String)Hibernate.STRING.nullSafeGet(rs, names[0]);
- if (rs.wasNull() || entityName == null)
+ if (rs.wasNull())
{
return null;
}
-
- final byte[] content = (byte[])Hibernate.BINARY.nullSafeGet(rs, names[2]);
- final CDOIDHibernate cdoID = new CDOIDHibernateImpl();
- cdoID.setContent(content);
- return cdoID;
+ final String idStr = (String)Hibernate.STRING.nullSafeGet(rs, names[1]);
+ if (rs.wasNull())
+ {
+ return null;
+ }
+ final String idClassName = (String)Hibernate.STRING.nullSafeGet(rs, names[2]);
+ if (rs.wasNull())
+ {
+ return null;
+ }
+ final Serializable id = getId(idStr, idClassName);
+ return CDOIDHibernateFactoryImpl.getInstance().createCDOID(id, entityName);
}
public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException
@@ -95,7 +109,7 @@ public class CDOIDUserType implements UserType
{
statement.setNull(index, Types.VARCHAR);
statement.setNull(index, Types.VARCHAR);
- statement.setNull(index, Types.VARBINARY);
+ statement.setNull(index, Types.VARCHAR);
}
if (value != null)
@@ -116,7 +130,7 @@ public class CDOIDUserType implements UserType
statement.setString(index, cdoID.getEntityName());
statement.setString(index + 1, cdoID.getId().toString());
- statement.setBytes(index + 2, cdoID.getContent());
+ statement.setString(index + 2, cdoID.getId().getClass().getName());
}
}
@@ -139,4 +153,25 @@ public class CDOIDUserType implements UserType
{
return x.hashCode();
}
+
+ /** Creates an id object of the correct type */
+ private Serializable getId(String idStr, String idType)
+ {
+ try
+ {
+ Constructor<?> constructor = constructors.get(idType);
+ if (constructor == null)
+ {
+ final Class<?> idClass = this.getClass().getClassLoader().loadClass(idType);
+ constructor = idClass.getConstructor(new Class[] { String.class });
+ constructors.put(idType, constructor);
+ }
+ return (Serializable)constructor.newInstance(new Object[] { idStr });
+ }
+ catch (Exception e)
+ {
+ throw WrappedException.wrap(e);
+ }
+ }
+
}