Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtaal2007-04-22 20:56:23 +0000
committermtaal2007-04-22 20:56:23 +0000
commita8c6f0510a08725cfad30f9e90322e7d51420eca (patch)
tree4f287f0034ea632e771b3484203d4e3a651f2b20
parent0865c23810b208ef5cbe8ca83075aad8fbd7c650 (diff)
downloadorg.eclipse.emf.teneo-a8c6f0510a08725cfad30f9e90322e7d51420eca.tar.gz
org.eclipse.emf.teneo-a8c6f0510a08725cfad30f9e90322e7d51420eca.tar.xz
org.eclipse.emf.teneo-a8c6f0510a08725cfad30f9e90322e7d51420eca.zip
[182815]
-rw-r--r--plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractMapper.java76
-rw-r--r--plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractPropertyMapper.java55
-rw-r--r--plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/BasicMapper.java4
-rw-r--r--plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/IdMapper.java22
-rw-r--r--plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/ManyAttributeMapper.java17
5 files changed, 86 insertions, 88 deletions
diff --git a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractMapper.java b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractMapper.java
index 6ad53c189..0840edac5 100644
--- a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractMapper.java
+++ b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractMapper.java
@@ -13,7 +13,7 @@
* Brian Vetter (bugzilla 175909)
* </copyright>
*
- * $Id: AbstractMapper.java,v 1.10.2.1 2007/03/05 18:07:36 mtaal Exp $
+ * $Id: AbstractMapper.java,v 1.10.2.2 2007/04/22 20:56:23 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate.mapper;
@@ -25,10 +25,13 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
import org.eclipse.emf.teneo.annotations.pannotation.Column;
+import org.eclipse.emf.teneo.annotations.pannotation.EnumType;
+import org.eclipse.emf.teneo.annotations.pannotation.Enumerated;
import org.eclipse.emf.teneo.annotations.pannotation.PannotationFactory;
import org.eclipse.emf.teneo.ecore.EClassNameStrategy;
import org.eclipse.emf.teneo.hibernate.hbannotation.Cache;
@@ -103,6 +106,8 @@ abstract class AbstractMapper {
typeElement.addElement("param").addAttribute("name", param.getName()).addText(param.getValue());
}
}
+ } else if (paAttribute.getEnumerated() != null) {
+ typeEnum(paAttribute, propElement);
} else {
final String hType = hbType(paAttribute);
if (hType != null) {
@@ -150,47 +155,100 @@ abstract class AbstractMapper {
} else if (eDataType.getInstanceClass() != null && eDataType.getInstanceClass() == Object.class) {
// null forces caller to use usertype
return null; // "org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserType";
- } else if (eDataType.getInstanceClass() != null) {
+ } else if (eDataType.getInstanceClass() != null) { // handle arrays
+ if (eDataType.getInstanceClass().isArray()) {
+ // get rid of the [] at the end
+ return eAttribute.getEType().getInstanceClassName().substring(0,
+ eAttribute.getEType().getInstanceClassName().length() - 2);
+ }
return eDataType.getInstanceClassName();
} else {
// all edatatypes are translatable to a string, done by caller
return null; // "org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserType";
}
}
-
+
+ /** Handle an enum type */
+ private void typeEnum(PAnnotatedEAttribute paAttribute, Element propElement) {
+ final Enumerated enumerated = paAttribute.getEnumerated();
+ final EClassifier eclassifier = paAttribute.getAnnotatedEAttribute().getEType();
+ final EAttribute eattr = paAttribute.getAnnotatedEAttribute();
+ if (getHbmContext().isEasyEMFGenerated(eclassifier)) {
+ final Class instanceClass = getHbmContext().getImpl(eclassifier);
+ propElement.addElement("type").addAttribute("name", getEnumUserType(enumerated)).addElement("param")
+ .addAttribute("name", "enumClassName").addText(instanceClass.getName());
+ } else if (getHbmContext().isEasyEMFDynamic(eclassifier)) {
+ final Element typeElement = propElement.addElement("type").addAttribute("name",
+ hbDynamicEnumType(enumerated));
+ typeElement.addElement("param").addAttribute("name", HbMapperConstants.ECLASSIFIER_PARAM).addText(
+ paAttribute.getAnnotatedEAttribute().getEType().getName());
+ typeElement.addElement("param").addAttribute("name", HbMapperConstants.EPACKAGE_PARAM).addText(
+ paAttribute.getAnnotatedEAttribute().getEType().getEPackage().getNsURI());
+ } else if (getHbmContext().isEMFGenerated(eclassifier)) {
+ propElement.addElement("type").addAttribute("name", getEnumUserType(enumerated)).addElement("param")
+ .addAttribute("name", HbMapperConstants.ENUM_CLASS_PARAM).addText(
+ eattr.getEType().getInstanceClass().getName());
+ } else { // must be emf dynamic
+ final Element typeElement = propElement.addElement("type").addAttribute("name",
+ hbDynamicEnumType(enumerated));
+ typeElement.addElement("param").addAttribute("name", HbMapperConstants.ECLASSIFIER_PARAM).addText(
+ paAttribute.getAnnotatedEAttribute().getEType().getName());
+ typeElement.addElement("param").addAttribute("name", HbMapperConstants.EPACKAGE_PARAM).addText(
+ paAttribute.getAnnotatedEAttribute().getEType().getEPackage().getNsURI());
+ }
+ }
+
+ /** Returns the correct enum primitive hibernate type, for Elver this is a hibernate user type. */
+ protected String hbDynamicEnumType(Enumerated enumerated) {
+ if (EnumType.STRING == enumerated.getValue().getValue()) {
+ return getHbmContext().getDynamicEnumUserType();
+ } else {
+ return getHbmContext().getDynamicEnumIntegerUserType();
+ }
+ }
+
+ /** Returns the correct enum primitive hibernate type, for Elver this is a hibernate user type. */
+ public String getEnumUserType(Enumerated enumerated) {
+ if (EnumType.STRING == enumerated.getValue().getValue()) {
+ return getHbmContext().getEnumUserType();
+ } else {
+ return getHbmContext().getEnumIntegerUserType();
+ }
+ }
+
/*
* @return The name of the java class needed to map the date type
*/
public String getEDateClass(EDataType eDataType) {
- assert(EcoreDataTypes.INSTANCE.isEDate(eDataType));
+ assert (EcoreDataTypes.INSTANCE.isEDate(eDataType));
// only override if the user did not specify a more specific class
if (eDataType.getInstanceClass() == Object.class) {
// EMF returns an XSD Date type as an Object instance. go figure.
// note that I would prefer to use the class instance to get the name
- // but for other reasons I do not want to have references to the
+ // but for other reasons I do not want to have references to the
// org.eclipse.emf.teneo.hibernate plugin.
return "org.eclipse.emf.teneo.hibernate.mapping.XSDDate";
}
// TODO: should it not use the eDataType.getInstanceClass()? Hmm if the user
// really wants a different mapping he/she should use maybe a usertype??
- return Date.class.getName();
+ return Date.class.getName();
}
/*
* @return The name of the java class needed to map the datetime/timestamp type
*/
public String getEDateTimeClass(EDataType eDataType) {
- assert(EcoreDataTypes.INSTANCE.isEDateTime(eDataType));
+ assert (EcoreDataTypes.INSTANCE.isEDateTime(eDataType));
if (eDataType.getInstanceClass() == Object.class) {
// EMF returns an XSD Date type as an Object instance. go figure.
// note that I would prefer to use the class instance to get the name
- // but for other reasons I do not want to have references to the
+ // but for other reasons I do not want to have references to the
// org.eclipse.emf.teneo.hibernate plugin.
return "org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime";
}
// TODO: should it not use the eDataType.getInstanceClass()? Hmm if the user
// really wants a different mapping he/she should use maybe a usertype??
- return Timestamp.class.getName();
+ return Timestamp.class.getName();
}
/**
diff --git a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractPropertyMapper.java b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractPropertyMapper.java
deleted file mode 100644
index 5f732b278..000000000
--- a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/AbstractPropertyMapper.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005, 2006, 2007 Springsite BV (The Netherlands) 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
- * Davide Marchignoli
- * </copyright>
- *
- * $Id: AbstractPropertyMapper.java,v 1.5 2007/02/01 12:35:54 mtaal Exp $
- */
-
-package org.eclipse.emf.teneo.hibernate.mapper;
-
-import org.eclipse.emf.teneo.annotations.pannotation.EnumType;
-import org.eclipse.emf.teneo.annotations.pannotation.Enumerated;
-
-/**
- * Base class for basic, enum, id etc. mappers. Mainly provides convenience methods.
- *
- * @author <a href="mailto:marchign at elver.org">Davide Marchignoli</a>
- * @author <a href="mailto:mtaal at elver.org">Martin Taal</a>
- */
-class AbstractPropertyMapper extends AbstractMapper {
-
- /**
- * @param hbmContext
- */
- public AbstractPropertyMapper(MappingContext hbmContext) {
- super(hbmContext);
- }
-
- /** Returns the correct enum primitive hibernate type, for Elver this is a hibernate user type. */
- public String getEnumUserType(Enumerated enumerated) {
- if (EnumType.STRING == enumerated.getValue().getValue()) {
- return getHbmContext().getEnumUserType();
- } else {
- return getHbmContext().getEnumIntegerUserType();
- }
- }
-
- /** Returns the correct enum primitive hibernate type, for Elver this is a hibernate user type. */
- protected String hbDynamicEnumType(Enumerated enumerated) {
- if (EnumType.STRING == enumerated.getValue().getValue()) {
- return getHbmContext().getDynamicEnumUserType();
- } else {
- return getHbmContext().getDynamicEnumIntegerUserType();
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/BasicMapper.java b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/BasicMapper.java
index bf2a836e2..ba0262f67 100644
--- a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/BasicMapper.java
+++ b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/BasicMapper.java
@@ -12,7 +12,7 @@
* Davide Marchignoli
* </copyright>
*
- * $Id: BasicMapper.java,v 1.8.2.1 2007/03/30 15:38:48 mtaal Exp $
+ * $Id: BasicMapper.java,v 1.8.2.2 2007/04/22 20:56:23 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate.mapper;
@@ -41,7 +41,7 @@ import org.eclipse.emf.teneo.simpledom.Element;
* @author <a href="mailto:marchign at elver.org">Davide Marchignoli</a>
* @author <a href="mailto:mtaal at elver.org">Martin Taal</a>
*/
-class BasicMapper extends AbstractPropertyMapper {
+class BasicMapper extends AbstractMapper {
/** Log it all */
private static final Log log = LogFactory.getLog(BasicMapper.class);
diff --git a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/IdMapper.java b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/IdMapper.java
index 4fdd379ac..d14c07a73 100644
--- a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/IdMapper.java
+++ b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/IdMapper.java
@@ -12,7 +12,7 @@
* Davide Marchignoli
* </copyright>
*
- * $Id: IdMapper.java,v 1.8 2007/02/08 23:13:12 mtaal Exp $
+ * $Id: IdMapper.java,v 1.7.2.1 2007/04/22 20:56:23 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate.mapper;
@@ -26,11 +26,9 @@ import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
-import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
-import org.eclipse.emf.teneo.annotations.pannotation.Column;
import org.eclipse.emf.teneo.annotations.pannotation.EnumType;
import org.eclipse.emf.teneo.annotations.pannotation.GeneratedValue;
import org.eclipse.emf.teneo.annotations.pannotation.GenerationType;
@@ -48,7 +46,7 @@ import org.eclipse.emf.teneo.simpledom.Element;
* @author <a href="mailto:marchign at elver.org">Davide Marchignoli</a>
* @author <a href="mailto:mtaal at elver.org">Martin Taal</a>
*/
-class IdMapper extends AbstractPropertyMapper {
+class IdMapper extends AbstractMapper {
/** The logger */
private static final Log log = LogFactory.getLog(IdMapper.class);
@@ -136,7 +134,9 @@ class IdMapper extends AbstractPropertyMapper {
final String className = getHbmContext().getInstanceClassName(aClass.getPaModel(), aClass.getAnnotatedEClass());
compositeIdElement.addAttribute("class", className);
getHbmContext().setCurrent(compositeIdElement);
- for (PAnnotatedEStructuralFeature aFeature : aClass.getPaEStructuralFeatures()) {
+ final List aFeatures = aClass.getPaEStructuralFeatures();
+ for (Iterator iter = aFeatures.iterator(); iter.hasNext();) {
+ PAnnotatedEStructuralFeature aFeature = (PAnnotatedEStructuralFeature) iter.next();
if (!(aFeature instanceof PAnnotatedEAttribute)) {
continue;
}
@@ -175,7 +175,7 @@ class IdMapper extends AbstractPropertyMapper {
}
final EAttribute eAttribute = id.getAnnotatedEAttribute();
- final List<Column> columns = getColumns(id);
+ final List columns = getColumns(id);
final GeneratedValue generatedValue = id.getGeneratedValue();
// if (column != null && column.getColumnDefinition() != null) {
@@ -215,7 +215,7 @@ class IdMapper extends AbstractPropertyMapper {
typeName = "org.elver.persistence.hibernate.type.EnumIntegerUserType";
}
- final Class<?> instanceClass = getHbmContext().getImpl(id.getAnnotatedEAttribute().getEType());
+ final Class instanceClass = getHbmContext().getImpl(id.getAnnotatedEAttribute().getEType());
usedIdElement.addElement("type").addAttribute("name", typeName).addElement("param").addAttribute(
"name", "enumClassName").addText(instanceClass.getName());
} else if (getHbmContext().isEasyEMFDynamic(id.getAnnotatedEAttribute().getEType())) {
@@ -253,7 +253,8 @@ class IdMapper extends AbstractPropertyMapper {
log.debug("GenericGenerator the strategy in the GeneratedValue is ignored (if even set)");
generatorElement.addAttribute("class", gg.getStrategy());
if (gg.getParameters() != null) {
- for (Parameter param : gg.getParameters()) {
+ for (Iterator params = gg.getParameters().iterator(); params.hasNext();) {
+ final Parameter param = (Parameter) params.next();
generatorElement.addElement("param").addAttribute("name", param.getName()).addText(
param.getValue());
}
@@ -293,9 +294,10 @@ class IdMapper extends AbstractPropertyMapper {
* passed for debugging purposes.
*/
public GenericGenerator getGenericGenerator(PAnnotatedModel paModel, String name) {
- for (Iterator<PAnnotatedEPackage> it = paModel.getPaEPackages().iterator(); it.hasNext();) {
+ for (Iterator it = paModel.getPaEPackages().iterator(); it.hasNext();) {
final HbAnnotatedEPackage pae = (HbAnnotatedEPackage) it.next();
- for (GenericGenerator gg : pae.getHbGenericGenerators()) {
+ for (Iterator sit = pae.getHbGenericGenerators().iterator(); sit.hasNext();) {
+ final GenericGenerator gg = (GenericGenerator) sit.next();
if (gg.getName() != null && gg.getName().compareTo(name) == 0) {
if (gg.getStrategy() == null) {
throw new MappingException("The GenericGenerator: " + name + " has no strategy defined!");
diff --git a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/ManyAttributeMapper.java b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/ManyAttributeMapper.java
index 74c83f383..856838411 100644
--- a/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/ManyAttributeMapper.java
+++ b/plugins/org.eclipse.emf.teneo.hibernate.mapper/src/org/eclipse/emf/teneo/hibernate/mapper/ManyAttributeMapper.java
@@ -12,7 +12,7 @@
* Davide Marchignoli
* </copyright>
*
- * $Id: ManyAttributeMapper.java,v 1.7 2007/02/08 23:13:12 mtaal Exp $
+ * $Id: ManyAttributeMapper.java,v 1.6.2.1 2007/04/22 20:56:23 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate.mapper;
@@ -26,8 +26,6 @@ import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
-import org.eclipse.emf.teneo.annotations.pannotation.Column;
-import org.eclipse.emf.teneo.annotations.pannotation.JoinColumn;
import org.eclipse.emf.teneo.annotations.pannotation.JoinTable;
import org.eclipse.emf.teneo.annotations.pannotation.OneToMany;
import org.eclipse.emf.teneo.hibernate.hbmodel.HbAnnotatedEAttribute;
@@ -80,7 +78,7 @@ class ManyAttributeMapper extends AbstractAssociationMapper {
final Element keyElement = collElement.addElement("key");
final JoinTable jt = paAttribute.getJoinTable();
- final List<JoinColumn> jcs = paAttribute.getJoinColumns() == null ? new ArrayList<JoinColumn>() : paAttribute.getJoinColumns();
+ final List jcs = paAttribute.getJoinColumns() == null ? new ArrayList() : (List) paAttribute.getJoinColumns();
final OneToMany otm = paAttribute.getOneToMany();
if (jt != null) {
@@ -116,14 +114,9 @@ class ManyAttributeMapper extends AbstractAssociationMapper {
* Add Element element in given collection element.
*/
private Element addElementElement(Element collElement, String defaultName, PAnnotatedEAttribute paAttribute,
- List<Column> columns, String targetEntity) {
- final Element elElement;
- if (targetEntity == null) {
- elElement = collElement.addElement("element");
- setType(paAttribute, elElement);
- } else {
- elElement = collElement.addElement("element").addAttribute("type", targetEntity);
- }
+ List columns, String targetEntity) {
+ final Element elElement = collElement.addElement("element");
+ setType(paAttribute, elElement);
if (columns != null && columns.size() > 0) {
addColumns(elElement, defaultName, columns, getHbmContext().isCurrentElementFeatureMap(), true);
}

Back to the top