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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*******************************************************************************
* Copyright (c) 2007, 2012 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.core.internal.resource.java.source;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.SecondaryTableAnnotation;
/**
* <code>javax.persistence.SecondaryTable</code>
*/
public final class SourceSecondaryTableAnnotation
extends SourceBaseTableAnnotation
implements SecondaryTableAnnotation
{
private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.SECONDARY_TABLES);
private final PkJoinColumnsAnnotationContainer pkJoinColumnsContainer = new PkJoinColumnsAnnotationContainer();
public static SourceSecondaryTableAnnotation buildSourceSecondaryTableAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement element, int index) {
IndexedDeclarationAnnotationAdapter idaa = buildSecondaryTableDeclarationAnnotationAdapter(index);
IndexedAnnotationAdapter iaa = buildSecondaryTableAnnotationAdapter(element, idaa);
return new SourceSecondaryTableAnnotation(
parent,
element,
idaa,
iaa);
}
private SourceSecondaryTableAnnotation(
JavaResourceAnnotatedElement parent,
AnnotatedElement element,
IndexedDeclarationAnnotationAdapter daa,
IndexedAnnotationAdapter annotationAdapter) {
super(parent, element, daa, annotationAdapter);
}
public String getAnnotationName() {
return ANNOTATION_NAME;
}
@Override
public void initialize(Annotation astAnnotation) {
super.initialize(astAnnotation);
this.pkJoinColumnsContainer.initializeFromContainerAnnotation(astAnnotation);
}
@Override
public void synchronizeWith(Annotation astAnnotation) {
super.synchronizeWith(astAnnotation);
this.pkJoinColumnsContainer.synchronize(astAnnotation);
}
// ********** SourceBaseTableAnnotation implementation **********
@Override
protected DeclarationAnnotationElementAdapter<String> buildNameDeclarationAdapter() {
return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JPA.SECONDARY_TABLE__NAME);
}
@Override
protected DeclarationAnnotationElementAdapter<String> buildSchemaDeclarationAdapter() {
return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JPA.SECONDARY_TABLE__SCHEMA);
}
@Override
protected DeclarationAnnotationElementAdapter<String> buildCatalogDeclarationAdapter() {
return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JPA.SECONDARY_TABLE__CATALOG);
}
@Override
protected String getUniqueConstraintsElementName() {
return JPA.SECONDARY_TABLE__UNIQUE_CONSTRAINTS;
}
// ************* SecondaryTableAnnotation implementation *******************
// ***** pk join columns
public ListIterable<PrimaryKeyJoinColumnAnnotation> getPkJoinColumns() {
return this.pkJoinColumnsContainer.getNestedAnnotations();
}
public int getPkJoinColumnsSize() {
return this.pkJoinColumnsContainer.getNestedAnnotationsSize();
}
public PrimaryKeyJoinColumnAnnotation pkJoinColumnAt(int index) {
return this.pkJoinColumnsContainer.getNestedAnnotation(index);
}
public PrimaryKeyJoinColumnAnnotation addPkJoinColumn(int index) {
return this.pkJoinColumnsContainer.addNestedAnnotation(index);
}
/* CU private */ PrimaryKeyJoinColumnAnnotation buildPkJoinColumn(int index) {
return SourcePrimaryKeyJoinColumnAnnotation.buildNestedSourcePrimaryKeyJoinColumnAnnotation(
this, this.annotatedElement, this.buildPkJoinColumnIndexedDeclarationAnnotationAdapter(index));
}
private IndexedDeclarationAnnotationAdapter buildPkJoinColumnIndexedDeclarationAnnotationAdapter(int index) {
return new NestedIndexedDeclarationAnnotationAdapter(
this.daa, JPA.SECONDARY_TABLE__PK_JOIN_COLUMNS, index, JPA.PRIMARY_KEY_JOIN_COLUMN);
}
public void movePkJoinColumn(int targetIndex, int sourceIndex) {
this.pkJoinColumnsContainer.moveNestedAnnotation(targetIndex, sourceIndex);
}
public void removePkJoinColumn(int index) {
this.pkJoinColumnsContainer.removeNestedAnnotation(index);
}
/**
* adapt the AnnotationContainer interface to the collection table's join columns
*/
class PkJoinColumnsAnnotationContainer
extends AnnotationContainer<PrimaryKeyJoinColumnAnnotation>
{
@Override
protected String getNestedAnnotationsListName() {
return PK_JOIN_COLUMNS_LIST;
}
@Override
protected String getElementName() {
return JPA.SECONDARY_TABLE__PK_JOIN_COLUMNS;
}
@Override
protected String getNestedAnnotationName() {
return JPA.PRIMARY_KEY_JOIN_COLUMN;
}
@Override
protected PrimaryKeyJoinColumnAnnotation buildNestedAnnotation(int index) {
return SourceSecondaryTableAnnotation.this.buildPkJoinColumn(index);
}
}
// ********** misc **********
@Override
public boolean isUnset() {
return super.isUnset() &&
this.pkJoinColumnsContainer.isEmpty();
}
// ********** static methods **********
private static IndexedAnnotationAdapter buildSecondaryTableAnnotationAdapter(AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) {
return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
}
private static IndexedDeclarationAnnotationAdapter buildSecondaryTableDeclarationAnnotationAdapter(int index) {
IndexedDeclarationAnnotationAdapter idaa =
new CombinationIndexedDeclarationAnnotationAdapter(
DECLARATION_ANNOTATION_ADAPTER,
CONTAINER_DECLARATION_ANNOTATION_ADAPTER,
index,
ANNOTATION_NAME);
return idaa;
}
}
|