/******************************************************************************* * Copyright (c) 2007 Oracle. 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: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.core.internal.mappings; import java.util.Iterator; import java.util.List; import org.eclipse.emf.common.util.EList; import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IPersistentAttribute; import org.eclipse.jpt.core.internal.ITextRange; import org.eclipse.jpt.core.internal.ITypeMapping; import org.eclipse.jpt.db.internal.Table; /** * * A representation of the model object 'IJoin Table'. * * *

* The following features are supported: *

*

* * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable() * @model kind="class" interface="true" abstract="true" * @generated */ public interface IJoinTable extends ITable { /** * Returns the value of the 'Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_JoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" transient="true" changeable="false" volatile="true" * @generated */ EList getJoinColumns(); /** * Returns the value of the 'Specified Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Specified Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Specified Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_SpecifiedJoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" * @generated */ EList getSpecifiedJoinColumns(); /** * Returns the value of the 'Default Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Default Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Default Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_DefaultJoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" * @generated */ EList getDefaultJoinColumns(); /** * Returns the value of the 'Inverse Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Inverse Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Inverse Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_InverseJoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" transient="true" changeable="false" volatile="true" * @generated */ EList getInverseJoinColumns(); /** * Returns the value of the 'Specified Inverse Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Specified Inverse Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Specified Inverse Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_SpecifiedInverseJoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" * @generated */ EList getSpecifiedInverseJoinColumns(); /** * Returns the value of the 'Default Inverse Join Columns' containment reference list. * The list contents are of type {@link org.eclipse.jpt.core.internal.mappings.IJoinColumn}. * *

* If the meaning of the 'Default Inverse Join Columns' containment reference list isn't clear, * there really should be more of a description here... *

* * @return the value of the 'Default Inverse Join Columns' containment reference list. * @see org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage#getIJoinTable_DefaultInverseJoinColumns() * @model type="org.eclipse.jpt.core.internal.mappings.IJoinColumn" containment="true" * @generated */ EList getDefaultInverseJoinColumns(); IJoinColumn createJoinColumn(int index); IJoinColumn createInverseJoinColumn(int index); boolean containsSpecifiedJoinColumns(); boolean containsSpecifiedInverseJoinColumns(); IRelationshipMapping relationshipMapping(); /** * just a little common behavior */ abstract class AbstractJoinColumnOwner implements IJoinColumn.Owner { private final IJoinTable joinTable; AbstractJoinColumnOwner(IJoinTable joinTable) { super(); this.joinTable = joinTable; } protected IJoinTable getJoinTable() { return this.joinTable; } public IRelationshipMapping getRelationshipMapping() { return joinTable.relationshipMapping(); } /** * the default table name is always valid and a specified table name * is prohibited (which will be handled elsewhere) */ public boolean tableNameIsInvalid(String tableName) { return false; } /** * the join column can only be on the join table itself */ public boolean tableIsAllowed() { return false; } public ITextRange getTextRange() { return joinTable.getTextRange(); } public ITypeMapping getTypeMapping() { return joinTable.getOwner().getTypeMapping(); } public Table dbTable(String tableName) { return (joinTable.getName().equals(tableName)) ? joinTable.dbTable() : null; } } /** * owner for "forward-pointer" JoinColumns; * these point at the target/inverse entity */ public class InverseJoinColumnOwner extends AbstractJoinColumnOwner { public InverseJoinColumnOwner(IJoinTable joinTable) { super(joinTable); } public List joinColumns() { return getJoinTable().getInverseJoinColumns(); } public IEntity targetEntity() { return getJoinTable().relationshipMapping().getResolvedTargetEntity(); } public String attributeName() { return getJoinTable().relationshipMapping().getPersistentAttribute().getName(); } public Table dbTable(String tableName) { Table dbTable = super.dbTable(tableName); if (dbTable != null) { return dbTable; } IEntity targetEntity = targetEntity(); return (targetEntity == null) ? null : targetEntity.dbTable(tableName); } public Table dbReferencedColumnTable() { IEntity targetEntity = targetEntity(); return (targetEntity == null) ? null : targetEntity.primaryDbTable(); } } /** * owner for "back-pointer" JoinColumns; * these point at the source/owning entity */ public class JoinColumnOwner extends AbstractJoinColumnOwner { public JoinColumnOwner(IJoinTable joinTable) { super(joinTable); } public List joinColumns() { return getJoinTable().getJoinColumns(); } public IEntity targetEntity() { return getJoinTable().relationshipMapping().getEntity(); } public String attributeName() { IEntity targetEntity = getJoinTable().relationshipMapping().getResolvedTargetEntity(); if (targetEntity == null) { return null; } String attributeName = getJoinTable().relationshipMapping().getPersistentAttribute().getName(); for (Iterator stream = targetEntity.getPersistentType().allAttributes(); stream.hasNext();) { IPersistentAttribute attribute = stream.next(); IAttributeMapping mapping = attribute.getMapping(); if (mapping instanceof INonOwningMapping) { String mappedBy = ((INonOwningMapping) mapping).getMappedBy(); if ((mappedBy != null) && mappedBy.equals(attributeName)) { return attribute.getName(); } } } return null; } public Table dbTable(String tableName) { Table dbTable = super.dbTable(tableName); if (dbTable != null) { return dbTable; } return getTypeMapping().dbTable(tableName); } public Table dbReferencedColumnTable() { return getTypeMapping().primaryDbTable(); } } }