svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / DefaultDatabaseWorkspaceManager.java @ 47209
History | View | Annotate | Download (32.9 KB)
1 | 44304 | jjdelcerro | package org.gvsig.fmap.dal.impl; |
---|---|---|---|
2 | 44297 | jjdelcerro | |
3 | 44346 | jjdelcerro | import java.io.File; |
4 | 44397 | jjdelcerro | import java.util.ArrayList; |
5 | import java.util.Collection; |
||
6 | import java.util.Collections; |
||
7 | import java.util.List; |
||
8 | 44750 | jjdelcerro | import java.util.Map; |
9 | 44633 | jjdelcerro | import java.util.Objects; |
10 | 44750 | jjdelcerro | import org.apache.commons.collections4.map.LRUMap; |
11 | 44297 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
12 | 44304 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
13 | 45165 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
14 | 44304 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionUtils; |
15 | 44397 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
16 | 44297 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
17 | import org.gvsig.fmap.dal.DataManager; |
||
18 | 44304 | jjdelcerro | import org.gvsig.fmap.dal.DataServerExplorer; |
19 | import org.gvsig.fmap.dal.DataServerExplorerParameters; |
||
20 | 44297 | jjdelcerro | import org.gvsig.fmap.dal.DataStoreParameters; |
21 | import org.gvsig.fmap.dal.DataTypes; |
||
22 | 46338 | fdiaz | import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
23 | 44346 | jjdelcerro | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYID; |
24 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYLABEL; |
||
25 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_NAME; |
||
26 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_VALUE; |
||
27 | 46338 | fdiaz | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_FLAGS; |
28 | 44304 | jjdelcerro | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_NAME; |
29 | 44346 | jjdelcerro | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_PARAMETERS; |
30 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_RESOURCES_NAME; |
||
31 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_RESOURCES_RESOURCE; |
||
32 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION; |
||
33 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION_NAME; |
||
34 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_REPOSITORY; |
||
35 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_REPOSITORY_NAME; |
||
36 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES; |
||
37 | import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES_NAME; |
||
38 | 46338 | fdiaz | import org.gvsig.fmap.dal.StoresRepository; |
39 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
40 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
41 | import org.gvsig.fmap.dal.feature.Feature; |
||
42 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
43 | 44304 | jjdelcerro | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
44 | 45100 | jjdelcerro | import org.gvsig.tools.dispose.DisposeUtils; |
45 | 44397 | jjdelcerro | import org.gvsig.tools.dynobject.DynClass; |
46 | import org.gvsig.tools.dynobject.DynField; |
||
47 | 44346 | jjdelcerro | import org.gvsig.tools.resourcesstorage.FilesResourcesStorage; |
48 | import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
||
49 | 44750 | jjdelcerro | import org.gvsig.tools.util.CachedValue; |
50 | 44397 | jjdelcerro | import org.gvsig.tools.util.FileTools; |
51 | import org.gvsig.tools.util.HasAFile; |
||
52 | 44297 | jjdelcerro | import org.slf4j.Logger; |
53 | import org.slf4j.LoggerFactory; |
||
54 | |||
55 | /**
|
||
56 | *
|
||
57 | * @author jjdelcerro
|
||
58 | */
|
||
59 | @SuppressWarnings("UseSpecificCatch") |
||
60 | 44346 | jjdelcerro | public class DefaultDatabaseWorkspaceManager |
61 | 44397 | jjdelcerro | extends AbstractSymbolTable
|
62 | implements DatabaseWorkspaceManager
|
||
63 | 44346 | jjdelcerro | { |
64 | 44297 | jjdelcerro | |
65 | 44304 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDatabaseWorkspaceManager.class); |
66 | 44397 | jjdelcerro | |
67 | private static final String CONFIG_NAME_BASEFOLDER = "BASEFOLDER"; |
||
68 | private static final String CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH = "ALTERNATIVE_RESOURCES_PATH"; |
||
69 | 44346 | jjdelcerro | |
70 | 44750 | jjdelcerro | private class CachedConfigValue extends CachedValue<String> { |
71 | 44397 | jjdelcerro | |
72 | 44750 | jjdelcerro | private final String name; |
73 | |||
74 | public CachedConfigValue(String name, String value) { |
||
75 | this.setValue(value);
|
||
76 | this.name = name;
|
||
77 | 44397 | jjdelcerro | } |
78 | 44750 | jjdelcerro | |
79 | public CachedConfigValue(String name, String value, long expireTime) { |
||
80 | this.name = name;
|
||
81 | this.setValue(value);
|
||
82 | this.setExpireTime(expireTime);
|
||
83 | 44397 | jjdelcerro | } |
84 | 44750 | jjdelcerro | |
85 | 44397 | jjdelcerro | @Override
|
86 | protected void reload() { |
||
87 | 46348 | jjdelcerro | // LOGGER.info("reload CachedConfigValue "+name);
|
88 | 44750 | jjdelcerro | String s = DefaultDatabaseWorkspaceManager.this.getConfigValue(name);
|
89 | 44397 | jjdelcerro | if( StringUtils.isBlank(s) ) {
|
90 | 44750 | jjdelcerro | this.setValue(null); |
91 | 44397 | jjdelcerro | } else {
|
92 | 44750 | jjdelcerro | this.setValue(s);
|
93 | 44397 | jjdelcerro | } |
94 | } |
||
95 | 46338 | fdiaz | |
96 | @Override
|
||
97 | public String toString() { |
||
98 | return this.name+" = "+this.getValue(); |
||
99 | } |
||
100 | |||
101 | |||
102 | 44397 | jjdelcerro | } |
103 | |||
104 | 44346 | jjdelcerro | private final DataServerExplorerParameters serverParameters; |
105 | 44304 | jjdelcerro | private Boolean existsConfiguration = null; |
106 | private StoresRepository storesRepository;
|
||
107 | 46338 | fdiaz | private CachedConfigValue alternativeResourcesFolder = null; |
108 | 44750 | jjdelcerro | private CachedValue<File> baseFolder; |
109 | private Map<String,CachedConfigValue> cachedConfigValues; |
||
110 | 44297 | jjdelcerro | |
111 | 44346 | jjdelcerro | public DefaultDatabaseWorkspaceManager(DataServerExplorerParameters serverParameters) {
|
112 | this.serverParameters = serverParameters;
|
||
113 | 44750 | jjdelcerro | this.baseFolder = new CachedValue() { |
114 | @Override
|
||
115 | protected void reload() { |
||
116 | String s = DefaultDatabaseWorkspaceManager.this.getConfigValue(CONFIG_NAME_BASEFOLDER);
|
||
117 | if( StringUtils.isBlank(s) ) {
|
||
118 | this.setValue(null); |
||
119 | } else {
|
||
120 | 46338 | fdiaz | s = ExpressionUtils.evaluateDynamicText(DefaultDatabaseWorkspaceManager.this, s); |
121 | 44750 | jjdelcerro | this.setValue(new File(s)); |
122 | } |
||
123 | } |
||
124 | |||
125 | }; |
||
126 | this.baseFolder.setExpireTime(20000); // 20seg |
||
127 | 46338 | fdiaz | this.alternativeResourcesFolder = new CachedConfigValue(CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH, null, 30000); |
128 | // this.alternativeResourcesFolder = new CachedValue() {
|
||
129 | // @Override
|
||
130 | // protected void reload() {
|
||
131 | // String s = DefaultDatabaseWorkspaceManager.this.getConfigValue(CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH);
|
||
132 | // if( StringUtils.isBlank(s) ) {
|
||
133 | // this.setValue(null);
|
||
134 | // } else {
|
||
135 | // this.setValue(new File(s));
|
||
136 | // }
|
||
137 | // }
|
||
138 | //
|
||
139 | // };
|
||
140 | // this.alternativeResourcesFolder.setExpireTime(30000); // 20seg
|
||
141 | 46334 | jjdelcerro | |
142 | 44750 | jjdelcerro | this.cachedConfigValues = new LRUMap<>(20, 20); |
143 | 45165 | jjdelcerro | ExpressionEvaluatorLocator.getExpressionEvaluatorManager().populateSymbolTable(this);
|
144 | |||
145 | 44297 | jjdelcerro | } |
146 | 44390 | jjdelcerro | |
147 | @Override
|
||
148 | public String toString() { |
||
149 | return this.getLabel(); |
||
150 | } |
||
151 | 44297 | jjdelcerro | |
152 | @Override
|
||
153 | 44346 | jjdelcerro | public String getId() { |
154 | String id = this.get(CONFIG_NAME_STORESREPOSITORYID); |
||
155 | return id;
|
||
156 | } |
||
157 | |||
158 | @Override
|
||
159 | public String getLabel() { |
||
160 | String label = this.get(CONFIG_NAME_STORESREPOSITORYLABEL); |
||
161 | 46930 | fdiaz | if (StringUtils.isBlank(label)) {
|
162 | return this.getId(); |
||
163 | } |
||
164 | 44346 | jjdelcerro | return label;
|
165 | } |
||
166 | 44390 | jjdelcerro | |
167 | @Override
|
||
168 | public DatabaseWorkspaceManager getValue() {
|
||
169 | return this; |
||
170 | } |
||
171 | 44346 | jjdelcerro | |
172 | @Override
|
||
173 | 44304 | jjdelcerro | public boolean existsTable(int tableid) { |
174 | switch(tableid) {
|
||
175 | case TABLE_RESOURCES:
|
||
176 | return this.existsTable(TABLE_RESOURCES_NAME); |
||
177 | case TABLE_REPOSITORY:
|
||
178 | return this.existsTable(TABLE_REPOSITORY_NAME); |
||
179 | case TABLE_CONFIGURATION:
|
||
180 | return this.existsTable(TABLE_CONFIGURATION_NAME); |
||
181 | default:
|
||
182 | throw new IllegalArgumentException("Invalid table identitier "+tableid); |
||
183 | } |
||
184 | 44297 | jjdelcerro | } |
185 | 44304 | jjdelcerro | |
186 | @Override
|
||
187 | public void createTable(int tableid) { |
||
188 | switch(tableid) {
|
||
189 | case TABLE_RESOURCES:
|
||
190 | createTableResources(); |
||
191 | break;
|
||
192 | case TABLE_REPOSITORY:
|
||
193 | createTableRepository(); |
||
194 | break;
|
||
195 | case TABLE_CONFIGURATION:
|
||
196 | createTableConfiguration(); |
||
197 | break;
|
||
198 | default:
|
||
199 | throw new IllegalArgumentException("Invalid table identitier "+tableid); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | @Override
|
||
204 | public void dropTable(int tableid) { |
||
205 | switch(tableid) {
|
||
206 | case TABLE_RESOURCES:
|
||
207 | this.dropTable(TABLE_RESOURCES_NAME);
|
||
208 | break;
|
||
209 | case TABLE_REPOSITORY:
|
||
210 | this.dropTable(TABLE_REPOSITORY_NAME);
|
||
211 | break;
|
||
212 | case TABLE_CONFIGURATION:
|
||
213 | this.dropTable(TABLE_CONFIGURATION_NAME);
|
||
214 | break;
|
||
215 | default:
|
||
216 | throw new IllegalArgumentException("Invalid table identitier "+tableid); |
||
217 | } |
||
218 | } |
||
219 | |||
220 | @Override
|
||
221 | public FeatureStore getTable(int tableid) { |
||
222 | switch(tableid) {
|
||
223 | case TABLE_RESOURCES:
|
||
224 | return this.getTable(TABLE_RESOURCES_NAME); |
||
225 | case TABLE_REPOSITORY:
|
||
226 | return this.getTable(TABLE_REPOSITORY_NAME); |
||
227 | case TABLE_CONFIGURATION:
|
||
228 | return this.getTable(TABLE_CONFIGURATION_NAME); |
||
229 | default:
|
||
230 | throw new IllegalArgumentException("Invalid table identitier "+tableid); |
||
231 | } |
||
232 | } |
||
233 | |||
234 | 44633 | jjdelcerro | @Override
|
235 | public DataServerExplorer getServerExplorer() {
|
||
236 | 44297 | jjdelcerro | try {
|
237 | DataManager dataManager = DALLocator.getDataManager(); |
||
238 | 44304 | jjdelcerro | DataServerExplorer server = dataManager.openServerExplorer( |
239 | 44346 | jjdelcerro | this.serverParameters.getProviderName(),
|
240 | this.serverParameters
|
||
241 | 44297 | jjdelcerro | ); |
242 | 44633 | jjdelcerro | return server;
|
243 | } catch (Exception ex) { |
||
244 | throw new RuntimeException("Can't get server explorer for workspace '"+Objects.toString(this.serverParameters)+"'", ex); |
||
245 | } |
||
246 | } |
||
247 | 46338 | fdiaz | |
248 | @Override
|
||
249 | public DataServerExplorerParameters getServerExplorerParameters() {
|
||
250 | return this.serverParameters; |
||
251 | } |
||
252 | 44633 | jjdelcerro | |
253 | 46338 | fdiaz | |
254 | |||
255 | 44633 | jjdelcerro | private boolean existsTable(String tableName) { |
256 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
257 | 44633 | jjdelcerro | try {
|
258 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
259 | 46368 | fdiaz | List<DataStoreParameters> list = server.list();
|
260 | if(list == null){ |
||
261 | return false; |
||
262 | } |
||
263 | 44297 | jjdelcerro | for (DataStoreParameters params : server.list()) {
|
264 | 44304 | jjdelcerro | String theTableName = (String) params.getDynValue("Table"); |
265 | 44297 | jjdelcerro | if( StringUtils.equals(theTableName, tableName) ) {
|
266 | return true; |
||
267 | } |
||
268 | } |
||
269 | } catch (Exception ex) { |
||
270 | LOGGER.warn("Can't check if the table '"+tableName+"' exists.",ex); |
||
271 | 45100 | jjdelcerro | } finally {
|
272 | DisposeUtils.disposeQuietly(server); |
||
273 | 44297 | jjdelcerro | } |
274 | return false; |
||
275 | } |
||
276 | |||
277 | private FeatureStore getTable(String tableName) { |
||
278 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
279 | 44297 | jjdelcerro | try {
|
280 | DataManager dataManager = DALLocator.getDataManager(); |
||
281 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
282 | 44297 | jjdelcerro | DataStoreParameters params = server.get(tableName); |
283 | if( params!=null ) { |
||
284 | FeatureStore store = (FeatureStore) dataManager.openStore( |
||
285 | 44326 | jjdelcerro | params.getProviderName(), |
286 | 45967 | jjdelcerro | params, |
287 | true
|
||
288 | 44297 | jjdelcerro | ); |
289 | return store;
|
||
290 | } |
||
291 | } catch (Exception ex) { |
||
292 | LOGGER.warn("Can't open table '"+tableName+"'.",ex); |
||
293 | 45100 | jjdelcerro | } finally {
|
294 | DisposeUtils.disposeQuietly(server); |
||
295 | 44297 | jjdelcerro | } |
296 | return null; |
||
297 | } |
||
298 | |||
299 | private void dropTable(String tableName) { |
||
300 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
301 | 44297 | jjdelcerro | try {
|
302 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
303 | 44297 | jjdelcerro | DataStoreParameters params = server.get(tableName); |
304 | if( params!=null ) { |
||
305 | server.remove(params); |
||
306 | } |
||
307 | } catch (Exception ex) { |
||
308 | LOGGER.warn("Can't drop table '"+tableName+"'.",ex); |
||
309 | 45100 | jjdelcerro | } finally {
|
310 | DisposeUtils.disposeQuietly(server); |
||
311 | 44297 | jjdelcerro | } |
312 | } |
||
313 | |||
314 | 46126 | jjdelcerro | @Override
|
315 | 45580 | jjdelcerro | public void createTableResources(String tableName) throws RuntimeException { |
316 | 45767 | fdiaz | // H2Spatial crea esta table a mano.
|
317 | // Si tocamos algo aqu? hay que modificar
|
||
318 | // la creacion de esta tabla en el helper de H2
|
||
319 | |||
320 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
321 | 44297 | jjdelcerro | try {
|
322 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
323 | 44304 | jjdelcerro | NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
324 | 44297 | jjdelcerro | EditableFeatureType ft = params.getDefaultFeatureType(); |
325 | 44304 | jjdelcerro | ft.add(FIELD_RESOURCES_NAME, DataTypes.STRING, 150)
|
326 | 44297 | jjdelcerro | .setAllowNull(false)
|
327 | .setIsPrimaryKey(true);
|
||
328 | 44304 | jjdelcerro | ft.add(FIELD_RESOURCES_RESOURCE, DataTypes.BYTEARRAY) |
329 | 44297 | jjdelcerro | .setAllowNull(true);
|
330 | server.add(tableName, params, false);
|
||
331 | } catch (Exception ex) { |
||
332 | 45580 | jjdelcerro | LOGGER.debug("Can't create resources table '"+tableName+"'.",ex); |
333 | throw new RuntimeException("Can't create resources table '"+tableName+"'.", ex); |
||
334 | 45100 | jjdelcerro | } finally {
|
335 | DisposeUtils.disposeQuietly(server); |
||
336 | 44297 | jjdelcerro | } |
337 | } |
||
338 | |||
339 | 45580 | jjdelcerro | private void createTableResources() { |
340 | createTableResources(TABLE_RESOURCES_NAME); |
||
341 | } |
||
342 | |||
343 | 46126 | jjdelcerro | @Override
|
344 | 45580 | jjdelcerro | public void createTableRepository(String tableName) throws RuntimeException { |
345 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
346 | 44304 | jjdelcerro | try {
|
347 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
348 | 44304 | jjdelcerro | NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
349 | EditableFeatureType ft = params.getDefaultFeatureType(); |
||
350 | ft.add(FIELD_REPOSITORY_NAME, DataTypes.STRING, 150)
|
||
351 | .setAllowNull(false)
|
||
352 | .setIsPrimaryKey(true);
|
||
353 | ft.add(FIELD_REPOSITORY_PARAMETERS, DataTypes.BYTEARRAY) |
||
354 | .setAllowNull(true);
|
||
355 | 45208 | omartinez | ft.add(FIELD_REPOSITORY_FLAGS, DataTypes.INT) |
356 | .setAllowNull(false)
|
||
357 | .setDefaultValue(0);
|
||
358 | 44304 | jjdelcerro | server.add(tableName, params, false);
|
359 | } catch (Exception ex) { |
||
360 | 45580 | jjdelcerro | LOGGER.debug("Can't create repository table '"+tableName+"'.",ex); |
361 | throw new RuntimeException("Can't create repository table '"+tableName+"'.", ex); |
||
362 | 45100 | jjdelcerro | } finally {
|
363 | DisposeUtils.disposeQuietly(server); |
||
364 | 44304 | jjdelcerro | } |
365 | 44297 | jjdelcerro | } |
366 | |||
367 | 45580 | jjdelcerro | private void createTableRepository() { |
368 | createTableRepository(TABLE_REPOSITORY_NAME); |
||
369 | } |
||
370 | |||
371 | 44304 | jjdelcerro | private void createTableConfiguration() { |
372 | 45767 | fdiaz | // H2Spatial crea esta table a mano.
|
373 | // Si tocamos algo aqu? hay que modificar
|
||
374 | // la creacion de esta tabla en el helper de H2
|
||
375 | 44304 | jjdelcerro | String tableName = TABLE_CONFIGURATION_NAME;
|
376 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
377 | 46126 | jjdelcerro | FeatureStore store = null;
|
378 | 44304 | jjdelcerro | try {
|
379 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
380 | 44304 | jjdelcerro | NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
381 | EditableFeatureType ft = params.getDefaultFeatureType(); |
||
382 | ft.add(FIELD_CONFIGURATION_NAME, DataTypes.STRING, 200)
|
||
383 | .setAllowNull(false)
|
||
384 | .setIsPrimaryKey(true);
|
||
385 | 45767 | fdiaz | ft.add(FIELD_CONFIGURATION_VALUE, DataTypes.STRING, 10240)
|
386 | 44304 | jjdelcerro | .setAllowNull(true);
|
387 | server.add(tableName, params, false);
|
||
388 | 46126 | jjdelcerro | |
389 | DataStoreParameters openParams = server.get(TABLE_CONFIGURATION_NAME); |
||
390 | store = (FeatureStore) DALLocator.getDataManager().openStore( |
||
391 | openParams.getProviderName(), openParams |
||
392 | ); |
||
393 | store.edit(); |
||
394 | EditableFeature efeature = store.createNewFeature(); |
||
395 | efeature.set(FIELD_CONFIGURATION_NAME, CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH); |
||
396 | efeature.set(FIELD_CONFIGURATION_VALUE, null);
|
||
397 | store.insert(efeature); |
||
398 | store.finishEditing(); |
||
399 | |||
400 | 45165 | jjdelcerro | this.existsConfiguration = null; |
401 | 44304 | jjdelcerro | } catch (Exception ex) { |
402 | LOGGER.warn("Can't create table '"+tableName+"'.",ex); |
||
403 | 46126 | jjdelcerro | FeatureStore.cancelEditingQuietly(store); |
404 | 45100 | jjdelcerro | } finally {
|
405 | DisposeUtils.disposeQuietly(server); |
||
406 | 46126 | jjdelcerro | DisposeUtils.disposeQuietly(store); |
407 | 44304 | jjdelcerro | } |
408 | 44297 | jjdelcerro | } |
409 | 44304 | jjdelcerro | |
410 | private boolean existsConfiguration() { |
||
411 | if( this.existsConfiguration==null ) { |
||
412 | this.existsConfiguration = this.existsTable(TABLE_CONFIGURATION_NAME); |
||
413 | } |
||
414 | return this.existsConfiguration; |
||
415 | } |
||
416 | 44297 | jjdelcerro | |
417 | @Override
|
||
418 | public String get(String name) { |
||
419 | 44304 | jjdelcerro | try {
|
420 | if( !this.existsConfiguration() ) { |
||
421 | return null; |
||
422 | } |
||
423 | 44750 | jjdelcerro | if( StringUtils.equalsIgnoreCase(name, CONFIG_NAME_BASEFOLDER) ) {
|
424 | 46338 | fdiaz | return Objects.toString(this.baseFolder.get(), null); |
425 | 44750 | jjdelcerro | } |
426 | 46338 | fdiaz | if( StringUtils.equalsIgnoreCase(name, CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH) ) {
|
427 | return Objects.toString(this.alternativeResourcesFolder.get(), null); |
||
428 | } |
||
429 | 44750 | jjdelcerro | CachedConfigValue cachedValue = this.cachedConfigValues.get(name);
|
430 | if( cachedValue != null ) { |
||
431 | return cachedValue.get();
|
||
432 | } |
||
433 | String value = this.getConfigValue(name); |
||
434 | this.cachedConfigValues.put(name, new CachedConfigValue(name, value, 15000)); |
||
435 | 46338 | fdiaz | value = ExpressionUtils.evaluateDynamicText(this, value);
|
436 | 44750 | jjdelcerro | return value;
|
437 | } catch (Exception ex) { |
||
438 | LOGGER.warn("Can't read configuration value '"+name+"'", ex); |
||
439 | return null; |
||
440 | } |
||
441 | } |
||
442 | |||
443 | private String getConfigValue(String name) { |
||
444 | 45100 | jjdelcerro | FeatureStore store = null;
|
445 | 44750 | jjdelcerro | try {
|
446 | if( !this.existsConfiguration() ) { |
||
447 | return null; |
||
448 | } |
||
449 | 45100 | jjdelcerro | store = this.getTable(TABLE_CONFIGURATION);
|
450 | 44304 | jjdelcerro | if( store == null ) { |
451 | return null; |
||
452 | } |
||
453 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
454 | String filter = builder.eq(
|
||
455 | builder.column(FIELD_CONFIGURATION_NAME), |
||
456 | builder.constant(name) |
||
457 | ).toString(); |
||
458 | Feature feature = store.findFirst(filter); |
||
459 | if( feature == null ) { |
||
460 | return null; |
||
461 | } |
||
462 | String value = feature.getString(FIELD_CONFIGURATION_VALUE);
|
||
463 | 46338 | fdiaz | // value = ExpressionUtils.evaluateDynamicText(this, value);
|
464 | 44304 | jjdelcerro | return value;
|
465 | |||
466 | } catch (Exception ex) { |
||
467 | LOGGER.warn("Can't read configuration value '"+name+"'", ex); |
||
468 | return null; |
||
469 | 45100 | jjdelcerro | } finally {
|
470 | DisposeUtils.disposeQuietly(store); |
||
471 | 44304 | jjdelcerro | } |
472 | 44297 | jjdelcerro | } |
473 | |||
474 | @Override
|
||
475 | 44326 | jjdelcerro | public boolean set(String name, String value) { |
476 | 45100 | jjdelcerro | FeatureStore store = null;
|
477 | 44326 | jjdelcerro | try {
|
478 | if( !this.existsConfiguration() ) { |
||
479 | return false; |
||
480 | } |
||
481 | 45100 | jjdelcerro | store = this.getTable(TABLE_CONFIGURATION);
|
482 | 44326 | jjdelcerro | if( store == null ) { |
483 | return false; |
||
484 | } |
||
485 | store.edit(); |
||
486 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
487 | String filter = builder.eq(
|
||
488 | builder.column(FIELD_CONFIGURATION_NAME), |
||
489 | builder.constant(name) |
||
490 | ).toString(); |
||
491 | Feature feature = store.findFirst(filter); |
||
492 | EditableFeature efeature; |
||
493 | if (feature == null) { |
||
494 | efeature = store.createNewFeature(); |
||
495 | efeature.set(FIELD_CONFIGURATION_NAME, name); |
||
496 | efeature.set(FIELD_CONFIGURATION_VALUE, value); |
||
497 | store.insert(efeature); |
||
498 | } else {
|
||
499 | efeature = feature.getEditable(); |
||
500 | efeature.set(FIELD_CONFIGURATION_VALUE, value); |
||
501 | store.update(efeature); |
||
502 | } |
||
503 | store.finishEditing(); |
||
504 | 46338 | fdiaz | if( StringUtils.equalsIgnoreCase(name, CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH)) {
|
505 | this.alternativeResourcesFolder.expired();
|
||
506 | } else if( this.cachedConfigValues.containsKey(name) ) { |
||
507 | value = ExpressionUtils.evaluateDynamicText(this, value);
|
||
508 | this.cachedConfigValues.get(name).set(value);
|
||
509 | 44750 | jjdelcerro | } |
510 | 44326 | jjdelcerro | return true; |
511 | } catch (Exception ex) { |
||
512 | LOGGER.warn("Can't write configuration value '"+name+"'", ex); |
||
513 | return false; |
||
514 | 45100 | jjdelcerro | } finally {
|
515 | DisposeUtils.disposeQuietly(store); |
||
516 | 44326 | jjdelcerro | } |
517 | 44297 | jjdelcerro | } |
518 | |||
519 | @Override
|
||
520 | public StoresRepository getStoresRepository() {
|
||
521 | 44304 | jjdelcerro | if( this.storesRepository==null ) { |
522 | String id = this.get(CONFIG_NAME_STORESREPOSITORYID); |
||
523 | String label = this.get(CONFIG_NAME_STORESREPOSITORYLABEL); |
||
524 | this.storesRepository = new DatabaseWorkspaceStoresRepository( |
||
525 | id, |
||
526 | label, |
||
527 | 44397 | jjdelcerro | this
|
528 | 44304 | jjdelcerro | ); |
529 | } |
||
530 | return this.storesRepository; |
||
531 | 44297 | jjdelcerro | } |
532 | 44346 | jjdelcerro | |
533 | public boolean contains(DataStoreParameters parameters) { |
||
534 | boolean c = this.getStoresRepository().contains(parameters); |
||
535 | return c;
|
||
536 | } |
||
537 | 44297 | jjdelcerro | |
538 | @Override
|
||
539 | public boolean canAnonymousUserWriteInTheTables() { |
||
540 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
541 | } |
||
542 | |||
543 | @Override
|
||
544 | 44397 | jjdelcerro | public File getBaseFolder() { |
545 | return this.baseFolder.get(); |
||
546 | } |
||
547 | |||
548 | @Override
|
||
549 | public void setBaseFolder(File baseFolder) { |
||
550 | this.baseFolder.set(baseFolder);
|
||
551 | 44750 | jjdelcerro | this.set(CONFIG_NAME_BASEFOLDER, baseFolder.toString());
|
552 | 44397 | jjdelcerro | } |
553 | |||
554 | 46352 | jjdelcerro | public File getWorkspaceFile() { |
555 | 45165 | jjdelcerro | if( this.serverParameters instanceof HasAFile ) { |
556 | return ((HasAFile)this.serverParameters).getFile(); |
||
557 | } |
||
558 | return null; |
||
559 | } |
||
560 | |||
561 | 44397 | jjdelcerro | private DataStoreParameters replaceInFilesToUseBaseFolder(DataStoreParameters parameters) {
|
562 | DynClass dynClass = parameters.getDynClass(); |
||
563 | if( dynClass == null ) { |
||
564 | return parameters;
|
||
565 | } |
||
566 | File theBaseFolder = this.getBaseFolder(); |
||
567 | 45165 | jjdelcerro | File wsfile = getWorkspaceFile();
|
568 | if( theBaseFolder==null && wsfile==null ) { |
||
569 | 44397 | jjdelcerro | return parameters;
|
570 | } |
||
571 | DataStoreParameters replaced = parameters; |
||
572 | for (DynField dynField : dynClass.getDynFields()) {
|
||
573 | switch(dynField.getType()) {
|
||
574 | case DataTypes.FILE:
|
||
575 | case DataTypes.FOLDER:
|
||
576 | File f = (File) parameters.getDynValue(dynField.getName()); |
||
577 | 45165 | jjdelcerro | File newf = null; |
578 | 44397 | jjdelcerro | if( f!=null ) { |
579 | 45165 | jjdelcerro | if( wsfile!=null ) { |
580 | if( wsfile.equals(f) ) {
|
||
581 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
582 | newf = ExpressionUtils.createDynamicFile( |
||
583 | builder.ifnull( |
||
584 | builder.variable("WORKSPACEFILE"),
|
||
585 | builder.constant(f.toString()), |
||
586 | builder.variable("WORKSPACEFILE")
|
||
587 | ) |
||
588 | ); |
||
589 | } |
||
590 | } |
||
591 | if( newf==null ) { |
||
592 | File frel = FileTools.relativizeFile(theBaseFolder, f);
|
||
593 | if( frel!=f ) {
|
||
594 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
595 | newf = ExpressionUtils.createDynamicFile( |
||
596 | builder.concat( |
||
597 | builder.variable(CONFIG_NAME_BASEFOLDER), |
||
598 | builder.constant("/"),
|
||
599 | builder.variable(frel.getPath()) |
||
600 | ) |
||
601 | ); |
||
602 | } |
||
603 | } |
||
604 | if( newf!=null ) { |
||
605 | 44397 | jjdelcerro | if( replaced == parameters ) {
|
606 | replaced = (DataStoreParameters) replaced.getCopy(); |
||
607 | } |
||
608 | 45165 | jjdelcerro | replaced.setDynValue(dynField.getName(), newf); |
609 | 44397 | jjdelcerro | } |
610 | } |
||
611 | break;
|
||
612 | } |
||
613 | } |
||
614 | return replaced;
|
||
615 | } |
||
616 | |||
617 | @Override
|
||
618 | 44346 | jjdelcerro | public boolean writeStoresRepositoryEntry(String name, DataStoreParameters parameters) { |
619 | 45100 | jjdelcerro | FeatureStore store = null;
|
620 | 44304 | jjdelcerro | try {
|
621 | 44397 | jjdelcerro | parameters = this.replaceInFilesToUseBaseFolder(parameters);
|
622 | 44304 | jjdelcerro | byte[] data = parameters.toByteArray(); |
623 | if( data == null ) { |
||
624 | throw new RuntimeException("Can't convert parameters to byte array."); |
||
625 | } |
||
626 | 45100 | jjdelcerro | store = this.getTable(TABLE_REPOSITORY);
|
627 | 44304 | jjdelcerro | store.edit(); |
628 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
629 | String filter = builder.eq(
|
||
630 | builder.column(FIELD_REPOSITORY_NAME), |
||
631 | builder.constant(name) |
||
632 | ).toString(); |
||
633 | Feature feature = store.findFirst(filter); |
||
634 | EditableFeature efeature; |
||
635 | if (feature == null) { |
||
636 | efeature = store.createNewFeature(); |
||
637 | efeature.set(FIELD_REPOSITORY_NAME, name); |
||
638 | efeature.set(FIELD_REPOSITORY_PARAMETERS, data); |
||
639 | 45208 | omartinez | // algun set sobre los flags?
|
640 | efeature.set(FIELD_REPOSITORY_FLAGS, 0);
|
||
641 | 44304 | jjdelcerro | store.insert(efeature); |
642 | } else {
|
||
643 | efeature = feature.getEditable(); |
||
644 | efeature.set(FIELD_REPOSITORY_PARAMETERS, data); |
||
645 | store.update(efeature); |
||
646 | } |
||
647 | store.finishEditing(); |
||
648 | 46334 | jjdelcerro | this.storesRepository = null; |
649 | 44304 | jjdelcerro | return true; |
650 | |||
651 | } catch (Exception ex) { |
||
652 | LOGGER.warn("Can't save entry '"+name+"' in repository information", ex); |
||
653 | return false; |
||
654 | 45100 | jjdelcerro | } finally {
|
655 | DisposeUtils.disposeQuietly(store); |
||
656 | 44304 | jjdelcerro | } |
657 | 44297 | jjdelcerro | } |
658 | |||
659 | @Override
|
||
660 | 44380 | jjdelcerro | public boolean isValid() { |
661 | 44728 | jjdelcerro | try {
|
662 | 44304 | jjdelcerro | String id = this.get(CONFIG_NAME_STORESREPOSITORYID); |
663 | if( StringUtils.isBlank(id) ) {
|
||
664 | return false; |
||
665 | } |
||
666 | 44380 | jjdelcerro | return true; |
667 | 44728 | jjdelcerro | } catch(Exception ex) { |
668 | return false; |
||
669 | } |
||
670 | 44380 | jjdelcerro | } |
671 | |||
672 | @Override
|
||
673 | public boolean isValidStoresRepository() { |
||
674 | if( !this.isValid() ) { |
||
675 | return false; |
||
676 | } |
||
677 | 44304 | jjdelcerro | if( !this.existsTable(TABLE_REPOSITORY_NAME) ) { |
678 | return false; |
||
679 | } |
||
680 | return true; |
||
681 | |||
682 | 44297 | jjdelcerro | } |
683 | 44346 | jjdelcerro | |
684 | @Override
|
||
685 | 44380 | jjdelcerro | public ResourcesStorage getAlternativeResourcesStorage(String tableName) { |
686 | 46348 | jjdelcerro | // LOGGER.info("getAlternativeResourcesStorage from cache: "+!this.alternativeResourcesFolder.isExpired());
|
687 | 46338 | fdiaz | String s = this.alternativeResourcesFolder.get(); |
688 | 46348 | jjdelcerro | // LOGGER.info("alternativeResourcesStorage: "+s);
|
689 | 46338 | fdiaz | if( StringUtils.isBlank(s) ) {
|
690 | return null; |
||
691 | } |
||
692 | |||
693 | s = ExpressionUtils.evaluateDynamicText(this, s);
|
||
694 | |||
695 | File folder = new File(s); |
||
696 | |||
697 | 44380 | jjdelcerro | if( folder==null ) { |
698 | return null; |
||
699 | } |
||
700 | String resourcesRoot = folder.getAbsolutePath().replace("\\","/") + "/" + tableName; |
||
701 | ResourcesStorage resources = new FilesResourcesStorage(resourcesRoot);
|
||
702 | return resources;
|
||
703 | 44346 | jjdelcerro | } |
704 | 46338 | fdiaz | |
705 | @Override
|
||
706 | public boolean hasAlternativeResourcesStorage() { |
||
707 | String path = this.get(CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH); |
||
708 | return StringUtils.isNotBlank(path);
|
||
709 | } |
||
710 | 44362 | jjdelcerro | |
711 | @Override
|
||
712 | 46334 | jjdelcerro | public void setAlternativeResourcesStorage(String resourcesPath) { |
713 | 46338 | fdiaz | // this.fix();
|
714 | this.set(CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH, resourcesPath);
|
||
715 | // this.alternativeResourcesFolder.expired();
|
||
716 | 46334 | jjdelcerro | } |
717 | |||
718 | @Override
|
||
719 | 44362 | jjdelcerro | public void drop() { |
720 | if( !this.existsTable(TABLE_RESOURCES) ) { |
||
721 | this.dropTable(TABLE_RESOURCES);
|
||
722 | } |
||
723 | if( !this.existsTable(TABLE_CONFIGURATION) ) { |
||
724 | this.dropTable(TABLE_CONFIGURATION);
|
||
725 | } |
||
726 | if( !this.existsTable(TABLE_REPOSITORY) ) { |
||
727 | this.dropTable(TABLE_REPOSITORY);
|
||
728 | } |
||
729 | } |
||
730 | 44346 | jjdelcerro | |
731 | 44362 | jjdelcerro | |
732 | @Override
|
||
733 | 44346 | jjdelcerro | public void create(String id, String description) { |
734 | if( !this.existsTable(TABLE_RESOURCES) ) { |
||
735 | this.createTable(TABLE_RESOURCES);
|
||
736 | } |
||
737 | if( !this.existsTable(TABLE_CONFIGURATION) ) { |
||
738 | this.createTable(TABLE_CONFIGURATION);
|
||
739 | } |
||
740 | if( !this.existsTable(TABLE_REPOSITORY) ) { |
||
741 | this.createTable(TABLE_REPOSITORY);
|
||
742 | } |
||
743 | this.set(CONFIG_NAME_STORESREPOSITORYID,id);
|
||
744 | this.set(CONFIG_NAME_STORESREPOSITORYLABEL,description);
|
||
745 | this.set(CONFIG_CAN_ANONYMOUS_USER_WRITE_IN_THE_TABLES,"true"); |
||
746 | 44397 | jjdelcerro | this.set(CONFIG_NAME_ALTERNATIVE_RESOURCES_PATH,""); |
747 | File theBaseFolder = this.getBaseFolder(); |
||
748 | if( this.serverParameters instanceof HasAFile && theBaseFolder==null ) { |
||
749 | File f = ((HasAFile)this.serverParameters).getFile(); |
||
750 | if( f != null ) { |
||
751 | theBaseFolder = f.getParentFile(); |
||
752 | this.setBaseFolder(theBaseFolder);
|
||
753 | } else {
|
||
754 | this.set(CONFIG_NAME_BASEFOLDER,""); |
||
755 | } |
||
756 | } else {
|
||
757 | this.set(CONFIG_NAME_BASEFOLDER,""); |
||
758 | } |
||
759 | 44346 | jjdelcerro | } |
760 | 44397 | jjdelcerro | |
761 | @Override
|
||
762 | public boolean exists(String name) { |
||
763 | 45100 | jjdelcerro | FeatureStore store = null;
|
764 | 44397 | jjdelcerro | try {
|
765 | 45165 | jjdelcerro | if( StringUtils.equalsIgnoreCase(name, "WORKSPACEFILE") ) { |
766 | File wsfile = getWorkspaceFile();
|
||
767 | if( wsfile!=null ) { |
||
768 | return true; |
||
769 | } |
||
770 | } |
||
771 | 44397 | jjdelcerro | if (this.existsConfiguration()) { |
772 | 44750 | jjdelcerro | if( StringUtils.equalsIgnoreCase(name, CONFIG_NAME_BASEFOLDER) ) {
|
773 | return true; |
||
774 | } |
||
775 | if( this.cachedConfigValues.containsKey(name) ) { |
||
776 | return true; |
||
777 | } |
||
778 | 45100 | jjdelcerro | store = this.getTable(TABLE_CONFIGURATION);
|
779 | 44750 | jjdelcerro | if (store != null) { |
780 | ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
||
781 | String filter = builder.eq(
|
||
782 | builder.column(FIELD_CONFIGURATION_NAME), |
||
783 | builder.constant(name) |
||
784 | ).toString(); |
||
785 | Feature feature = store.findFirst(filter); |
||
786 | if (feature != null) { |
||
787 | String value = feature.getString(FIELD_CONFIGURATION_VALUE);
|
||
788 | value = ExpressionUtils.evaluateDynamicText(this, value);
|
||
789 | this.cachedConfigValues.put(name, new CachedConfigValue(name, value, 15000)); |
||
790 | return true; |
||
791 | } |
||
792 | 44397 | jjdelcerro | } |
793 | } |
||
794 | return super.exists(name); |
||
795 | } catch (Exception ex) { |
||
796 | LOGGER.warn("Can't read configuration value '" + name + "'", ex); |
||
797 | return false; |
||
798 | 45100 | jjdelcerro | } finally {
|
799 | DisposeUtils.disposeQuietly(store); |
||
800 | 44397 | jjdelcerro | } |
801 | } |
||
802 | |||
803 | @Override
|
||
804 | public Object value(String name) { |
||
805 | 45165 | jjdelcerro | if( StringUtils.equalsIgnoreCase(name, "WORKSPACEFILE") ) { |
806 | File wsfile = getWorkspaceFile();
|
||
807 | if( wsfile!=null ) { |
||
808 | return wsfile.toString();
|
||
809 | } |
||
810 | } |
||
811 | 44397 | jjdelcerro | String v = this.get(name); |
812 | if( v!=null ) { |
||
813 | return v;
|
||
814 | } |
||
815 | return super.value(name); |
||
816 | } |
||
817 | |||
818 | @Override
|
||
819 | public Collection<String> localvariables() { |
||
820 | 45100 | jjdelcerro | FeatureStore store = null;
|
821 | 44397 | jjdelcerro | try {
|
822 | final List<String> theVars = new ArrayList<>(); |
||
823 | if (this.existsConfiguration()) { |
||
824 | 45100 | jjdelcerro | store = this.getTable(TABLE_CONFIGURATION);
|
825 | 44397 | jjdelcerro | if (store != null) { |
826 | 44728 | jjdelcerro | store.accept((Object obj) -> {
|
827 | Feature feature = (Feature) obj; |
||
828 | theVars.add(feature.getString(FIELD_CONFIGURATION_NAME)); |
||
829 | 44397 | jjdelcerro | }); |
830 | } |
||
831 | } |
||
832 | return theVars;
|
||
833 | } catch (Exception ex) { |
||
834 | LOGGER.warn("Can't read configuration variables", ex);
|
||
835 | return Collections.EMPTY_LIST; |
||
836 | 45100 | jjdelcerro | } finally {
|
837 | DisposeUtils.disposeQuietly(store); |
||
838 | 44397 | jjdelcerro | } |
839 | } |
||
840 | |||
841 | 44419 | jjdelcerro | @Override
|
842 | public ResourcesStorage getResourcesStorage() {
|
||
843 | 45100 | jjdelcerro | DataServerExplorer server = null;
|
844 | 44419 | jjdelcerro | try {
|
845 | 45100 | jjdelcerro | server = this.getServerExplorer();
|
846 | 44419 | jjdelcerro | ResourcesStorage resourcesStorage = server.getResourcesStorage(); |
847 | return resourcesStorage;
|
||
848 | } catch (Exception ex) { |
||
849 | LOGGER.warn("Can't get resorces storage.",ex);
|
||
850 | return null; |
||
851 | 45100 | jjdelcerro | } finally {
|
852 | DisposeUtils.disposeQuietly(server); |
||
853 | 44419 | jjdelcerro | } |
854 | } |
||
855 | 44728 | jjdelcerro | |
856 | public void fix() { |
||
857 | if( !(this.serverParameters instanceof HasAFile) ) { |
||
858 | return;
|
||
859 | } |
||
860 | HasAFile f = (HasAFile) this.serverParameters;
|
||
861 | if( f.getFile()==null ) { |
||
862 | return;
|
||
863 | } |
||
864 | if( !this.isValid() ) { |
||
865 | return;
|
||
866 | } |
||
867 | this.set(CONFIG_NAME_BASEFOLDER, f.getFile().getParent());
|
||
868 | } |
||
869 | 44419 | jjdelcerro | |
870 | 44728 | jjdelcerro | @Override
|
871 | public void connect() { |
||
872 | DataManager manager = DALLocator.getDataManager(); |
||
873 | this.fix();
|
||
874 | manager.addDatabaseWorkspace(this);
|
||
875 | } |
||
876 | 44397 | jjdelcerro | |
877 | 44821 | jjdelcerro | @Override
|
878 | public void disconnect() { |
||
879 | DataManager manager = DALLocator.getDataManager(); |
||
880 | manager.removeDatabaseWorkspace(this);
|
||
881 | } |
||
882 | 46338 | fdiaz | |
883 | @Override
|
||
884 | public boolean isConnected() { |
||
885 | DataManager manager = DALLocator.getDataManager(); |
||
886 | DatabaseWorkspaceManager ws = manager.getDatabaseWorkspace(this.getId());
|
||
887 | if(ws == null){ |
||
888 | return false; |
||
889 | } |
||
890 | if(ws.getServerExplorerParameters().isTheSameServerExplorer(this.getServerExplorerParameters())){ |
||
891 | return true; |
||
892 | } |
||
893 | return false; |
||
894 | } |
||
895 | |||
896 | @Override
|
||
897 | public String getLabelOrId() { |
||
898 | String label = this.getLabel(); |
||
899 | if(StringUtils.isBlank(label)){
|
||
900 | label = this.getId();
|
||
901 | } |
||
902 | return label;
|
||
903 | } |
||
904 | |||
905 | 44297 | jjdelcerro | } |