Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2ff745f0f39b8c7625b6178db1cc21c3282454db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2008, 2010 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.jpa.ui.internal.details;

import java.util.ListIterator;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumnRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.db.Schema;
import org.eclipse.jpt.jpa.db.Table;

/**
 * The state object used to create or edit a primary key join column on a
 * relationship mapping.
 *
 * @see JoinColumn
 * @see JoinColumnRelationshipStrategy
 * @see JoinColumnInJoiningStrategyDialog
 *
 * @version 2.3
 * @since 2.0
 */
public class JoinColumnInJoiningStrategyStateObject 
	extends JoinColumnStateObject
{
	/**
	 * Creates a new <code>JoinColumnInJoiningStrategyStateObject</code>.
	 *
	 * @param joiningStrategy The owner of the join column to create
	 * @param joinColumn The join column to edit or <code>null</code> if this is
	 * used to create a new one
	 */
	public JoinColumnInJoiningStrategyStateObject(
			ReadOnlyJoinColumnRelationshipStrategy joiningStrategy,
		    ReadOnlyJoinColumn joinColumn) {
		super(joiningStrategy, joinColumn);
	}
	
	
	@Override
	public JoinColumnRelationshipStrategy getOwner() {
		return (JoinColumnRelationshipStrategy) super.getOwner();
	}

	@Override
	public ListIterator<String> tables() {
		Schema schema = getDbSchema();
		return schema == null ? super.tables() : CollectionTools.list(schema.getSortedTableIdentifiers()).listIterator();
	}
	
	protected Schema getDbSchema() {
		TypeMapping typeMapping = getRelationshipSource();
		return typeMapping == null ? null : typeMapping.getDbSchema();
	}

	protected TypeMapping getRelationshipSource() {
		return getOwner().getRelationshipSource();
	}
	
	protected TypeMapping getRelationshipTarget() {
		return getOwner().getRelationshipTarget();
	}
	
	@Override
	public String getDefaultTable() {
		JoinColumn joinColumn = getJoinColumn();

		if (joinColumn != null) {
			return joinColumn.getDefaultTable();
		}
		TypeMapping typeMapping = getRelationshipSource();		
		return typeMapping == null ? null : typeMapping.getPrimaryTableName();
	}
	
	@Override
	public Table getNameTable() {
		TypeMapping typeMapping = getRelationshipSource();
		return typeMapping == null ? null : typeMapping.getPrimaryDbTable();
	}
	
	@Override
	public Table getReferencedNameTable() {
		TypeMapping relationshipTarget = getRelationshipTarget();
		return relationshipTarget == null ? null : relationshipTarget.getPrimaryDbTable();
	}

}

Back to the top