Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e111a1f1fc8cf6a9516c07ec41671d82f847d286 (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
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
186
/*******************************************************************************
 * Copyright (c) 2013 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.jpa2_1.context.java;

import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.jpa.core.jpa2_1.ParameterMode2_1;
import org.eclipse.jpt.jpa.core.jpa2_1.context.StoredProcedureParameter2_1;
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;

/**
 * Java stored procedure parameter
 */
public class GenericJavaStoredProcedureParameter2_1
	extends AbstractJavaJpaContextNode
	implements JavaStoredProcedureParameter2_1
{
	protected final StoredProcedureParameter2_1Annotation parameterAnnotation;

	protected String name;
	
	protected ParameterMode2_1 specifiedMode;
	protected ParameterMode2_1 defaultMode;
	
	protected String typeName;
	protected String fullyQualifiedTypeName;


	public GenericJavaStoredProcedureParameter2_1(JavaNamedStoredProcedureQuery2_1 parent, StoredProcedureParameter2_1Annotation parameterAnnotation) {
		super(parent);
		this.parameterAnnotation = parameterAnnotation;
		this.name = parameterAnnotation.getName();
		this.specifiedMode = this.buildSpecifiedMode();
		this.typeName = parameterAnnotation.getTypeName();
	}


	// ********** synchronize/update **********

	@Override
	public void synchronizeWithResourceModel() {
		super.synchronizeWithResourceModel();
		this.setName_(this.parameterAnnotation.getName());
		this.setSpecifiedMode_(this.buildSpecifiedMode());
		this.setTypeName_(this.parameterAnnotation.getTypeName());
	}

	@Override
	public void update() {
		super.update();
		this.setDefaultMode(this.buildDefaultMode());
		this.setFullyQualifiedTypeName(this.buildFullyQualifiedTypeName());
	}

	// ********* name **************

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.parameterAnnotation.setName(name);
		this.setName_(name);
	}

	protected void setName_(String name) {
		String old = this.name;
		this.name = name;
		this.firePropertyChanged(NAME_PROPERTY, old, name);
	}


	// ********** mode **********

	public ParameterMode2_1 getMode() {
		return (this.specifiedMode != null) ? this.specifiedMode : this.defaultMode;
	}

	public ParameterMode2_1 getSpecifiedMode() {
		return this.specifiedMode;
	}

	public void setSpecifiedMode(ParameterMode2_1 mode) {
		this.parameterAnnotation.setMode(ParameterMode2_1.toJavaResourceModel(mode));
		this.setSpecifiedMode_(mode);
	}

	protected void setSpecifiedMode_(ParameterMode2_1 mode) {
		ParameterMode2_1 old = this.specifiedMode;
		this.specifiedMode = mode;
		this.firePropertyChanged(SPECIFIED_MODE_PROPERTY, old, mode);
	}

	protected ParameterMode2_1 buildSpecifiedMode() {
		return 	ParameterMode2_1.fromJavaResourceModel(this.parameterAnnotation.getMode());
	}

	public ParameterMode2_1 getDefaultMode() {
		return this.defaultMode;
	}

	protected void setDefaultMode(ParameterMode2_1 mode) {
		ParameterMode2_1 old = this.defaultMode;
		this.defaultMode = mode;
		this.firePropertyChanged(DEFAULT_MODE_PROPERTY, old, mode);
	}

	protected ParameterMode2_1 buildDefaultMode() {
		return ParameterMode2_1.IN;
	}


	// ********** type **********

	public String getTypeName() {
		return this.typeName;
	}

	public void setTypeName(String typeName) {
		this.parameterAnnotation.setTypeName(typeName);
		this.setTypeName_(typeName);
	}

	protected void setTypeName_(String typeName) {
		String old = this.typeName;
		this.typeName = typeName;
		this.firePropertyChanged(TYPE_NAME_PROPERTY, old, typeName);
	}

	public String getFullyQualifiedTypeName() {
		return this.fullyQualifiedTypeName;
	}

	protected void setFullyQualifiedTypeName(String typeName) {
		String old = this.fullyQualifiedTypeName;
		this.fullyQualifiedTypeName = typeName;
		this.firePropertyChanged(FULLY_QUALIFIED_TYPE_NAME_PROPERTY, old, typeName);
	}

	protected String buildFullyQualifiedTypeName() {
		return this.parameterAnnotation.getFullyQualifiedTypeName();
	}

	public char getTypeEnclosingTypeSeparator() {
		return '.';
	}


	// ********** validation **********

	public TextRange getValidationTextRange() {
		TextRange textRange = this.parameterAnnotation.getTextRange();
		return (textRange != null) ? textRange : this.getQuery().getValidationTextRange();
	}

	public boolean isEquivalentTo(StoredProcedureParameter2_1 parameter) {
		return ObjectTools.equals(this.name, parameter.getName()) &&
				ObjectTools.equals(this.specifiedMode, parameter.getMode()) &&
				ObjectTools.equals(this.typeName, parameter.getTypeName()) ;
	}


	// ********** misc **********

	@Override
	public JavaNamedStoredProcedureQuery2_1 getParent() {
		return (JavaNamedStoredProcedureQuery2_1) super.getParent();
	}

	protected JavaNamedStoredProcedureQuery2_1 getQuery() {
		return this.getParent();
	}

	public StoredProcedureParameter2_1Annotation getStoredProcedureParameter2_1Annotation() {
		return this.parameterAnnotation;
	}

}

Back to the top