svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc2 / spi / JDBCServerExplorerBase.java @ 46830
History | View | Annotate | Download (44.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.store.jdbc2.spi; |
25 |
|
26 |
import org.gvsig.tools.resourcesstorage.CompoundResourcesStorage; |
27 |
import java.io.File; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Arrays; |
30 |
import java.util.Collections; |
31 |
import java.util.HashMap; |
32 |
import java.util.List; |
33 |
import java.util.Map; |
34 |
import java.util.Objects; |
35 |
import javax.json.JsonObject; |
36 |
import javax.json.JsonString; |
37 |
import javax.json.JsonValue; |
38 |
import org.apache.commons.codec.binary.Hex; |
39 |
import org.apache.commons.collections.map.LRUMap; |
40 |
import org.apache.commons.lang3.BooleanUtils; |
41 |
import org.apache.commons.lang3.ObjectUtils; |
42 |
import org.apache.commons.lang3.StringUtils; |
43 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
44 |
import org.apache.commons.lang3.tuple.Pair; |
45 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
46 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
47 |
import org.gvsig.fmap.dal.DALLocator; |
48 |
import org.gvsig.fmap.dal.DataManager; |
49 |
import org.gvsig.fmap.dal.DataStore; |
50 |
import org.gvsig.fmap.dal.DataStoreParameters; |
51 |
import org.gvsig.fmap.dal.DataTransaction; |
52 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
53 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_NAME; |
54 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_VALUE; |
55 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION_NAME; |
56 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES_NAME; |
57 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
58 |
import org.gvsig.fmap.dal.SQLBuilder; |
59 |
import org.gvsig.fmap.dal.SQLBuilder.Privilege; |
60 |
import org.gvsig.fmap.dal.exception.CloseException; |
61 |
import org.gvsig.fmap.dal.exception.DataException; |
62 |
import org.gvsig.fmap.dal.exception.InitializeException; |
63 |
import org.gvsig.fmap.dal.exception.OpenException; |
64 |
import org.gvsig.fmap.dal.exception.RemoveException; |
65 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
66 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
67 |
import org.gvsig.fmap.dal.feature.Feature; |
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
69 |
import org.gvsig.fmap.dal.feature.FeatureType; |
70 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
71 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
72 |
import org.gvsig.fmap.dal.serverexplorer.db.spi.AbstractDBServerExplorer; |
73 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
74 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
75 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
76 |
import org.gvsig.fmap.dal.spi.DataTransactionServices; |
77 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
78 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
79 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
80 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
81 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
82 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
83 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
84 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
85 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCResourcesStorage.TABLENAME_SERVER_EXPLORER_MARK; |
86 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CanCreateTablesOperation; |
87 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation; |
88 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.DropTableOperation; |
89 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ExecuteOperation; |
90 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
91 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ListTablesOperation; |
92 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.RetrieveValueOperation; |
93 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation; |
94 |
import org.gvsig.json.Json; |
95 |
import org.gvsig.json.JsonObjectBuilder; |
96 |
import org.gvsig.tools.ToolsLocator; |
97 |
import org.gvsig.tools.dispose.DisposeUtils; |
98 |
import org.gvsig.tools.exception.BaseException; |
99 |
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage; |
100 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
101 |
import org.gvsig.tools.util.CachedValue; |
102 |
import org.slf4j.Logger; |
103 |
import org.slf4j.LoggerFactory; |
104 |
|
105 |
@SuppressWarnings("UseSpecificCatch") |
106 |
public class JDBCServerExplorerBase extends AbstractDBServerExplorer implements JDBCServerExplorer { |
107 |
|
108 |
private static final Logger LOG = LoggerFactory.getLogger(JDBCServerExplorerBase.class); |
109 |
private static final String CONFIG_NAME_CUSTOM_RESOURCES = "CUSTOM_RESOURCES"; |
110 |
|
111 |
protected JDBCHelper helper = null; |
112 |
|
113 |
private Boolean canAdd; |
114 |
|
115 |
private static final Map<String, CachedValue<List<JDBCStoreParameters>>> CACHED_TABLES = Collections.synchronizedMap(new LRUMap(10)); |
116 |
private static final Map<String, CachedValue<CustomResourcesConfig>> CACHED_CUSTOM_RESOURCES_CONFIG = Collections.synchronizedMap(new LRUMap(10)); |
117 |
|
118 |
private static class CustomResourcesConfig { |
119 |
|
120 |
private static final String CUSTOM_RESOURCES_CACHETIME = "CacheTime"; |
121 |
private static final String CUSTOM_RESOURCES_MAPPING = "Mapping"; |
122 |
private static final String CUSTOM_RESOURCES_READONLY = "ResourcesReadonly"; |
123 |
|
124 |
|
125 |
private int cacheTime; |
126 |
private Map<String, String> mapping; |
127 |
private Map<String,Boolean> resourcesReadonly; |
128 |
|
129 |
public CustomResourcesConfig(String jsonConfig) { |
130 |
this.cacheTime = 30*60*1000; // 30min |
131 |
this.mapping = new HashMap<>(); |
132 |
this.resourcesReadonly = new HashMap<>(); |
133 |
|
134 |
if (StringUtils.isNotBlank(jsonConfig)) {
|
135 |
try {
|
136 |
JsonObject config = Json.createObject(jsonConfig); |
137 |
this.cacheTime = config.getInt(CUSTOM_RESOURCES_CACHETIME, this.cacheTime); |
138 |
if (config.containsKey(CUSTOM_RESOURCES_MAPPING)) {
|
139 |
JsonObject m = config.getJsonObject(CUSTOM_RESOURCES_MAPPING); |
140 |
for (Map.Entry<String, JsonValue> entry : m.entrySet()) { |
141 |
String key = entry.getKey();
|
142 |
JsonValue value = entry.getValue(); |
143 |
if (value instanceof JsonString) { |
144 |
this.mapping.put(key, ((JsonString) value).getString());
|
145 |
} |
146 |
} |
147 |
} |
148 |
if (config.containsKey(CUSTOM_RESOURCES_READONLY)) {
|
149 |
JsonObject resreadonly = config.getJsonObject(CUSTOM_RESOURCES_READONLY); |
150 |
for (Map.Entry<String, JsonValue> entry : resreadonly.entrySet()) { |
151 |
String key = entry.getKey();
|
152 |
JsonValue value = entry.getValue(); |
153 |
if (value == JsonValue.TRUE) {
|
154 |
this.resourcesReadonly.put(key, true); |
155 |
} else if (value == JsonValue.FALSE) { |
156 |
this.resourcesReadonly.put(key, false); |
157 |
} |
158 |
} |
159 |
} |
160 |
} catch (Exception ex) { |
161 |
LOG.debug("Can't parse json from "+CONFIG_NAME_CUSTOM_RESOURCES+" variable", ex); |
162 |
// Do nothing.
|
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
public String toJsonString() { |
168 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
169 |
builder.add(CUSTOM_RESOURCES_CACHETIME, this.cacheTime);
|
170 |
JsonObjectBuilder m = Json.createObjectBuilder(); |
171 |
for (Map.Entry<String, String> entry : this.mapping.entrySet()) { |
172 |
String key = entry.getKey();
|
173 |
String value = entry.getValue();
|
174 |
m.add(key, value); |
175 |
} |
176 |
builder.add(CUSTOM_RESOURCES_MAPPING, m); |
177 |
JsonObjectBuilder resreadonly = Json.createObjectBuilder(); |
178 |
for (Map.Entry<String, Boolean> entry : this.resourcesReadonly.entrySet()) { |
179 |
String key = entry.getKey();
|
180 |
Boolean readonly = entry.getValue();
|
181 |
resreadonly.add(key,readonly); |
182 |
} |
183 |
builder.add(CUSTOM_RESOURCES_READONLY, resreadonly); |
184 |
return builder.build().toString();
|
185 |
} |
186 |
|
187 |
public int getCacheExpireTimeInMillis() { |
188 |
return cacheTime;
|
189 |
} |
190 |
|
191 |
public String getResourcesTablename(String tablename) { |
192 |
String resourceTablename = mapping.get(tablename);
|
193 |
// LOG.info("Resource of table "+tablename+" = "+resourceTablename);
|
194 |
return resourceTablename;
|
195 |
} |
196 |
|
197 |
public void addResourceMapping(String tablename, String resourcesTablename) { |
198 |
this.mapping.put(tablename, resourcesTablename);
|
199 |
} |
200 |
|
201 |
private boolean isInternalTable(String storeName) { |
202 |
if (DatabaseWorkspaceManager.isInternalTable(storeName)) {
|
203 |
return true; |
204 |
} |
205 |
for (String resourcesTablename : this.mapping.values()) { |
206 |
if( StringUtils.equals(storeName, resourcesTablename) ) {
|
207 |
return true; |
208 |
} |
209 |
} |
210 |
return false; |
211 |
} |
212 |
|
213 |
public void setResourcesReadOnly(String resourcesTableName, boolean readonly) { |
214 |
this.resourcesReadonly.put(resourcesTableName,readonly);
|
215 |
} |
216 |
|
217 |
public boolean isResourcesReadOnly(String resourcesTableName) { |
218 |
return this.resourcesReadonly.getOrDefault(resourcesTableName,false); |
219 |
} |
220 |
} |
221 |
|
222 |
private static class CachedCustomResourcesConfig extends CachedValue<CustomResourcesConfig> { |
223 |
|
224 |
private final JDBCStoreParameters openParameters; |
225 |
|
226 |
private CachedCustomResourcesConfig(JDBCStoreParameters openParameters) {
|
227 |
this.openParameters = openParameters;
|
228 |
this.setExpireTime(30*60*1000); // 30min |
229 |
} |
230 |
|
231 |
@Override
|
232 |
protected void reload() { |
233 |
String jsonConfig = getConfigValue(this.openParameters, CONFIG_NAME_CUSTOM_RESOURCES); |
234 |
// LOGGER.info("reload CustomResourcesConfig "+jsonConfig);
|
235 |
CustomResourcesConfig config = new CustomResourcesConfig(jsonConfig);
|
236 |
this.setExpireTime(config.getCacheExpireTimeInMillis());
|
237 |
this.setValue(config);
|
238 |
} |
239 |
|
240 |
} |
241 |
|
242 |
private static class CachedTablesValue extends CachedValue<List<JDBCStoreParameters>> { |
243 |
|
244 |
private final int mode; |
245 |
private final JDBCServerExplorerParameters serverParameters; |
246 |
private final boolean informationTables; |
247 |
private JDBCHelper helper;
|
248 |
private final int tablesOrViews; |
249 |
|
250 |
public CachedTablesValue(JDBCHelper helper, int mode, JDBCServerExplorerParameters serverParameters, boolean informationTables, int tablesOrViews) { |
251 |
this.mode = mode;
|
252 |
this.serverParameters = serverParameters;
|
253 |
this.informationTables = informationTables;
|
254 |
this.helper = helper;
|
255 |
this.tablesOrViews = tablesOrViews;
|
256 |
} |
257 |
|
258 |
public CachedTablesValue(JDBCHelper helper, int mode, JDBCServerExplorerParameters serverParameters, boolean informationTables, long expireTime, int tablesOrViews) { |
259 |
this.mode = mode;
|
260 |
this.setExpireTime(expireTime);
|
261 |
this.serverParameters = serverParameters;
|
262 |
this.informationTables = informationTables;
|
263 |
this.helper = helper;
|
264 |
this.tablesOrViews = tablesOrViews;
|
265 |
} |
266 |
|
267 |
@Override
|
268 |
protected void reload() { |
269 |
// LOGGER.info("reload list of tables");
|
270 |
List<JDBCStoreParameters> tables = null; |
271 |
if(helper == null){ |
272 |
this.setValue(tables);
|
273 |
return;
|
274 |
} |
275 |
OperationsFactory operations = helper.getOperations(); |
276 |
if (operations == null) { |
277 |
this.setValue(null); |
278 |
LOG.debug("Sets tables to null to force reload tables from new ServerExplorar.");
|
279 |
return;
|
280 |
} |
281 |
try {
|
282 |
ListTablesOperation listTables = operations.createListTables( |
283 |
this.mode, serverParameters, informationTables, tablesOrViews
|
284 |
); |
285 |
tables = (List<JDBCStoreParameters>) listTables.perform();
|
286 |
} catch (Exception ex) { |
287 |
LOG.debug("Can't reload cached list of tables.", ex);
|
288 |
} |
289 |
this.setValue(tables);
|
290 |
} |
291 |
|
292 |
public JDBCHelper getHelper(){
|
293 |
return this.helper; |
294 |
} |
295 |
|
296 |
public void dispose() { |
297 |
this.helper = null; |
298 |
} |
299 |
} |
300 |
|
301 |
public JDBCServerExplorerBase(
|
302 |
JDBCServerExplorerParameters parameters, |
303 |
DataServerExplorerProviderServices services, |
304 |
JDBCHelper helper |
305 |
) throws InitializeException {
|
306 |
super(parameters, services);
|
307 |
this.helper = helper;
|
308 |
} |
309 |
|
310 |
@Override
|
311 |
public String getProviderName() { |
312 |
return this.getHelper().getProviderName(); |
313 |
} |
314 |
|
315 |
@Override
|
316 |
public String getStoreName() { |
317 |
return this.getHelper().getProviderName(); |
318 |
} |
319 |
|
320 |
protected DataManagerProviderServices getManager() {
|
321 |
return (DataManagerProviderServices) DALLocator.getDataManager();
|
322 |
} |
323 |
|
324 |
@Override
|
325 |
public JDBCServerExplorerParameters getParameters() {
|
326 |
return (JDBCServerExplorerParameters) super.getParameters(); |
327 |
} |
328 |
|
329 |
@Override
|
330 |
public boolean closeResourceRequested(ResourceProvider resource) { |
331 |
this.getHelper().getResulSetControler().pack();
|
332 |
return true; |
333 |
} |
334 |
|
335 |
@Override
|
336 |
public void resourceChanged(ResourceProvider resource) { |
337 |
// Nothing to do
|
338 |
} |
339 |
|
340 |
protected JDBCHelper getHelper() {
|
341 |
return helper;
|
342 |
} |
343 |
|
344 |
protected OperationsFactory getOperations() {
|
345 |
return this.getHelper().getOperations(); |
346 |
} |
347 |
|
348 |
@Override
|
349 |
public DataStore open(DataStoreParameters params) throws DataException { |
350 |
checkIsMine(params); |
351 |
DataStore store = super.open(params);
|
352 |
return store;
|
353 |
} |
354 |
|
355 |
@Override
|
356 |
public DataStore open(String tableName) throws DataException { |
357 |
JDBCStoreParameters params = this.get(tableName);
|
358 |
DataStore store = super.open(params);
|
359 |
return store;
|
360 |
} |
361 |
|
362 |
@Override
|
363 |
public List list(int mode) throws DataException { |
364 |
return list(mode, SHOW_TABLES_AND_VIEWS);
|
365 |
} |
366 |
|
367 |
@Override
|
368 |
public List list(int mode, int tablesOrViews) throws DataException { |
369 |
boolean informationTables = BooleanUtils.isTrue(
|
370 |
this.getParameters().getShowInformationDBTables()
|
371 |
); |
372 |
|
373 |
JDBCServerExplorerParameters serverParams = this.getParameters();
|
374 |
|
375 |
String key = buildKeyForCachedTables(mode, serverParams, informationTables, tablesOrViews);
|
376 |
CachedValue<List<JDBCStoreParameters>> tablesValue = CACHED_TABLES.get(key);
|
377 |
List<JDBCStoreParameters> tables = null; |
378 |
if (tablesValue != null) { |
379 |
tables = tablesValue.get(); |
380 |
} |
381 |
if (tables != null) { |
382 |
return tables;
|
383 |
} |
384 |
tablesValue = new CachedTablesValue(this.helper, mode, serverParams, informationTables, 60000, tablesOrViews); //60" |
385 |
CACHED_TABLES.put(key, tablesValue); |
386 |
tables = tablesValue.get(); |
387 |
return tables;
|
388 |
} |
389 |
|
390 |
public String buildKeyForCachedTables(int mode, JDBCServerExplorerParameters params, boolean informationTables, int tablesOrViews) { |
391 |
JDBCServerExplorerParameters clonedParams = (JDBCServerExplorerParameters) params.getCopy(); |
392 |
clonedParams.setSchema(null);
|
393 |
clonedParams.setCatalog(null);
|
394 |
|
395 |
StringBuilder builder = new StringBuilder(); |
396 |
builder.append(String.valueOf(mode));
|
397 |
builder.append(Hex.encodeHex(clonedParams.toByteArray())); |
398 |
builder.append(String.valueOf(informationTables));
|
399 |
builder.append(String.valueOf(tablesOrViews));
|
400 |
String key = builder.toString();
|
401 |
return key;
|
402 |
} |
403 |
|
404 |
@Override
|
405 |
public void remove(DataStoreParameters theParams) throws RemoveException { |
406 |
JDBCStoreParameters params = (JDBCStoreParameters) theParams; |
407 |
DropTableOperation removeTable = this.getOperations().createDropTable(
|
408 |
this.getOperations().createTableReference(params)
|
409 |
); |
410 |
if ((Boolean) removeTable.perform()) { |
411 |
this.dropCachedTables();
|
412 |
} |
413 |
} |
414 |
|
415 |
@Override
|
416 |
public JDBCStoreParameters getOpenParameters() throws DataException { |
417 |
JDBCStoreParameters params = this.helper.createOpenStoreParameters(this.getParameters()); |
418 |
if(StringUtils.isBlank(params.getSchema())){
|
419 |
params.setSchema(this.createSQLBuilder().default_schema());
|
420 |
} |
421 |
return params;
|
422 |
} |
423 |
|
424 |
@Override
|
425 |
public NewDataStoreParameters getAddParameters(String storeName) |
426 |
throws DataException {
|
427 |
JDBCNewStoreParameters params = this.getAddParameters();
|
428 |
params.setTable(storeName); |
429 |
return params;
|
430 |
} |
431 |
|
432 |
@Override
|
433 |
public JDBCNewStoreParameters getAddParameters() throws DataException { |
434 |
JDBCServerExplorerParameters parameters = getParameters(); |
435 |
JDBCNewStoreParameters params = this.helper.createNewStoreParameters();
|
436 |
params.setHost(parameters.getHost()); |
437 |
params.setPort(parameters.getPort()); |
438 |
params.setDBName(parameters.getDBName()); |
439 |
params.setUser(parameters.getUser()); |
440 |
params.setPassword(parameters.getPassword()); |
441 |
params.setCatalog(parameters.getCatalog()); |
442 |
params.setSchema(parameters.getSchema()); |
443 |
params.setJDBCDriverClassName(parameters.getJDBCDriverClassName()); |
444 |
params.setUrl(parameters.getUrl()); |
445 |
if (parameters instanceof FilesystemStoreParameters) { |
446 |
File f = ((FilesystemStoreParameters) parameters).getFile();
|
447 |
((FilesystemStoreParameters) params).setFile(f); |
448 |
} |
449 |
|
450 |
params.setDefaultFeatureType(this.getServerExplorerProviderServices()
|
451 |
.createNewFeatureType()); |
452 |
|
453 |
return params;
|
454 |
} |
455 |
|
456 |
protected void checkIsMine(DataStoreParameters dsp) { |
457 |
if (!(dsp instanceof JDBCConnectionParameters)) { |
458 |
throw new IllegalArgumentException( |
459 |
"not instance of FilesystemStoreParameters");
|
460 |
} |
461 |
JDBCServerExplorerParameters parameters = getParameters(); |
462 |
|
463 |
JDBCConnectionParameters pgp = (JDBCConnectionParameters) dsp; |
464 |
if (!StringUtils.equals(pgp.getHost(), parameters.getHost())) {
|
465 |
throw new IllegalArgumentException("wrong explorer: Host (mine: " |
466 |
+ parameters.getHost() + " other:" + pgp.getHost() + ")"); |
467 |
} |
468 |
if (!ObjectUtils.equals(pgp.getPort(), parameters.getPort())) {
|
469 |
throw new IllegalArgumentException("wrong explorer: Port (mine: " |
470 |
+ parameters.getPort() + " other:" + pgp.getPort() + ")"); |
471 |
} |
472 |
if (!StringUtils.equals(pgp.getDBName(), parameters.getDBName())) {
|
473 |
throw new IllegalArgumentException("wrong explorer: DBName (mine: " |
474 |
+ parameters.getDBName() + " other:" + pgp.getDBName()
|
475 |
+ ")");
|
476 |
} |
477 |
if (!StringUtils.isEmpty(parameters.getCatalog())) {
|
478 |
if (!StringUtils.equals(pgp.getCatalog(), parameters.getCatalog())) {
|
479 |
throw new IllegalArgumentException( |
480 |
"wrong explorer: Catalog (mine: "
|
481 |
+ parameters.getCatalog() + " other:"
|
482 |
+ pgp.getCatalog() + ")");
|
483 |
} |
484 |
} |
485 |
if (!StringUtils.isEmpty(parameters.getSchema())) {
|
486 |
if (!StringUtils.equals(pgp.getSchema(), parameters.getSchema())) {
|
487 |
throw new IllegalArgumentException( |
488 |
"wrong explorer: Schema (mine: "
|
489 |
+ parameters.getSchema() + " other:"
|
490 |
+ pgp.getSchema() + ")");
|
491 |
} |
492 |
} |
493 |
} |
494 |
|
495 |
@Override
|
496 |
public void open() throws OpenException { |
497 |
|
498 |
} |
499 |
|
500 |
@Override
|
501 |
public void close() throws CloseException { |
502 |
|
503 |
} |
504 |
|
505 |
@Override
|
506 |
protected void doDispose() throws BaseException { |
507 |
synchronized (CACHED_TABLES) {
|
508 |
List<String> toRemove = new ArrayList<>(); |
509 |
for (Map.Entry<String, CachedValue<List<JDBCStoreParameters>>> entry : CACHED_TABLES.entrySet()) { |
510 |
CachedTablesValue value = (CachedTablesValue) entry.getValue(); |
511 |
if (value.getHelper() == this.helper) { |
512 |
toRemove.add(entry.getKey()); |
513 |
value.dispose(); |
514 |
} |
515 |
} |
516 |
for (String key : toRemove) { |
517 |
CACHED_TABLES.remove(key); |
518 |
} |
519 |
helper.dispose(); |
520 |
helper = null;
|
521 |
} |
522 |
} |
523 |
|
524 |
@Override
|
525 |
public boolean canAdd() { |
526 |
if (this.canAdd == null) { |
527 |
CanCreateTablesOperation canAdd_ = this.getOperations().createCanCreateTables();
|
528 |
this.canAdd = (Boolean) canAdd_.perform(); |
529 |
} |
530 |
return this.canAdd; |
531 |
} |
532 |
|
533 |
@Override
|
534 |
public FeatureType getFeatureType(DataStoreParameters theParams)
|
535 |
throws DataException {
|
536 |
|
537 |
JDBCStoreParameters params = (JDBCStoreParameters) theParams; |
538 |
|
539 |
checkIsMine(params); |
540 |
|
541 |
EditableFeatureType fetureType |
542 |
= this.getServerExplorerProviderServices().createNewFeatureType();
|
543 |
|
544 |
List<String> primaryKeys = null; |
545 |
if (params.getPkFields() != null) { |
546 |
primaryKeys = Arrays.asList(params.getPkFields());
|
547 |
} |
548 |
|
549 |
FetchFeatureTypeOperation fetch = this.getOperations().createFetchFeatureType(
|
550 |
fetureType, |
551 |
this.getOperations().createTableReference(params),
|
552 |
primaryKeys, |
553 |
params.getDefaultGeometryField(), |
554 |
params.getCRS() |
555 |
); |
556 |
fetch.perform(); |
557 |
return fetureType;
|
558 |
} |
559 |
|
560 |
@Override
|
561 |
public boolean add(String providerName, NewDataStoreParameters theParams, boolean overwrite) |
562 |
throws DataException {
|
563 |
|
564 |
List<Pair<String, Privilege>> userAndPrivileges = new ArrayList<>(); |
565 |
JDBCNewStoreParameters params = (JDBCNewStoreParameters) theParams; |
566 |
if (!StringUtils.isEmpty(params.getAllRole())) {
|
567 |
userAndPrivileges.add( |
568 |
new ImmutablePair<>(params.getAllRole(), Privilege.ALL)
|
569 |
); |
570 |
} |
571 |
if (!StringUtils.isEmpty(params.getDeleteRole())) {
|
572 |
userAndPrivileges.add( |
573 |
new ImmutablePair<>(params.getDeleteRole(), Privilege.DELETE)
|
574 |
); |
575 |
} |
576 |
if (!StringUtils.isEmpty(params.getInsertRole())) {
|
577 |
userAndPrivileges.add( |
578 |
new ImmutablePair<>(params.getInsertRole(), Privilege.INSERT)
|
579 |
); |
580 |
} |
581 |
if (!StringUtils.isEmpty(params.getReferenceRole())) {
|
582 |
userAndPrivileges.add( |
583 |
new ImmutablePair<>(params.getReferenceRole(), Privilege.REFERENCE)
|
584 |
); |
585 |
} |
586 |
if (!StringUtils.isEmpty(params.getSelectRole())) {
|
587 |
userAndPrivileges.add( |
588 |
new ImmutablePair<>(params.getSelectRole(), Privilege.SELECT)
|
589 |
); |
590 |
} |
591 |
if (!StringUtils.isEmpty(params.getTriggerRole())) {
|
592 |
userAndPrivileges.add( |
593 |
new ImmutablePair<>(params.getTriggerRole(), Privilege.TRIGGER)
|
594 |
); |
595 |
} |
596 |
if (!StringUtils.isEmpty(params.getTruncateRole())) {
|
597 |
userAndPrivileges.add( |
598 |
new ImmutablePair<>(params.getTruncateRole(), Privilege.TRUNCATE)
|
599 |
); |
600 |
} |
601 |
if (!StringUtils.isEmpty(params.getUpdateRole())) {
|
602 |
userAndPrivileges.add( |
603 |
new ImmutablePair<>(params.getUpdateRole(), Privilege.UPDATE)
|
604 |
); |
605 |
} |
606 |
List<String> additionalSQLs = new ArrayList<>(); |
607 |
if (!StringUtils.isEmpty(params.getPostCreatingStatement())) {
|
608 |
additionalSQLs.add(params.getPostCreatingStatement()); |
609 |
} |
610 |
CreateTableOperation createTable = this.getOperations().createTable(
|
611 |
this.getOperations().createTableReference(params),
|
612 |
params.getDefaultFeatureType(), |
613 |
userAndPrivileges, |
614 |
additionalSQLs |
615 |
); |
616 |
|
617 |
boolean isOk = (boolean) createTable.perform(); |
618 |
if (!isOk) {
|
619 |
return false; |
620 |
} |
621 |
|
622 |
// We collect the featureType of the operation because
|
623 |
// the provider has been able to make changes to it
|
624 |
params.setDefaultFeatureType(createTable.getType()); |
625 |
|
626 |
if (theParams instanceof NewFeatureStoreParameters) { |
627 |
DataManager dataManager = DALLocator.getDataManager(); |
628 |
ResourcesStorage resources = this.getResourcesStorage(theParams);
|
629 |
dataManager.writeDALResource(resources, ((NewFeatureStoreParameters) theParams).getDefaultFeatureType()); |
630 |
} |
631 |
this.dropCachedTables();
|
632 |
return true; |
633 |
} |
634 |
|
635 |
private void dropCachedTables() { |
636 |
boolean informationTables = BooleanUtils.isTrue(
|
637 |
this.getParameters().getShowInformationDBTables()
|
638 |
); |
639 |
synchronized(CACHED_TABLES){
|
640 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_ALL, this.getParameters(), informationTables, SHOW_TABLES_AND_VIEWS));
|
641 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_FEATURE, this.getParameters(), informationTables, SHOW_TABLES_AND_VIEWS));
|
642 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_GEOMETRY, this.getParameters(), informationTables, SHOW_TABLES_AND_VIEWS));
|
643 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_ALL, this.getParameters(), informationTables, SHOW_TABLES));
|
644 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_FEATURE, this.getParameters(), informationTables, SHOW_TABLES));
|
645 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_GEOMETRY, this.getParameters(), informationTables, SHOW_TABLES));
|
646 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_ALL, this.getParameters(), informationTables, SHOW_VIEWS));
|
647 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_FEATURE, this.getParameters(), informationTables, SHOW_VIEWS));
|
648 |
CACHED_TABLES.remove(buildKeyForCachedTables(MODE_GEOMETRY, this.getParameters(), informationTables, SHOW_VIEWS));
|
649 |
} |
650 |
} |
651 |
|
652 |
@Override
|
653 |
public List getDataStoreProviderNames() { |
654 |
List x = new ArrayList(1); |
655 |
x.add(this.getProviderName());
|
656 |
return x;
|
657 |
} |
658 |
|
659 |
@Override
|
660 |
public void updateTableStatistics(String database, String schema, String table) throws JDBCExecuteSQLException { |
661 |
UpdateTableStatisticsOperation updateStatistics = this.getOperations().createUpdateTableStatistics(
|
662 |
this.getOperations().createTableReference(database, schema, table, null) |
663 |
); |
664 |
updateStatistics.perform(); |
665 |
} |
666 |
|
667 |
@Override
|
668 |
public Object execute(String sql) { |
669 |
ExecuteOperation execute = this.getOperations().createExecute(sql);
|
670 |
return execute.perform();
|
671 |
} |
672 |
|
673 |
@Override
|
674 |
public JDBCStoreParameters get(String name) throws DataException { |
675 |
JDBCStoreParameters params = this.getOpenParameters(name);
|
676 |
return params;
|
677 |
} |
678 |
|
679 |
@Override
|
680 |
public SQLBuilder createSQLBuilder() {
|
681 |
JDBCSQLBuilderBase builder = this.getHelper().createSQLBuilder();
|
682 |
return builder;
|
683 |
} |
684 |
|
685 |
private CustomResourcesConfig getCustomResourcesConfig() {
|
686 |
JDBCServerExplorerParameters serverParams = this.getParameters();
|
687 |
String key = buildKeyForCachedTables(MODE_ALL, serverParams, false, SHOW_TABLES_AND_VIEWS); //??? |
688 |
CachedValue<CustomResourcesConfig> cachedConfig = CACHED_CUSTOM_RESOURCES_CONFIG.get(key); |
689 |
if (cachedConfig != null) { |
690 |
// LOG.info("Get CustomResourcesConfig from CACHE_1: "+!cachedConfig.isExpired());
|
691 |
CustomResourcesConfig config = cachedConfig.get(); |
692 |
return config;
|
693 |
} |
694 |
JDBCStoreParameters params = this.helper.createOpenStoreParameters(this.getParameters()); |
695 |
cachedConfig = new CachedCustomResourcesConfig(params);
|
696 |
CACHED_CUSTOM_RESOURCES_CONFIG.put(key, cachedConfig); |
697 |
// LOG.info("Get CustomResourcesConfig from CACHE_2: "+!cachedConfig.isExpired());
|
698 |
return cachedConfig.get();
|
699 |
} |
700 |
|
701 |
private void refreshCustomResourcesConfig() { |
702 |
JDBCServerExplorerParameters serverParams = this.getParameters();
|
703 |
String key = buildKeyForCachedTables(MODE_ALL, serverParams, false, SHOW_TABLES_AND_VIEWS); //??? |
704 |
CachedValue<CustomResourcesConfig> cachedConfig = CACHED_CUSTOM_RESOURCES_CONFIG.get(key); |
705 |
if (cachedConfig != null) { |
706 |
// LOG.info("Force expire CustomResourcesConfig cache");
|
707 |
cachedConfig.expired(); |
708 |
} |
709 |
} |
710 |
|
711 |
private ResourcesStorage getResourcesStorage(DataStoreParameters parameters, String storeName) { |
712 |
if (DatabaseWorkspaceManager.isInternalTable(storeName)) {
|
713 |
ResourcesStorage resourcesStorage = ResourcesStorage.EMPTY_RESOURCESSTORAGE; |
714 |
return resourcesStorage;
|
715 |
} |
716 |
String resourcesTablename = null; |
717 |
try {
|
718 |
ResourcesStorage alternateResourcesStorage = null;
|
719 |
DataManager dataManager = DALLocator.getDataManager(); |
720 |
DatabaseWorkspaceManager workspace = dataManager.getDatabaseWorkspace(parameters); |
721 |
if (workspace != null) { |
722 |
alternateResourcesStorage = workspace.getAlternativeResourcesStorage(storeName); |
723 |
} |
724 |
|
725 |
ResourcesStorage defaultResourcesStorage = null;
|
726 |
ResourcesStorage customResourcesStorage = null;
|
727 |
|
728 |
// TODO: Habria que ver de localizar los parametros sin tener que hacer un list.
|
729 |
resourcesTablename = TABLE_RESOURCES_NAME; |
730 |
List<JDBCStoreParameters> tables = this.list(); |
731 |
for (JDBCStoreParameters params : tables) {
|
732 |
String theTableName = params.getTable();
|
733 |
if (StringUtils.equals(theTableName, resourcesTablename)) {
|
734 |
defaultResourcesStorage = new JDBCResourcesStorage(
|
735 |
this.helper,
|
736 |
alternateResourcesStorage, |
737 |
params, |
738 |
storeName |
739 |
); |
740 |
break;
|
741 |
} |
742 |
} |
743 |
CustomResourcesConfig config = getCustomResourcesConfig(); |
744 |
if( config!=null ) { |
745 |
if( config.isInternalTable(storeName) ) {
|
746 |
defaultResourcesStorage = ResourcesStorage.EMPTY_RESOURCESSTORAGE; |
747 |
} else {
|
748 |
resourcesTablename = config.getResourcesTablename(storeName); |
749 |
if( StringUtils.isNotBlank(resourcesTablename) ) {
|
750 |
JDBCStoreParameters params = this.getOpenParameters(resourcesTablename);
|
751 |
customResourcesStorage = new JDBCResourcesStorage(
|
752 |
this.helper,
|
753 |
alternateResourcesStorage, |
754 |
params, |
755 |
storeName, |
756 |
config.isResourcesReadOnly(resourcesTablename) |
757 |
); |
758 |
} |
759 |
} |
760 |
} |
761 |
return new CompoundResourcesStorage(defaultResourcesStorage, customResourcesStorage); |
762 |
} catch (Throwable ex) { |
763 |
LOG.warn("Can't retrieve reources storage for table '" + storeName + "' in '" + this.getParameters().getUrl() + " ("+resourcesTablename+").", ex); |
764 |
} |
765 |
ResourcesStorage theResourcesStorage = ResourcesStorage.EMPTY_RESOURCESSTORAGE; |
766 |
return theResourcesStorage;
|
767 |
} |
768 |
|
769 |
public ResourcesStorage getResourcesStorage(String name) { |
770 |
JDBCStoreParameters params; |
771 |
try {
|
772 |
ResourcesStorage customResourcesStorage = null;
|
773 |
CustomResourcesConfig config = getCustomResourcesConfig(); |
774 |
if( config!=null ) { |
775 |
if( !config.isInternalTable(name) ) {
|
776 |
String resourcesTablename = config.getResourcesTablename(name);
|
777 |
if( StringUtils.isNotBlank(resourcesTablename) ) {
|
778 |
params = this.getOpenParameters(resourcesTablename);
|
779 |
customResourcesStorage = new JDBCResourcesStorage(
|
780 |
this.helper,
|
781 |
null,
|
782 |
params, |
783 |
TABLENAME_SERVER_EXPLORER_MARK, |
784 |
config.isResourcesReadOnly(resourcesTablename) |
785 |
); |
786 |
} |
787 |
} |
788 |
} |
789 |
params = this.getOpenParameters(DatabaseWorkspaceManager.TABLE_RESOURCES_NAME);
|
790 |
JDBCResourcesStorage defaultResourcesStorage = new JDBCResourcesStorage(
|
791 |
this.helper,
|
792 |
null,
|
793 |
params, |
794 |
TABLENAME_SERVER_EXPLORER_MARK |
795 |
); |
796 |
if( customResourcesStorage==null ) { |
797 |
return defaultResourcesStorage;
|
798 |
} |
799 |
return new CompoundResourcesStorage(defaultResourcesStorage, customResourcesStorage); |
800 |
} catch (DataException ex) {
|
801 |
return null; |
802 |
} |
803 |
} |
804 |
|
805 |
@Override
|
806 |
public ResourcesStorage getResourcesStorage() {
|
807 |
JDBCStoreParameters params; |
808 |
try {
|
809 |
params = this.getOpenParameters(DatabaseWorkspaceManager.TABLE_RESOURCES_NAME);
|
810 |
// params.setTable(DatabaseWorkspaceManager.TABLE_RESOURCES_NAME);
|
811 |
JDBCResourcesStorage theResourcesStorage = new JDBCResourcesStorage(
|
812 |
this.helper,
|
813 |
null,
|
814 |
params, |
815 |
TABLENAME_SERVER_EXPLORER_MARK |
816 |
); |
817 |
return theResourcesStorage;
|
818 |
} catch (DataException ex) {
|
819 |
return null; |
820 |
} |
821 |
} |
822 |
|
823 |
@Override
|
824 |
public ResourcesStorage getResourcesStorage(DataStoreParameters parameters) {
|
825 |
if (parameters == null) { |
826 |
throw new IllegalArgumentException("null is a valid value for parameters."); |
827 |
} |
828 |
String tableName;
|
829 |
if (parameters instanceof JDBCNewStoreParameters) { |
830 |
tableName = ((JDBCNewStoreParameters) parameters).getTable(); |
831 |
} else if (parameters instanceof JDBCStoreParameters) { |
832 |
tableName = ((JDBCStoreParameters) parameters).getTable(); |
833 |
} else {
|
834 |
throw new IllegalArgumentException("Required a JDBCStoreParameters or JDBCNewStoreParameters parameters, received " + parameters.getClass().getName() + "."); |
835 |
} |
836 |
return this.getResourcesStorage(parameters, tableName); |
837 |
} |
838 |
|
839 |
@Override
|
840 |
public ResourcesStorage getResourcesStorage(DataStore dataStore) {
|
841 |
return this.getResourcesStorage((JDBCStoreParameters) dataStore.getParameters(), |
842 |
dataStore.getName() |
843 |
); |
844 |
} |
845 |
|
846 |
@Override
|
847 |
public boolean exists(DataStoreParameters parameters) throws DataException { |
848 |
JDBCStoreParameters params = (JDBCStoreParameters) parameters; |
849 |
JDBCSQLBuilderBase builder = this.getHelper().createSQLBuilder();
|
850 |
SQLBuilder.TableNameBuilder searchTable = builder.createTableNameBuilder() |
851 |
.database(params.getDBName()) |
852 |
.schema(params.getSchema()) |
853 |
.name(params.getTable()); |
854 |
SQLBuilder.TableNameBuilder table = builder.createTableNameBuilder(); |
855 |
|
856 |
List<JDBCStoreParameters> l = this.list(); |
857 |
for (JDBCStoreParameters current : l) {
|
858 |
table.database(current.getDBName()) |
859 |
.schema(current.getSchema()) |
860 |
.name(current.getTable()); |
861 |
if (table.equals(searchTable)) {
|
862 |
return true; |
863 |
} |
864 |
} |
865 |
return false; |
866 |
} |
867 |
|
868 |
@Override
|
869 |
public void setCustomResources(String tableName, String resourcesTableName) { |
870 |
this.setCustomResources(tableName, resourcesTableName, false); |
871 |
} |
872 |
|
873 |
@Override
|
874 |
public void setCustomResources(String tableName, String resourcesTableName, boolean readonly) { |
875 |
CustomResourcesConfig config = getCustomResourcesConfig(); |
876 |
if( config==null ) { |
877 |
throw new RuntimeException("Can't retrieve alternative resources configuration"); |
878 |
} |
879 |
config.addResourceMapping(tableName, resourcesTableName); |
880 |
config.setResourcesReadOnly(resourcesTableName,readonly); |
881 |
JDBCStoreParameters params = this.helper.createOpenStoreParameters(this.getParameters()); |
882 |
if(!setConfigValue(params, CONFIG_NAME_CUSTOM_RESOURCES, config.toJsonString())) {
|
883 |
throw new RuntimeException("Can't save custom resources configuration"); |
884 |
} |
885 |
refreshCustomResourcesConfig(); |
886 |
|
887 |
|
888 |
if (StringUtils.isNotBlank(resourcesTableName)) {
|
889 |
try {
|
890 |
params = this.getOpenParameters(resourcesTableName);
|
891 |
JDBCResourcesStorage resourcesStorage = new JDBCResourcesStorage(
|
892 |
this.helper,
|
893 |
null,
|
894 |
params, |
895 |
tableName, |
896 |
config.isResourcesReadOnly(resourcesTableName) |
897 |
); |
898 |
resourcesStorage.clearCache(); |
899 |
} catch (Exception ex) { |
900 |
LOG.debug("Can't remove local cache for table "+tableName, ex);
|
901 |
} |
902 |
} |
903 |
|
904 |
|
905 |
} |
906 |
|
907 |
private static boolean setConfigValue(JDBCStoreParameters params, String name, String value) { |
908 |
FeatureStore store = null;
|
909 |
try {
|
910 |
DataManager dataManager = DALLocator.getDataManager(); |
911 |
params.setTable(TABLE_CONFIGURATION_NAME); |
912 |
store = (FeatureStore) dataManager.openStore( |
913 |
params.getProviderName(), |
914 |
params |
915 |
); |
916 |
} catch (Exception ex) { |
917 |
LOG.trace("Can't read configuration value '"+name+"'", ex); |
918 |
// Do noting
|
919 |
// } finally {
|
920 |
// DisposeUtils.disposeQuietly(store);
|
921 |
} |
922 |
if( store == null ) { |
923 |
return false; |
924 |
} |
925 |
try {
|
926 |
store.edit(); |
927 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
928 |
String filter = builder.eq(
|
929 |
builder.column(FIELD_CONFIGURATION_NAME), |
930 |
builder.constant(name) |
931 |
).toString(); |
932 |
Feature feature = store.findFirst(filter); |
933 |
EditableFeature efeature; |
934 |
if (feature == null) { |
935 |
efeature = store.createNewFeature(); |
936 |
efeature.set(FIELD_CONFIGURATION_NAME, name); |
937 |
efeature.set(FIELD_CONFIGURATION_VALUE, value); |
938 |
store.insert(efeature); |
939 |
} else {
|
940 |
efeature = feature.getEditable(); |
941 |
efeature.set(FIELD_CONFIGURATION_VALUE, value); |
942 |
store.update(efeature); |
943 |
} |
944 |
store.finishEditing(); |
945 |
return true; |
946 |
} catch (Exception ex) { |
947 |
LOG.debug("Can't write configuration value for '"+name+"'", ex); |
948 |
return false; |
949 |
} finally {
|
950 |
DisposeUtils.disposeQuietly(store); |
951 |
} |
952 |
} |
953 |
|
954 |
// private static String getConfigValue_useStore(JDBCStoreParameters params, String name) {
|
955 |
// FeatureStore store = null;
|
956 |
// try {
|
957 |
// DataManager dataManager = DALLocator.getDataManager();
|
958 |
// params.setTable(TABLE_CONFIGURATION_NAME);
|
959 |
// store = (FeatureStore) dataManager.openStore(
|
960 |
// params.getProviderName(),
|
961 |
// params
|
962 |
// );
|
963 |
// } catch (Exception ex) {
|
964 |
// LOG.trace("Can't read configuration value '"+name+"'", ex);
|
965 |
// // Do noting
|
966 |
//// } finally {
|
967 |
//// DisposeUtils.disposeQuietly(store);
|
968 |
// }
|
969 |
// if( store == null ) {
|
970 |
// return null;
|
971 |
// }
|
972 |
// try {
|
973 |
// ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
|
974 |
// String filter = builder.eq(
|
975 |
// builder.column(FIELD_CONFIGURATION_NAME),
|
976 |
// builder.constant(name)
|
977 |
// ).toString();
|
978 |
// Feature feature = store.findFirst(filter);
|
979 |
// if( feature == null ) {
|
980 |
// return null;
|
981 |
// }
|
982 |
// String value = feature.getString(FIELD_CONFIGURATION_VALUE);
|
983 |
// return value;
|
984 |
// } catch (Exception ex) {
|
985 |
// LOG.debug("Can't read configuration value '"+name+"'", ex);
|
986 |
// return null;
|
987 |
// } finally {
|
988 |
// DisposeUtils.disposeQuietly(store);
|
989 |
// }
|
990 |
// }
|
991 |
|
992 |
private static String getConfigValue(JDBCStoreParameters params, String name) { |
993 |
JDBCServerExplorerBase explorer = null;
|
994 |
try {
|
995 |
DataManager dataManager = DALLocator.getDataManager(); |
996 |
params.setTable(TABLE_CONFIGURATION_NAME); |
997 |
JDBCServerExplorerParameters explorerParams = (JDBCServerExplorerParameters) dataManager.createServerExplorerParameters(params.getProviderName()); |
998 |
ToolsLocator.getDynObjectManager().copy(params, explorerParams); |
999 |
|
1000 |
explorer = (JDBCServerExplorerBase) dataManager.openServerExplorer(explorerParams.getProviderName(), explorerParams); |
1001 |
|
1002 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
1003 |
String filter = builder.eq(
|
1004 |
builder.column(FIELD_CONFIGURATION_NAME), |
1005 |
builder.constant(name) |
1006 |
).toString(); |
1007 |
OperationsFactory operations = explorer.getOperations(); |
1008 |
RetrieveValueOperation op = operations.createRetrieveValue( |
1009 |
operations.createTableReference(params), |
1010 |
filter, |
1011 |
null, //order |
1012 |
FIELD_CONFIGURATION_VALUE |
1013 |
); |
1014 |
Object value = op.perform();
|
1015 |
return Objects.toString(value,null); |
1016 |
} catch (Exception ex) { |
1017 |
LOG.debug("Can't read configuration value '"+name+"'", ex); |
1018 |
return null; |
1019 |
} finally {
|
1020 |
DisposeUtils.disposeQuietly(explorer); |
1021 |
} |
1022 |
} |
1023 |
|
1024 |
@Override
|
1025 |
public boolean exists() { |
1026 |
try {
|
1027 |
JDBCServerExplorerParameters serverParameters = this.getParameters();
|
1028 |
OperationsFactory operations = helper.getOperations(); |
1029 |
ListTablesOperation listTables = operations.createListTables( |
1030 |
MODE_ALL, serverParameters, false, SHOW_TABLES
|
1031 |
); |
1032 |
List<JDBCStoreParameters> tables = (List<JDBCStoreParameters>) listTables.perform(); |
1033 |
return true; |
1034 |
} catch(Throwable th) { |
1035 |
return false; |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
@Override
|
1040 |
public String getConnectionProviderStatus() { |
1041 |
return this.helper.getConnectionProviderStatus(); |
1042 |
} |
1043 |
|
1044 |
@Override
|
1045 |
public void setTransaction(DataTransaction transaction) { |
1046 |
if( this.helper!=null ) { |
1047 |
this.helper.setTransaction((DataTransactionServices) transaction);
|
1048 |
} |
1049 |
} |
1050 |
|
1051 |
@Override
|
1052 |
public DataTransaction getTransaction() {
|
1053 |
if( this.helper==null ) { |
1054 |
return null; |
1055 |
} |
1056 |
return this.helper.getTransaction(); |
1057 |
} |
1058 |
|
1059 |
private JDBCStoreParameters getOpenParameters(String tableName) throws DataException { |
1060 |
//No esta claro si se debe hacer este bucle o no. NO BORRAR ALEGREMENTE
|
1061 |
|
1062 |
// List<JDBCStoreParameters> tables = this.list();
|
1063 |
// for (JDBCStoreParameters params : tables) {
|
1064 |
// String theTableName = params.getTable();
|
1065 |
// if (StringUtils.equals(theTableName, tableName)) {
|
1066 |
// return params;
|
1067 |
// }
|
1068 |
// }
|
1069 |
JDBCStoreParameters p = this.getOpenParameters();
|
1070 |
p.setTable(tableName); |
1071 |
return p;
|
1072 |
} |
1073 |
} |