diff options
-rw-r--r-- | plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java b/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java index 666170aae..686af8be6 100644 --- a/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java +++ b/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java @@ -11,7 +11,7 @@ * Martin Taal * </copyright> * - * $Id: DefaultAnnotator.java,v 1.25.2.8 2007/03/24 11:55:00 mtaal Exp $ + * $Id: DefaultAnnotator.java,v 1.25.2.9 2007/03/30 15:39:09 mtaal Exp $ */ package org.eclipse.emf.teneo.annotations.mapper; @@ -82,7 +82,7 @@ import org.eclipse.emf.teneo.util.StoreUtil; * information. It sets the default annotations according to the ejb3 spec. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.25.2.8 $ + * @version $Revision: 1.25.2.9 $ */ public class DefaultAnnotator { @@ -384,10 +384,9 @@ public class DefaultAnnotator { // if the strategy is all classes of one hierarchy in one table and this is not the superclass // then all properties should be nullable - // TODO when not all eclasses are entities then this computation is incorrect, the isInheritanceRoot - // should be the top most class in the hierarchy which is an entity - final boolean forceOptional = !isInheritanceRoot - && inheritanceType.equals(InheritanceType.SINGLE_TABLE_LITERAL); + // this is now done in the individual mappers +// final boolean forceOptional = !isInheritanceRoot +// && inheritanceType.equals(InheritanceType.SINGLE_TABLE_LITERAL); // For hibernate as well as jpox the discriminator column is only required for // single table, the ejb3 spec does not make a clear statement about the requirement @@ -410,7 +409,7 @@ public class DefaultAnnotator { for (Iterator it = aClass.getPaEStructuralFeatures().iterator(); it.hasNext();) { PAnnotatedEStructuralFeature aStructuralFeature = (PAnnotatedEStructuralFeature) it.next(); - processEFeature(aStructuralFeature, forceOptional); + processEFeature(aStructuralFeature); } // Add default PkJoinColumns for SecondaryTables. @@ -432,7 +431,7 @@ public class DefaultAnnotator { } /** Process the features of the eclass */ - protected void processEFeature(PAnnotatedEStructuralFeature aStructuralFeature, boolean forceOptional) { + protected void processEFeature(PAnnotatedEStructuralFeature aStructuralFeature) { EStructuralFeature eStructuralFeature = aStructuralFeature.getAnnotatedEStructuralFeature(); boolean errorOccured = true; @@ -482,9 +481,9 @@ public class DefaultAnnotator { } if (isMany) { - processOneToManyAttribute(aAttribute, forceOptional); + processOneToManyAttribute(aAttribute); } else { - processSingleAttribute(aAttribute, forceOptional); + processSingleAttribute(aAttribute); } if (aAttribute.getColumn() != null && aAttribute.getColumn().getName() == null) { @@ -526,17 +525,17 @@ public class DefaultAnnotator { final boolean mtoUnidirectionalRelation = !isMany && eOpposite == null && !otoUnidirectionalRelation; if (mtmBidirectionalRelation) { - processBidirectionalManyToManyReference(aReference, forceOptional); + processBidirectionalManyToManyReference(aReference); } else if (mtmUnidirectionalRelation) { - processUnidirectionalManyToManyReference(aReference, forceOptional); + processUnidirectionalManyToManyReference(aReference); } else if (otmBidirectionalRelation || otmUnidirectionalRelation) { - processOneToManyReference(aReference, forceOptional); + processOneToManyReference(aReference); } else if (otoBidirectionalRelation || otoUnidirectionalRelation) { - processOneToOneReference(aReference, forceOptional); + processOneToOneReference(aReference); } else if (mtoBidirectionalRelation) { - processManyToOneReference(aReference, forceOptional); + processManyToOneReference(aReference); } else if (mtoUnidirectionalRelation) { - processManyToOneReference(aReference, forceOptional); + processManyToOneReference(aReference); } // handle column naming at this level @@ -566,7 +565,7 @@ public class DefaultAnnotator { } /** Add default annotation to aAttribute: these are id, basic and enum */ - protected void processSingleAttribute(PAnnotatedEAttribute aAttribute, boolean forceNullable) { + protected void processSingleAttribute(PAnnotatedEAttribute aAttribute) { log.debug(" Adding default annotations for EAttribute " + aAttribute.getAnnotatedElement().getName()); @@ -626,12 +625,9 @@ public class DefaultAnnotator { // NOTE: the ejb3 spec says that for primitivie optional does not apply, this is // confusing why having this then? If this applies then for each basic and nullable // field a column annotation has to be added to force nullability - basic.setOptional(forceNullable || !eAttribute.isRequired() || eAttribute.isUnsettable()); + basic.setOptional(!eAttribute.isRequired() || eAttribute.isUnsettable()); aAttribute.setBasic(basic); } - if (forceNullable) { - aAttribute.getBasic().setOptional(true); - } if (aAttribute.getId() != null) { aAttribute.getBasic().setOptional(false); @@ -677,7 +673,7 @@ public class DefaultAnnotator { } /** Handles a many EAttribute which is a list of simple types */ - protected void processOneToManyAttribute(PAnnotatedEAttribute aAttribute, boolean forceNullable) { + protected void processOneToManyAttribute(PAnnotatedEAttribute aAttribute) { final String logStr = aAttribute.getAnnotatedEAttribute().getName() + "/" + aAttribute.getAnnotatedEAttribute().getEContainingClass().getName(); @@ -788,7 +784,7 @@ public class DefaultAnnotator { /** * Adds default annotations to a onetomany ereference, this method handles both the uni- and the bidirectional case */ - protected void processOneToManyReference(PAnnotatedEReference aReference, boolean forceOptional) { + protected void processOneToManyReference(PAnnotatedEReference aReference) { final String logStr = aReference.getAnnotatedEReference().getName() + "/" + aReference.getAnnotatedEReference().getEContainingClass().getName(); @@ -885,7 +881,7 @@ public class DefaultAnnotator { } /** Adds default annotations to a bidirectional many to many ereference */ - protected void processBidirectionalManyToManyReference(PAnnotatedEReference aReference, boolean forceOptional) { + protected void processBidirectionalManyToManyReference(PAnnotatedEReference aReference) { final String featureLogStr = aReference.getAnnotatedEReference().getName() + "/" + aReference.getAnnotatedEReference().getEContainingClass().getName(); @@ -1016,7 +1012,7 @@ public class DefaultAnnotator { } /** Adds default annotations to a unidirectional many to many ereference */ - protected void processUnidirectionalManyToManyReference(PAnnotatedEReference aReference, boolean forceOptional) { + protected void processUnidirectionalManyToManyReference(PAnnotatedEReference aReference) { final String featureLogStr = aReference.getAnnotatedEReference().getName() + "/" + aReference.getAnnotatedEReference().getEContainingClass().getName(); @@ -1061,12 +1057,12 @@ public class DefaultAnnotator { } if (joinTable.getJoinColumns() == null) { joinTable.getJoinColumns().addAll( - getJoinColumns(aReference.getPaEClass(), eReference, forceOptional, false, true)); + getJoinColumns(aReference.getPaEClass(), eReference, false, false, true)); } } /** Adds default annotations for a one to one reference */ - protected void processOneToOneReference(PAnnotatedEReference aReference, boolean forceOptional) { + protected void processOneToOneReference(PAnnotatedEReference aReference) { final String logStr = aReference.getAnnotatedEReference().getName() + "/" + aReference.getAnnotatedEReference().getEContainingClass().getName(); @@ -1083,13 +1079,11 @@ public class DefaultAnnotator { log.debug("EReference + " + logStr + " does not have a onetoone annotation, adding one"); oto = aFactory.createOneToOne(); aReference.setOneToOne(oto); - oto.setOptional(forceOptional || !eReference.isRequired() || eReference.isUnsettable()); + oto.setOptional(!eReference.isRequired() || eReference.isUnsettable()); oto.setEModelElement(eReference); } else { log.debug("EReference + " + logStr + " has an onetoone annotation setting defaults if required"); } - if (forceOptional) - oto.setOptional(true); // determine where to put the mapped-by if (oto.getMappedBy() == null && setMappedBy(eReference)) { // only works with different names @@ -1106,7 +1100,7 @@ public class DefaultAnnotator { } /** Handles many to one for bidirectional and unidirectional cases */ - protected void processManyToOneReference(PAnnotatedEReference aReference, boolean forceOptional) { + protected void processManyToOneReference(PAnnotatedEReference aReference) { final String logStr = aReference.getAnnotatedEReference().getName() + "/" + aReference.getAnnotatedEReference().getEContainingClass().getName(); @@ -1122,14 +1116,11 @@ public class DefaultAnnotator { log.debug("EReference + " + logStr + " does not have a manytoone annotation, adding one"); mto = aFactory.createManyToOne(); aReference.setManyToOne(mto); - mto.setOptional(forceOptional || !eReference.isRequired() || eReference.isUnsettable() + mto.setOptional(!eReference.isRequired() || eReference.isUnsettable() || eReference.getEOpposite() != null); mto.setEModelElement(eReference); } else { log.debug("EReference + " + logStr + " does have a manytoone annotation, using it"); - log.debug("Setting optional because of inheritance mapping, this is a subclass"); - if (forceOptional) - mto.setOptional(forceOptional); } setCascade(mto.getCascade(), eReference.isContainment()); |