Lines 9-15
Link Here
|
9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
10 |
package org.eclipse.jpt.core.internal.facet; |
10 |
package org.eclipse.jpt.core.internal.facet; |
11 |
|
11 |
|
12 |
import java.util.Collections; |
|
|
13 |
import java.util.Comparator; |
12 |
import java.util.Comparator; |
14 |
import java.util.HashMap; |
13 |
import java.util.HashMap; |
15 |
import java.util.Iterator; |
14 |
import java.util.Iterator; |
Lines 29-39
Link Here
|
29 |
import org.eclipse.jpt.db.DatabaseFinder; |
28 |
import org.eclipse.jpt.db.DatabaseFinder; |
30 |
import org.eclipse.jpt.db.JptDbPlugin; |
29 |
import org.eclipse.jpt.db.JptDbPlugin; |
31 |
import org.eclipse.jpt.db.Schema; |
30 |
import org.eclipse.jpt.db.Schema; |
|
|
31 |
import org.eclipse.jpt.db.SchemaContainer; |
32 |
import org.eclipse.jpt.utility.internal.CollectionTools; |
32 |
import org.eclipse.jpt.utility.internal.CollectionTools; |
33 |
import org.eclipse.jpt.utility.internal.StringTools; |
|
|
34 |
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; |
35 |
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; |
33 |
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; |
36 |
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; |
|
|
37 |
import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; |
34 |
import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; |
38 |
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; |
35 |
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; |
39 |
import org.eclipse.osgi.util.NLS; |
36 |
import org.eclipse.osgi.util.NLS; |
Lines 41-61
Link Here
|
41 |
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; |
38 |
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; |
42 |
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; |
39 |
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; |
43 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
40 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
44 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages; |
|
|
45 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; |
46 |
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; |
41 |
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; |
47 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
42 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
48 |
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
43 |
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
49 |
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; |
44 |
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; |
50 |
|
45 |
|
51 |
public class JpaFacetDataModelProvider extends FacetInstallDataModelProvider |
46 |
public class JpaFacetDataModelProvider |
|
|
47 |
extends FacetInstallDataModelProvider |
52 |
implements JpaFacetDataModelProperties |
48 |
implements JpaFacetDataModelProperties |
53 |
{ |
49 |
{ |
54 |
private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; |
50 |
private LibraryInstallDelegate defaultLibraryProvider; |
55 |
|
51 |
|
56 |
private static final String RUNTIME_NONE = |
52 |
/** cache the connection profile - change it whenever the user selects a different name */ |
57 |
WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null); |
53 |
private ConnectionProfile connectionProfile; |
|
|
54 |
|
58 |
|
55 |
|
|
|
56 |
private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; |
57 |
|
59 |
private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = |
58 |
private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = |
60 |
buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED); |
59 |
buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED); |
61 |
|
60 |
|
Lines 63-91
Link Here
|
63 |
buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED); |
62 |
buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED); |
64 |
|
63 |
|
65 |
private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = |
64 |
private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = |
66 |
buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); |
65 |
buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); |
67 |
|
66 |
|
68 |
private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = |
67 |
private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = |
69 |
buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); |
68 |
buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); |
70 |
|
69 |
|
71 |
private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = |
70 |
|
72 |
buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED); |
|
|
73 |
|
74 |
private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = |
75 |
buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30); |
76 |
|
77 |
|
78 |
private LibraryInstallDelegate defaultLibraryProvider; |
79 |
|
80 |
|
81 |
/** |
71 |
/** |
82 |
* required default constructor |
72 |
* required default constructor |
83 |
*/ |
73 |
*/ |
84 |
public JpaFacetDataModelProvider() { |
74 |
public JpaFacetDataModelProvider() { |
85 |
super(); |
75 |
super(); |
86 |
} |
76 |
} |
87 |
|
77 |
|
88 |
|
|
|
89 |
@Override |
78 |
@Override |
90 |
public Set<String> getPropertyNames() { |
79 |
public Set<String> getPropertyNames() { |
91 |
@SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames(); |
80 |
@SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames(); |
Lines 105-128
Link Here
|
105 |
propertyNames.add(CREATE_ORM_XML); |
94 |
propertyNames.add(CREATE_ORM_XML); |
106 |
return propertyNames; |
95 |
return propertyNames; |
107 |
} |
96 |
} |
|
|
97 |
|
98 |
|
99 |
// ********** properties ********** |
100 |
|
101 |
private String getPlatformId() { |
102 |
return (String) this.getProperty(PLATFORM_ID); |
103 |
} |
104 |
|
105 |
private String getConnectionName() { |
106 |
return (String) this.getProperty(CONNECTION); |
107 |
} |
108 |
|
109 |
private boolean userWantsToAddDbDriverJarsToClasspath() { |
110 |
return this.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); |
111 |
} |
112 |
|
113 |
private String getDriverName() { |
114 |
return (String) this.getProperty(DB_DRIVER_NAME); |
115 |
} |
116 |
|
117 |
private boolean userWantsToOverrideDefaultCatalog() { |
118 |
return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); |
119 |
} |
108 |
|
120 |
|
|
|
121 |
private String getUserOverrideDefaultCatalog() { |
122 |
return (String) this.getProperty(USER_OVERRIDE_DEFAULT_CATALOG); |
123 |
} |
124 |
|
125 |
private boolean userWantsToOverrideDefaultSchema() { |
126 |
return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); |
127 |
} |
128 |
|
129 |
private String getUserOverrideDefaultSchema() { |
130 |
return (String) this.getProperty(USER_OVERRIDE_DEFAULT_SCHEMA); |
131 |
} |
132 |
|
133 |
private boolean discoverAnnotatedClasses() { |
134 |
return this.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES); |
135 |
} |
136 |
|
137 |
private IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() { |
138 |
return (IFacetedProjectWorkingCopy) this.getProperty(FACETED_PROJECT_WORKING_COPY); |
139 |
} |
140 |
|
141 |
private IProjectFacetVersion getProjectFacetVersion() { |
142 |
return (IProjectFacetVersion) this.getProperty(FACET_VERSION); |
143 |
} |
144 |
|
145 |
private IRuntime getRuntime() { |
146 |
return (IRuntime) this.getProperty(RUNTIME); |
147 |
} |
148 |
|
149 |
private LibraryInstallDelegate getLibraryInstallDelegate() { |
150 |
return (LibraryInstallDelegate) this.getProperty(LIBRARY_PROVIDER_DELEGATE); |
151 |
} |
152 |
|
153 |
|
154 |
// ********** enabled ********** |
155 |
|
109 |
@Override |
156 |
@Override |
110 |
public boolean isPropertyEnabled(String propertyName) { |
157 |
public boolean isPropertyEnabled(String propertyName) { |
111 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
|
|
112 |
return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); |
113 |
} |
114 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
115 |
return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); |
116 |
} |
117 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
158 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
118 |
return getConnectionProfile() != null; |
159 |
return (this.getConnectionProfile() != null); |
119 |
} |
160 |
} |
120 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
161 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
121 |
return getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); |
162 |
return this.userWantsToAddDbDriverJarsToClasspath(); |
122 |
} |
163 |
} |
|
|
164 |
|
165 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
166 |
return this.connectionIsActive() && this.databaseSupportsCatalogs(); |
167 |
} |
168 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
169 |
return this.userWantsToOverrideDefaultCatalog(); |
170 |
} |
171 |
|
172 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
173 |
return this.connectionIsActive(); |
174 |
} |
175 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
176 |
return this.userWantsToOverrideDefaultSchema(); |
177 |
} |
178 |
|
123 |
return super.isPropertyEnabled(propertyName); |
179 |
return super.isPropertyEnabled(propertyName); |
124 |
} |
180 |
} |
125 |
|
181 |
|
|
|
182 |
|
183 |
// ********** defaults ********** |
184 |
|
126 |
@Override |
185 |
@Override |
127 |
public Object getDefaultProperty(String propertyName) { |
186 |
public Object getDefaultProperty(String propertyName) { |
128 |
if (propertyName.equals(RUNTIME)) { |
187 |
if (propertyName.equals(RUNTIME)) { |
Lines 135-171
Link Here
|
135 |
return JptCorePlugin.getDefaultJpaPlatformId(); |
194 |
return JptCorePlugin.getDefaultJpaPlatformId(); |
136 |
} |
195 |
} |
137 |
if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { |
196 |
if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { |
138 |
return getDefaultLibraryProvider(); |
197 |
return this.getDefaultLibraryProvider(); |
139 |
} |
198 |
} |
140 |
if (propertyName.equals(CONNECTION)) { |
199 |
if (propertyName.equals(CONNECTION)) { |
141 |
return null; |
200 |
return null; |
142 |
} |
201 |
} |
143 |
if (propertyName.equals(CONNECTION_ACTIVE)) { |
202 |
if (propertyName.equals(CONNECTION_ACTIVE)) { |
144 |
return Boolean.valueOf(connectionIsActive()); |
203 |
return Boolean.valueOf(this.connectionIsActive()); |
145 |
} |
204 |
} |
146 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
205 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
147 |
return Boolean.FALSE; |
206 |
return Boolean.FALSE; |
148 |
} |
207 |
} |
149 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
208 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
150 |
return getDefaultDriverName(); |
209 |
return this.getDefaultDriverName(); |
151 |
} |
210 |
} |
152 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
211 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
153 |
return Boolean.FALSE; |
212 |
return Boolean.FALSE; |
154 |
} |
213 |
} |
155 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
214 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
156 |
return getDefaultCatalogName(); |
215 |
return this.getDefaultCatalogName(); |
157 |
} |
216 |
} |
158 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
217 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
159 |
return Boolean.FALSE; |
218 |
return Boolean.FALSE; |
160 |
} |
219 |
} |
161 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
220 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
162 |
return getDefaultSchemaName(); |
221 |
return this.getDefaultSchemaName(); |
163 |
} |
222 |
} |
164 |
if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
223 |
if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
165 |
return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime())); |
224 |
return Boolean.valueOf(this.runtimeSupportsEjb30()); |
166 |
} |
225 |
} |
167 |
if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
226 |
if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
168 |
return Boolean.valueOf( ! getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); |
227 |
return Boolean.valueOf( ! this.discoverAnnotatedClasses()); |
169 |
} |
228 |
} |
170 |
if (propertyName.equals(CREATE_ORM_XML)) { |
229 |
if (propertyName.equals(CREATE_ORM_XML)) { |
171 |
return Boolean.TRUE; |
230 |
return Boolean.TRUE; |
Lines 173-235
Link Here
|
173 |
|
232 |
|
174 |
return super.getDefaultProperty(propertyName); |
233 |
return super.getDefaultProperty(propertyName); |
175 |
} |
234 |
} |
176 |
|
235 |
|
177 |
private String getDefaultDriverName() { |
236 |
private LibraryInstallDelegate getDefaultLibraryProvider() { |
178 |
ConnectionProfile cp = this.getConnectionProfile(); |
237 |
// delegate itself changes, not the instance of delegate |
179 |
if (cp == null) { |
238 |
if (this.defaultLibraryProvider == null) { |
180 |
return null; |
239 |
this.defaultLibraryProvider = this.buildDefaultLibraryProvider(); |
181 |
} |
240 |
} |
182 |
return cp.getDriverName(); |
241 |
return defaultLibraryProvider; |
183 |
} |
242 |
} |
184 |
|
243 |
|
185 |
private String getDefaultCatalogName() { |
244 |
private LibraryInstallDelegate buildDefaultLibraryProvider() { |
186 |
ConnectionProfile cp = this.getConnectionProfile(); |
245 |
IFacetedProjectWorkingCopy fpjwc = this.getFacetedProjectWorkingCopy(); |
187 |
if (cp == null) { |
246 |
if (fpjwc == null) { |
188 |
return null; |
247 |
return null; |
189 |
} |
248 |
} |
190 |
Database db = cp.getDatabase(); |
249 |
IProjectFacetVersion pfv = this.getProjectFacetVersion(); |
191 |
if (db == null) { |
250 |
if (pfv == null) { |
192 |
return null; |
251 |
return null; |
193 |
} |
252 |
} |
194 |
Catalog catalog = db.getDefaultCatalog(); |
253 |
LibraryInstallDelegate lp = new LibraryInstallDelegate(fpjwc, pfv, this.buildEnablementVariables()); |
|
|
254 |
lp.addListener(this.buildLibraryProviderListener()); |
255 |
return lp; |
256 |
} |
257 |
|
258 |
private Map<String, Object> buildEnablementVariables() { |
259 |
Map<String, Object> enablementVariables = new HashMap<String, Object>(); |
260 |
enablementVariables.put(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, this.getPlatformId()); |
261 |
return enablementVariables; |
262 |
} |
263 |
|
264 |
private IPropertyChangeListener buildLibraryProviderListener() { |
265 |
return new IPropertyChangeListener() { |
266 |
public void propertyChanged(String property, Object oldValue, Object newValue ) { |
267 |
JpaFacetDataModelProvider.this.getDataModel().notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); |
268 |
} |
269 |
}; |
270 |
} |
271 |
|
272 |
private String getDefaultDriverName() { |
273 |
ConnectionProfile cp = this.getConnectionProfile(); |
274 |
return (cp == null) ? null : cp.getDriverName(); |
275 |
} |
276 |
|
277 |
private String getDefaultCatalogName() { |
278 |
Catalog catalog = this.getDefaultCatalog(); |
195 |
return (catalog == null) ? null : catalog.getIdentifier(); |
279 |
return (catalog == null) ? null : catalog.getIdentifier(); |
196 |
} |
280 |
} |
197 |
|
281 |
|
|
|
282 |
private Catalog getDefaultCatalog() { |
283 |
Database db = this.getDatabase(); |
284 |
return (db == null) ? null : db.getDefaultCatalog(); |
285 |
} |
286 |
|
198 |
private String getDefaultSchemaName() { |
287 |
private String getDefaultSchemaName() { |
199 |
ConnectionProfile cp = this.getConnectionProfile(); |
288 |
Schema schema = this.getDefaultSchema(); |
200 |
if (cp == null) { |
|
|
201 |
return null; |
202 |
} |
203 |
Database db = cp.getDatabase(); |
204 |
if (db == null) { |
205 |
return null; |
206 |
} |
207 |
Schema schema = db.getDefaultSchema(); |
208 |
return (schema == null) ? null : schema.getIdentifier(); |
289 |
return (schema == null) ? null : schema.getIdentifier(); |
209 |
} |
290 |
} |
210 |
|
291 |
|
211 |
private LibraryInstallDelegate getDefaultLibraryProvider() { |
292 |
private Schema getDefaultSchema() { |
212 |
// delegate itself changes, not the instance of delegate |
293 |
SchemaContainer sc = this.getSchemaContainer(); |
213 |
if (defaultLibraryProvider == null) { |
294 |
return (sc == null) ? null : sc.getDefaultSchema(); |
214 |
IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(FACETED_PROJECT_WORKING_COPY); |
|
|
215 |
IProjectFacetVersion fv = (IProjectFacetVersion) getProperty(FACET_VERSION); |
216 |
if (fpjwc != null && fv != null ) { |
217 |
Map<String, Object> enablementVariables = new HashMap<String, Object>(); |
218 |
enablementVariables.put( |
219 |
JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, |
220 |
getPlatformId()); |
221 |
defaultLibraryProvider = new LibraryInstallDelegate(fpjwc, fv, enablementVariables); |
222 |
defaultLibraryProvider.addListener( |
223 |
new IPropertyChangeListener() { |
224 |
public void propertyChanged(final String property, final Object oldValue, final Object newValue ) { |
225 |
JpaFacetDataModelProvider.this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); |
226 |
} |
227 |
}); |
228 |
} |
229 |
} |
230 |
return defaultLibraryProvider; |
231 |
} |
295 |
} |
232 |
|
296 |
|
|
|
297 |
private boolean runtimeSupportsEjb30() { |
298 |
IRuntime runtime = this.getRuntime(); |
299 |
return (runtime != null) && runtime.supports(this.getEJB30()); |
300 |
} |
301 |
|
302 |
private IProjectFacetVersion getEJB30() { |
303 |
return ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ |
304 |
} |
305 |
|
306 |
|
307 |
// ********** synchronize data model ********** |
308 |
|
233 |
@Override |
309 |
@Override |
234 |
public boolean propertySet(String propertyName, Object propertyValue) { |
310 |
public boolean propertySet(String propertyName, Object propertyValue) { |
235 |
boolean ok = super.propertySet(propertyName, propertyValue); |
311 |
boolean ok = super.propertySet(propertyName, propertyValue); |
Lines 237-247
Link Here
|
237 |
if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { |
313 |
if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { |
238 |
//no-op |
314 |
//no-op |
239 |
} |
315 |
} |
240 |
if( propertyName.equals(FACET_VERSION)){ |
316 |
else if (propertyName.equals(FACET_VERSION)) { |
241 |
this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); |
317 |
this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); |
242 |
} |
318 |
} |
243 |
if (propertyName.equals(RUNTIME)) { |
319 |
else if (propertyName.equals(RUNTIME)) { |
244 |
LibraryInstallDelegate lid = getLibraryInstallDelegate(); |
320 |
LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); |
245 |
if (lid != null) { |
321 |
if (lid != null) { |
246 |
// may be null while model is being built up |
322 |
// may be null while model is being built up |
247 |
// ... or in tests |
323 |
// ... or in tests |
Lines 250-570
Link Here
|
250 |
this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
326 |
this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
251 |
this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
327 |
this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
252 |
} |
328 |
} |
253 |
if (propertyName.equals(PLATFORM_ID)) { |
329 |
else if (propertyName.equals(PLATFORM_ID)) { |
254 |
LibraryInstallDelegate lid = getLibraryInstallDelegate(); |
330 |
LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); |
255 |
if (lid != null) { |
331 |
if (lid != null) { |
256 |
// may be null while model is being built up |
332 |
// may be null while model is being built up |
257 |
// ... or in tests |
333 |
// ... or in tests |
258 |
lid.setEnablementContextVariable( |
334 |
lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue); |
259 |
JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, |
|
|
260 |
(String) propertyValue); |
261 |
} |
335 |
} |
262 |
} |
336 |
} |
263 |
if (propertyName.equals(CONNECTION)) { |
337 |
else if (propertyName.equals(CONNECTION)) { |
264 |
this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); |
338 |
this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive()); |
265 |
this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive()); |
339 |
|
|
|
340 |
// db driver |
341 |
if (propertyValue == null) { // connection set to '<None>' |
342 |
this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false); |
343 |
} |
344 |
this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); |
266 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); |
345 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); |
267 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); |
346 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); |
|
|
347 |
|
348 |
// catalog |
349 |
if ((propertyValue == null) || ! this.databaseSupportsCatalogs()) { // connection set to '<None>' or "non-catalog" database |
350 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); |
351 |
} |
352 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
268 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
353 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
269 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
354 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
|
|
355 |
|
356 |
// schema |
357 |
if (propertyValue == null) { // connection set to '<None>' |
358 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); |
359 |
} |
360 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
270 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
361 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
271 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
362 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
272 |
} |
363 |
} |
273 |
if (propertyName.equals(CONNECTION_ACTIVE)) { |
364 |
else if (propertyName.equals(CONNECTION_ACTIVE)) { |
|
|
365 |
// catalog |
366 |
if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive |
367 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); |
368 |
} |
369 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
274 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
370 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
275 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
371 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
|
|
372 |
|
373 |
// schema |
374 |
if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive |
375 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); |
376 |
} |
377 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
276 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
378 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
277 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
379 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
278 |
this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); |
|
|
279 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); |
280 |
} |
380 |
} |
281 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
381 |
else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
282 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); |
382 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); |
283 |
if (! ((Boolean) propertyValue).booleanValue()) { |
383 |
if (this.propertyValueIsFalse(propertyValue)) { |
284 |
this.model.setProperty(DB_DRIVER_NAME, null); |
384 |
this.setProperty(DB_DRIVER_NAME, null); |
285 |
} |
385 |
} |
286 |
} |
386 |
} |
287 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
387 |
else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
288 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
388 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
289 |
if (! ((Boolean) propertyValue).booleanValue()) { |
389 |
if (this.propertyValueIsFalse(propertyValue)) { |
290 |
this.model.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); |
390 |
this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); |
291 |
} |
391 |
} |
292 |
} |
392 |
} |
293 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
393 |
else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
294 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
394 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
295 |
if (! ((Boolean) propertyValue).booleanValue()) { |
395 |
if (this.propertyValueIsFalse(propertyValue)) { |
296 |
this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); |
396 |
this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); |
297 |
} |
397 |
} |
298 |
} |
398 |
} |
299 |
// if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { |
399 |
else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
300 |
// this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue()); |
400 |
this.setBooleanProperty(LIST_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); |
301 |
// } |
|
|
302 |
// if (propertyName.equals(USE_USER_JPA_LIBRARY)) { |
303 |
// this.model.setBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION, ! ((Boolean) propertyValue).booleanValue()); |
304 |
// this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG); |
305 |
// } |
306 |
if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
307 |
this.model.setBooleanProperty(LIST_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); |
308 |
} |
401 |
} |
309 |
if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
402 |
else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
310 |
this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); |
403 |
this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); |
311 |
} |
404 |
} |
312 |
return ok; |
405 |
return ok; |
313 |
} |
406 |
} |
314 |
|
407 |
|
315 |
private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; |
408 |
private boolean propertyValueIsFalse(Object propertyValue) { |
|
|
409 |
return ! this.propertyValueIsTrue(propertyValue); |
410 |
} |
411 |
|
412 |
private boolean propertyValueIsTrue(Object propertyValue) { |
413 |
return ((Boolean) propertyValue).booleanValue(); |
414 |
} |
415 |
|
416 |
|
417 |
// ********** property descriptors ********** |
316 |
|
418 |
|
317 |
@Override |
419 |
@Override |
318 |
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { |
420 |
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { |
319 |
if (propertyName.equals(PLATFORM_ID)) { |
421 |
if (propertyName.equals(PLATFORM_ID)) { |
320 |
return CollectionTools.sort( |
422 |
return this.buildValidPlatformDescriptors(); |
321 |
CollectionTools.array( |
|
|
322 |
new TransformationIterator<String, DataModelPropertyDescriptor>( |
323 |
JpaPlatformRegistry.instance().jpaPlatformIds()) { |
324 |
@Override |
325 |
protected DataModelPropertyDescriptor transform(String platformId) { |
326 |
return platformIdPropertyDescriptor(platformId); |
327 |
} |
328 |
}, |
329 |
EMPTY_DMPD_ARRAY), |
330 |
new Comparator<DataModelPropertyDescriptor>() { |
331 |
public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { |
332 |
return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); |
333 |
}; |
334 |
}); |
335 |
} |
423 |
} |
|
|
424 |
|
336 |
if (propertyName.equals(CONNECTION)) { |
425 |
if (propertyName.equals(CONNECTION)) { |
337 |
return CollectionTools.array( |
426 |
return this.buildValidConnectionDescriptors(); |
338 |
new TransformationIterator<String, DataModelPropertyDescriptor>( |
|
|
339 |
new CompositeIterator<String>(null, connectionNames())) { |
340 |
@Override |
341 |
protected DataModelPropertyDescriptor transform(String next) { |
342 |
return connectionPropertyDescriptor(next); |
343 |
} |
344 |
}, |
345 |
EMPTY_DMPD_ARRAY); |
346 |
} |
427 |
} |
|
|
428 |
|
347 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
429 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
348 |
return CollectionTools.array( |
430 |
return this.buildValidDriverDescriptors(); |
349 |
new TransformationIterator<String, DataModelPropertyDescriptor>(driverNames()) { |
|
|
350 |
@Override |
351 |
protected DataModelPropertyDescriptor transform(String next) { |
352 |
return new DataModelPropertyDescriptor(next); |
353 |
} |
354 |
}, |
355 |
EMPTY_DMPD_ARRAY); |
356 |
} |
431 |
} |
|
|
432 |
|
357 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
433 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
358 |
return CollectionTools.array( |
434 |
return this.buildValidCatalogDescriptors(); |
359 |
new TransformationIterator<String, DataModelPropertyDescriptor>(catalogNames()) { |
|
|
360 |
@Override |
361 |
protected DataModelPropertyDescriptor transform(String next) { |
362 |
return new DataModelPropertyDescriptor(next); |
363 |
} |
364 |
}, |
365 |
EMPTY_DMPD_ARRAY); |
366 |
} |
435 |
} |
|
|
436 |
|
367 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
437 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
368 |
return CollectionTools.array( |
438 |
return this.buildValidSchemaDescriptors(); |
369 |
new TransformationIterator<String, DataModelPropertyDescriptor>(schemaNames()) { |
|
|
370 |
@Override |
371 |
protected DataModelPropertyDescriptor transform(String next) { |
372 |
return new DataModelPropertyDescriptor(next); |
373 |
} |
374 |
}, |
375 |
EMPTY_DMPD_ARRAY); |
376 |
} |
439 |
} |
377 |
|
440 |
|
378 |
return super.getValidPropertyDescriptors(propertyName); |
441 |
return super.getValidPropertyDescriptors(propertyName); |
379 |
} |
442 |
} |
380 |
|
443 |
|
|
|
444 |
private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { |
445 |
List<String> platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds()); |
446 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()]; |
447 |
for (int i = 0; i < descriptors.length; i++) { |
448 |
descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i)); |
449 |
} |
450 |
return CollectionTools.sort(descriptors, this.buildDescriptorComparator()); |
451 |
} |
452 |
|
453 |
/** |
454 |
* sort the descriptors by 'description' (as opposed to 'value') |
455 |
*/ |
456 |
private Comparator<DataModelPropertyDescriptor> buildDescriptorComparator() { |
457 |
return new Comparator<DataModelPropertyDescriptor>() { |
458 |
public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { |
459 |
return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); |
460 |
} |
461 |
}; |
462 |
} |
463 |
|
464 |
private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() { |
465 |
List<String> connectionNames = this.buildValidConnectionNames(); |
466 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()]; |
467 |
for (int i = 0; i < descriptors.length; i++) { |
468 |
descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i)); |
469 |
} |
470 |
return descriptors; |
471 |
} |
472 |
|
473 |
/** |
474 |
* put a null entry at the top of the list (for <none>) |
475 |
*/ |
476 |
private List<String> buildValidConnectionNames() { |
477 |
List<String> connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames())); |
478 |
connectionNames.add(0, null); |
479 |
return connectionNames; |
480 |
} |
481 |
|
482 |
private DataModelPropertyDescriptor[] buildValidDriverDescriptors() { |
483 |
return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) }; |
484 |
} |
485 |
|
486 |
private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() { |
487 |
Database db = this.getDatabase(); |
488 |
return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogNames(db)); |
489 |
} |
490 |
|
491 |
/** |
492 |
* pre-condition: 'db' is not null |
493 |
*/ |
494 |
private List<String> buildValidCatalogNames(Database db) { |
495 |
return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogName()); |
496 |
} |
497 |
|
498 |
private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() { |
499 |
Database db = this.getDatabase(); |
500 |
return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaNames()); |
501 |
} |
502 |
|
503 |
private List<String> buildValidSchemaNames() { |
504 |
return this.buildValidStrings(this.schemaNames(), this.getDefaultSchemaName()); |
505 |
} |
506 |
|
507 |
private Iterator<String> schemaNames() { |
508 |
SchemaContainer sc = this.getSchemaContainer(); |
509 |
return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers(); |
510 |
} |
511 |
|
512 |
/** |
513 |
* put an entry for the default at the top of the list |
514 |
*/ |
515 |
private List<String> buildValidStrings(Iterator<String> stream, String defaultString) { |
516 |
List<String> strings = CollectionTools.list(stream); |
517 |
if ((defaultString != null) && ! strings.contains(defaultString)) { |
518 |
strings.add(0, defaultString); |
519 |
} |
520 |
return strings; |
521 |
} |
522 |
|
523 |
private DataModelPropertyDescriptor[] buildDescriptors(List<String> strings) { |
524 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()]; |
525 |
for (int i = 0; i < descriptors.length; i++) { |
526 |
descriptors[i] = new DataModelPropertyDescriptor(strings.get(i)); |
527 |
} |
528 |
return descriptors; |
529 |
} |
530 |
|
531 |
private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; |
532 |
|
533 |
/** |
534 |
* platform and connection have 'description's (in addition to 'value's) |
535 |
*/ |
381 |
@Override |
536 |
@Override |
382 |
public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { |
537 |
public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { |
383 |
if (propertyName.equals(PLATFORM_ID)) { |
538 |
if (propertyName.equals(PLATFORM_ID)) { |
384 |
return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID)); |
539 |
return this.buildPlatformIdDescriptor(this.getPlatformId()); |
385 |
} |
540 |
} |
386 |
if (propertyName.equals(CONNECTION)) { |
541 |
if (propertyName.equals(CONNECTION)) { |
387 |
return connectionPropertyDescriptor(getStringProperty(CONNECTION)); |
542 |
return this.buildConnectionDescriptor(this.getConnectionName()); |
388 |
} |
543 |
} |
389 |
return super.getPropertyDescriptor(propertyName); |
544 |
return super.getPropertyDescriptor(propertyName); |
390 |
} |
545 |
} |
391 |
|
546 |
|
392 |
DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) { |
547 |
DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) { |
393 |
return new DataModelPropertyDescriptor( |
548 |
return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId)); |
394 |
platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId)); |
|
|
395 |
} |
549 |
} |
396 |
|
550 |
|
397 |
DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) { |
551 |
private String getPlatformLabel(String platformId) { |
398 |
return StringTools.stringIsEmpty(connection) ? |
552 |
return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); |
399 |
new DataModelPropertyDescriptor(null, JptCoreMessages.NONE) |
|
|
400 |
: |
401 |
new DataModelPropertyDescriptor(connection); |
402 |
} |
553 |
} |
403 |
|
554 |
|
404 |
@Override |
555 |
private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { |
405 |
public IStatus validate(String name) { |
556 |
String description = (connectionName == null) ? JptCoreMessages.NONE : null; |
406 |
if (name.equals(PLATFORM_ID)) { |
557 |
return new DataModelPropertyDescriptor(connectionName, description); |
407 |
return this.validatePlatformId(this.getStringProperty(name)); |
|
|
408 |
} |
409 |
if (name.equals(LIBRARY_PROVIDER_DELEGATE)) { |
410 |
LibraryInstallDelegate delegate = (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); |
411 |
return delegate.validate(); |
412 |
} |
413 |
if (name.equals(CONNECTION)) { |
414 |
return this.validateConnectionName(this.getStringProperty(name)); |
415 |
} |
416 |
if (name.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) |
417 |
|| name.equals(DB_DRIVER_NAME)) { |
418 |
return this.validateDbDriverName(); |
419 |
} |
420 |
if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) |
421 |
|| name.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
422 |
return this.validateUserOverrideDefaultCatalog(); |
423 |
} |
424 |
if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) |
425 |
|| name.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
426 |
return this.validateUserOverrideDefaultSchema(); |
427 |
} |
428 |
if (name.equals(DISCOVER_ANNOTATED_CLASSES)) { |
429 |
return this.validatePersistentClassManagement(this.getBooleanProperty(name)); |
430 |
} |
431 |
|
432 |
return super.validate(name); |
433 |
} |
558 |
} |
434 |
|
559 |
|
435 |
private IRuntime runtime() { |
560 |
|
436 |
return (IRuntime) this.getProperty(RUNTIME); |
561 |
// ********** database ********** |
|
|
562 |
|
563 |
private SchemaContainer getSchemaContainer() { |
564 |
return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); |
437 |
} |
565 |
} |
438 |
|
566 |
|
439 |
private boolean runtimeSupportsEjb30(IRuntime runtime) { |
567 |
private Catalog getCatalog() { |
440 |
IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ |
568 |
String name = this.getUserOverrideDefaultCatalog(); |
441 |
return (runtime == null) ? false : runtime.supports(ejb30); |
569 |
return (name == null) ? null : this.getCatalog(name); |
442 |
} |
570 |
} |
443 |
|
571 |
|
444 |
private String getPlatformId() { |
572 |
/** |
445 |
return this.getStringProperty(PLATFORM_ID); |
573 |
* pre-condition: 'name' is not null |
|
|
574 |
*/ |
575 |
private Catalog getCatalog(String name) { |
576 |
Database db = this.getDatabase(); |
577 |
return (db == null) ? null : db.getCatalogForIdentifier(name); |
578 |
} |
579 |
|
580 |
private boolean databaseSupportsCatalogs() { |
581 |
Database db = this.getDatabase(); |
582 |
return (db != null) && db.supportsCatalogs(); |
446 |
} |
583 |
} |
447 |
|
584 |
|
448 |
private LibraryInstallDelegate getLibraryInstallDelegate() { |
585 |
private Database getDatabase() { |
449 |
return (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); |
586 |
ConnectionProfile cp = this.getConnectionProfile(); |
|
|
587 |
return (cp == null) ? null : cp.getDatabase(); |
450 |
} |
588 |
} |
451 |
|
589 |
|
452 |
private String getConnectionName() { |
590 |
private boolean connectionIsActive() { |
453 |
return this.getStringProperty(CONNECTION); |
591 |
ConnectionProfile cp = this.getConnectionProfile(); |
|
|
592 |
return (cp != null) && cp.isActive(); |
454 |
} |
593 |
} |
455 |
|
594 |
|
456 |
private ConnectionProfile getConnectionProfile() { |
595 |
private ConnectionProfile getConnectionProfile() { |
457 |
return this.buildConnectionProfile(this.getConnectionName()); |
596 |
String name = this.getConnectionName(); |
|
|
597 |
return (name == null) ? null : this.getConnectionProfile(name); |
458 |
} |
598 |
} |
459 |
|
599 |
|
460 |
private ConnectionProfileFactory getConnectionProfileFactory() { |
600 |
/** |
461 |
// we don't have a JPA project yet, so go to the db plug-in directly to get the factory |
601 |
* pre-condition: 'name' is not null |
462 |
return JptDbPlugin.instance().getConnectionProfileFactory(); |
602 |
*/ |
|
|
603 |
private ConnectionProfile getConnectionProfile(String name) { |
604 |
if (this.cachedConnectionProfileIsStale(name)) { |
605 |
this.connectionProfile = this.buildConnectionProfile(name); |
606 |
} |
607 |
return this.connectionProfile; |
463 |
} |
608 |
} |
464 |
|
609 |
|
465 |
private ConnectionProfile buildConnectionProfile(String name) { |
610 |
private boolean cachedConnectionProfileIsStale(String name) { |
466 |
return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); |
611 |
return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name); |
467 |
} |
612 |
} |
468 |
|
613 |
|
469 |
private boolean connectionIsActive() { |
614 |
private ConnectionProfile buildConnectionProfile(String name) { |
470 |
return this.connectionIsActive(this.getConnectionName()); |
615 |
return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); |
471 |
} |
616 |
} |
472 |
|
617 |
|
473 |
private boolean connectionIsActive(String connectionName) { |
618 |
private Iterator<String> connectionProfileNames() { |
474 |
ConnectionProfile cp = this.buildConnectionProfile(connectionName); |
619 |
return this.getConnectionProfileFactory().connectionProfileNames(); |
475 |
return (cp != null) && cp.isActive(); |
|
|
476 |
} |
620 |
} |
477 |
|
621 |
|
478 |
private Iterator<String> connectionNames() { |
622 |
private ConnectionProfileFactory getConnectionProfileFactory() { |
479 |
String setValue = getStringProperty(CONNECTION); |
623 |
// we don't have a JPA project yet, so go to the db plug-in directly to get the factory |
480 |
|
624 |
return JptDbPlugin.instance().getConnectionProfileFactory(); |
481 |
List<String> connectionNames = CollectionTools.sort(CollectionTools.list( |
|
|
482 |
this.getConnectionProfileFactory().connectionProfileNames())); |
483 |
|
484 |
if (! StringTools.stringIsEmpty(setValue) && ! connectionNames.contains(setValue)) { |
485 |
return new CompositeIterator<String>(setValue, connectionNames.iterator()); |
486 |
} |
487 |
return connectionNames.iterator(); |
488 |
} |
625 |
} |
489 |
|
626 |
|
490 |
private List<String> buildSortedCatalogNames() { |
627 |
|
491 |
ConnectionProfile cp = this.getConnectionProfile(); |
628 |
// ********** validation ********** |
492 |
if (cp == null) { |
629 |
|
493 |
return Collections.emptyList(); |
630 |
@Override |
|
|
631 |
public IStatus validate(String propertyName) { |
632 |
if (propertyName.equals(PLATFORM_ID)) { |
633 |
return this.validatePlatformId(); |
494 |
} |
634 |
} |
495 |
Database db = cp.getDatabase(); |
635 |
if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { |
496 |
if (db == null) { |
636 |
return this.getLibraryInstallDelegate().validate(); |
497 |
return Collections.emptyList(); |
|
|
498 |
} |
637 |
} |
499 |
return CollectionTools.list(db.sortedCatalogIdentifiers()); |
638 |
if (propertyName.equals(CONNECTION)) { |
500 |
} |
639 |
return this.validateConnection(); |
501 |
|
|
|
502 |
private Iterator<String> catalogNames() { |
503 |
String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG); |
504 |
List<String> catalogNames = this.buildSortedCatalogNames(); |
505 |
|
506 |
if (StringTools.stringIsEmpty(setValue) || catalogNames.contains(setValue)) { |
507 |
return catalogNames.iterator(); |
508 |
} |
640 |
} |
509 |
return new CompositeIterator<String>(setValue, catalogNames.iterator()); |
641 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) |
510 |
} |
642 |
|| propertyName.equals(DB_DRIVER_NAME)) { |
511 |
|
643 |
return this.validateDbDriverName(); |
512 |
private List<String> buildSortedSchemaNames() { |
|
|
513 |
ConnectionProfile cp = this.getConnectionProfile(); |
514 |
if (cp == null) { |
515 |
return Collections.emptyList(); |
516 |
} |
644 |
} |
517 |
Database db = cp.getDatabase(); |
645 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) |
518 |
if (db == null) { |
646 |
|| propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
519 |
return Collections.emptyList(); |
647 |
return this.validateUserOverrideDefaultCatalog(); |
520 |
} |
648 |
} |
521 |
return CollectionTools.list(db.sortedSchemaIdentifiers()); // use identifiers? names seem OK since combo-box is read-only? |
649 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) |
522 |
} |
650 |
|| propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
523 |
|
651 |
return this.validateUserOverrideDefaultSchema(); |
524 |
private Iterator<String> schemaNames() { |
652 |
} |
525 |
String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA); |
653 |
if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
526 |
List<String> schemaNames = this.buildSortedSchemaNames(); |
654 |
return this.validatePersistentClassManagement(); |
527 |
|
|
|
528 |
if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) { |
529 |
return schemaNames.iterator(); |
530 |
} |
655 |
} |
531 |
return new CompositeIterator<String>(setValue, schemaNames.iterator()); |
|
|
532 |
} |
533 |
|
534 |
private Iterator<String> driverNames() { |
535 |
String setValue = getStringProperty(DB_DRIVER_NAME); |
536 |
|
656 |
|
537 |
return new CompositeIterator<String>(setValue, EmptyIterator.<String> instance()); |
657 |
return super.validate(propertyName); |
538 |
} |
658 |
} |
539 |
|
659 |
|
540 |
|
660 |
private IStatus validatePlatformId() { |
541 |
// ********** validation ********** |
661 |
return (this.getPlatformId() == null) ? PLATFORM_NOT_SPECIFIED_STATUS : OK_STATUS; |
542 |
|
|
|
543 |
private IStatus validatePlatformId(String platformId) { |
544 |
return StringTools.stringIsEmpty(platformId) ? |
545 |
PLATFORM_NOT_SPECIFIED_STATUS |
546 |
: |
547 |
OK_STATUS; |
548 |
} |
662 |
} |
549 |
|
663 |
|
550 |
private IStatus validateConnectionName(String connectionName) { |
664 |
private IStatus validateConnection() { |
551 |
if (StringTools.stringIsEmpty(connectionName)) { |
665 |
String connectionName = this.getConnectionName(); |
552 |
return OK_STATUS; |
666 |
return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName); |
553 |
} |
667 |
} |
554 |
ConnectionProfile connectionProfile = getConnectionProfile(); |
|
|
555 |
if (connectionProfile == null) { |
556 |
return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); |
557 |
|
668 |
|
|
|
669 |
private IStatus validateNonNullConnection(String connectionName) { |
670 |
ConnectionProfile cp = this.getConnectionProfile(connectionName); |
671 |
if (cp == null) { |
672 |
return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); |
558 |
} |
673 |
} |
559 |
if (! connectionProfile.isActive()) { |
674 |
if ( ! cp.isActive()) { |
560 |
return CONNECTION_NOT_CONNECTED_STATUS; |
675 |
return CONNECTION_NOT_CONNECTED_STATUS; |
561 |
} |
676 |
} |
562 |
return OK_STATUS; |
677 |
return OK_STATUS; |
563 |
} |
678 |
} |
564 |
|
679 |
|
|
|
680 |
private IStatus validateDbDriverName() { |
681 |
return OK_STATUS; |
682 |
} |
683 |
|
565 |
private IStatus validateUserOverrideDefaultCatalog() { |
684 |
private IStatus validateUserOverrideDefaultCatalog() { |
566 |
if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
685 |
if (this.userWantsToOverrideDefaultCatalog()) { |
567 |
if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG))) { |
686 |
if (this.getUserOverrideDefaultCatalog() == null) { |
568 |
return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; |
687 |
return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; |
569 |
} |
688 |
} |
570 |
} |
689 |
} |
Lines 572-594
Link Here
|
572 |
} |
691 |
} |
573 |
|
692 |
|
574 |
private IStatus validateUserOverrideDefaultSchema() { |
693 |
private IStatus validateUserOverrideDefaultSchema() { |
575 |
if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
694 |
if (this.userWantsToOverrideDefaultSchema()) { |
576 |
if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) { |
695 |
if (this.getUserOverrideDefaultSchema() == null) { |
577 |
return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; |
696 |
return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; |
578 |
} |
697 |
} |
579 |
} |
698 |
} |
580 |
return OK_STATUS; |
699 |
return OK_STATUS; |
581 |
} |
700 |
} |
582 |
|
701 |
|
583 |
private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) { |
702 |
private IStatus validatePersistentClassManagement() { |
|
|
703 |
@SuppressWarnings("unused") boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses(); |
584 |
// TODO warning if "discovery" is used, but no runtime specified ?? |
704 |
// TODO warning if "discovery" is used, but no runtime specified ?? |
585 |
return OK_STATUS; |
705 |
return OK_STATUS; |
586 |
} |
706 |
} |
587 |
|
707 |
|
588 |
private IStatus validateDbDriverName() { |
|
|
589 |
return OK_STATUS; |
590 |
} |
591 |
|
592 |
|
708 |
|
593 |
// ********** static methods ********** |
709 |
// ********** static methods ********** |
594 |
|
710 |
|
Lines 596-604
Link Here
|
596 |
return buildStatus(IStatus.INFO, message); |
712 |
return buildStatus(IStatus.INFO, message); |
597 |
} |
713 |
} |
598 |
|
714 |
|
599 |
private static IStatus buildWarningStatus(String message) { |
715 |
// private static IStatus buildWarningStatus(String message) { |
600 |
return buildStatus(IStatus.WARNING, message); |
716 |
// return buildStatus(IStatus.WARNING, message); |
601 |
} |
717 |
// } |
602 |
|
718 |
|
603 |
private static IStatus buildErrorStatus(String message) { |
719 |
private static IStatus buildErrorStatus(String message) { |
604 |
return buildStatus(IStatus.ERROR, message); |
720 |
return buildStatus(IStatus.ERROR, message); |
Lines 607-610
Link Here
|
607 |
private static IStatus buildStatus(int severity, String message) { |
723 |
private static IStatus buildStatus(int severity, String message) { |
608 |
return new Status(severity, JptCorePlugin.PLUGIN_ID, message); |
724 |
return new Status(severity, JptCorePlugin.PLUGIN_ID, message); |
609 |
} |
725 |
} |
|
|
726 |
|
610 |
} |
727 |
} |