diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf')
11 files changed, 985 insertions, 985 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProvider.java index 10e1fd4861..041c120afb 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProvider.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/TeneoHibernateMappingProvider.java @@ -1,220 +1,220 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.internal.teneo;
-
-import org.eclipse.emf.cdo.common.model.CDOModelUtil;
-import org.eclipse.emf.cdo.eresource.EresourcePackage;
-import org.eclipse.emf.cdo.etypes.EtypesPackage;
-import org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM;
-import org.eclipse.emf.cdo.server.hibernate.teneo.CDOMappingGenerator;
-import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants;
-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.tuplizer.CDOBlobUserType;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOClobUserType;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EDataType;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
-import org.eclipse.emf.teneo.Constants;
-import org.eclipse.emf.teneo.PackageRegistryProvider;
-import org.eclipse.emf.teneo.PersistenceOptions;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Uses the ecore string in the ePackages of the store to generate a mapping.
- *
- * @author Martin Taal
- * @author Eike Stepper
- * @since 3.0
- */
-public class TeneoHibernateMappingProvider extends HibernateMappingProvider
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TeneoHibernateMappingProvider.class);
-
- private Map<String, String> extensions = new HashMap<String, String>();
-
- private Properties mappingProviderProperties = new Properties();
-
- public TeneoHibernateMappingProvider()
- {
- }
-
- public void putExtension(String extensionClassName, String extendingClassName)
- {
- extensions.put(extensionClassName, extendingClassName);
- }
-
- @Override
- public HibernateStore getHibernateStore()
- {
- return (HibernateStore)super.getHibernateStore();
- }
-
- public String getMapping()
- {
- final String mapping = generateMapping();
- if (TRACER.isEnabled())
- {
- TRACER.trace("Generated hibernate mapping:"); //$NON-NLS-1$
- TRACER.trace(mapping);
- }
-
- return mapping;
- }
-
- // the passed modelObjects collection is defined as a collection of Objects
- // to prevent binary dependency on emf.
- public String generateMapping()
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Generating Hibernate Mapping"); //$NON-NLS-1$
- }
-
- final Properties storeProperties = getHibernateStore().getProperties();
-
- // merge the store properties with the mapping provider properties
- // the mapping provider props take precedence
- final Properties properties = new Properties();
-
- properties.putAll(storeProperties);
- properties.putAll(mappingProviderProperties);
-
- PackageRegistryProvider.getInstance().setThreadPackageRegistry(
- getHibernateStore().getRepository().getPackageRegistry());
-
- // translate the list of EPackages to an array
- boolean hasXMLTypePackage = false;
- final List<EPackage> epacks = getHibernateStore().getPackageHandler().getEPackages();
- final ListIterator<EPackage> iterator = epacks.listIterator();
- while (iterator.hasNext())
- {
- final EPackage epack = iterator.next();
- if (CDOModelUtil.isSystemPackage(epack) && epack != EtypesPackage.eINSTANCE)
- {
- iterator.remove();
- }
- else if (epack == XMLTypePackage.eINSTANCE)
- {
- hasXMLTypePackage = true;
- // iterator.remove();
- }
- }
-
- if (hasXMLTypePackage)
- {
- addTypeAnnotationToXMLTypes();
- }
-
- addUniqueConstraintAnnotation();
-
- final EPackage[] ePackageArray = epacks.toArray(new EPackage[epacks.size()]);
- // remove the persistence xml if no epackages as this won't work without
- // epackages
- if (ePackageArray.length == 0 && properties.getProperty(PersistenceOptions.PERSISTENCE_XML) != null)
- {
- properties.remove(PersistenceOptions.PERSISTENCE_XML);
- }
-
- // add some annotations to the CDO model so that the mapping gets generated correctly
- addTypeAnnotationToEDataType(EtypesPackage.eINSTANCE.getBlob(), CDOBlobUserType.class.getName());
- addTypeAnnotationToEDataType(EtypesPackage.eINSTANCE.getClob(), CDOClobUserType.class.getName());
-
- final CDOMappingGenerator mappingGenerator = new CDOMappingGenerator();
- mappingGenerator.getExtensions().putAll(extensions);
- String hbm = mappingGenerator.generateMapping(ePackageArray, properties);
- // to solve an issue with older versions of teneo
- hbm = hbm.replaceAll("_cont", "cont"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // System.err.println(hbm);
-
- return hbm;
- }
-
- private void addTypeAnnotationToXMLTypes()
- {
- for (EClassifier eClassifier : XMLTypePackage.eINSTANCE.getEClassifiers())
- {
- if (eClassifier instanceof EDataType)
- {
- final EDataType eDataType = (EDataType)eClassifier;
- if (eDataType.getEAnnotation(Constants.ANNOTATION_SOURCE_TENEO_JPA) != null)
- {
- continue;
- }
-
- final EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
- eAnnotation.setSource(Constants.ANNOTATION_SOURCE_TENEO_JPA);
- final String typeAnnotation = "@Type(type=\"org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.XMLUserType$"
- + eDataType.getName() + "\")";
- eAnnotation.getDetails().put("value", typeAnnotation);
- eDataType.getEAnnotations().add(eAnnotation);
- }
- }
- }
-
- private void addTypeAnnotationToEDataType(EDataType eDataType, String type)
- {
- if (eDataType.getEAnnotation(Constants.ANNOTATION_SOURCE_TENEO_JPA) != null)
- {
- return;
- }
-
- final EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
- eAnnotation.setSource(Constants.ANNOTATION_SOURCE_TENEO_JPA);
- final String typeAnnotation = "@Type(type=\"" + type + "\")";
- eAnnotation.getDetails().put("value", typeAnnotation);
- eDataType.getEAnnotations().add(eAnnotation);
- }
-
- // see the CDOEntityMapper, there an explicit unique-key is added to
- // a column also
- private void addUniqueConstraintAnnotation()
- {
- final EClass eClass = EresourcePackage.eINSTANCE.getCDOResourceNode();
- // already been here
- if (eClass.getEAnnotation("teneo.jpa") != null) //$NON-NLS-1$
- {
- return;
- }
-
- final EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
- annotation.setSource("teneo.jpa"); //$NON-NLS-1$
- final String tableAnnotation = "@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"" //$NON-NLS-1$
- + CDOHibernateConstants.CONTAINER_PROPERTY_COLUMN + "\", \"" //$NON-NLS-1$
- + EresourcePackage.eINSTANCE.getCDOResourceNode_Name().getName() + "\"})})"; //$NON-NLS-1$
- annotation.getDetails().put("value", tableAnnotation); //$NON-NLS-1$
- eClass.getEAnnotations().add(annotation);
- }
-
- public Properties getMappingProviderProperties()
- {
- return mappingProviderProperties;
- }
-
- public void setMappingProviderProperties(Properties mappingProviderProperties)
- {
- this.mappingProviderProperties = mappingProviderProperties;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.internal.teneo; + +import org.eclipse.emf.cdo.common.model.CDOModelUtil; +import org.eclipse.emf.cdo.eresource.EresourcePackage; +import org.eclipse.emf.cdo.etypes.EtypesPackage; +import org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM; +import org.eclipse.emf.cdo.server.hibernate.teneo.CDOMappingGenerator; +import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants; +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.tuplizer.CDOBlobUserType; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOClobUserType; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; +import org.eclipse.emf.teneo.Constants; +import org.eclipse.emf.teneo.PackageRegistryProvider; +import org.eclipse.emf.teneo.PersistenceOptions; + +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Properties; + +/** + * Uses the ecore string in the ePackages of the store to generate a mapping. + * + * @author Martin Taal + * @author Eike Stepper + * @since 3.0 + */ +public class TeneoHibernateMappingProvider extends HibernateMappingProvider +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TeneoHibernateMappingProvider.class); + + private Map<String, String> extensions = new HashMap<String, String>(); + + private Properties mappingProviderProperties = new Properties(); + + public TeneoHibernateMappingProvider() + { + } + + public void putExtension(String extensionClassName, String extendingClassName) + { + extensions.put(extensionClassName, extendingClassName); + } + + @Override + public HibernateStore getHibernateStore() + { + return (HibernateStore)super.getHibernateStore(); + } + + public String getMapping() + { + final String mapping = generateMapping(); + if (TRACER.isEnabled()) + { + TRACER.trace("Generated hibernate mapping:"); //$NON-NLS-1$ + TRACER.trace(mapping); + } + + return mapping; + } + + // the passed modelObjects collection is defined as a collection of Objects + // to prevent binary dependency on emf. + public String generateMapping() + { + if (TRACER.isEnabled()) + { + TRACER.trace("Generating Hibernate Mapping"); //$NON-NLS-1$ + } + + final Properties storeProperties = getHibernateStore().getProperties(); + + // merge the store properties with the mapping provider properties + // the mapping provider props take precedence + final Properties properties = new Properties(); + + properties.putAll(storeProperties); + properties.putAll(mappingProviderProperties); + + PackageRegistryProvider.getInstance().setThreadPackageRegistry( + getHibernateStore().getRepository().getPackageRegistry()); + + // translate the list of EPackages to an array + boolean hasXMLTypePackage = false; + final List<EPackage> epacks = getHibernateStore().getPackageHandler().getEPackages(); + final ListIterator<EPackage> iterator = epacks.listIterator(); + while (iterator.hasNext()) + { + final EPackage epack = iterator.next(); + if (CDOModelUtil.isSystemPackage(epack) && epack != EtypesPackage.eINSTANCE) + { + iterator.remove(); + } + else if (epack == XMLTypePackage.eINSTANCE) + { + hasXMLTypePackage = true; + // iterator.remove(); + } + } + + if (hasXMLTypePackage) + { + addTypeAnnotationToXMLTypes(); + } + + addUniqueConstraintAnnotation(); + + final EPackage[] ePackageArray = epacks.toArray(new EPackage[epacks.size()]); + // remove the persistence xml if no epackages as this won't work without + // epackages + if (ePackageArray.length == 0 && properties.getProperty(PersistenceOptions.PERSISTENCE_XML) != null) + { + properties.remove(PersistenceOptions.PERSISTENCE_XML); + } + + // add some annotations to the CDO model so that the mapping gets generated correctly + addTypeAnnotationToEDataType(EtypesPackage.eINSTANCE.getBlob(), CDOBlobUserType.class.getName()); + addTypeAnnotationToEDataType(EtypesPackage.eINSTANCE.getClob(), CDOClobUserType.class.getName()); + + final CDOMappingGenerator mappingGenerator = new CDOMappingGenerator(); + mappingGenerator.getExtensions().putAll(extensions); + String hbm = mappingGenerator.generateMapping(ePackageArray, properties); + // to solve an issue with older versions of teneo + hbm = hbm.replaceAll("_cont", "cont"); //$NON-NLS-1$ //$NON-NLS-2$ + + // System.err.println(hbm); + + return hbm; + } + + private void addTypeAnnotationToXMLTypes() + { + for (EClassifier eClassifier : XMLTypePackage.eINSTANCE.getEClassifiers()) + { + if (eClassifier instanceof EDataType) + { + final EDataType eDataType = (EDataType)eClassifier; + if (eDataType.getEAnnotation(Constants.ANNOTATION_SOURCE_TENEO_JPA) != null) + { + continue; + } + + final EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); + eAnnotation.setSource(Constants.ANNOTATION_SOURCE_TENEO_JPA); + final String typeAnnotation = "@Type(type=\"org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.XMLUserType$" + + eDataType.getName() + "\")"; + eAnnotation.getDetails().put("value", typeAnnotation); + eDataType.getEAnnotations().add(eAnnotation); + } + } + } + + private void addTypeAnnotationToEDataType(EDataType eDataType, String type) + { + if (eDataType.getEAnnotation(Constants.ANNOTATION_SOURCE_TENEO_JPA) != null) + { + return; + } + + final EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); + eAnnotation.setSource(Constants.ANNOTATION_SOURCE_TENEO_JPA); + final String typeAnnotation = "@Type(type=\"" + type + "\")"; + eAnnotation.getDetails().put("value", typeAnnotation); + eDataType.getEAnnotations().add(eAnnotation); + } + + // see the CDOEntityMapper, there an explicit unique-key is added to + // a column also + private void addUniqueConstraintAnnotation() + { + final EClass eClass = EresourcePackage.eINSTANCE.getCDOResourceNode(); + // already been here + if (eClass.getEAnnotation("teneo.jpa") != null) //$NON-NLS-1$ + { + return; + } + + final EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation(); + annotation.setSource("teneo.jpa"); //$NON-NLS-1$ + final String tableAnnotation = "@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"" //$NON-NLS-1$ + + CDOHibernateConstants.CONTAINER_PROPERTY_COLUMN + "\", \"" //$NON-NLS-1$ + + EresourcePackage.eINSTANCE.getCDOResourceNode_Name().getName() + "\"})})"; //$NON-NLS-1$ + annotation.getDetails().put("value", tableAnnotation); //$NON-NLS-1$ + eClass.getEAnnotations().add(annotation); + } + + public Properties getMappingProviderProperties() + { + return mappingProviderProperties; + } + + public void setMappingProviderProperties(Properties mappingProviderProperties) + { + this.mappingProviderProperties = mappingProviderProperties; + } +} 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 index 5c3acc331b..18b3b62960 100644 --- 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 @@ -1,82 +1,82 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.internal.teneo;
-
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import java.util.Properties;
-
-/**
- * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
- *
- * @author Eike Stepper
- * @since 3.0
- */
-public class TeneoHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory
-{
- public static final String TYPE = "teneo"; //$NON-NLS-1$
-
- private static final String PROPERTY_TAG = "property"; //$NON-NLS-1$
-
- private static final String EXTENSION_TAG = "extension"; //$NON-NLS-1$
-
- private static final String NAME_ATTR = "name"; //$NON-NLS-1$
-
- private static final String VALUE_ATTR = "value"; //$NON-NLS-1$
-
- public TeneoHibernateMappingProviderFactory()
- {
- }
-
- public String getType()
- {
- return TYPE;
- }
-
- public TeneoHibernateMappingProvider create(Element config)
- {
-
- final Properties properties = new Properties();
- final NodeList propertyNodes = config.getElementsByTagName(PROPERTY_TAG);
- for (int i = 0; i < propertyNodes.getLength(); i++)
- {
- final Element propertyElement = (Element)propertyNodes.item(i);
- properties.setProperty(propertyElement.getAttribute(NAME_ATTR), propertyElement.getAttribute(VALUE_ATTR));
- }
-
- final TeneoHibernateMappingProvider mappingProvider = new TeneoHibernateMappingProvider();
- mappingProvider.setMappingProviderProperties(properties);
- collectExtensions(config, mappingProvider);
- return mappingProvider;
- }
-
- private void collectExtensions(Element config, TeneoHibernateMappingProvider mappingProvider)
- {
- final NodeList extensionNodes = config.getElementsByTagName(EXTENSION_TAG);
- for (int i = 0; i < extensionNodes.getLength(); i++)
- {
- final Element extensionElement = (Element)extensionNodes.item(i);
- final String nameAttrValue = extensionElement.getAttribute(NAME_ATTR);
- final String valueAttrValue = extensionElement.getAttribute(VALUE_ATTR);
- if (nameAttrValue == null || valueAttrValue == null)
- {
- throw new IllegalArgumentException(
- "Extension element has incorrect format, both the name and value attribute should be present"); //$NON-NLS-1$
- }
-
- mappingProvider.putExtension(nameAttrValue, valueAttrValue);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.internal.teneo; + +import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import java.util.Properties; + +/** + * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration. + * + * @author Eike Stepper + * @since 3.0 + */ +public class TeneoHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory +{ + public static final String TYPE = "teneo"; //$NON-NLS-1$ + + private static final String PROPERTY_TAG = "property"; //$NON-NLS-1$ + + private static final String EXTENSION_TAG = "extension"; //$NON-NLS-1$ + + private static final String NAME_ATTR = "name"; //$NON-NLS-1$ + + private static final String VALUE_ATTR = "value"; //$NON-NLS-1$ + + public TeneoHibernateMappingProviderFactory() + { + } + + public String getType() + { + return TYPE; + } + + public TeneoHibernateMappingProvider create(Element config) + { + + final Properties properties = new Properties(); + final NodeList propertyNodes = config.getElementsByTagName(PROPERTY_TAG); + for (int i = 0; i < propertyNodes.getLength(); i++) + { + final Element propertyElement = (Element)propertyNodes.item(i); + properties.setProperty(propertyElement.getAttribute(NAME_ATTR), propertyElement.getAttribute(VALUE_ATTR)); + } + + final TeneoHibernateMappingProvider mappingProvider = new TeneoHibernateMappingProvider(); + mappingProvider.setMappingProviderProperties(properties); + collectExtensions(config, mappingProvider); + return mappingProvider; + } + + private void collectExtensions(Element config, TeneoHibernateMappingProvider mappingProvider) + { + final NodeList extensionNodes = config.getElementsByTagName(EXTENSION_TAG); + for (int i = 0; i < extensionNodes.getLength(); i++) + { + final Element extensionElement = (Element)extensionNodes.item(i); + final String nameAttrValue = extensionElement.getAttribute(NAME_ATTR); + final String valueAttrValue = extensionElement.getAttribute(VALUE_ATTR); + if (nameAttrValue == null || valueAttrValue == null) + { + throw new IllegalArgumentException( + "Extension element has incorrect format, both the name and value attribute should be present"); //$NON-NLS-1$ + } + + mappingProvider.putExtension(nameAttrValue, valueAttrValue); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOBasicMapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOBasicMapper.java index 5dcdb55f60..fe8b386ee5 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOBasicMapper.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOBasicMapper.java @@ -1,56 +1,56 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
-import org.eclipse.emf.teneo.hibernate.mapper.BasicMapper;
-import org.eclipse.emf.teneo.hibernate.mapper.HbMapperConstants;
-import org.eclipse.emf.teneo.simpledom.Element;
-
-/**
- * Extends enum mapping with parameters for epackage and eclass. This will be solved in the next build of Teneo.
- *
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- * @since 3.0
- */
-public class CDOBasicMapper extends BasicMapper
-{
- public CDOBasicMapper()
- {
- }
-
- @Override
- protected void setType(PAnnotatedEAttribute paAttribute, Element propElement)
- {
- super.setType(paAttribute, propElement);
- if (paAttribute.getEnumerated() != null)
- {
- final Element typeElement = propElement.element("type"); //$NON-NLS-1$
- for (Element element : typeElement.getChildren())
- {
- if (element.getName().equals(HbMapperConstants.ECLASSIFIER_PARAM))
- {
- // it has been done already
- return;
- }
- }
-
- // add the type elements
- final EAttribute eAttribute = paAttribute.getModelEAttribute();
- typeElement.addElement("param").addAttribute("name", HbMapperConstants.ECLASSIFIER_PARAM).addText( //$NON-NLS-1$ //$NON-NLS-2$
- eAttribute.getEAttributeType().getName());
- typeElement.addElement("param").addAttribute("name", HbMapperConstants.EPACKAGE_PARAM).addText( //$NON-NLS-1$//$NON-NLS-2$
- eAttribute.getEAttributeType().getEPackage().getNsURI());
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute; +import org.eclipse.emf.teneo.hibernate.mapper.BasicMapper; +import org.eclipse.emf.teneo.hibernate.mapper.HbMapperConstants; +import org.eclipse.emf.teneo.simpledom.Element; + +/** + * Extends enum mapping with parameters for epackage and eclass. This will be solved in the next build of Teneo. + * + * @author <a href="mtaal@elver.org">Martin Taal</a> + * @since 3.0 + */ +public class CDOBasicMapper extends BasicMapper +{ + public CDOBasicMapper() + { + } + + @Override + protected void setType(PAnnotatedEAttribute paAttribute, Element propElement) + { + super.setType(paAttribute, propElement); + if (paAttribute.getEnumerated() != null) + { + final Element typeElement = propElement.element("type"); //$NON-NLS-1$ + for (Element element : typeElement.getChildren()) + { + if (element.getName().equals(HbMapperConstants.ECLASSIFIER_PARAM)) + { + // it has been done already + return; + } + } + + // add the type elements + final EAttribute eAttribute = paAttribute.getModelEAttribute(); + typeElement.addElement("param").addAttribute("name", HbMapperConstants.ECLASSIFIER_PARAM).addText( //$NON-NLS-1$ //$NON-NLS-2$ + eAttribute.getEAttributeType().getName()); + typeElement.addElement("param").addAttribute("name", HbMapperConstants.EPACKAGE_PARAM).addText( //$NON-NLS-1$//$NON-NLS-2$ + eAttribute.getEAttributeType().getEPackage().getNsURI()); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEDataTypeAnnotator.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEDataTypeAnnotator.java index ebaaca1885..a33155e009 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEDataTypeAnnotator.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEDataTypeAnnotator.java @@ -1,34 +1,34 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.hibernate.teneo;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOCustomTypeUserType;
-
-import org.eclipse.emf.teneo.hibernate.annotations.HbEDataTypeAnnotator;
-
-/**
- * Makes sure that the default type is a String.
- *
- * @author Martin Taal
- * @since 3.0
- */
-public class CDOEDataTypeAnnotator extends HbEDataTypeAnnotator
-{
- public CDOEDataTypeAnnotator()
- {
- }
-
- @Override
- public String getDefaultUserType()
- {
- return CDOCustomTypeUserType.class.getName();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.hibernate.teneo; + +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOCustomTypeUserType; + +import org.eclipse.emf.teneo.hibernate.annotations.HbEDataTypeAnnotator; + +/** + * Makes sure that the default type is a String. + * + * @author Martin Taal + * @since 3.0 + */ +public class CDOEDataTypeAnnotator extends HbEDataTypeAnnotator +{ + public CDOEDataTypeAnnotator() + { + } + + @Override + public String getDefaultUserType() + { + return CDOCustomTypeUserType.class.getName(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEFeatureAnnotator.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEFeatureAnnotator.java index 2bee81d1ff..27c05c7486 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEFeatureAnnotator.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEFeatureAnnotator.java @@ -1,53 +1,53 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
-import org.eclipse.emf.teneo.annotations.pannotation.PannotationFactory;
-
-/**
- * Extends the Teneo EFeatureAnnotator to add an external annotation to each EReference to an EModelElement.
- *
- * @author Martin Taal
- * @since 3.0
- */
-public class CDOEFeatureAnnotator extends EFeatureAnnotator
-{
- public CDOEFeatureAnnotator()
- {
- }
-
- @Override
- public void annotate(PAnnotatedEStructuralFeature aStructuralFeature)
- {
- super.annotate(aStructuralFeature);
-
- // now determine if it needs to be annotated with External
- if (aStructuralFeature instanceof PAnnotatedEReference)
- {
- final PAnnotatedEReference paReference = (PAnnotatedEReference)aStructuralFeature;
- final boolean refersToEcoreModelElement = paReference.getModelEReference().getEReferenceType().getEPackage() == EcorePackage.eINSTANCE;
-
- // these are done with a <any ..> mapping
- final boolean refersToEObject = paReference.getModelEReference().getEReferenceType() == EcorePackage.eINSTANCE
- .getEObject();
- final boolean isPartOfEcoreModel = paReference.getModelEReference().getEContainingClass().getEPackage() == EcorePackage.eINSTANCE;
- if (refersToEcoreModelElement && !isPartOfEcoreModel && !refersToEObject)
- {
- paReference.setExternal(PannotationFactory.eINSTANCE.createExternal());
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator; +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference; +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature; +import org.eclipse.emf.teneo.annotations.pannotation.PannotationFactory; + +/** + * Extends the Teneo EFeatureAnnotator to add an external annotation to each EReference to an EModelElement. + * + * @author Martin Taal + * @since 3.0 + */ +public class CDOEFeatureAnnotator extends EFeatureAnnotator +{ + public CDOEFeatureAnnotator() + { + } + + @Override + public void annotate(PAnnotatedEStructuralFeature aStructuralFeature) + { + super.annotate(aStructuralFeature); + + // now determine if it needs to be annotated with External + if (aStructuralFeature instanceof PAnnotatedEReference) + { + final PAnnotatedEReference paReference = (PAnnotatedEReference)aStructuralFeature; + final boolean refersToEcoreModelElement = paReference.getModelEReference().getEReferenceType().getEPackage() == EcorePackage.eINSTANCE; + + // these are done with a <any ..> mapping + final boolean refersToEObject = paReference.getModelEReference().getEReferenceType() == EcorePackage.eINSTANCE + .getEObject(); + final boolean isPartOfEcoreModel = paReference.getModelEReference().getEContainingClass().getEPackage() == EcorePackage.eINSTANCE; + if (refersToEcoreModelElement && !isPartOfEcoreModel && !refersToEObject) + { + paReference.setExternal(PannotationFactory.eINSTANCE.createExternal()); + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEntityMapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEntityMapper.java index 7ea5549f9f..a44be5b6ba 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEntityMapper.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOEntityMapper.java @@ -1,100 +1,100 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.hibernate.teneo;
-
-import org.eclipse.emf.cdo.eresource.EresourcePackage;
-import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType;
-
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
-import org.eclipse.emf.teneo.hibernate.mapper.EntityMapper;
-import org.eclipse.emf.teneo.simpledom.Element;
-
-import java.util.List;
-
-/**
- * Adds mapping for econtainer and eresource.
- *
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- * @since 3.0
- */
-public class CDOEntityMapper extends EntityMapper
-{
- private PAnnotatedEClass currentEntity;
-
- private boolean addedExtraMappings;
-
- public CDOEntityMapper()
- {
- }
-
- @Override
- public void processEntity(PAnnotatedEClass entity)
- {
- // not the nicest solution
- currentEntity = entity;
- try
- {
- addedExtraMappings = false;
- super.processEntity(entity);
- }
- finally
- {
- currentEntity = null;
- }
- }
-
- // add container and resource mappings
- @Override
- protected void processFeatures(List<PAnnotatedEStructuralFeature> features)
- {
- super.processFeatures(features);
-
- final Element entityElement = getHbmContext().getCurrent();
- entityElement.addAttribute("lazy", "true");
-
- if (!addedExtraMappings && currentEntity.getPaSuperEntity() == null)
- {
- final Element resourceElement = entityElement.addElement("property"); //$NON-NLS-1$
- resourceElement.addAttribute("name", CDOHibernateConstants.RESOURCE_PROPERTY); //$NON-NLS-1$
- resourceElement.addElement("column").addAttribute("name", CDOHibernateConstants.RESOURCE_PROPERTY_COLUMN); //$NON-NLS-1$//$NON-NLS-2$
- resourceElement.addAttribute("type", CDOIDUserType.class.getName()); //$NON-NLS-1$
-
- final Element containerElement = entityElement.addElement("property"); //$NON-NLS-1$
- containerElement.addAttribute("name", CDOHibernateConstants.CONTAINER_PROPERTY).addAttribute("type", "string"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
- final Element columnElement = containerElement.addElement("column").addAttribute("name", //$NON-NLS-1$ //$NON-NLS-2$
- CDOHibernateConstants.CONTAINER_PROPERTY_COLUMN);
-
- final Element versionElement = entityElement.addElement("property"); //$NON-NLS-1$
- // add cdo_teneo prefix to prop name prevent name clashes with
- // efeatures which are accidentally called version
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=378050
- versionElement.addAttribute("name", "cdo_teneo_" + getHbmContext().getVersionColumnName()); //$NON-NLS-1$
- versionElement.addElement("meta").addAttribute("attribute", "version").setText("true");
- versionElement.addElement("column").addAttribute("name", getHbmContext().getVersionColumnName()); //$NON-NLS-1$//$NON-NLS-2$
- versionElement.addAttribute("type", Integer.class.getName()); //$NON-NLS-1$
-
- final Element timeStampElement = entityElement.addElement("property"); //$NON-NLS-1$
- timeStampElement.addAttribute("name", CDOHibernateConstants.COMMITTIMESTAMP_PROPERTY); //$NON-NLS-1$
- timeStampElement.addAttribute("type", Long.class.getName()); //$NON-NLS-1$
-
- if (getHbmContext().getCurrentEClass() == EresourcePackage.eINSTANCE.getCDOResourceNode())
- {
- // not nice but teneo will assign the first unique-key the number c0
- // and there is only one unique constraint
- columnElement.addAttribute("unique-key", "c0"); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- addedExtraMappings = true;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.hibernate.teneo; + +import org.eclipse.emf.cdo.eresource.EresourcePackage; +import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType; + +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass; +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature; +import org.eclipse.emf.teneo.hibernate.mapper.EntityMapper; +import org.eclipse.emf.teneo.simpledom.Element; + +import java.util.List; + +/** + * Adds mapping for econtainer and eresource. + * + * @author <a href="mtaal@elver.org">Martin Taal</a> + * @since 3.0 + */ +public class CDOEntityMapper extends EntityMapper +{ + private PAnnotatedEClass currentEntity; + + private boolean addedExtraMappings; + + public CDOEntityMapper() + { + } + + @Override + public void processEntity(PAnnotatedEClass entity) + { + // not the nicest solution + currentEntity = entity; + try + { + addedExtraMappings = false; + super.processEntity(entity); + } + finally + { + currentEntity = null; + } + } + + // add container and resource mappings + @Override + protected void processFeatures(List<PAnnotatedEStructuralFeature> features) + { + super.processFeatures(features); + + final Element entityElement = getHbmContext().getCurrent(); + entityElement.addAttribute("lazy", "true"); + + if (!addedExtraMappings && currentEntity.getPaSuperEntity() == null) + { + final Element resourceElement = entityElement.addElement("property"); //$NON-NLS-1$ + resourceElement.addAttribute("name", CDOHibernateConstants.RESOURCE_PROPERTY); //$NON-NLS-1$ + resourceElement.addElement("column").addAttribute("name", CDOHibernateConstants.RESOURCE_PROPERTY_COLUMN); //$NON-NLS-1$//$NON-NLS-2$ + resourceElement.addAttribute("type", CDOIDUserType.class.getName()); //$NON-NLS-1$ + + final Element containerElement = entityElement.addElement("property"); //$NON-NLS-1$ + containerElement.addAttribute("name", CDOHibernateConstants.CONTAINER_PROPERTY).addAttribute("type", "string"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + final Element columnElement = containerElement.addElement("column").addAttribute("name", //$NON-NLS-1$ //$NON-NLS-2$ + CDOHibernateConstants.CONTAINER_PROPERTY_COLUMN); + + final Element versionElement = entityElement.addElement("property"); //$NON-NLS-1$ + // add cdo_teneo prefix to prop name prevent name clashes with + // efeatures which are accidentally called version + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=378050 + versionElement.addAttribute("name", "cdo_teneo_" + getHbmContext().getVersionColumnName()); //$NON-NLS-1$ + versionElement.addElement("meta").addAttribute("attribute", "version").setText("true"); + versionElement.addElement("column").addAttribute("name", getHbmContext().getVersionColumnName()); //$NON-NLS-1$//$NON-NLS-2$ + versionElement.addAttribute("type", Integer.class.getName()); //$NON-NLS-1$ + + final Element timeStampElement = entityElement.addElement("property"); //$NON-NLS-1$ + timeStampElement.addAttribute("name", CDOHibernateConstants.COMMITTIMESTAMP_PROPERTY); //$NON-NLS-1$ + timeStampElement.addAttribute("type", Long.class.getName()); //$NON-NLS-1$ + + if (getHbmContext().getCurrentEClass() == EresourcePackage.eINSTANCE.getCDOResourceNode()) + { + // not nice but teneo will assign the first unique-key the number c0 + // and there is only one unique constraint + columnElement.addAttribute("unique-key", "c0"); //$NON-NLS-1$//$NON-NLS-2$ + } + + addedExtraMappings = true; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOManyAttributeMapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOManyAttributeMapper.java index a9696813f6..ce8c4ca4b6 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOManyAttributeMapper.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOManyAttributeMapper.java @@ -1,36 +1,36 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
-import org.eclipse.emf.teneo.annotations.pannotation.FetchType;
-import org.eclipse.emf.teneo.hibernate.mapper.ManyAttributeMapper;
-
-/**
- * Extends the Teneo ManyAttributeMapper to force eager load of all primitive type lists.
- *
- * @author Martin Taal
- * @since 3.0
- */
-public class CDOManyAttributeMapper extends ManyAttributeMapper
-{
- public CDOManyAttributeMapper()
- {
- }
-
- @Override
- public void processManyAttribute(PAnnotatedEAttribute paAttribute)
- {
- paAttribute.getOneToMany().setFetch(FetchType.EAGER);
- super.processManyAttribute(paAttribute);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute; +import org.eclipse.emf.teneo.annotations.pannotation.FetchType; +import org.eclipse.emf.teneo.hibernate.mapper.ManyAttributeMapper; + +/** + * Extends the Teneo ManyAttributeMapper to force eager load of all primitive type lists. + * + * @author Martin Taal + * @since 3.0 + */ +public class CDOManyAttributeMapper extends ManyAttributeMapper +{ + public CDOManyAttributeMapper() + { + } + + @Override + public void processManyAttribute(PAnnotatedEAttribute paAttribute) + { + paAttribute.getOneToMany().setFetch(FetchType.EAGER); + super.processManyAttribute(paAttribute); + } +} 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 index a5ba9fc25e..1b80865dcd 100644 --- 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 @@ -1,156 +1,156 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOCustomTypeUserType;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOENumIntegerType;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOENumStringType;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticIdPropertyHandler;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.FeatureMapEntryTuplizer;
-import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry;
-
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
-import org.eclipse.emf.teneo.extension.ExtensionManager;
-import org.eclipse.emf.teneo.hibernate.mapper.EntityMapper;
-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>
- * @since 3.0
- */
-public class CDOMappingContext extends MappingContext
-{
- public CDOMappingContext()
- {
- }
-
- /** 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", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- CDORevisionTuplizer.class.getName());
- entityElement.add(0, tuplizerElement);
- tuplizerElement = new Element("tuplizer").addAttribute("entity-mode", "pojo").addAttribute("class", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- CDORevisionTuplizer.class.getName());
- entityElement.add(0, tuplizerElement);
- }
-
- @Override
- public void setExtensionManager(ExtensionManager extensionManager)
- {
- super.setExtensionManager(extensionManager);
- extensionManager.registerExtension(EntityMapper.class.getName(), CDOEntityMapper.class.getName());
- }
-
- @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 getExternalUserType()
- {
- return CDOIDExternalUserType.class.getName();
- }
-
- @Override
- public String getComponentFeatureMapTuplizer()
- {
- return FeatureMapEntryTuplizer.class.getName();
- }
-
- @Override
- public String getFeatureMapEntryClassName()
- {
- return CDOFeatureMapEntry.class.getName();
- }
-
- @Override
- public String getEnumUserType()
- {
- return CDOENumStringType.class.getName();
- }
-
- @Override
- public String getEnumIntegerUserType()
- {
- return CDOENumIntegerType.class.getName();
- }
-
- @Override
- public String getSyntheticIdPropertyHandlerName()
- {
- return CDOSyntheticIdPropertyHandler.class.getName();
- }
-
- @Override
- public String getSyntheticVersionPropertyHandlerName()
- {
- return CDOSyntheticVersionPropertyHandler.class.getName();
- }
-
- @Override
- public String getDynamicEnumUserType()
- {
- return CDOENumStringType.class.getName();
- }
-
- @Override
- public String getDynamicEnumIntegerUserType()
- {
- return CDOENumIntegerType.class.getName();
- }
-
- @Override
- public String getDefaultUserType()
- {
- return CDOCustomTypeUserType.class.getName();
- }
-
- @Override
- public String getXSDDateUserType()
- {
- return super.getXSDDateUserType();
- }
-
- @Override
- public String getXSDDateTimeUserType()
- {
- return super.getXSDDateTimeUserType();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOCustomTypeUserType; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOENumIntegerType; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOENumStringType; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticIdPropertyHandler; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.FeatureMapEntryTuplizer; +import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry; + +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.hibernate.mapper.EntityMapper; +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> + * @since 3.0 + */ +public class CDOMappingContext extends MappingContext +{ + public CDOMappingContext() + { + } + + /** 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", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + CDORevisionTuplizer.class.getName()); + entityElement.add(0, tuplizerElement); + tuplizerElement = new Element("tuplizer").addAttribute("entity-mode", "pojo").addAttribute("class", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + CDORevisionTuplizer.class.getName()); + entityElement.add(0, tuplizerElement); + } + + @Override + public void setExtensionManager(ExtensionManager extensionManager) + { + super.setExtensionManager(extensionManager); + extensionManager.registerExtension(EntityMapper.class.getName(), CDOEntityMapper.class.getName()); + } + + @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 getExternalUserType() + { + return CDOIDExternalUserType.class.getName(); + } + + @Override + public String getComponentFeatureMapTuplizer() + { + return FeatureMapEntryTuplizer.class.getName(); + } + + @Override + public String getFeatureMapEntryClassName() + { + return CDOFeatureMapEntry.class.getName(); + } + + @Override + public String getEnumUserType() + { + return CDOENumStringType.class.getName(); + } + + @Override + public String getEnumIntegerUserType() + { + return CDOENumIntegerType.class.getName(); + } + + @Override + public String getSyntheticIdPropertyHandlerName() + { + return CDOSyntheticIdPropertyHandler.class.getName(); + } + + @Override + public String getSyntheticVersionPropertyHandlerName() + { + return CDOSyntheticVersionPropertyHandler.class.getName(); + } + + @Override + public String getDynamicEnumUserType() + { + return CDOENumStringType.class.getName(); + } + + @Override + public String getDynamicEnumIntegerUserType() + { + return CDOENumIntegerType.class.getName(); + } + + @Override + public String getDefaultUserType() + { + return CDOCustomTypeUserType.class.getName(); + } + + @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/CDOMappingGenerator.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingGenerator.java index 02e9bd1ee0..236f016e6e 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingGenerator.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOMappingGenerator.java @@ -1,119 +1,119 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.common.util.WrappedException;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.teneo.PersistenceOptions;
-import org.eclipse.emf.teneo.annotations.mapper.EDataTypeAnnotator;
-import org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator;
-import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceContentHandler;
-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.ManyAttributeMapper;
-import org.eclipse.emf.teneo.hibernate.mapper.MappingContext;
-import org.eclipse.emf.teneo.hibernate.mapper.MappingUtil;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Generates a CDO enabled mapping for Hibernate.
- *
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- * @since 3.0
- */
-public class CDOMappingGenerator
-{
- private static Map<String, String> extensions = new HashMap<String, String>();
-
- private ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create();
-
- public CDOMappingGenerator()
- {
- }
-
- public void registerCDOExtensions(ExtensionManager extensionManager)
- {
- MappingUtil.registerHbExtensions(extensionManager);
-
- // very strange but these can not go into the constructor...
- // get a class not found exception then
- addDefaultExtension(MappingContext.class, CDOMappingContext.class, extensionManager);
- addDefaultExtension(EFeatureAnnotator.class, CDOEFeatureAnnotator.class, extensionManager);
- addDefaultExtension(ManyAttributeMapper.class, CDOManyAttributeMapper.class, extensionManager);
- addDefaultExtension(XmlPersistenceContentHandler.class, CDOXmlPersistenceContentHandler.class, extensionManager);
- addDefaultExtension(EDataTypeAnnotator.class, CDOEDataTypeAnnotator.class, extensionManager);
-
- for (String key : extensions.keySet())
- {
- try
- {
- final Class<?> keyClass = Thread.currentThread().getContextClassLoader().loadClass(key);
- final Class<?> valueClass = Thread.currentThread().getContextClassLoader().loadClass(extensions.get(key));
- extensionManager.registerExtension(ExtensionUtil.createExtension(keyClass, valueClass, false));
- }
- catch (Exception e)
- {
- throw new WrappedException(e);
- }
- }
- }
-
- protected void addDefaultExtension(Class<?> extensionClass, Class<?> extendingClass, ExtensionManager extensionManager)
- {
- if (extensions.containsKey(extensionClass.getName()))
- {
- return;
- }
-
- extensionManager.registerExtension(ExtensionUtil.createExtension(extensionClass, extendingClass, false));
- }
-
- public Map<String, String> getExtensions()
- {
- return extensions;
- }
-
- public void putExtension(String extensionClassName, String extendingClassName)
- {
- extensions.put(extensionClassName, extendingClassName);
- }
-
- /**
- * Separate utility method, generates a hibernate mapping for a set of epackages and options. The hibernate.hbm.xml is
- * returned as a string. The mapping is not registered or used in any other way by Elver.
- */
- public String generateMapping(EPackage[] epackages, Properties props)
- {
- // set some default properties
- // never use hibernate optimistic locking
- props.put(PersistenceOptions.ALWAYS_VERSION, "false"); //$NON-NLS-1$
-
- if (!props.containsKey(PersistenceOptions.ID_COLUMN_NAME))
- {
- props.put(PersistenceOptions.ID_COLUMN_NAME, "idcol"); //$NON-NLS-1$
- }
-
- if (!props.containsKey(PersistenceOptions.VERSION_COLUMN_NAME))
- {
- props.put(PersistenceOptions.VERSION_COLUMN_NAME, "version"); //$NON-NLS-1$
- }
-
- props.put(PersistenceOptions.ALSO_MAP_AS_CLASS, "false"); //$NON-NLS-1$
- props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "false"); //$NON-NLS-1$
- registerCDOExtensions(extensionManager);
- return MappingUtil.generateMapping(epackages, props, extensionManager);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.common.util.WrappedException; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.annotations.mapper.EDataTypeAnnotator; +import org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator; +import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceContentHandler; +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.ManyAttributeMapper; +import org.eclipse.emf.teneo.hibernate.mapper.MappingContext; +import org.eclipse.emf.teneo.hibernate.mapper.MappingUtil; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * Generates a CDO enabled mapping for Hibernate. + * + * @author <a href="mtaal@elver.org">Martin Taal</a> + * @since 3.0 + */ +public class CDOMappingGenerator +{ + private static Map<String, String> extensions = new HashMap<String, String>(); + + private ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create(); + + public CDOMappingGenerator() + { + } + + public void registerCDOExtensions(ExtensionManager extensionManager) + { + MappingUtil.registerHbExtensions(extensionManager); + + // very strange but these can not go into the constructor... + // get a class not found exception then + addDefaultExtension(MappingContext.class, CDOMappingContext.class, extensionManager); + addDefaultExtension(EFeatureAnnotator.class, CDOEFeatureAnnotator.class, extensionManager); + addDefaultExtension(ManyAttributeMapper.class, CDOManyAttributeMapper.class, extensionManager); + addDefaultExtension(XmlPersistenceContentHandler.class, CDOXmlPersistenceContentHandler.class, extensionManager); + addDefaultExtension(EDataTypeAnnotator.class, CDOEDataTypeAnnotator.class, extensionManager); + + for (String key : extensions.keySet()) + { + try + { + final Class<?> keyClass = Thread.currentThread().getContextClassLoader().loadClass(key); + final Class<?> valueClass = Thread.currentThread().getContextClassLoader().loadClass(extensions.get(key)); + extensionManager.registerExtension(ExtensionUtil.createExtension(keyClass, valueClass, false)); + } + catch (Exception e) + { + throw new WrappedException(e); + } + } + } + + protected void addDefaultExtension(Class<?> extensionClass, Class<?> extendingClass, ExtensionManager extensionManager) + { + if (extensions.containsKey(extensionClass.getName())) + { + return; + } + + extensionManager.registerExtension(ExtensionUtil.createExtension(extensionClass, extendingClass, false)); + } + + public Map<String, String> getExtensions() + { + return extensions; + } + + public void putExtension(String extensionClassName, String extendingClassName) + { + extensions.put(extensionClassName, extendingClassName); + } + + /** + * Separate utility method, generates a hibernate mapping for a set of epackages and options. The hibernate.hbm.xml is + * returned as a string. The mapping is not registered or used in any other way by Elver. + */ + public String generateMapping(EPackage[] epackages, Properties props) + { + // set some default properties + // never use hibernate optimistic locking + props.put(PersistenceOptions.ALWAYS_VERSION, "false"); //$NON-NLS-1$ + + if (!props.containsKey(PersistenceOptions.ID_COLUMN_NAME)) + { + props.put(PersistenceOptions.ID_COLUMN_NAME, "idcol"); //$NON-NLS-1$ + } + + if (!props.containsKey(PersistenceOptions.VERSION_COLUMN_NAME)) + { + props.put(PersistenceOptions.VERSION_COLUMN_NAME, "version"); //$NON-NLS-1$ + } + + props.put(PersistenceOptions.ALSO_MAP_AS_CLASS, "false"); //$NON-NLS-1$ + props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "false"); //$NON-NLS-1$ + registerCDOExtensions(extensionManager); + return MappingUtil.generateMapping(epackages, props, extensionManager); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOXmlPersistenceContentHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOXmlPersistenceContentHandler.java index 931e0c2bbd..26fe19912e 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOXmlPersistenceContentHandler.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/teneo/CDOXmlPersistenceContentHandler.java @@ -1,99 +1,99 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.hibernate.teneo;
-
-import org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.teneo.PackageRegistryProvider;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
-import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceContentHandler;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-/**
- * With cdo packages are registered at runtime so if the package in the xml is not yet present then be lenient about it.
- *
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- * @since 3.0
- */
-public class CDOXmlPersistenceContentHandler extends XmlPersistenceContentHandler
-{
- private PAnnotatedEPackage localPAPackage;
-
- // is also present in super class, should be made protected there
- private static final int ROOT = 0;
-
- public CDOXmlPersistenceContentHandler()
- {
- }
-
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException
- {
- // unknown epackage, ignore for now
- if (localPAPackage == null)
- {
- return;
- }
-
- super.characters(ch, start, length);
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException
- {
- // unknown epackage, ignore for now
- if (localPAPackage == null)
- {
- return;
- }
-
- super.endElement(uri, localName, qName);
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
- {
- if (getParseState() != ROOT)
- {
- if (localName.equals("epackage")) //$NON-NLS-1$
- {
- final String nameSpaceUri = attributes.getValue("namespace-uri"); //$NON-NLS-1$
- final EPackage ePackage = PackageRegistryProvider.getInstance().getPackageRegistry().getEPackage(nameSpaceUri);
- if (ePackage != null)
- {
- localPAPackage = getPAnnotatedModel().getPAnnotated(ePackage);
- }
- else
- {
- localPAPackage = null;
- }
-
- if (localPAPackage == null)
- {
- OM.LOG.warn("No EPackage found for namespace " + nameSpaceUri //$NON-NLS-1$
- + ". This is not a problem if this EPackage is registered later."); //$NON-NLS-1$
- }
- }
-
- // unknown epackage, ignore for now
- if (localPAPackage == null)
- {
- return;
- }
- }
-
- super.startElement(uri, localName, qName, attributes);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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 + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.hibernate.teneo; + +import org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PackageRegistryProvider; +import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage; +import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceContentHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * With cdo packages are registered at runtime so if the package in the xml is not yet present then be lenient about it. + * + * @author <a href="mtaal@elver.org">Martin Taal</a> + * @since 3.0 + */ +public class CDOXmlPersistenceContentHandler extends XmlPersistenceContentHandler +{ + private PAnnotatedEPackage localPAPackage; + + // is also present in super class, should be made protected there + private static final int ROOT = 0; + + public CDOXmlPersistenceContentHandler() + { + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException + { + // unknown epackage, ignore for now + if (localPAPackage == null) + { + return; + } + + super.characters(ch, start, length); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException + { + // unknown epackage, ignore for now + if (localPAPackage == null) + { + return; + } + + super.endElement(uri, localName, qName); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException + { + if (getParseState() != ROOT) + { + if (localName.equals("epackage")) //$NON-NLS-1$ + { + final String nameSpaceUri = attributes.getValue("namespace-uri"); //$NON-NLS-1$ + final EPackage ePackage = PackageRegistryProvider.getInstance().getPackageRegistry().getEPackage(nameSpaceUri); + if (ePackage != null) + { + localPAPackage = getPAnnotatedModel().getPAnnotated(ePackage); + } + else + { + localPAPackage = null; + } + + if (localPAPackage == null) + { + OM.LOG.warn("No EPackage found for namespace " + nameSpaceUri //$NON-NLS-1$ + + ". This is not a problem if this EPackage is registered later."); //$NON-NLS-1$ + } + } + + // unknown epackage, ignore for now + if (localPAPackage == null) + { + return; + } + } + + super.startElement(uri, localName, qName, attributes); + } +} 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 index c61da1df6d..217b3b586b 100644 --- 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 @@ -1,30 +1,30 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.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();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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.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(); + } +} |