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 / DefaultDataManager.java @ 44346
History | View | Annotate | Download (42.7 KB)
1 |
package org.gvsig.fmap.dal.impl; |
---|---|
2 |
|
3 |
import java.io.ByteArrayInputStream; |
4 |
import java.io.File; |
5 |
import java.io.InputStream; |
6 |
import java.net.URL; |
7 |
import java.net.URLClassLoader; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Collections; |
10 |
import java.util.HashMap; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
import org.apache.commons.io.IOUtils; |
14 |
import org.apache.commons.lang3.StringUtils; |
15 |
import org.gvsig.expressionevaluator.Expression; |
16 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
17 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
18 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
19 |
|
20 |
import org.gvsig.fmap.dal.DataFactory; |
21 |
import org.gvsig.fmap.dal.DataManager; |
22 |
import org.gvsig.fmap.dal.DataParameters; |
23 |
import org.gvsig.fmap.dal.DataServerExplorer; |
24 |
import org.gvsig.fmap.dal.DataServerExplorerFactory; |
25 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
26 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
27 |
import org.gvsig.fmap.dal.DataStore; |
28 |
import org.gvsig.fmap.dal.DataStoreFactory_v2_4; |
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
30 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
31 |
import org.gvsig.fmap.dal.DataTypes; |
32 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
33 |
|
34 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
35 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
36 |
import org.gvsig.fmap.dal.Register; |
37 |
import org.gvsig.fmap.dal.StoresRepository; |
38 |
import org.gvsig.fmap.dal.exception.DataException; |
39 |
import org.gvsig.fmap.dal.exception.InitializeException; |
40 |
import org.gvsig.fmap.dal.exception.OpenException; |
41 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
42 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
43 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
44 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
45 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
46 |
import org.gvsig.fmap.dal.feature.DataProfile; |
47 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
48 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
49 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
52 |
import org.gvsig.fmap.dal.feature.impl.DALFile; |
53 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
54 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
55 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
56 |
import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
57 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
58 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
59 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
60 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
61 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
62 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
63 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
64 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
65 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultExpressionEvaluator; |
66 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
67 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
68 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
69 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
70 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
71 |
import org.gvsig.fmap.dal.spi.DALSPILocator; |
72 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
73 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
74 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
75 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
76 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
77 |
import org.gvsig.tools.ToolsLocator; |
78 |
import org.gvsig.tools.dataTypes.DataType; |
79 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
80 |
import org.gvsig.tools.dynobject.DynObject; |
81 |
import org.gvsig.tools.dynobject.DynStruct; |
82 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
83 |
import org.gvsig.tools.dynobject.Tags; |
84 |
import org.gvsig.tools.evaluator.Evaluator; |
85 |
import org.gvsig.tools.exception.BaseException; |
86 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
87 |
import org.gvsig.tools.folders.FoldersManager; |
88 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
89 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
90 |
import org.gvsig.tools.persistence.PersistenceManager; |
91 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
92 |
import org.gvsig.tools.service.spi.Services; |
93 |
import org.slf4j.Logger; |
94 |
import org.slf4j.LoggerFactory; |
95 |
|
96 |
@SuppressWarnings("UseSpecificCatch") |
97 |
public class DefaultDataManager |
98 |
implements DataManager, DataManagerProviderServices, Services {
|
99 |
|
100 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataManager.class); |
101 |
|
102 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
103 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
104 |
"DAL cache providers";
|
105 |
|
106 |
public static final String FILESYSTEM_EXPLORER_NAME = "FilesystemExplorer"; |
107 |
|
108 |
|
109 |
private class Registers { |
110 |
|
111 |
private final Register store; |
112 |
private final Register storeProvider; |
113 |
private final Register serverExplorer; |
114 |
private final Register featureIndexProvider; |
115 |
|
116 |
public Registers() {
|
117 |
this.store = new RegisterImpl( |
118 |
"Data.manager.stores.factory",
|
119 |
"DAL store factories"
|
120 |
); |
121 |
this.storeProvider = new RegisterImpl( |
122 |
"Data.manager.providers.factory",
|
123 |
"DAL store provider factories"
|
124 |
); |
125 |
this.serverExplorer = new RegisterImpl( |
126 |
"Data.manager.servereexplorer.factory",
|
127 |
"DAL server explorer factories"
|
128 |
); |
129 |
this.featureIndexProvider = new RegisterImpl( |
130 |
"Data.manager.feature.index.factory",
|
131 |
"DAL feature index factories"
|
132 |
); |
133 |
|
134 |
this.store.register(new FeatureStoreFactory()); |
135 |
} |
136 |
} |
137 |
private static final String TAG_DAL_OPENSTORE = "dal.openstore."; |
138 |
|
139 |
private final Registers registers; |
140 |
|
141 |
private final Map<Integer, String> defaultDataIndexProviders; |
142 |
|
143 |
private OpenErrorHandler openErrorHandler = null; |
144 |
|
145 |
private DataServerExplorerPool dataServerExplorerPool = null; |
146 |
|
147 |
private List<DataType> dataTypes = null; |
148 |
|
149 |
private ClassLoader resourcesLoader = null; |
150 |
|
151 |
private List<DataProfile> dataProfiles; |
152 |
|
153 |
private final Map<String, DatabaseWorkspaceManager> databaseWorkspaces = new HashMap<>(); |
154 |
|
155 |
public DefaultDataManager() {
|
156 |
this.registers = new Registers(); |
157 |
this.defaultDataIndexProviders = new HashMap<>(); |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public Register getStoreRegister() {
|
162 |
return this.registers.store; |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public Register getStoreProviderRegister() {
|
167 |
return this.registers.storeProvider; |
168 |
} |
169 |
|
170 |
@Override
|
171 |
public Register getServerExplorerRegister() {
|
172 |
return this.registers.serverExplorer; |
173 |
} |
174 |
|
175 |
@Override
|
176 |
public Register getFeatureIndexRegister() {
|
177 |
return this.registers.featureIndexProvider; |
178 |
} |
179 |
|
180 |
private String getStoreName(DataStoreParameters parameters) { |
181 |
for (DataFactory factory : this.getStoreRegister()) { |
182 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) factory; |
183 |
if (storeFactory.canUse(parameters)) {
|
184 |
return storeFactory.getName();
|
185 |
} |
186 |
} |
187 |
return null; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @deprecated
|
192 |
*/
|
193 |
@Override
|
194 |
public void registerDefaultRasterStore(Class rasterStoreClass) { |
195 |
// Metodo usado por el raster nuevo para regstrar su factoria de store
|
196 |
this.getStoreRegister().register(new RasterStoreFactory(rasterStoreClass)); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* @deprecated
|
201 |
*/
|
202 |
@Override
|
203 |
public void registerStoreFactory(String name, Class storeFactoryClass) { |
204 |
// Metodo usado por el raster viejo para registrar las factorias de sus stores
|
205 |
this.getStoreRegister().register(new RasterStoreOldFactory(name, storeFactoryClass)); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* @param name
|
210 |
* @param storeProviderClass
|
211 |
* @param parametersClass
|
212 |
* @deprecated use registerStoreProviderFactory
|
213 |
*/
|
214 |
@Override
|
215 |
public void registerStoreProvider(String name, Class storeProviderClass, |
216 |
Class parametersClass) {
|
217 |
if (name == null || storeProviderClass == null || parametersClass == null) { |
218 |
throw new IllegalArgumentException("Any parameters can be null"); |
219 |
} |
220 |
|
221 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
222 |
throw new IllegalArgumentException(parametersClass.getName() |
223 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
224 |
} |
225 |
|
226 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
227 |
// Envuelve al proveedor en una factoria por defecto.
|
228 |
this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
229 |
name, "", storeProviderClass, parametersClass));
|
230 |
return;
|
231 |
} |
232 |
|
233 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
234 |
// Envuelve al proveedor en una factoria por defecto.
|
235 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
236 |
name, "", storeProviderClass, parametersClass));
|
237 |
return;
|
238 |
} |
239 |
|
240 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
241 |
+ name + " provider class=" + storeProviderClass.getName());
|
242 |
|
243 |
} |
244 |
|
245 |
@Override
|
246 |
public void registerExplorerProvider(String name, Class explorerClass, Class parametersClass) { |
247 |
if (name == null || explorerClass == null || parametersClass == null) { |
248 |
// FIXME Exception
|
249 |
throw new IllegalArgumentException("Any parameters can be null"); |
250 |
} |
251 |
|
252 |
if (!DataServerExplorerParameters.class
|
253 |
.isAssignableFrom(parametersClass)) { |
254 |
// FIXME Exception
|
255 |
throw new IllegalArgumentException( |
256 |
parametersClass.getName() |
257 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
258 |
} |
259 |
|
260 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
261 |
// FIXME Exception
|
262 |
throw new IllegalArgumentException(explorerClass.getName() |
263 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
264 |
} |
265 |
|
266 |
// Envuelve al proveedor en una factoria por defecto.
|
267 |
this.registerServerExplorerFactory(
|
268 |
new DataServerExplorerToDataExplorerFactoryWrapper(
|
269 |
name, "", explorerClass, parametersClass
|
270 |
) |
271 |
); |
272 |
|
273 |
} |
274 |
|
275 |
@Override
|
276 |
public void registerStoreFactory(DataStoreFactory_v2_4 factory) { |
277 |
this.getStoreRegister().register(factory);
|
278 |
} |
279 |
|
280 |
@Override
|
281 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
282 |
this.getStoreProviderRegister().register(factory);
|
283 |
} |
284 |
|
285 |
@Override
|
286 |
public void registerServerExplorerFactory(DataServerExplorerFactory factory) { |
287 |
this.getServerExplorerRegister().register(factory);
|
288 |
} |
289 |
|
290 |
@Override
|
291 |
public DataStoreParameters createStoreParameters(byte[] data) { |
292 |
try {
|
293 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
294 |
ByteArrayInputStream stream = new ByteArrayInputStream(data); |
295 |
DataStoreParameters parameters = (DataStoreParameters) persistenceManager.getObject(stream); |
296 |
return parameters;
|
297 |
} catch (Exception ex) { |
298 |
LOGGER.warn("Can't get parameters from byte[].",ex);
|
299 |
return null; |
300 |
} |
301 |
} |
302 |
|
303 |
@Override
|
304 |
public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
305 |
if( providerName == null ) { |
306 |
String msg = "Provider name can't be null."; |
307 |
LOGGER.warn(msg); |
308 |
throw new IllegalArgumentException(msg); |
309 |
} |
310 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
311 |
if( providerFactory == null ) { |
312 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
313 |
LOGGER.warn(msg); |
314 |
throw new IllegalArgumentException(msg); |
315 |
} |
316 |
return (DataStoreParameters) providerFactory.createParameters();
|
317 |
} |
318 |
|
319 |
@Override
|
320 |
public NewDataStoreParameters createNewStoreParameters(String explorerName, String providerName) throws InitializeException, ProviderNotRegisteredException { |
321 |
try {
|
322 |
DataServerExplorer explorer = this.openServerExplorer(explorerName, (DataServerExplorerParameters)null); |
323 |
return explorer.getAddParameters(providerName);
|
324 |
} catch (Exception ex) { |
325 |
throw new InitializeException(ex); |
326 |
} |
327 |
} |
328 |
|
329 |
@Override
|
330 |
public DataServerExplorerParameters createServerExplorerParameters(String explorerName) throws InitializeException, ProviderNotRegisteredException { |
331 |
if( explorerName == null ) { |
332 |
String msg = "Explorer name can't be null."; |
333 |
LOGGER.warn(msg); |
334 |
throw new IllegalArgumentException(msg); |
335 |
} |
336 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
337 |
if( explorerFactory == null ) { |
338 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
339 |
LOGGER.warn(msg); |
340 |
throw new IllegalArgumentException(msg); |
341 |
} |
342 |
DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
343 |
return params;
|
344 |
} |
345 |
|
346 |
@Override
|
347 |
public DataStoreParameters createMemoryStoreParameters(String autoOrderAttributeName) throws InitializeException { |
348 |
try {
|
349 |
DataStoreParameters parameters = createStoreParameters(MemoryStoreProvider.NAME); |
350 |
if (autoOrderAttributeName != null) { |
351 |
parameters.setDynValue( |
352 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
353 |
autoOrderAttributeName); |
354 |
} |
355 |
return parameters;
|
356 |
} catch (Exception ex) { |
357 |
throw new InitializeException(ex); |
358 |
} |
359 |
} |
360 |
|
361 |
@Override
|
362 |
public DataServerExplorer openServerExplorer(String explorerName, DataServerExplorerParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
363 |
if( explorerName == null ) { |
364 |
String msg = "Explorer name can't be null."; |
365 |
LOGGER.warn(msg); |
366 |
throw new IllegalArgumentException(msg); |
367 |
} |
368 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
369 |
if( explorerFactory == null ) { |
370 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
371 |
LOGGER.warn(msg); |
372 |
throw new IllegalArgumentException(msg); |
373 |
} |
374 |
if (parameters == null) { |
375 |
parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
376 |
} |
377 |
DataServerExplorer explorer = (DataServerExplorer) explorerFactory.create( |
378 |
parameters, |
379 |
new DefaultDataServerExplorerProviderServices()
|
380 |
); |
381 |
return explorer;
|
382 |
} |
383 |
|
384 |
@Override
|
385 |
public DataServerExplorer openServerExplorer(String explorerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
386 |
if( arguments.length==1 && arguments[0] instanceof DataServerExplorerParameters ) { |
387 |
// Esto hace falta ya que desde scripting si se invoca a openServerExplorercon solo
|
388 |
// un parametro de tipo DataServerExplorerParameters llama ha este metodo en lugar de
|
389 |
// llamar al que toca.
|
390 |
return openServerExplorer(explorerName, (DataServerExplorerParameters)(arguments[0])); |
391 |
} |
392 |
if( explorerName == null ) { |
393 |
String msg = "Explorer name can't be null."; |
394 |
LOGGER.warn(msg); |
395 |
throw new IllegalArgumentException(msg); |
396 |
} |
397 |
if( (arguments.length % 2)!= 0 ) { |
398 |
throw new ValidateDataParametersException(); |
399 |
} |
400 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
401 |
DataServerExplorerParameters parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
402 |
for( int i=0; i<arguments.length; i+=2 ) { |
403 |
String name = (String) arguments[i]; |
404 |
Object value = arguments[i+1]; |
405 |
parameters.setDynValue(name, value); |
406 |
} |
407 |
return this.openServerExplorer(explorerName, parameters); |
408 |
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* @param parameters
|
413 |
* @return
|
414 |
* @throws org.gvsig.fmap.dal.exception.InitializeException
|
415 |
* @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
|
416 |
* @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
|
417 |
* @deprecated see openServerExplorer
|
418 |
*/
|
419 |
@Override
|
420 |
public DataServerExplorer createServerExplorer(
|
421 |
DataServerExplorerParameters parameters) throws InitializeException,
|
422 |
ProviderNotRegisteredException, ValidateDataParametersException { |
423 |
return openServerExplorer(parameters.getExplorerName(), parameters);
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* @deprecated use openStore
|
428 |
* @param parameters
|
429 |
* @return
|
430 |
* @throws InitializeException
|
431 |
* @throws ProviderNotRegisteredException
|
432 |
* @throws ValidateDataParametersException
|
433 |
*/
|
434 |
@Override
|
435 |
public DataStore createStore(DataStoreParameters parameters)
|
436 |
throws InitializeException, ProviderNotRegisteredException,
|
437 |
ValidateDataParametersException { |
438 |
return openStore(parameters.getDataStoreName(), parameters);
|
439 |
} |
440 |
|
441 |
@Override
|
442 |
public DataStore openStore(String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
443 |
if( providerName == null ) { |
444 |
String msg = "Provider name can't be null."; |
445 |
LOGGER.warn(msg); |
446 |
throw new IllegalArgumentException(msg); |
447 |
} |
448 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
449 |
if (!identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, providerName)) {
|
450 |
throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, providerName); |
451 |
} |
452 |
|
453 |
parameters.validate(); |
454 |
|
455 |
String storeName = this.getStoreName(parameters); |
456 |
if( StringUtils.isEmpty(storeName) ) {
|
457 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
458 |
LOGGER.warn(msg); |
459 |
throw new IllegalArgumentException(msg); |
460 |
} |
461 |
|
462 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
463 |
if( storeFactory == null ) { |
464 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
465 |
LOGGER.warn(msg); |
466 |
throw new IllegalArgumentException(msg); |
467 |
} |
468 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
469 |
if( providerFactory == null ) { |
470 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
471 |
LOGGER.warn(msg); |
472 |
throw new IllegalArgumentException(msg); |
473 |
} |
474 |
|
475 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
476 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
477 |
|
478 |
storeFactory.setProvider(store, provider); |
479 |
return store;
|
480 |
} |
481 |
|
482 |
public DataStore openStore(DataStoreParameters parameters, DataStoreProvider provider) {
|
483 |
String storeName = this.getStoreName(parameters); |
484 |
if( StringUtils.isEmpty(storeName) ) {
|
485 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
486 |
LOGGER.warn(msg); |
487 |
throw new IllegalArgumentException(msg); |
488 |
} |
489 |
|
490 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
491 |
if( storeFactory == null ) { |
492 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
493 |
LOGGER.warn(msg); |
494 |
throw new IllegalArgumentException(msg); |
495 |
} |
496 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
497 |
storeFactory.setProvider(store, provider); |
498 |
return store;
|
499 |
} |
500 |
|
501 |
@Override
|
502 |
public DataStore openStore(String provider, DynObject parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
503 |
DataStoreParameters params = toDataStoreParameters(provider, parameters); |
504 |
DataStore store = openStore(params.getDataStoreName(), params); |
505 |
return store;
|
506 |
} |
507 |
|
508 |
@Override
|
509 |
public DataStore openStore(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
510 |
if( arguments.length == 1 ) { |
511 |
// Desde jython entra por este metodo en lugar de los especificos
|
512 |
// de DataStoreParameters o DynObject
|
513 |
if( arguments[0] instanceof DataStoreParameters ) { |
514 |
return this.openStore(providerName, (DataStoreParameters)(arguments[0])); |
515 |
} else if( arguments[0] instanceof DynObject ) { |
516 |
return this.openStore(providerName, (DynObject)(arguments[0])); |
517 |
} |
518 |
} |
519 |
if( (arguments.length % 2)!= 0 ) { |
520 |
throw new ValidateDataParametersException(); |
521 |
} |
522 |
if( providerName == null ) { |
523 |
String msg = "Provider name can't be null."; |
524 |
LOGGER.warn(msg); |
525 |
throw new IllegalArgumentException(msg); |
526 |
} |
527 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
528 |
DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
529 |
for( int i=0; i<arguments.length; i+=2 ) { |
530 |
String name = (String) arguments[i]; |
531 |
Object value = arguments[i+1]; |
532 |
parameters.setDynValue(name, value); |
533 |
} |
534 |
return this.openStore(providerName, parameters); |
535 |
} |
536 |
|
537 |
@Override
|
538 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) throws InitializeException { |
539 |
try {
|
540 |
DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
541 |
DataStore store = openStore(MemoryStoreProvider.NAME, parameters); |
542 |
return (FeatureStore) store;
|
543 |
} catch (Exception ex) { |
544 |
throw new InitializeException(ex); |
545 |
} |
546 |
} |
547 |
|
548 |
@Override
|
549 |
public DataStoreProviderFactory getStoreProviderFactory(String providerName) { |
550 |
if( providerName == null ) { |
551 |
String msg = "Provider name can't be null."; |
552 |
LOGGER.warn(msg); |
553 |
throw new IllegalArgumentException(msg); |
554 |
} |
555 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
556 |
return (DataStoreProviderFactory) providerFactory;
|
557 |
} |
558 |
|
559 |
@Override
|
560 |
public List<String> getStoreProviders() { |
561 |
return this.getStoreProviderRegister().getFactoryNames(); |
562 |
} |
563 |
|
564 |
@Override
|
565 |
public List<String> getStoreProviders(String explorerName) { |
566 |
if( explorerName == null ) { |
567 |
String msg = "Explorer name can't be null."; |
568 |
LOGGER.warn(msg); |
569 |
throw new IllegalArgumentException(msg); |
570 |
} |
571 |
try {
|
572 |
DataServerExplorer explorer = openServerExplorer(explorerName, (DataServerExplorerParameters)null);
|
573 |
List names = explorer.getDataStoreProviderNames();
|
574 |
return names;
|
575 |
} catch (Exception ex) { |
576 |
throw new RuntimeException("Can't get stores availables for explorer '" + explorerName + "'.", ex); |
577 |
} |
578 |
} |
579 |
|
580 |
@Override
|
581 |
public List<String> getExplorerProviders() { |
582 |
List<String> names = this.getServerExplorerRegister().getFactoryNames(); |
583 |
return names;
|
584 |
} |
585 |
|
586 |
@Override
|
587 |
public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
588 |
|
589 |
String providerName = parameters.getDataStoreName();
|
590 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
591 |
if (providerFactory == null) { |
592 |
throw new ProviderNotRegisteredException(providerName); |
593 |
} |
594 |
while (true) { |
595 |
try {
|
596 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create( |
597 |
parameters, providerServices |
598 |
); |
599 |
return provider;
|
600 |
} catch (Exception e) { |
601 |
if (openErrorHandler == null) { |
602 |
throw new InitializeException(providerName, e); |
603 |
} |
604 |
boolean retry = openErrorHandler.canRetryOpen(e, parameters);
|
605 |
if (!retry) {
|
606 |
throw new InitializeException(providerName, e); |
607 |
} |
608 |
} |
609 |
} |
610 |
} |
611 |
|
612 |
@Override
|
613 |
public List<String> getFeatureIndexProviders() { |
614 |
List<String> names = this.getFeatureIndexRegister().getFactoryNames(); |
615 |
return names;
|
616 |
} |
617 |
|
618 |
@Override
|
619 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
620 |
this.defaultDataIndexProviders.put(dataType, name);
|
621 |
} |
622 |
|
623 |
@Override
|
624 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
625 |
return this.defaultDataIndexProviders.get(dataType); |
626 |
} |
627 |
|
628 |
@Override
|
629 |
public FeatureIndexProviderServices createFeatureIndexProvider(
|
630 |
String name,
|
631 |
FeatureStore store, |
632 |
FeatureType type, |
633 |
String indexName,
|
634 |
FeatureAttributeDescriptor attr |
635 |
) throws InitializeException, ProviderNotRegisteredException {
|
636 |
|
637 |
if (name == null) { |
638 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
639 |
} |
640 |
|
641 |
if (name == null) { |
642 |
throw new InitializeException( |
643 |
"There not any index provider registered.", null); |
644 |
} |
645 |
DataFactory indexfactory = this.getFeatureIndexRegister().getFactory(name);
|
646 |
if (indexfactory == null) { |
647 |
throw new InitializeException( |
648 |
"There not any index provider registered with name '" + name + "'.", null); |
649 |
|
650 |
} |
651 |
FeatureIndexProvider provider = (FeatureIndexProvider) indexfactory.create(null, null); |
652 |
|
653 |
FeatureIndexProviderServices services = new DefaultFeatureIndex(
|
654 |
(FeatureStoreProviderServices) store, |
655 |
type, |
656 |
provider, |
657 |
attr.getName(), |
658 |
indexName |
659 |
); |
660 |
services.initialize(); |
661 |
return services;
|
662 |
|
663 |
} |
664 |
|
665 |
@Override
|
666 |
public String getTemporaryDirectory() { |
667 |
FoldersManager manager = ToolsLocator.getFoldersManager(); |
668 |
File folder = manager.getUniqueTemporaryFile("_daltmp_"); |
669 |
return folder.getAbsolutePath();
|
670 |
} |
671 |
|
672 |
@Override
|
673 |
public DataStoreParameters createStoreParameters(DynStruct struct) throws InitializeException, ProviderNotRegisteredException { |
674 |
if (!(struct instanceof DynStruct_v2)) { |
675 |
throw new IllegalArgumentException("A DynStruct_v2 is required."); |
676 |
} |
677 |
Tags tags = ((DynStruct_v2) struct).getTags(); |
678 |
return this.createStoreParameters(tags); |
679 |
} |
680 |
|
681 |
@Override
|
682 |
public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException { |
683 |
String providerName = (String) tags.get(TAG_DAL_OPENSTORE + "provider"); |
684 |
if (providerName == null) { |
685 |
throw new IllegalArgumentException("Tag DAL.OpenStore.provider is missing in struct."); |
686 |
} |
687 |
int prefixlen = TAG_DAL_OPENSTORE.length();
|
688 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
689 |
for (String key : tags) { |
690 |
if (key.startsWith(TAG_DAL_OPENSTORE)) {
|
691 |
parameters.setDynValue(key.substring(prefixlen), tags.get(key)); |
692 |
} |
693 |
} |
694 |
return parameters;
|
695 |
} |
696 |
|
697 |
@Override
|
698 |
public DataStore openStore(DynStruct struct) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
699 |
DataStoreParameters paramters = this.createStoreParameters(struct);
|
700 |
DataStore store = this.openStore(paramters.getDataStoreName(), paramters);
|
701 |
return store;
|
702 |
} |
703 |
|
704 |
@Override
|
705 |
public void newStore(String explorerName, String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
706 |
if( explorerName == null ) { |
707 |
String msg = "Explorer name can't be null."; |
708 |
LOGGER.warn(msg); |
709 |
throw new IllegalArgumentException(msg); |
710 |
} |
711 |
if( providerName == null ) { |
712 |
String msg = "Provider name can't be null."; |
713 |
LOGGER.warn(msg); |
714 |
throw new IllegalArgumentException(msg); |
715 |
} |
716 |
|
717 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
718 |
if (!identityManager.getCurrentIdentity().isAuthorized(CREATE_STORE_AUTHORIZATION, parameters, providerName)) {
|
719 |
throw new UnauthorizedException(CREATE_STORE_AUTHORIZATION, parameters, providerName); |
720 |
} |
721 |
parameters.validate(); |
722 |
try {
|
723 |
DataServerExplorerParameters explorerParameters = this.createServerExplorerParameters(explorerName);
|
724 |
DataServerExplorer server = this.openServerExplorer(explorerName, explorerParameters);
|
725 |
server.add(providerName, parameters, overwrite); |
726 |
} catch (Exception e) { |
727 |
throw new InitializeException(e); |
728 |
} |
729 |
} |
730 |
|
731 |
@Override
|
732 |
@Deprecated
|
733 |
public Evaluator createExpresion(String expression) throws InitializeException { |
734 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
735 |
exp.setPhrase(expression); |
736 |
return this.createExpresion(exp); |
737 |
} |
738 |
|
739 |
@Override
|
740 |
@Deprecated
|
741 |
public Evaluator createExpresion(Expression expression) throws InitializeException { |
742 |
DefaultExpressionEvaluator exp = new DefaultExpressionEvaluator(expression);
|
743 |
return exp;
|
744 |
} |
745 |
|
746 |
|
747 |
@Override
|
748 |
public Evaluator createFilter(String expression) throws InitializeException { |
749 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
750 |
exp.setPhrase(expression); |
751 |
return this.createFilter(exp); |
752 |
} |
753 |
|
754 |
@Override
|
755 |
public Evaluator createFilter(Expression expression) throws InitializeException { |
756 |
DefaultExpressionEvaluator exp = new DefaultExpressionEvaluator(expression);
|
757 |
return exp;
|
758 |
} |
759 |
|
760 |
@Override
|
761 |
public FeaturePagingHelper createFeaturePagingHelper(
|
762 |
FeatureStore featureStore, int pageSize) throws BaseException { |
763 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
764 |
} |
765 |
|
766 |
@Override
|
767 |
public FeaturePagingHelper createFeaturePagingHelper(
|
768 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
769 |
throws BaseException {
|
770 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
771 |
} |
772 |
|
773 |
@Override
|
774 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
775 |
openErrorHandler = handler; |
776 |
} |
777 |
|
778 |
@Override
|
779 |
public OpenErrorHandler getOpenErrorHandler() {
|
780 |
return this.openErrorHandler; |
781 |
} |
782 |
|
783 |
@Override
|
784 |
public EditableFeatureType createFeatureType() {
|
785 |
return new DefaultEditableFeatureType(null); |
786 |
} |
787 |
|
788 |
@Override
|
789 |
public DataServerExplorerPool getDataServerExplorerPool() {
|
790 |
if (this.dataServerExplorerPool == null) { |
791 |
this.dataServerExplorerPool = new DefaultDataServerExplorerPool(); |
792 |
} |
793 |
return this.dataServerExplorerPool; |
794 |
} |
795 |
|
796 |
@Override
|
797 |
public void setDataServerExplorerPool(DataServerExplorerPool pool) { |
798 |
this.dataServerExplorerPool = pool;
|
799 |
} |
800 |
|
801 |
public DataStoreParameters toDataStoreParameters(String provider, DynObject params) throws InitializeException, ProviderNotRegisteredException { |
802 |
if (params instanceof DataStoreParameters) { |
803 |
return (DataStoreParameters) params;
|
804 |
} |
805 |
String providerName;
|
806 |
try {
|
807 |
providerName = (String) params.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
|
808 |
} catch (Exception ex) { |
809 |
providerName = provider; |
810 |
} |
811 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
812 |
ToolsLocator.getDynObjectManager().copy(params, parameters); |
813 |
return parameters;
|
814 |
} |
815 |
|
816 |
@Override
|
817 |
public List<DataType> getDataTypes() { |
818 |
if (dataTypes == null) { |
819 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
820 |
dataTypes = new ArrayList<>(); |
821 |
dataTypes.add(manager.get(DataTypes.STRING)); |
822 |
dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
823 |
dataTypes.add(manager.get(DataTypes.INT)); |
824 |
dataTypes.add(manager.get(DataTypes.DOUBLE)); |
825 |
dataTypes.add(manager.get(DataTypes.DATE)); |
826 |
dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
827 |
} |
828 |
return dataTypes;
|
829 |
} |
830 |
|
831 |
@Override
|
832 |
public void setResourcesLoader(ClassLoader loader) { |
833 |
this.resourcesLoader = loader;
|
834 |
} |
835 |
|
836 |
@Override
|
837 |
public void setResourcesLoader(File folder) { |
838 |
if (folder == null) { |
839 |
this.resourcesLoader = null; |
840 |
return;
|
841 |
} |
842 |
try {
|
843 |
URL[] urls = new URL[]{folder.toURI().toURL()}; |
844 |
this.resourcesLoader = new URLClassLoader(urls); |
845 |
} catch (Exception ex) { |
846 |
throw new IllegalArgumentException("Can't create a ClassLoader from '" + folder.toString() + "'.", ex); |
847 |
} |
848 |
} |
849 |
|
850 |
@Override
|
851 |
public URL getResource(Object reourceLoader, String name) { |
852 |
URL x;
|
853 |
if (this.resourcesLoader != null) { |
854 |
x = this.resourcesLoader.getResource(name);
|
855 |
if (x != null) { |
856 |
return x;
|
857 |
} |
858 |
} |
859 |
x = reourceLoader.getClass().getResource(name); |
860 |
return x;
|
861 |
} |
862 |
|
863 |
@Override
|
864 |
public InputStream getResourceAsStream(Object reourceLoader, String name) { |
865 |
InputStream x;
|
866 |
if (this.resourcesLoader != null) { |
867 |
x = this.resourcesLoader.getResourceAsStream(name);
|
868 |
if (x != null) { |
869 |
return x;
|
870 |
} |
871 |
} |
872 |
x = reourceLoader.getClass().getResourceAsStream(name); |
873 |
return x;
|
874 |
} |
875 |
|
876 |
@Override
|
877 |
public ExpressionBuilder createExpressionBuilder() {
|
878 |
return ExpressionEvaluatorLocator.getManager().createExpressionBuilder();
|
879 |
} |
880 |
|
881 |
public void registerFeatureCacheProvider( |
882 |
FeatureCacheProviderFactory providerFactory) { |
883 |
ToolsLocator.getExtensionPointManager() |
884 |
.add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
885 |
.append(providerFactory.getName(), "", providerFactory);
|
886 |
} |
887 |
|
888 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
889 |
DynObject parameters) throws DataException {
|
890 |
if (name == null) { |
891 |
throw new InitializeException( |
892 |
"It is necessary to provide a cache name", null); |
893 |
} |
894 |
if (parameters == null) { |
895 |
throw new InitializeException( |
896 |
"It is necessary to provide parameters to create the explorer",
|
897 |
null);
|
898 |
} |
899 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
900 |
try {
|
901 |
featureCacheProviderFactory = |
902 |
(FeatureCacheProviderFactory) ToolsLocator |
903 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
904 |
.create(name); |
905 |
if (featureCacheProviderFactory == null) { |
906 |
throw new ProviderNotRegisteredException(name); |
907 |
} |
908 |
return featureCacheProviderFactory.createCacheProvider(parameters);
|
909 |
} catch (InstantiationException e) { |
910 |
throw new InitializeException(e); |
911 |
} catch (IllegalAccessException e) { |
912 |
throw new InitializeException(e); |
913 |
} |
914 |
} |
915 |
|
916 |
@Override
|
917 |
public List getFeatureCacheProviders() { |
918 |
ExtensionPoint extensionPoint = |
919 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
920 |
if (extensionPoint != null) { |
921 |
return ToolsLocator.getExtensionPointManager()
|
922 |
.get(DATA_MANAGER_CACHE).getNames(); |
923 |
} else {
|
924 |
return new ArrayList(); |
925 |
} |
926 |
} |
927 |
|
928 |
@Override
|
929 |
public DynObject createCacheParameters(String name) |
930 |
throws InitializeException, ProviderNotRegisteredException {
|
931 |
if (name == null) { |
932 |
throw new InitializeException( |
933 |
"It is necessary to provide a cache name", null); |
934 |
} |
935 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
936 |
try {
|
937 |
featureCacheProviderFactory = |
938 |
(FeatureCacheProviderFactory) ToolsLocator |
939 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
940 |
.create(name); |
941 |
if (featureCacheProviderFactory == null) { |
942 |
throw new ProviderNotRegisteredException(name); |
943 |
} |
944 |
return featureCacheProviderFactory.createParameters();
|
945 |
} catch (InstantiationException e) { |
946 |
throw new InitializeException(e); |
947 |
} catch (IllegalAccessException e) { |
948 |
throw new InitializeException(e); |
949 |
} |
950 |
} |
951 |
|
952 |
@Override
|
953 |
public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException { |
954 |
DataManagerProviderServices dataManager = DALSPILocator.getDataManagerProviderServices(); |
955 |
DataServerExplorerParameters eparams = null;
|
956 |
DataServerExplorer serverExplorer; |
957 |
try {
|
958 |
serverExplorer = dataManager.openServerExplorer(FILESYSTEM_EXPLORER_NAME, eparams); |
959 |
} catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
960 |
throw new OpenException(FILESYSTEM_EXPLORER_NAME, e); |
961 |
} |
962 |
|
963 |
try {
|
964 |
serverExplorer.add(providerName, params, overwrite); |
965 |
} catch (DataException e) {
|
966 |
throw new CreateFileStoreException(e, providerName); |
967 |
} |
968 |
} |
969 |
|
970 |
@Override
|
971 |
public FeatureSymbolTable createFeatureSymbolTable() {
|
972 |
FeatureSymbolTable symbolTable = new DefaultFeatureSymbolTable();
|
973 |
return symbolTable;
|
974 |
} |
975 |
|
976 |
@Override
|
977 |
public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression) { |
978 |
FeatureAttributeEmulatorExpression emulator = new DefaultFeatureAttributeEmulatorExpression(type, expression);
|
979 |
return emulator;
|
980 |
} |
981 |
|
982 |
@Override
|
983 |
public void registerDataProfile(DataProfile profile) { |
984 |
if( profile==null ) { |
985 |
return;
|
986 |
} |
987 |
if( this.dataProfiles==null ) { |
988 |
this.dataProfiles = new ArrayList<>(); |
989 |
this.dataProfiles.add(profile);
|
990 |
return;
|
991 |
} |
992 |
for (DataProfile theProfile : this.dataProfiles) { |
993 |
if( theProfile.getID().equalsIgnoreCase(profile.getID()) ) {
|
994 |
return;
|
995 |
} |
996 |
} |
997 |
this.dataProfiles.add(profile);
|
998 |
} |
999 |
|
1000 |
@Override
|
1001 |
public List<DataProfile> getDataProfiles() { |
1002 |
if( this.dataProfiles==null ) { |
1003 |
return null; |
1004 |
} |
1005 |
return Collections.unmodifiableList(this.dataProfiles); |
1006 |
} |
1007 |
|
1008 |
@Override
|
1009 |
public DataProfile getDataProfile(String name) { |
1010 |
if( StringUtils.isBlank(name) ) {
|
1011 |
return null; |
1012 |
} |
1013 |
for (DataProfile theProfile : this.dataProfiles) { |
1014 |
if( name.equalsIgnoreCase(theProfile.getName()) ) {
|
1015 |
return theProfile;
|
1016 |
} |
1017 |
} |
1018 |
return null; |
1019 |
} |
1020 |
|
1021 |
private StoresRepository storesRepository;
|
1022 |
|
1023 |
@Override
|
1024 |
public StoresRepository getStoresRepository() {
|
1025 |
if( this.storesRepository==null ) { |
1026 |
this.storesRepository = new BaseStoresRepository("DAL"); |
1027 |
} |
1028 |
return this.storesRepository; |
1029 |
} |
1030 |
|
1031 |
@Override
|
1032 |
public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection) {
|
1033 |
DatabaseWorkspaceManager workspace = new DefaultDatabaseWorkspaceManager(connection);
|
1034 |
return workspace;
|
1035 |
} |
1036 |
|
1037 |
@Override
|
1038 |
public void addDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1039 |
this.databaseWorkspaces.put(databaseWorkspace.getId(),databaseWorkspace);
|
1040 |
StoresRepository repo = databaseWorkspace.getStoresRepository(); |
1041 |
this.getStoresRepository().addRepository(repo);
|
1042 |
} |
1043 |
|
1044 |
@Override
|
1045 |
public DatabaseWorkspaceManager getDatabaseWorkspace(String name) { |
1046 |
return this.databaseWorkspaces.get(name); |
1047 |
} |
1048 |
|
1049 |
@Override
|
1050 |
public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params) {
|
1051 |
for (DatabaseWorkspaceManager databaseWorkspace : this.databaseWorkspaces.values()) { |
1052 |
if( databaseWorkspace.getStoresRepository().contains(params) ) {
|
1053 |
return databaseWorkspace;
|
1054 |
} |
1055 |
} |
1056 |
return null; |
1057 |
} |
1058 |
|
1059 |
@Override
|
1060 |
public void writeDALResource(ResourcesStorage resources, DataStore store) { |
1061 |
ResourcesStorage.Resource resource = null;
|
1062 |
try {
|
1063 |
if( resources == null || resources.isReadOnly() ) { |
1064 |
return;
|
1065 |
} |
1066 |
resource = resources.getResource("dal");
|
1067 |
if( resource == null || resource.isReadOnly() ) { |
1068 |
return;
|
1069 |
} |
1070 |
DALFile dalFile = DALFile.getDALFile(); |
1071 |
dalFile.setStore((DefaultFeatureStore) store); |
1072 |
if( !dalFile.isEmpty() ) {
|
1073 |
dalFile.write(resource); |
1074 |
} |
1075 |
} catch (Throwable ex) { |
1076 |
LOGGER.warn("Can't save DAL resource", ex);
|
1077 |
} finally {
|
1078 |
IOUtils.closeQuietly(resource); |
1079 |
} |
1080 |
|
1081 |
|
1082 |
} |
1083 |
|
1084 |
@Override
|
1085 |
public void writeDALResource(ResourcesStorage resources, FeatureType featureType) { |
1086 |
ResourcesStorage.Resource resource = null;
|
1087 |
try {
|
1088 |
if( resources == null || resources.isReadOnly() ) { |
1089 |
return;
|
1090 |
} |
1091 |
resource = resources.getResource("dal");
|
1092 |
if( resource == null || resource.isReadOnly() ) { |
1093 |
return;
|
1094 |
} |
1095 |
DALFile dalFile = DALFile.getDALFile(); |
1096 |
dalFile.setFeatureType(featureType); |
1097 |
if( !dalFile.isEmpty() ) {
|
1098 |
dalFile.write(resource); |
1099 |
} |
1100 |
} catch (Throwable ex) { |
1101 |
LOGGER.warn("Can't save DAL resource", ex);
|
1102 |
} finally {
|
1103 |
IOUtils.closeQuietly(resource); |
1104 |
} |
1105 |
} |
1106 |
} |