diff options
author | kmoore | 2007-05-07 15:52:45 +0000 |
---|---|---|
committer | kmoore | 2007-05-07 15:52:45 +0000 |
commit | fbb558a7b717ef2b2031f7993fb6a7bed5c2a7b0 (patch) | |
tree | ddfe43469ed39a6a93dba7ad7ffdeb46c37116c9 | |
parent | f4bf44aa6b97ba82134ba386482bdccefe836e86 (diff) | |
download | webtools.dali-fbb558a7b717ef2b2031f7993fb6a7bed5c2a7b0.tar.gz webtools.dali-fbb558a7b717ef2b2031f7993fb6a7bed5c2a7b0.tar.xz webtools.dali-fbb558a7b717ef2b2031f7993fb6a7bed5c2a7b0.zip |
added secondary table pk joinColumns support to the model
11 files changed, 900 insertions, 17 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/model/core.ecore b/jpa/plugins/org.eclipse.jpt.core/model/core.ecore index 1494dd9ae6..84ecb1fb29 100644 --- a/jpa/plugins/org.eclipse.jpt.core/model/core.ecore +++ b/jpa/plugins/org.eclipse.jpt.core/model/core.ecore @@ -420,7 +420,18 @@ <eLiterals name="INTEGER" value="3" literal="Integer"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="ISecondaryTable" abstract="true" interface="true" - eSuperTypes="#//mappings/ITable"/> + eSuperTypes="#//mappings/ITable"> + <eOperations name="typeMapping" eType="#//ITypeMapping"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="primaryKeyJoinColumns" + upperBound="-1" eType="#//mappings/IPrimaryKeyJoinColumn" changeable="false" + volatile="true" transient="true" containment="true" resolveProxies="false"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="specifiedPrimaryKeyJoinColumns" + upperBound="-1" eType="#//mappings/IPrimaryKeyJoinColumn" containment="true" + resolveProxies="false"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="defaultPrimaryKeyJoinColumns" + upperBound="-1" eType="#//mappings/IPrimaryKeyJoinColumn" containment="true" + resolveProxies="false"/> + </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="IPrimaryKeyJoinColumn" abstract="true" interface="true" eSuperTypes="#//mappings/IAbstractJoinColumn"/> <eClassifiers xsi:type="ecore:EClass" name="IGenerator" abstract="true" interface="true" diff --git a/jpa/plugins/org.eclipse.jpt.core/model/coreModels.genmodel b/jpa/plugins/org.eclipse.jpt.core/model/coreModels.genmodel index 44f0351c69..8482f39ca5 100644 --- a/jpa/plugins/org.eclipse.jpt.core/model/coreModels.genmodel +++ b/jpa/plugins/org.eclipse.jpt.core/model/coreModels.genmodel @@ -156,6 +156,7 @@ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute core.ecore#//mappings/IEntity/specifiedName"/> <genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute core.ecore#//mappings/IEntity/defaultName"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/IEntity/table"/> + <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/IEntity/specifiedSecondaryTables"/> <genFeatures property="None" children="true" createChild="false" ecoreFeature="ecore:EReference core.ecore#//mappings/IEntity/primaryKeyJoinColumns"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/IEntity/specifiedPrimaryKeyJoinColumns"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/IEntity/defaultPrimaryKeyJoinColumns"/> @@ -312,7 +313,12 @@ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute core.ecore#//mappings/IDiscriminatorColumn/specifiedLength"/> <genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute core.ecore#//mappings/IDiscriminatorColumn/length"/> </genClasses> - <genClasses ecoreClass="core.ecore#//mappings/ISecondaryTable"/> + <genClasses ecoreClass="core.ecore#//mappings/ISecondaryTable"> + <genFeatures property="None" children="true" createChild="false" ecoreFeature="ecore:EReference core.ecore#//mappings/ISecondaryTable/primaryKeyJoinColumns"/> + <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/ISecondaryTable/specifiedPrimaryKeyJoinColumns"/> + <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference core.ecore#//mappings/ISecondaryTable/defaultPrimaryKeyJoinColumns"/> + <genOperations ecoreOperation="core.ecore#//mappings/ISecondaryTable/typeMapping"/> + </genClasses> <genClasses image="false" ecoreClass="core.ecore#//mappings/IPrimaryKeyJoinColumn"/> <genClasses image="false" ecoreClass="core.ecore#//mappings/IGenerator"> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute core.ecore#//mappings/IGenerator/name"/> @@ -399,9 +405,7 @@ <nestedGenPackages prefix="JpaJavaMappings" basePackage="org.eclipse.jpt.core.internal.content.java" disposableProviderFactory="true" ecorePackage="java.ecore#//mappings"> <genClasses image="false" ecoreClass="java.ecore#//mappings/JavaTypeMapping"/> - <genClasses ecoreClass="java.ecore#//mappings/JavaEntity"> - <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference java.ecore#//mappings/JavaEntity/secondaryTables"/> - </genClasses> + <genClasses ecoreClass="java.ecore#//mappings/JavaEntity"/> <genClasses ecoreClass="java.ecore#//mappings/JavaMappedSuperclass"/> <genClasses ecoreClass="java.ecore#//mappings/JavaEmbeddable"/> <genClasses ecoreClass="java.ecore#//mappings/JavaNullTypeMapping"/> @@ -503,8 +507,7 @@ </genClasses> <genClasses ecoreClass="orm.ecore#//XmlEntity"> <genFeatures property="None" children="true" createChild="false" ecoreFeature="ecore:EReference orm.ecore#//XmlEntity/secondaryTables"/> - <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference orm.ecore#//XmlEntity/specifiedSecondaryTables"/> - <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference orm.ecore#//XmlEntity/defaultSecondaryTables"/> + <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference orm.ecore#//XmlEntity/virtualSecondaryTables"/> </genClasses> <genClasses ecoreClass="orm.ecore#//XmlEmbeddable"/> <genClasses image="false" ecoreClass="orm.ecore#//XmlAttributeMapping"> diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AccessType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AccessType.java index 26706f251c..a21c66d681 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AccessType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AccessType.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal; +import static org.eclipse.jpt.core.internal.AccessType.DEFAULT_VALUE; +import static org.eclipse.jpt.core.internal.AccessType.FIELD_VALUE; +import static org.eclipse.jpt.core.internal.AccessType.PROPERTY_VALUE; import java.util.Arrays; import java.util.Collections; import java.util.List; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java index ae51ad5ce0..a9fa652caf 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java @@ -9,9 +9,18 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.content.java.mappings; +import java.util.Collection; +import java.util.List; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.NotificationChain; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.emf.ecore.util.InternalEList; import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.ITypeMapping; import org.eclipse.jpt.core.internal.jdtutility.CombinationIndexedDeclarationAnnotationAdapter; import org.eclipse.jpt.core.internal.jdtutility.ConversionDeclarationAnnotationElementAdapter; import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter; @@ -20,7 +29,11 @@ import org.eclipse.jpt.core.internal.jdtutility.IndexedAnnotationAdapter; import org.eclipse.jpt.core.internal.jdtutility.IndexedDeclarationAnnotationAdapter; import org.eclipse.jpt.core.internal.jdtutility.Member; import org.eclipse.jpt.core.internal.jdtutility.MemberIndexedAnnotationAdapter; +import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; /** * <!-- begin-user-doc --> @@ -35,6 +48,26 @@ import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; public class JavaSecondaryTable extends AbstractJavaTable implements ISecondaryTable { + /** + * The cached value of the '{@link #getSpecifiedPrimaryKeyJoinColumns() <em>Specified Primary Key Join Columns</em>}' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSpecifiedPrimaryKeyJoinColumns() + * @generated + * @ordered + */ + protected EList<IPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; + + /** + * The cached value of the '{@link #getDefaultPrimaryKeyJoinColumns() <em>Default Primary Key Join Columns</em>}' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getDefaultPrimaryKeyJoinColumns() + * @generated + * @ordered + */ + protected EList<IPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns; + private final IndexedAnnotationAdapter annotationAdapter; protected JavaSecondaryTable() { @@ -48,6 +81,61 @@ public class JavaSecondaryTable extends AbstractJavaTable } /** + * check for changes to the 'specifiedJoinColumns' and + * 'specifiedInverseJoinColumns' lists so we can notify the + * model adapter of any changes; + * also listen for changes to the 'defaultJoinColumns' and + * 'defaultInverseJoinColumns' lists so we can spank the developer + */ + @Override + protected void notifyChanged(Notification notification) { + super.notifyChanged(notification); + switch (notification.getFeatureID(ISecondaryTable.class)) { + case JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + specifiedPKJoinColumnsChanged(notification); + break; + default : + break; + } + } + + void specifiedPKJoinColumnsChanged(Notification notification) { + switch (notification.getEventType()) { + case Notification.ADD : + specifiedPKJoinColumnAdded(notification.getPosition(), (IPrimaryKeyJoinColumn) notification.getNewValue()); + break; + case Notification.ADD_MANY : + specifiedPKJoinColumnsAdded(notification.getPosition(), (List<IPrimaryKeyJoinColumn>) notification.getNewValue()); + break; + case Notification.REMOVE : + specifiedPKJoinColumnRemoved(notification.getPosition(), (IPrimaryKeyJoinColumn) notification.getOldValue()); + break; + case Notification.REMOVE_MANY : + if (notification.getPosition() == Notification.NO_INDEX) { + specifiedPKJoinColumnsCleared((List<IPrimaryKeyJoinColumn>) notification.getOldValue()); + } + else { + // Notification.getNewValue() returns an array of the positions of objects that were removed + specifiedPKJoinColumnsRemoved((int[]) notification.getNewValue(), (List<IPrimaryKeyJoinColumn>) notification.getOldValue()); + } + break; + case Notification.SET : + if (!notification.isTouch()) { + specifiedPKJoinColumnSet(notification.getPosition(), (IPrimaryKeyJoinColumn) notification.getOldValue(), (IPrimaryKeyJoinColumn) notification.getNewValue()); + } + break; + case Notification.MOVE : + // Notification.getOldValue() returns the source index + // Notification.getPositon() returns the target index + // Notification.getNewValue() returns the moved object + specifiedPKJoinColumnMoved(notification.getOldIntValue(), notification.getPosition(), (IPrimaryKeyJoinColumn) notification.getNewValue()); + break; + default : + break; + } + } + + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -57,6 +145,193 @@ public class JavaSecondaryTable extends AbstractJavaTable return JpaJavaMappingsPackage.Literals.JAVA_SECONDARY_TABLE; } + public EList<IPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { + return this.getSpecifiedPrimaryKeyJoinColumns().isEmpty() ? this.getDefaultPrimaryKeyJoinColumns() : this.getSpecifiedPrimaryKeyJoinColumns(); + } + + /** + * Returns the value of the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Specified Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Specified Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getISecondaryTable_SpecifiedPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + public EList<IPrimaryKeyJoinColumn> getSpecifiedPrimaryKeyJoinColumns() { + if (specifiedPrimaryKeyJoinColumns == null) { + specifiedPrimaryKeyJoinColumns = new EObjectContainmentEList<IPrimaryKeyJoinColumn>(IPrimaryKeyJoinColumn.class, this, JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS); + } + return specifiedPrimaryKeyJoinColumns; + } + + /** + * Returns the value of the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Default Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Default Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getISecondaryTable_DefaultPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + public EList<IPrimaryKeyJoinColumn> getDefaultPrimaryKeyJoinColumns() { + if (defaultPrimaryKeyJoinColumns == null) { + defaultPrimaryKeyJoinColumns = new EObjectContainmentEList<IPrimaryKeyJoinColumn>(IPrimaryKeyJoinColumn.class, this, JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS); + } + return defaultPrimaryKeyJoinColumns; + } + + public ITypeMapping typeMapping() { + return (ITypeMapping) eContainer(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getSpecifiedPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getDefaultPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return getPrimaryKeyJoinColumns(); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return getSpecifiedPrimaryKeyJoinColumns(); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return getDefaultPrimaryKeyJoinColumns(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @SuppressWarnings("unchecked") + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + getSpecifiedPrimaryKeyJoinColumns().clear(); + getSpecifiedPrimaryKeyJoinColumns().addAll((Collection<? extends IPrimaryKeyJoinColumn>) newValue); + return; + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + getDefaultPrimaryKeyJoinColumns().clear(); + getDefaultPrimaryKeyJoinColumns().addAll((Collection<? extends IPrimaryKeyJoinColumn>) newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + getSpecifiedPrimaryKeyJoinColumns().clear(); + return; + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + getDefaultPrimaryKeyJoinColumns().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return !getPrimaryKeyJoinColumns().isEmpty(); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return specifiedPrimaryKeyJoinColumns != null && !specifiedPrimaryKeyJoinColumns.isEmpty(); + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return defaultPrimaryKeyJoinColumns != null && !defaultPrimaryKeyJoinColumns.isEmpty(); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) { + if (baseClass == ISecondaryTable.class) { + switch (derivedFeatureID) { + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS; + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS; + case JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS; + default : + return -1; + } + } + return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) { + if (baseClass == ISecondaryTable.class) { + switch (baseFeatureID) { + case JpaCoreMappingsPackage.ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS; + case JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS; + case JpaCoreMappingsPackage.ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return JpaJavaMappingsPackage.JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS; + default : + return -1; + } + } + return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass); + } + /** * allow owners to verify the annotation */ @@ -85,6 +360,18 @@ public class JavaSecondaryTable extends AbstractJavaTable return new ConversionDeclarationAnnotationElementAdapter(daa, JPA.SECONDARY_TABLE__CATALOG); } + public IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index) { + return this.createJavaPrimaryKeyJoinColumn(index); + } + + private JavaPrimaryKeyJoinColumn createJavaPrimaryKeyJoinColumn(int index) { + return JavaPrimaryKeyJoinColumn.createJavaPrimaryKeyJoinColumn(buildPkJoinColumnOwner(), ((JavaTypeMapping) typeMapping()).getType(), index); + } + + protected IAbstractJoinColumn.Owner buildPkJoinColumnOwner() { + return new ISecondaryTable.PrimaryKeyJoinColumnOwner(this); + } + // ********** persistence model -> java annotations ********** void moveAnnotation(int newIndex) { this.annotationAdapter.moveAnnotation(newIndex); @@ -98,6 +385,88 @@ public class JavaSecondaryTable extends AbstractJavaTable this.annotationAdapter.removeAnnotation(); } + // ********** jpa model -> java annotations ********** + /** + * slide over all the annotations that follow the new join column + */ + public void specifiedPKJoinColumnAdded(int index, IPrimaryKeyJoinColumn joinColumn) { + //JoinColumn was added to persistence model when udating from java, do not need + //to edit the java in this case. TODO is there a better way to handle this?? + if (((JavaPrimaryKeyJoinColumn) joinColumn).annotation(getMember().astRoot()) == null) { + this.synchPKJoinColumnAnnotationsAfterAdd(index + 1); + ((JavaPrimaryKeyJoinColumn) joinColumn).newAnnotation(); + } + } + + // bjv look at this + public void specifiedPKJoinColumnsAdded(int index, List<IPrimaryKeyJoinColumn> joinColumns) { + //JoinColumn was added to persistence model when udating from java, do not need + //to edit the java in this case. TODO is there a better way to handle this?? + if (!joinColumns.isEmpty() && ((JavaPrimaryKeyJoinColumn) joinColumns.get(0)).annotation(getMember().astRoot()) == null) { + this.synchPKJoinColumnAnnotationsAfterAdd(index + joinColumns.size()); + for (IPrimaryKeyJoinColumn joinColumn : joinColumns) { + ((JavaPrimaryKeyJoinColumn) joinColumn).newAnnotation(); + } + } + } + + public void specifiedPKJoinColumnRemoved(int index, IPrimaryKeyJoinColumn joinColumn) { + ((JavaPrimaryKeyJoinColumn) joinColumn).removeAnnotation(); + this.synchPKJoinColumnAnnotationsAfterRemove(index); + } + + public void specifiedPKJoinColumnsRemoved(int[] indexes, List<IPrimaryKeyJoinColumn> joinColumns) { + for (IPrimaryKeyJoinColumn joinColumn : joinColumns) { + ((JavaPrimaryKeyJoinColumn) joinColumn).removeAnnotation(); + } + this.synchPKJoinColumnAnnotationsAfterRemove(indexes[0]); + } + + public void specifiedPKJoinColumnsCleared(List<IPrimaryKeyJoinColumn> joinColumns) { + for (IPrimaryKeyJoinColumn joinColumn : joinColumns) { + ((JavaPrimaryKeyJoinColumn) joinColumn).removeAnnotation(); + } + } + + public void specifiedPKJoinColumnSet(int index, IPrimaryKeyJoinColumn oldJoinColumn, IPrimaryKeyJoinColumn newJoinColumn) { + ((JavaPrimaryKeyJoinColumn) newJoinColumn).newAnnotation(); + } + + public void specifiedPKJoinColumnMoved(int sourceIndex, int targetIndex, IPrimaryKeyJoinColumn joinColumn) { + List<IPrimaryKeyJoinColumn> joinColumns = this.getSpecifiedPrimaryKeyJoinColumns(); + int begin = Math.min(sourceIndex, targetIndex); + int end = Math.max(sourceIndex, targetIndex); + for (int i = begin; i-- > end;) { + this.synch(joinColumns.get(i), i); + } + } + + /** + * synchronize the annotations with the model join columns, + * starting at the end of the list to prevent overlap + */ + private void synchPKJoinColumnAnnotationsAfterAdd(int index) { + List<IPrimaryKeyJoinColumn> joinColumns = this.getSpecifiedPrimaryKeyJoinColumns(); + for (int i = joinColumns.size(); i-- > index;) { + this.synch(joinColumns.get(i), i); + } + } + + /** + * synchronize the annotations with the model join columns, + * starting at the specified index to prevent overlap + */ + private void synchPKJoinColumnAnnotationsAfterRemove(int index) { + List<IPrimaryKeyJoinColumn> joinColumns = this.getSpecifiedPrimaryKeyJoinColumns(); + for (int i = index; i < joinColumns.size(); i++) { + this.synch(joinColumns.get(i), i); + } + } + + private void synch(IPrimaryKeyJoinColumn joinColumn, int index) { + ((JavaPrimaryKeyJoinColumn) joinColumn).moveAnnotation(index); + } + // ********** static methods ********** static JavaSecondaryTable createJavaSecondaryTable(Owner owner, Member member, int index) { return JpaJavaMappingsFactory.eINSTANCE.createJavaSecondaryTable(owner, member, buildDeclarationAnnotationAdapter(index)); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JpaJavaMappingsPackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JpaJavaMappingsPackage.java index 08cb67fdc5..7496198060 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JpaJavaMappingsPackage.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JpaJavaMappingsPackage.java @@ -1760,13 +1760,40 @@ public class JpaJavaMappingsPackage extends EPackageImpl public static final int JAVA_SECONDARY_TABLE__DEFAULT_SCHEMA = ABSTRACT_JAVA_TABLE__DEFAULT_SCHEMA; /** + * The feature id for the '<em><b>Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int JAVA_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_JAVA_TABLE_FEATURE_COUNT + 0; + + /** + * The feature id for the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int JAVA_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_JAVA_TABLE_FEATURE_COUNT + 1; + + /** + * The feature id for the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int JAVA_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_JAVA_TABLE_FEATURE_COUNT + 2; + + /** * The number of structural features of the '<em>Java Secondary Table</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated * @ordered */ - public static final int JAVA_SECONDARY_TABLE_FEATURE_COUNT = ABSTRACT_JAVA_TABLE_FEATURE_COUNT + 0; + public static final int JAVA_SECONDARY_TABLE_FEATURE_COUNT = ABSTRACT_JAVA_TABLE_FEATURE_COUNT + 3; /** * The feature id for the '<em><b>Name</b></em>' attribute. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/OrmPackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/OrmPackage.java index 0ad15225bc..72c5ff5a68 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/OrmPackage.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/OrmPackage.java @@ -4575,13 +4575,40 @@ public class OrmPackage extends EPackageImpl public static final int XML_SECONDARY_TABLE__SPECIFIED_SCHEMA_FOR_XML = ABSTRACT_XML_TABLE__SPECIFIED_SCHEMA_FOR_XML; /** + * The feature id for the '<em><b>Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_XML_TABLE_FEATURE_COUNT + 0; + + /** + * The feature id for the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_XML_TABLE_FEATURE_COUNT + 1; + + /** + * The feature id for the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS = ABSTRACT_XML_TABLE_FEATURE_COUNT + 2; + + /** * The number of structural features of the '<em>Xml Secondary Table</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated * @ordered */ - public static final int XML_SECONDARY_TABLE_FEATURE_COUNT = ABSTRACT_XML_TABLE_FEATURE_COUNT + 0; + public static final int XML_SECONDARY_TABLE_FEATURE_COUNT = ABSTRACT_XML_TABLE_FEATURE_COUNT + 3; /** * The meta object id for the '{@link org.eclipse.jpt.core.internal.content.orm.XmlPrimaryKeyJoinColumn <em>Xml Primary Key Join Column</em>}' class. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java index 4deac7353f..3c46560724 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java @@ -9,8 +9,18 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.content.orm; +import java.util.Collection; +import org.eclipse.emf.common.notify.NotificationChain; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.jpt.core.internal.ITypeMapping; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; /** * <!-- begin-user-doc --> @@ -25,6 +35,26 @@ import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; public class XmlSecondaryTable extends AbstractXmlTable implements ISecondaryTable { + /** + * The cached value of the '{@link #getSpecifiedPrimaryKeyJoinColumns() <em>Specified Primary Key Join Columns</em>}' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSpecifiedPrimaryKeyJoinColumns() + * @generated + * @ordered + */ + protected EList<IPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; + + /** + * The cached value of the '{@link #getDefaultPrimaryKeyJoinColumns() <em>Default Primary Key Join Columns</em>}' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getDefaultPrimaryKeyJoinColumns() + * @generated + * @ordered + */ + protected EList<IPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns; + private XmlSecondaryTable() { super(); } @@ -43,6 +73,193 @@ public class XmlSecondaryTable extends AbstractXmlTable return OrmPackage.Literals.XML_SECONDARY_TABLE; } + public EList<IPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { + return this.getSpecifiedPrimaryKeyJoinColumns().isEmpty() ? this.getDefaultPrimaryKeyJoinColumns() : this.getSpecifiedPrimaryKeyJoinColumns(); + } + + /** + * Returns the value of the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Specified Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Specified Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.content.orm.OrmPackage#getISecondaryTable_SpecifiedPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + public EList<IPrimaryKeyJoinColumn> getSpecifiedPrimaryKeyJoinColumns() { + if (specifiedPrimaryKeyJoinColumns == null) { + specifiedPrimaryKeyJoinColumns = new EObjectContainmentEList<IPrimaryKeyJoinColumn>(IPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS); + } + return specifiedPrimaryKeyJoinColumns; + } + + /** + * Returns the value of the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Default Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Default Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.content.orm.OrmPackage#getISecondaryTable_DefaultPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + public EList<IPrimaryKeyJoinColumn> getDefaultPrimaryKeyJoinColumns() { + if (defaultPrimaryKeyJoinColumns == null) { + defaultPrimaryKeyJoinColumns = new EObjectContainmentEList<IPrimaryKeyJoinColumn>(IPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS); + } + return defaultPrimaryKeyJoinColumns; + } + + public ITypeMapping typeMapping() { + return (ITypeMapping) eContainer(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getSpecifiedPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return ((InternalEList<?>) getDefaultPrimaryKeyJoinColumns()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return getPrimaryKeyJoinColumns(); + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return getSpecifiedPrimaryKeyJoinColumns(); + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return getDefaultPrimaryKeyJoinColumns(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @SuppressWarnings("unchecked") + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + getSpecifiedPrimaryKeyJoinColumns().clear(); + getSpecifiedPrimaryKeyJoinColumns().addAll((Collection<? extends IPrimaryKeyJoinColumn>) newValue); + return; + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + getDefaultPrimaryKeyJoinColumns().clear(); + getDefaultPrimaryKeyJoinColumns().addAll((Collection<? extends IPrimaryKeyJoinColumn>) newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + getSpecifiedPrimaryKeyJoinColumns().clear(); + return; + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + getDefaultPrimaryKeyJoinColumns().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return !getPrimaryKeyJoinColumns().isEmpty(); + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return specifiedPrimaryKeyJoinColumns != null && !specifiedPrimaryKeyJoinColumns.isEmpty(); + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return defaultPrimaryKeyJoinColumns != null && !defaultPrimaryKeyJoinColumns.isEmpty(); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) { + if (baseClass == ISecondaryTable.class) { + switch (derivedFeatureID) { + case OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS; + case OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS; + case OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return JpaCoreMappingsPackage.ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS; + default : + return -1; + } + } + return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) { + if (baseClass == ISecondaryTable.class) { + switch (baseFeatureID) { + case JpaCoreMappingsPackage.ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS : + return OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS; + case JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS : + return OrmPackage.XML_SECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS; + case JpaCoreMappingsPackage.ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS : + return OrmPackage.XML_SECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS; + default : + return -1; + } + } + return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass); + } + private XmlEntityInternal entity() { return (XmlEntityInternal) eContainer(); } @@ -58,4 +275,9 @@ public class XmlSecondaryTable extends AbstractXmlTable //secondaryTables are part of a collection, the secondary-table element will be removed/added //when the XmlSecondaryTable is removed/added to the XmlEntity collection } + + public IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index) { + return OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(new ISecondaryTable.PrimaryKeyJoinColumnOwner(this)); + } + } // XmlSecondaryTable diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/SecondaryTableTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/SecondaryTableTranslator.java index 1b9b70c1cd..85a4fd8b0c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/SecondaryTableTranslator.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/SecondaryTableTranslator.java @@ -9,8 +9,12 @@ package org.eclipse.jpt.core.internal.content.orm.resource; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jpt.core.internal.content.orm.OrmFactory; +import org.eclipse.jpt.core.internal.content.orm.resource.PrimaryKeyJoinColumnTranslator.PrimaryKeyJoinColumnBuilder; import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; import org.eclipse.wst.common.internal.emf.resource.IDTranslator; import org.eclipse.wst.common.internal.emf.resource.Translator; @@ -19,6 +23,8 @@ public class SecondaryTableTranslator extends AbstractTableTranslator private IEntity entity; + private ISecondaryTable secondaryTable; + public SecondaryTableTranslator() { super(SECONDARY_TABLE, MAPPINGS_PKG.getIEntity_SpecifiedSecondaryTables()); } @@ -34,7 +40,8 @@ public class SecondaryTableTranslator extends AbstractTableTranslator @Override public EObject createEMFObject(String nodeName, String readAheadName) { - return getEntity().createSecondaryTable(0); + this.secondaryTable = getEntity().createSecondaryTable(0); + return this.secondaryTable; } @@ -44,14 +51,24 @@ public class SecondaryTableTranslator extends AbstractTableTranslator createNameTranslator(), createCatalogTranslator(), createSchemaTranslator(), - createPrimaryKeyJoinColumnTranslator(), + createPrimaryKeyJoinColumnsTranslator(), createUniqueConstraintTranslator(), }; } - //placeholder until we support primaryKeyJoinColumns - protected Translator createPrimaryKeyJoinColumnTranslator() { - return new Translator(SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMN, (EStructuralFeature) null); + protected Translator createPrimaryKeyJoinColumnsTranslator() { + return new PrimaryKeyJoinColumnTranslator( + SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMN, + JpaCoreMappingsPackage.eINSTANCE.getISecondaryTable_SpecifiedPrimaryKeyJoinColumns(), + buildPrimaryKeyJoinColumnsBuilder()); + } + + private PrimaryKeyJoinColumnBuilder buildPrimaryKeyJoinColumnsBuilder() { + return new PrimaryKeyJoinColumnBuilder() { + public IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn() { + return OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(new ISecondaryTable.PrimaryKeyJoinColumnOwner(secondaryTable)); + } + }; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java index 8ab0a6e34f..be5ff4b7f3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java @@ -9,15 +9,116 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.mappings; +import org.eclipse.emf.common.util.EList; +import org.eclipse.jpt.core.internal.ITextRange; +import org.eclipse.jpt.core.internal.ITypeMapping; +import org.eclipse.jpt.db.internal.Table; + /** * <!-- begin-user-doc --> * A representation of the model object '<em><b>ISecondary Table</b></em>'. * <!-- end-user-doc --> * + * <p> + * The following features are supported: + * <ul> + * <li>{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getPrimaryKeyJoinColumns <em>Primary Key Join Columns</em>}</li> + * <li>{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getSpecifiedPrimaryKeyJoinColumns <em>Specified Primary Key Join Columns</em>}</li> + * <li>{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getDefaultPrimaryKeyJoinColumns <em>Default Primary Key Join Columns</em>}</li> + * </ul> + * </p> * * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getISecondaryTable() * @model kind="class" interface="true" abstract="true" * @generated */ public interface ISecondaryTable extends ITable -{} // ISecondaryTable +{ + /** + * Returns the value of the '<em><b>Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getISecondaryTable_PrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" transient="true" changeable="false" volatile="true" + * @generated + */ + EList<IPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns(); + + /** + * Returns the value of the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Specified Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Specified Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getISecondaryTable_SpecifiedPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + EList<IPrimaryKeyJoinColumn> getSpecifiedPrimaryKeyJoinColumns(); + + /** + * Returns the value of the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Default Primary Key Join Columns</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Default Primary Key Join Columns</em>' containment reference list. + * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getISecondaryTable_DefaultPrimaryKeyJoinColumns() + * @model type="org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn" containment="true" + * @generated + */ + EList<IPrimaryKeyJoinColumn> getDefaultPrimaryKeyJoinColumns(); + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @model + * @generated + */ + ITypeMapping typeMapping(); + + /** + * Create a primary key join column with the given index + */ + IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index); + + class PrimaryKeyJoinColumnOwner implements IAbstractJoinColumn.Owner + { + private ISecondaryTable secondaryTable; + + public PrimaryKeyJoinColumnOwner(ISecondaryTable secondaryTable) { + this.secondaryTable = secondaryTable; + } + + public ITextRange getTextRange() { + return this.secondaryTable.getTextRange(); + } + + public ITypeMapping getTypeMapping() { + return this.secondaryTable.typeMapping(); + } + + //TODO 1 do these 2 need to be swapped?? + public Table dbTable(String tableName) { + return this.secondaryTable.dbTable(); + } + + //TODO 2 do these 2 need to be swapped?? + public Table dbReferencedColumnTable() { + return getTypeMapping().primaryDbTable(); + } + } +} // ISecondaryTable diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/JpaCoreMappingsPackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/JpaCoreMappingsPackage.java index 9102771c4b..7bce0ac7a8 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/JpaCoreMappingsPackage.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/JpaCoreMappingsPackage.java @@ -2434,13 +2434,40 @@ public class JpaCoreMappingsPackage extends EPackageImpl public static final int ISECONDARY_TABLE__DEFAULT_SCHEMA = ITABLE__DEFAULT_SCHEMA; /** + * The feature id for the '<em><b>Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS = ITABLE_FEATURE_COUNT + 0; + + /** + * The feature id for the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS = ITABLE_FEATURE_COUNT + 1; + + /** + * The feature id for the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS = ITABLE_FEATURE_COUNT + 2; + + /** * The number of structural features of the '<em>ISecondary Table</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated * @ordered */ - public static final int ISECONDARY_TABLE_FEATURE_COUNT = ITABLE_FEATURE_COUNT + 0; + public static final int ISECONDARY_TABLE_FEATURE_COUNT = ITABLE_FEATURE_COUNT + 3; /** * The meta object id for the '{@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn <em>IPrimary Key Join Column</em>}' class. @@ -5354,6 +5381,45 @@ public class JpaCoreMappingsPackage extends EPackageImpl } /** + * Returns the meta object for the containment reference list '{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getPrimaryKeyJoinColumns <em>Primary Key Join Columns</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the containment reference list '<em>Primary Key Join Columns</em>'. + * @see org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getPrimaryKeyJoinColumns() + * @see #getISecondaryTable() + * @generated + */ + public EReference getISecondaryTable_PrimaryKeyJoinColumns() { + return (EReference) iSecondaryTableEClass.getEStructuralFeatures().get(0); + } + + /** + * Returns the meta object for the containment reference list '{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getSpecifiedPrimaryKeyJoinColumns <em>Specified Primary Key Join Columns</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the containment reference list '<em>Specified Primary Key Join Columns</em>'. + * @see org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getSpecifiedPrimaryKeyJoinColumns() + * @see #getISecondaryTable() + * @generated + */ + public EReference getISecondaryTable_SpecifiedPrimaryKeyJoinColumns() { + return (EReference) iSecondaryTableEClass.getEStructuralFeatures().get(1); + } + + /** + * Returns the meta object for the containment reference list '{@link org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getDefaultPrimaryKeyJoinColumns <em>Default Primary Key Join Columns</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the containment reference list '<em>Default Primary Key Join Columns</em>'. + * @see org.eclipse.jpt.core.internal.mappings.ISecondaryTable#getDefaultPrimaryKeyJoinColumns() + * @see #getISecondaryTable() + * @generated + */ + public EReference getISecondaryTable_DefaultPrimaryKeyJoinColumns() { + return (EReference) iSecondaryTableEClass.getEStructuralFeatures().get(2); + } + + /** * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn <em>IPrimary Key Join Column</em>}'. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -6255,6 +6321,9 @@ public class JpaCoreMappingsPackage extends EPackageImpl createEAttribute(iDiscriminatorColumnEClass, IDISCRIMINATOR_COLUMN__SPECIFIED_LENGTH); createEAttribute(iDiscriminatorColumnEClass, IDISCRIMINATOR_COLUMN__LENGTH); iSecondaryTableEClass = createEClass(ISECONDARY_TABLE); + createEReference(iSecondaryTableEClass, ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS); + createEReference(iSecondaryTableEClass, ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS); + createEReference(iSecondaryTableEClass, ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS); iPrimaryKeyJoinColumnEClass = createEClass(IPRIMARY_KEY_JOIN_COLUMN); iGeneratorEClass = createEClass(IGENERATOR); createEAttribute(iGeneratorEClass, IGENERATOR__NAME); @@ -6524,6 +6593,10 @@ public class JpaCoreMappingsPackage extends EPackageImpl initEAttribute(getIDiscriminatorColumn_SpecifiedLength(), theEcorePackage.getEInt(), "specifiedLength", "-1", 0, 1, IDiscriminatorColumn.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getIDiscriminatorColumn_Length(), theEcorePackage.getEInt(), "length", null, 0, 1, IDiscriminatorColumn.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED); initEClass(iSecondaryTableEClass, ISecondaryTable.class, "ISecondaryTable", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEReference(getISecondaryTable_PrimaryKeyJoinColumns(), this.getIPrimaryKeyJoinColumn(), null, "primaryKeyJoinColumns", null, 0, -1, ISecondaryTable.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getISecondaryTable_SpecifiedPrimaryKeyJoinColumns(), this.getIPrimaryKeyJoinColumn(), null, "specifiedPrimaryKeyJoinColumns", null, 0, -1, ISecondaryTable.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getISecondaryTable_DefaultPrimaryKeyJoinColumns(), this.getIPrimaryKeyJoinColumn(), null, "defaultPrimaryKeyJoinColumns", null, 0, -1, ISecondaryTable.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + addEOperation(iSecondaryTableEClass, theJpaCorePackage.getITypeMapping(), "typeMapping", 0, 1); initEClass(iPrimaryKeyJoinColumnEClass, IPrimaryKeyJoinColumn.class, "IPrimaryKeyJoinColumn", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEClass(iGeneratorEClass, IGenerator.class, "IGenerator", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEAttribute(getIGenerator_Name(), ecorePackage.getEString(), "name", null, 0, 1, IGenerator.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); @@ -7695,6 +7768,30 @@ public class JpaCoreMappingsPackage extends EPackageImpl public static final EClass ISECONDARY_TABLE = eINSTANCE.getISecondaryTable(); /** + * The meta object literal for the '<em><b>Primary Key Join Columns</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference ISECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS = eINSTANCE.getISecondaryTable_PrimaryKeyJoinColumns(); + + /** + * The meta object literal for the '<em><b>Specified Primary Key Join Columns</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS = eINSTANCE.getISecondaryTable_SpecifiedPrimaryKeyJoinColumns(); + + /** + * The meta object literal for the '<em><b>Default Primary Key Join Columns</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference ISECONDARY_TABLE__DEFAULT_PRIMARY_KEY_JOIN_COLUMNS = eINSTANCE.getISecondaryTable_DefaultPrimaryKeyJoinColumns(); + + /** * The meta object literal for the '{@link org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn <em>IPrimary Key Join Column</em>}' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java index 9037e2c68d..d24c80a73a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java @@ -27,6 +27,7 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; import org.eclipse.jpt.core.internal.mappings.ITable; import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; @@ -193,6 +194,11 @@ public class SecondaryTablesComposite extends BaseJpaComposite secondaryTable.setSpecifiedName(name); secondaryTable.setSpecifiedCatalog(catalog); secondaryTable.setSpecifiedSchema(schema); + + IPrimaryKeyJoinColumn joinColumn = secondaryTable.createPrimaryKeyJoinColumn(0); + secondaryTable.getSpecifiedPrimaryKeyJoinColumns().add(joinColumn); + joinColumn.setSpecifiedName("foo"); + joinColumn.setSpecifiedReferencedColumnName("bar"); } } |