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(); |
|
|
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(); |
122 |
} |
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 |
|
309 |
/** |
310 |
* The specified property's value has changed to the specified value. |
311 |
* Return whether to fire a VALUE_CHG DataModelEvent. |
312 |
*/ |
233 |
@Override |
313 |
@Override |
234 |
public boolean propertySet(String propertyName, Object propertyValue) { |
314 |
public boolean propertySet(String propertyName, Object propertyValue) { |
235 |
boolean ok = super.propertySet(propertyName, propertyValue); |
315 |
boolean ok = super.propertySet(propertyName, propertyValue); |
Lines 237-247
Link Here
|
237 |
if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { |
317 |
if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { |
238 |
//no-op |
318 |
//no-op |
239 |
} |
319 |
} |
240 |
if( propertyName.equals(FACET_VERSION)){ |
320 |
else if (propertyName.equals(FACET_VERSION)) { |
241 |
this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); |
321 |
this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); |
242 |
} |
322 |
} |
243 |
if (propertyName.equals(RUNTIME)) { |
323 |
else if (propertyName.equals(RUNTIME)) { |
244 |
LibraryInstallDelegate lid = getLibraryInstallDelegate(); |
324 |
LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); |
245 |
if (lid != null) { |
325 |
if (lid != null) { |
246 |
// may be null while model is being built up |
326 |
// may be null while model is being built up |
247 |
// ... or in tests |
327 |
// ... or in tests |
Lines 250-570
Link Here
|
250 |
this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
330 |
this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
251 |
this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
331 |
this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); |
252 |
} |
332 |
} |
253 |
if (propertyName.equals(PLATFORM_ID)) { |
333 |
else if (propertyName.equals(PLATFORM_ID)) { |
254 |
LibraryInstallDelegate lid = getLibraryInstallDelegate(); |
334 |
LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); |
255 |
if (lid != null) { |
335 |
if (lid != null) { |
256 |
// may be null while model is being built up |
336 |
// may be null while model is being built up |
257 |
// ... or in tests |
337 |
// ... or in tests |
258 |
lid.setEnablementContextVariable( |
338 |
lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue); |
259 |
JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, |
|
|
260 |
(String) propertyValue); |
261 |
} |
339 |
} |
262 |
} |
340 |
} |
263 |
if (propertyName.equals(CONNECTION)) { |
341 |
else if (propertyName.equals(CONNECTION)) { |
264 |
this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); |
342 |
this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive()); |
265 |
this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive()); |
343 |
|
|
|
344 |
// db driver |
345 |
if (propertyValue == null) { // connection set to '<None>' |
346 |
this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false); |
347 |
} |
348 |
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); |
349 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); |
267 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); |
350 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); |
|
|
351 |
|
352 |
// catalog |
353 |
if ((propertyValue != null) && this.databaseSupportsCatalogs()) { // connection set to something that supports catalogs |
354 |
this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, this.getDefaultCatalogName()); |
355 |
} else { // connection either '<None>' or non-catalog database |
356 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); |
357 |
} |
358 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
268 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
359 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
269 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
360 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
|
|
361 |
|
362 |
// schema |
363 |
if (propertyValue == null) { // connection set to '<None>' |
364 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); |
365 |
} else { |
366 |
this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, this.getDefaultSchemaName()); |
367 |
} |
368 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
270 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
369 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
271 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
370 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
272 |
} |
371 |
} |
273 |
if (propertyName.equals(CONNECTION_ACTIVE)) { |
372 |
else if (propertyName.equals(CONNECTION_ACTIVE)) { |
|
|
373 |
// catalog |
374 |
if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive |
375 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); |
376 |
} |
377 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
274 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
378 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); |
275 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
379 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); |
|
|
380 |
|
381 |
// schema |
382 |
if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive |
383 |
this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); |
384 |
} |
385 |
this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
276 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
386 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); |
277 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); |
387 |
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 |
} |
388 |
} |
281 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
389 |
else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { |
282 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); |
390 |
this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); |
283 |
if (! ((Boolean) propertyValue).booleanValue()) { |
391 |
if (this.propertyValueIsFalse(propertyValue)) { |
284 |
this.model.setProperty(DB_DRIVER_NAME, null); |
392 |
this.setProperty(DB_DRIVER_NAME, null); |
285 |
} |
393 |
} |
286 |
} |
394 |
} |
287 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
395 |
else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
288 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
396 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); |
289 |
if (! ((Boolean) propertyValue).booleanValue()) { |
397 |
if (this.propertyValueIsFalse(propertyValue)) { |
290 |
this.model.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); |
398 |
this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); |
291 |
} |
399 |
} |
292 |
} |
400 |
} |
293 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
401 |
else if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
|
|
402 |
this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, this.getDefaultSchemaName()); |
403 |
} |
404 |
else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
294 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
405 |
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); |
295 |
if (! ((Boolean) propertyValue).booleanValue()) { |
406 |
if (this.propertyValueIsFalse(propertyValue)) { |
296 |
this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); |
407 |
this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); |
297 |
} |
408 |
} |
298 |
} |
409 |
} |
299 |
// if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { |
410 |
else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
300 |
// this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue()); |
411 |
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 |
} |
412 |
} |
309 |
if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
413 |
else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { |
310 |
this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); |
414 |
this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); |
311 |
} |
415 |
} |
312 |
return ok; |
416 |
return ok; |
313 |
} |
417 |
} |
314 |
|
418 |
|
315 |
private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; |
419 |
private boolean propertyValueIsFalse(Object propertyValue) { |
|
|
420 |
return ! this.propertyValueIsTrue(propertyValue); |
421 |
} |
422 |
|
423 |
private boolean propertyValueIsTrue(Object propertyValue) { |
424 |
return ((Boolean) propertyValue).booleanValue(); |
425 |
} |
426 |
|
427 |
|
428 |
// ********** property descriptors ********** |
316 |
|
429 |
|
317 |
@Override |
430 |
@Override |
318 |
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { |
431 |
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { |
319 |
if (propertyName.equals(PLATFORM_ID)) { |
432 |
if (propertyName.equals(PLATFORM_ID)) { |
320 |
return CollectionTools.sort( |
433 |
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 |
} |
434 |
} |
|
|
435 |
|
336 |
if (propertyName.equals(CONNECTION)) { |
436 |
if (propertyName.equals(CONNECTION)) { |
337 |
return CollectionTools.array( |
437 |
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 |
} |
438 |
} |
|
|
439 |
|
347 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
440 |
if (propertyName.equals(DB_DRIVER_NAME)) { |
348 |
return CollectionTools.array( |
441 |
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 |
} |
442 |
} |
|
|
443 |
|
357 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
444 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
358 |
return CollectionTools.array( |
445 |
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 |
} |
446 |
} |
|
|
447 |
|
367 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
448 |
if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
368 |
return CollectionTools.array( |
449 |
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 |
} |
450 |
} |
377 |
|
451 |
|
378 |
return super.getValidPropertyDescriptors(propertyName); |
452 |
return super.getValidPropertyDescriptors(propertyName); |
379 |
} |
453 |
} |
380 |
|
454 |
|
|
|
455 |
private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { |
456 |
List<String> platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds()); |
457 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()]; |
458 |
for (int i = 0; i < descriptors.length; i++) { |
459 |
descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i)); |
460 |
} |
461 |
return CollectionTools.sort(descriptors, this.buildDescriptorComparator()); |
462 |
} |
463 |
|
464 |
/** |
465 |
* sort the descriptors by 'description' (as opposed to 'value') |
466 |
*/ |
467 |
private Comparator<DataModelPropertyDescriptor> buildDescriptorComparator() { |
468 |
return new Comparator<DataModelPropertyDescriptor>() { |
469 |
public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { |
470 |
return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); |
471 |
} |
472 |
}; |
473 |
} |
474 |
|
475 |
private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() { |
476 |
List<String> connectionNames = this.buildValidConnectionNames(); |
477 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()]; |
478 |
for (int i = 0; i < descriptors.length; i++) { |
479 |
descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i)); |
480 |
} |
481 |
return descriptors; |
482 |
} |
483 |
|
484 |
/** |
485 |
* put a null entry at the top of the list (for <none>) |
486 |
*/ |
487 |
private List<String> buildValidConnectionNames() { |
488 |
List<String> connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames())); |
489 |
connectionNames.add(0, null); |
490 |
return connectionNames; |
491 |
} |
492 |
|
493 |
private DataModelPropertyDescriptor[] buildValidDriverDescriptors() { |
494 |
return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) }; |
495 |
} |
496 |
|
497 |
private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() { |
498 |
Database db = this.getDatabase(); |
499 |
return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogNames(db)); |
500 |
} |
501 |
|
502 |
/** |
503 |
* pre-condition: 'db' is not null |
504 |
*/ |
505 |
private List<String> buildValidCatalogNames(Database db) { |
506 |
return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogName()); |
507 |
} |
508 |
|
509 |
private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() { |
510 |
Database db = this.getDatabase(); |
511 |
return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaNames()); |
512 |
} |
513 |
|
514 |
private List<String> buildValidSchemaNames() { |
515 |
return this.buildValidStrings(this.schemaNames(), this.getDefaultSchemaName()); |
516 |
} |
517 |
|
518 |
private Iterator<String> schemaNames() { |
519 |
SchemaContainer sc = this.getSchemaContainer(); |
520 |
return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers(); |
521 |
} |
522 |
|
523 |
/** |
524 |
* put an entry for the default at the top of the list |
525 |
*/ |
526 |
private List<String> buildValidStrings(Iterator<String> stream, String defaultString) { |
527 |
List<String> strings = CollectionTools.list(stream); |
528 |
if ((defaultString != null) && ! strings.contains(defaultString)) { |
529 |
strings.add(0, defaultString); |
530 |
} |
531 |
return strings; |
532 |
} |
533 |
|
534 |
private DataModelPropertyDescriptor[] buildDescriptors(List<String> strings) { |
535 |
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()]; |
536 |
for (int i = 0; i < descriptors.length; i++) { |
537 |
descriptors[i] = new DataModelPropertyDescriptor(strings.get(i)); |
538 |
} |
539 |
return descriptors; |
540 |
} |
541 |
|
542 |
private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; |
543 |
|
544 |
/** |
545 |
* platform and connection have 'description's (in addition to 'value's) |
546 |
*/ |
381 |
@Override |
547 |
@Override |
382 |
public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { |
548 |
public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { |
383 |
if (propertyName.equals(PLATFORM_ID)) { |
549 |
if (propertyName.equals(PLATFORM_ID)) { |
384 |
return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID)); |
550 |
return this.buildPlatformIdDescriptor(this.getPlatformId()); |
385 |
} |
551 |
} |
386 |
if (propertyName.equals(CONNECTION)) { |
552 |
if (propertyName.equals(CONNECTION)) { |
387 |
return connectionPropertyDescriptor(getStringProperty(CONNECTION)); |
553 |
return this.buildConnectionDescriptor(this.getConnectionName()); |
388 |
} |
554 |
} |
389 |
return super.getPropertyDescriptor(propertyName); |
555 |
return super.getPropertyDescriptor(propertyName); |
390 |
} |
556 |
} |
391 |
|
557 |
|
392 |
DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) { |
558 |
DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) { |
393 |
return new DataModelPropertyDescriptor( |
559 |
return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId)); |
394 |
platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId)); |
|
|
395 |
} |
560 |
} |
396 |
|
561 |
|
397 |
DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) { |
562 |
private String getPlatformLabel(String platformId) { |
398 |
return StringTools.stringIsEmpty(connection) ? |
563 |
return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); |
399 |
new DataModelPropertyDescriptor(null, JptCoreMessages.NONE) |
|
|
400 |
: |
401 |
new DataModelPropertyDescriptor(connection); |
402 |
} |
564 |
} |
403 |
|
565 |
|
404 |
@Override |
566 |
private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { |
405 |
public IStatus validate(String name) { |
567 |
String description = (connectionName == null) ? JptCoreMessages.NONE : null; |
406 |
if (name.equals(PLATFORM_ID)) { |
568 |
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 |
} |
569 |
} |
434 |
|
570 |
|
435 |
private IRuntime runtime() { |
571 |
|
436 |
return (IRuntime) this.getProperty(RUNTIME); |
572 |
// ********** database ********** |
|
|
573 |
|
574 |
private SchemaContainer getSchemaContainer() { |
575 |
return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); |
437 |
} |
576 |
} |
438 |
|
577 |
|
439 |
private boolean runtimeSupportsEjb30(IRuntime runtime) { |
578 |
private Catalog getCatalog() { |
440 |
IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ |
579 |
String name = this.getUserOverrideDefaultCatalog(); |
441 |
return (runtime == null) ? false : runtime.supports(ejb30); |
580 |
return (name == null) ? null : this.getCatalog(name); |
442 |
} |
581 |
} |
443 |
|
582 |
|
444 |
private String getPlatformId() { |
583 |
/** |
445 |
return this.getStringProperty(PLATFORM_ID); |
584 |
* pre-condition: 'name' is not null |
|
|
585 |
*/ |
586 |
private Catalog getCatalog(String name) { |
587 |
Database db = this.getDatabase(); |
588 |
return (db == null) ? null : db.getCatalogForIdentifier(name); |
589 |
} |
590 |
|
591 |
private boolean databaseSupportsCatalogs() { |
592 |
Database db = this.getDatabase(); |
593 |
return (db != null) && db.supportsCatalogs(); |
446 |
} |
594 |
} |
447 |
|
595 |
|
448 |
private LibraryInstallDelegate getLibraryInstallDelegate() { |
596 |
private Database getDatabase() { |
449 |
return (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); |
597 |
ConnectionProfile cp = this.getConnectionProfile(); |
|
|
598 |
return (cp == null) ? null : cp.getDatabase(); |
450 |
} |
599 |
} |
451 |
|
600 |
|
452 |
private String getConnectionName() { |
601 |
private boolean connectionIsActive() { |
453 |
return this.getStringProperty(CONNECTION); |
602 |
ConnectionProfile cp = this.getConnectionProfile(); |
|
|
603 |
return (cp != null) && cp.isActive(); |
454 |
} |
604 |
} |
455 |
|
605 |
|
456 |
private ConnectionProfile getConnectionProfile() { |
606 |
private ConnectionProfile getConnectionProfile() { |
457 |
return this.buildConnectionProfile(this.getConnectionName()); |
607 |
String name = this.getConnectionName(); |
|
|
608 |
return (name == null) ? null : this.getConnectionProfile(name); |
458 |
} |
609 |
} |
459 |
|
610 |
|
460 |
private ConnectionProfileFactory getConnectionProfileFactory() { |
611 |
/** |
461 |
// we don't have a JPA project yet, so go to the db plug-in directly to get the factory |
612 |
* pre-condition: 'name' is not null |
462 |
return JptDbPlugin.instance().getConnectionProfileFactory(); |
613 |
*/ |
|
|
614 |
private ConnectionProfile getConnectionProfile(String name) { |
615 |
if (this.cachedConnectionProfileIsStale(name)) { |
616 |
this.connectionProfile = this.buildConnectionProfile(name); |
617 |
} |
618 |
return this.connectionProfile; |
463 |
} |
619 |
} |
464 |
|
620 |
|
465 |
private ConnectionProfile buildConnectionProfile(String name) { |
621 |
private boolean cachedConnectionProfileIsStale(String name) { |
466 |
return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); |
622 |
return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name); |
467 |
} |
623 |
} |
468 |
|
624 |
|
469 |
private boolean connectionIsActive() { |
625 |
private ConnectionProfile buildConnectionProfile(String name) { |
470 |
return this.connectionIsActive(this.getConnectionName()); |
626 |
return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); |
471 |
} |
627 |
} |
472 |
|
628 |
|
473 |
private boolean connectionIsActive(String connectionName) { |
629 |
private Iterator<String> connectionProfileNames() { |
474 |
ConnectionProfile cp = this.buildConnectionProfile(connectionName); |
630 |
return this.getConnectionProfileFactory().connectionProfileNames(); |
475 |
return (cp != null) && cp.isActive(); |
|
|
476 |
} |
631 |
} |
477 |
|
632 |
|
478 |
private Iterator<String> connectionNames() { |
633 |
private ConnectionProfileFactory getConnectionProfileFactory() { |
479 |
String setValue = getStringProperty(CONNECTION); |
634 |
// we don't have a JPA project yet, so go to the db plug-in directly to get the factory |
480 |
|
635 |
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 |
} |
636 |
} |
489 |
|
637 |
|
490 |
private List<String> buildSortedCatalogNames() { |
638 |
|
491 |
ConnectionProfile cp = this.getConnectionProfile(); |
639 |
// ********** validation ********** |
492 |
if (cp == null) { |
640 |
|
493 |
return Collections.emptyList(); |
641 |
@Override |
|
|
642 |
public IStatus validate(String propertyName) { |
643 |
if (propertyName.equals(PLATFORM_ID)) { |
644 |
return this.validatePlatformId(); |
494 |
} |
645 |
} |
495 |
Database db = cp.getDatabase(); |
646 |
if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { |
496 |
if (db == null) { |
647 |
return this.getLibraryInstallDelegate().validate(); |
497 |
return Collections.emptyList(); |
|
|
498 |
} |
648 |
} |
499 |
return CollectionTools.list(db.sortedCatalogIdentifiers()); |
649 |
if (propertyName.equals(CONNECTION)) { |
500 |
} |
650 |
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 |
} |
651 |
} |
509 |
return new CompositeIterator<String>(setValue, catalogNames.iterator()); |
652 |
if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) |
510 |
} |
653 |
|| propertyName.equals(DB_DRIVER_NAME)) { |
511 |
|
654 |
return this.validateDbDriverName(); |
512 |
private List<String> buildSortedSchemaNames() { |
|
|
513 |
ConnectionProfile cp = this.getConnectionProfile(); |
514 |
if (cp == null) { |
515 |
return Collections.emptyList(); |
516 |
} |
655 |
} |
517 |
Database db = cp.getDatabase(); |
656 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) |
518 |
if (db == null) { |
657 |
|| propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { |
519 |
return Collections.emptyList(); |
658 |
return this.validateUserOverrideDefaultCatalog(); |
520 |
} |
659 |
} |
521 |
return CollectionTools.list(db.sortedSchemaIdentifiers()); // use identifiers? names seem OK since combo-box is read-only? |
660 |
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) |
522 |
} |
661 |
|| propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { |
523 |
|
662 |
return this.validateUserOverrideDefaultSchema(); |
524 |
private Iterator<String> schemaNames() { |
663 |
} |
525 |
String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA); |
664 |
if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { |
526 |
List<String> schemaNames = this.buildSortedSchemaNames(); |
665 |
return this.validatePersistentClassManagement(); |
527 |
|
|
|
528 |
if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) { |
529 |
return schemaNames.iterator(); |
530 |
} |
666 |
} |
531 |
return new CompositeIterator<String>(setValue, schemaNames.iterator()); |
|
|
532 |
} |
533 |
|
534 |
private Iterator<String> driverNames() { |
535 |
String setValue = getStringProperty(DB_DRIVER_NAME); |
536 |
|
667 |
|
537 |
return new CompositeIterator<String>(setValue, EmptyIterator.<String> instance()); |
668 |
return super.validate(propertyName); |
538 |
} |
669 |
} |
539 |
|
670 |
|
540 |
|
671 |
private IStatus validatePlatformId() { |
541 |
// ********** validation ********** |
672 |
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 |
} |
673 |
} |
549 |
|
674 |
|
550 |
private IStatus validateConnectionName(String connectionName) { |
675 |
private IStatus validateConnection() { |
551 |
if (StringTools.stringIsEmpty(connectionName)) { |
676 |
String connectionName = this.getConnectionName(); |
552 |
return OK_STATUS; |
677 |
return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName); |
553 |
} |
678 |
} |
554 |
ConnectionProfile connectionProfile = getConnectionProfile(); |
|
|
555 |
if (connectionProfile == null) { |
556 |
return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); |
557 |
|
679 |
|
|
|
680 |
private IStatus validateNonNullConnection(String connectionName) { |
681 |
ConnectionProfile cp = this.getConnectionProfile(connectionName); |
682 |
if (cp == null) { |
683 |
return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); |
558 |
} |
684 |
} |
559 |
if (! connectionProfile.isActive()) { |
685 |
if ( ! cp.isActive()) { |
560 |
return CONNECTION_NOT_CONNECTED_STATUS; |
686 |
return CONNECTION_NOT_CONNECTED_STATUS; |
561 |
} |
687 |
} |
562 |
return OK_STATUS; |
688 |
return OK_STATUS; |
563 |
} |
689 |
} |
564 |
|
690 |
|
|
|
691 |
private IStatus validateDbDriverName() { |
692 |
return OK_STATUS; |
693 |
} |
694 |
|
565 |
private IStatus validateUserOverrideDefaultCatalog() { |
695 |
private IStatus validateUserOverrideDefaultCatalog() { |
566 |
if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { |
696 |
if (this.userWantsToOverrideDefaultCatalog()) { |
567 |
if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG))) { |
697 |
if (this.getUserOverrideDefaultCatalog() == null) { |
568 |
return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; |
698 |
return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; |
569 |
} |
699 |
} |
570 |
} |
700 |
} |
Lines 572-594
Link Here
|
572 |
} |
702 |
} |
573 |
|
703 |
|
574 |
private IStatus validateUserOverrideDefaultSchema() { |
704 |
private IStatus validateUserOverrideDefaultSchema() { |
575 |
if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { |
705 |
if (this.userWantsToOverrideDefaultSchema()) { |
576 |
if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) { |
706 |
if (this.getUserOverrideDefaultSchema() == null) { |
577 |
return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; |
707 |
return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; |
578 |
} |
708 |
} |
579 |
} |
709 |
} |
580 |
return OK_STATUS; |
710 |
return OK_STATUS; |
581 |
} |
711 |
} |
582 |
|
712 |
|
583 |
private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) { |
713 |
private IStatus validatePersistentClassManagement() { |
|
|
714 |
@SuppressWarnings("unused") boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses(); |
584 |
// TODO warning if "discovery" is used, but no runtime specified ?? |
715 |
// TODO warning if "discovery" is used, but no runtime specified ?? |
585 |
return OK_STATUS; |
716 |
return OK_STATUS; |
586 |
} |
717 |
} |
587 |
|
718 |
|
588 |
private IStatus validateDbDriverName() { |
|
|
589 |
return OK_STATUS; |
590 |
} |
591 |
|
592 |
|
719 |
|
593 |
// ********** static methods ********** |
720 |
// ********** static methods ********** |
594 |
|
721 |
|
Lines 596-604
Link Here
|
596 |
return buildStatus(IStatus.INFO, message); |
723 |
return buildStatus(IStatus.INFO, message); |
597 |
} |
724 |
} |
598 |
|
725 |
|
599 |
private static IStatus buildWarningStatus(String message) { |
726 |
// private static IStatus buildWarningStatus(String message) { |
600 |
return buildStatus(IStatus.WARNING, message); |
727 |
// return buildStatus(IStatus.WARNING, message); |
601 |
} |
728 |
// } |
602 |
|
729 |
|
603 |
private static IStatus buildErrorStatus(String message) { |
730 |
private static IStatus buildErrorStatus(String message) { |
604 |
return buildStatus(IStatus.ERROR, message); |
731 |
return buildStatus(IStatus.ERROR, message); |
Lines 607-610
Link Here
|
607 |
private static IStatus buildStatus(int severity, String message) { |
734 |
private static IStatus buildStatus(int severity, String message) { |
608 |
return new Status(severity, JptCorePlugin.PLUGIN_ID, message); |
735 |
return new Status(severity, JptCorePlugin.PLUGIN_ID, message); |
609 |
} |
736 |
} |
|
|
737 |
|
610 |
} |
738 |
} |