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
History | View | Annotate | Download (64.3 KB)
1 | 43020 | jjdelcerro | package org.gvsig.fmap.dal.impl; |
---|---|---|---|
2 | |||
3 | 47080 | jjdelcerro | import java.io.ByteArrayOutputStream; |
4 | 43020 | jjdelcerro | 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 | 44128 | jjdelcerro | import java.util.Collections; |
10 | 43020 | jjdelcerro | import java.util.HashMap; |
11 | 44871 | jjdelcerro | import java.util.HashSet; |
12 | 43020 | jjdelcerro | import java.util.List; |
13 | 47209 | jjdelcerro | import java.util.Locale; |
14 | 43020 | jjdelcerro | import java.util.Map; |
15 | 44871 | jjdelcerro | import java.util.Set; |
16 | 44409 | jjdelcerro | import java.util.UUID; |
17 | 45696 | jjdelcerro | import java.util.function.Predicate; |
18 | 47606 | fdiaz | import java.util.logging.Level; |
19 | 45696 | jjdelcerro | import javax.json.JsonArray; |
20 | 45043 | jjdelcerro | import javax.json.JsonObject; |
21 | 45696 | jjdelcerro | import javax.json.JsonValue; |
22 | 47880 | jjdelcerro | import org.apache.commons.codec.digest.DigestUtils; |
23 | 46805 | jjdelcerro | import org.apache.commons.io.FileUtils; |
24 | 44328 | jjdelcerro | import org.apache.commons.io.IOUtils; |
25 | 43450 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
26 | 43984 | jjdelcerro | import org.gvsig.expressionevaluator.Expression; |
27 | 44042 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
28 | 44023 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
29 | 44750 | jjdelcerro | import org.gvsig.expressionevaluator.impl.DefaultDALExpressionBuilder; |
30 | 45739 | jjdelcerro | import org.gvsig.expressionevaluator.impl.DefaultFeatureRuleExpression; |
31 | 44738 | jjdelcerro | import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
32 | 44304 | jjdelcerro | import org.gvsig.fmap.dal.BaseStoresRepository; |
33 | 47880 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
34 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.DataFactory; |
35 | import org.gvsig.fmap.dal.DataManager; |
||
36 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
37 | import org.gvsig.fmap.dal.DataServerExplorerFactory; |
||
38 | import org.gvsig.fmap.dal.DataServerExplorerParameters; |
||
39 | import org.gvsig.fmap.dal.DataServerExplorerPool; |
||
40 | import org.gvsig.fmap.dal.DataStore; |
||
41 | import org.gvsig.fmap.dal.DataStoreFactory_v2_4; |
||
42 | 44871 | jjdelcerro | import org.gvsig.fmap.dal.DataStoreNotification; |
43 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.DataStoreParameters; |
44 | import org.gvsig.fmap.dal.DataStoreProviderFactory; |
||
45 | 45445 | jjdelcerro | import org.gvsig.fmap.dal.DataTransaction; |
46 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
47 | 44304 | jjdelcerro | import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
48 | 45426 | fdiaz | import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
49 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.NewDataStoreParameters; |
50 | import org.gvsig.fmap.dal.OpenErrorHandler; |
||
51 | import org.gvsig.fmap.dal.Register; |
||
52 | 44253 | jjdelcerro | import org.gvsig.fmap.dal.StoresRepository; |
53 | 45426 | fdiaz | import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
54 | 43056 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
55 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.exception.InitializeException; |
56 | 43205 | fdiaz | import org.gvsig.fmap.dal.exception.OpenException; |
57 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
58 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
59 | 44750 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
60 | 43989 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
61 | 43983 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
62 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.DataProfile; |
63 | 47209 | jjdelcerro | import org.gvsig.fmap.dal.feature.DataTypeDetector; |
64 | 45696 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeature; |
65 | 44753 | omartinez | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
66 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
67 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
68 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
69 | 45739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureRuleExpression; |
70 | 45696 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureSet; |
71 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
72 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
73 | 46996 | jjdelcerro | import org.gvsig.fmap.dal.feature.LabelsCacheForFieldValues; |
74 | 46012 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.UnsupportedDataTypeException; |
75 | 44328 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.DALFile; |
76 | 47209 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.DataTypeDetectorImpl; |
77 | 44753 | omartinez | import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureAttributeDescriptor; |
78 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
79 | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
||
80 | 44328 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
81 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
82 | 46996 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.LabelsCacheForFieldValuesImpl; |
83 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
84 | import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
||
85 | import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
||
86 | import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
||
87 | 47606 | fdiaz | import org.gvsig.fmap.dal.feature.spi.LocalTransaction; |
88 | 43056 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
89 | import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
||
90 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
91 | import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
||
92 | 45426 | fdiaz | import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
93 | 45366 | omartinez | import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureExpressionEvaluator; |
94 | 43205 | fdiaz | import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
95 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
96 | import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
||
97 | 44816 | jjdelcerro | import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
98 | 43205 | fdiaz | import org.gvsig.fmap.dal.spi.DALSPILocator; |
99 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
100 | 45426 | fdiaz | import org.gvsig.fmap.dal.spi.DataServerExplorerPoolImpl; |
101 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.spi.DataStoreProvider; |
102 | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
||
103 | 45426 | fdiaz | import static org.gvsig.fmap.dal.spi.DataStoreProviderServices.PROVIDER_PARAMTER_NAME; |
104 | 47880 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
105 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
106 | import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
||
107 | 45426 | fdiaz | import org.gvsig.json.Json; |
108 | 43020 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
109 | import org.gvsig.tools.dataTypes.DataType; |
||
110 | import org.gvsig.tools.dataTypes.DataTypesManager; |
||
111 | import org.gvsig.tools.dynobject.DynObject; |
||
112 | import org.gvsig.tools.dynobject.DynStruct; |
||
113 | import org.gvsig.tools.dynobject.DynStruct_v2; |
||
114 | import org.gvsig.tools.dynobject.Tags; |
||
115 | import org.gvsig.tools.evaluator.Evaluator; |
||
116 | import org.gvsig.tools.exception.BaseException; |
||
117 | 43056 | jjdelcerro | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
118 | 43241 | jjdelcerro | import org.gvsig.tools.folders.FoldersManager; |
119 | 43020 | jjdelcerro | import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
120 | import org.gvsig.tools.identitymanagement.UnauthorizedException; |
||
121 | 45426 | fdiaz | import org.gvsig.tools.observer.Observer; |
122 | 47080 | jjdelcerro | import org.gvsig.tools.resourcesstorage.BytesResource; |
123 | 44328 | jjdelcerro | import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
124 | 44419 | jjdelcerro | import org.gvsig.tools.script.Script; |
125 | import org.gvsig.tools.script.ScriptManager; |
||
126 | 43020 | jjdelcerro | import org.gvsig.tools.service.spi.Services; |
127 | 45696 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
128 | 46996 | jjdelcerro | import org.gvsig.tools.task.SimpleTaskStatus; |
129 | 45461 | jjdelcerro | import org.gvsig.tools.util.Factory; |
130 | 46996 | jjdelcerro | import org.gvsig.tools.util.Invocable; |
131 | 47138 | jjdelcerro | import org.gvsig.tools.util.PropertiesSupportHelper; |
132 | 43450 | jjdelcerro | import org.slf4j.Logger; |
133 | import org.slf4j.LoggerFactory; |
||
134 | 43020 | jjdelcerro | |
135 | 44304 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
136 | 43020 | jjdelcerro | public class DefaultDataManager |
137 | implements DataManager, DataManagerProviderServices, Services {
|
||
138 | 43205 | fdiaz | |
139 | 44023 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataManager.class); |
140 | 43450 | jjdelcerro | |
141 | 43056 | jjdelcerro | final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
142 | final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
||
143 | "DAL cache providers";
|
||
144 | 43205 | fdiaz | |
145 | public static final String FILESYSTEM_EXPLORER_NAME = "FilesystemExplorer"; |
||
146 | 45426 | fdiaz | |
147 | 45467 | fdiaz | public static final long DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION = 2000000000; |
148 | 45772 | omartinez | |
149 | 43020 | jjdelcerro | private class Registers { |
150 | |||
151 | private final Register store; |
||
152 | private final Register storeProvider; |
||
153 | private final Register serverExplorer; |
||
154 | private final Register featureIndexProvider; |
||
155 | |||
156 | public Registers() {
|
||
157 | this.store = new RegisterImpl( |
||
158 | "Data.manager.stores.factory",
|
||
159 | "DAL store factories"
|
||
160 | ); |
||
161 | this.storeProvider = new RegisterImpl( |
||
162 | "Data.manager.providers.factory",
|
||
163 | "DAL store provider factories"
|
||
164 | ); |
||
165 | this.serverExplorer = new RegisterImpl( |
||
166 | "Data.manager.servereexplorer.factory",
|
||
167 | "DAL server explorer factories"
|
||
168 | ); |
||
169 | this.featureIndexProvider = new RegisterImpl( |
||
170 | "Data.manager.feature.index.factory",
|
||
171 | "DAL feature index factories"
|
||
172 | ); |
||
173 | |||
174 | this.store.register(new FeatureStoreFactory()); |
||
175 | } |
||
176 | } |
||
177 | private static final String TAG_DAL_OPENSTORE = "dal.openstore."; |
||
178 | |||
179 | private final Registers registers; |
||
180 | |||
181 | private final Map<Integer, String> defaultDataIndexProviders; |
||
182 | |||
183 | private OpenErrorHandler openErrorHandler = null; |
||
184 | |||
185 | private DataServerExplorerPool dataServerExplorerPool = null; |
||
186 | |||
187 | private List<DataType> dataTypes = null; |
||
188 | |||
189 | private ClassLoader resourcesLoader = null; |
||
190 | |||
191 | 46419 | fdiaz | private Map<String,DataProfile> dataProfiles; |
192 | 44128 | jjdelcerro | |
193 | 44346 | jjdelcerro | private final Map<String, DatabaseWorkspaceManager> databaseWorkspaces = new HashMap<>(); |
194 | 44419 | jjdelcerro | |
195 | 44821 | jjdelcerro | private final Map<String,DatabaseWorkspaceListener> addDatabaseWorkspaceListeners = new HashMap<>(); |
196 | 44871 | jjdelcerro | |
197 | private final Set<Observer>storeObservers = new HashSet<>(); |
||
198 | 44346 | jjdelcerro | |
199 | 45426 | fdiaz | private long maxSizeForSmallFeatureSelection; |
200 | 45461 | jjdelcerro | |
201 | private Factory largeMapFactory;
|
||
202 | private Factory largeSetFactory;
|
||
203 | 45426 | fdiaz | |
204 | 43020 | jjdelcerro | public DefaultDataManager() {
|
205 | this.registers = new Registers(); |
||
206 | this.defaultDataIndexProviders = new HashMap<>(); |
||
207 | 45426 | fdiaz | this.maxSizeForSmallFeatureSelection = DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION;
|
208 | 45461 | jjdelcerro | this.largeMapFactory = new Factory() { |
209 | @Override
|
||
210 | public String getName() { |
||
211 | return "HashMapFactory"; |
||
212 | } |
||
213 | |||
214 | @Override
|
||
215 | public Object create(Object... parameters) { |
||
216 | return new HashMap(); |
||
217 | } |
||
218 | }; |
||
219 | this.largeSetFactory = new Factory() { |
||
220 | @Override
|
||
221 | public String getName() { |
||
222 | return "HashSetFactory"; |
||
223 | } |
||
224 | |||
225 | @Override
|
||
226 | public Object create(Object... parameters) { |
||
227 | return new HashSet(); |
||
228 | } |
||
229 | }; |
||
230 | 43020 | jjdelcerro | } |
231 | |||
232 | @Override
|
||
233 | public Register getStoreRegister() {
|
||
234 | return this.registers.store; |
||
235 | } |
||
236 | |||
237 | @Override
|
||
238 | public Register getStoreProviderRegister() {
|
||
239 | return this.registers.storeProvider; |
||
240 | } |
||
241 | |||
242 | @Override
|
||
243 | public Register getServerExplorerRegister() {
|
||
244 | return this.registers.serverExplorer; |
||
245 | } |
||
246 | |||
247 | @Override
|
||
248 | public Register getFeatureIndexRegister() {
|
||
249 | return this.registers.featureIndexProvider; |
||
250 | } |
||
251 | |||
252 | private String getStoreName(DataStoreParameters parameters) { |
||
253 | for (DataFactory factory : this.getStoreRegister()) { |
||
254 | DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) factory; |
||
255 | if (storeFactory.canUse(parameters)) {
|
||
256 | return storeFactory.getName();
|
||
257 | } |
||
258 | } |
||
259 | return null; |
||
260 | } |
||
261 | |||
262 | /**
|
||
263 | * @deprecated
|
||
264 | */
|
||
265 | @Override
|
||
266 | public void registerDefaultRasterStore(Class rasterStoreClass) { |
||
267 | // Metodo usado por el raster nuevo para regstrar su factoria de store
|
||
268 | this.getStoreRegister().register(new RasterStoreFactory(rasterStoreClass)); |
||
269 | } |
||
270 | |||
271 | 44831 | jjdelcerro | |
272 | private boolean oldRasterRegistered = false; |
||
273 | 43020 | jjdelcerro | /**
|
274 | * @deprecated
|
||
275 | */
|
||
276 | @Override
|
||
277 | public void registerStoreFactory(String name, Class storeFactoryClass) { |
||
278 | // Metodo usado por el raster viejo para registrar las factorias de sus stores
|
||
279 | this.getStoreRegister().register(new RasterStoreOldFactory(name, storeFactoryClass)); |
||
280 | 44831 | jjdelcerro | this.oldRasterRegistered = true; |
281 | 43020 | jjdelcerro | } |
282 | |||
283 | 44831 | jjdelcerro | @Override
|
284 | public boolean isTheOldRasterRegistered() { |
||
285 | return this.oldRasterRegistered; |
||
286 | } |
||
287 | |||
288 | 43020 | jjdelcerro | /**
|
289 | * @param name
|
||
290 | * @param storeProviderClass
|
||
291 | * @param parametersClass
|
||
292 | * @deprecated use registerStoreProviderFactory
|
||
293 | */
|
||
294 | @Override
|
||
295 | public void registerStoreProvider(String name, Class storeProviderClass, |
||
296 | Class parametersClass) {
|
||
297 | if (name == null || storeProviderClass == null || parametersClass == null) { |
||
298 | throw new IllegalArgumentException("Any parameters can be null"); |
||
299 | } |
||
300 | |||
301 | if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
||
302 | throw new IllegalArgumentException(parametersClass.getName() |
||
303 | + " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
||
304 | } |
||
305 | |||
306 | if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
||
307 | // Envuelve al proveedor en una factoria por defecto.
|
||
308 | this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
||
309 | name, "", storeProviderClass, parametersClass));
|
||
310 | return;
|
||
311 | } |
||
312 | |||
313 | if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
||
314 | // Envuelve al proveedor en una factoria por defecto.
|
||
315 | this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
||
316 | name, "", storeProviderClass, parametersClass));
|
||
317 | return;
|
||
318 | } |
||
319 | |||
320 | throw new IllegalArgumentException("Not supported implemtation: name=" |
||
321 | + name + " provider class=" + storeProviderClass.getName());
|
||
322 | |||
323 | } |
||
324 | |||
325 | @Override
|
||
326 | public void registerExplorerProvider(String name, Class explorerClass, Class parametersClass) { |
||
327 | if (name == null || explorerClass == null || parametersClass == null) { |
||
328 | // FIXME Exception
|
||
329 | throw new IllegalArgumentException("Any parameters can be null"); |
||
330 | } |
||
331 | |||
332 | if (!DataServerExplorerParameters.class
|
||
333 | .isAssignableFrom(parametersClass)) { |
||
334 | // FIXME Exception
|
||
335 | throw new IllegalArgumentException( |
||
336 | parametersClass.getName() |
||
337 | + " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
||
338 | } |
||
339 | |||
340 | if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
||
341 | // FIXME Exception
|
||
342 | throw new IllegalArgumentException(explorerClass.getName() |
||
343 | + " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
||
344 | } |
||
345 | |||
346 | // Envuelve al proveedor en una factoria por defecto.
|
||
347 | this.registerServerExplorerFactory(
|
||
348 | new DataServerExplorerToDataExplorerFactoryWrapper(
|
||
349 | name, "", explorerClass, parametersClass
|
||
350 | ) |
||
351 | ); |
||
352 | |||
353 | } |
||
354 | |||
355 | @Override
|
||
356 | public void registerStoreFactory(DataStoreFactory_v2_4 factory) { |
||
357 | this.getStoreRegister().register(factory);
|
||
358 | } |
||
359 | |||
360 | @Override
|
||
361 | public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
||
362 | this.getStoreProviderRegister().register(factory);
|
||
363 | } |
||
364 | |||
365 | @Override
|
||
366 | public void registerServerExplorerFactory(DataServerExplorerFactory factory) { |
||
367 | this.getServerExplorerRegister().register(factory);
|
||
368 | } |
||
369 | |||
370 | @Override
|
||
371 | 44304 | jjdelcerro | public DataStoreParameters createStoreParameters(byte[] data) { |
372 | 44816 | jjdelcerro | DataStoreParameters parameters = (DataStoreParameters) AbstractDataParameters.fromByteArray(data); |
373 | return parameters;
|
||
374 | 44304 | jjdelcerro | } |
375 | |||
376 | 44743 | jjdelcerro | public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
377 | // Cuando desde python se llama a createStoreParameters con solo un argumento
|
||
378 | // acaba entrando por aqui en lugar de por
|
||
379 | // createStoreParameters(String providerName, Object... arguments)
|
||
380 | return this.createStoreParameters(providerName, (Object[]) null); |
||
381 | } |
||
382 | |||
383 | 44304 | jjdelcerro | @Override
|
384 | 44738 | jjdelcerro | public DataStoreParameters createStoreParameters(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException { |
385 | 43503 | jjdelcerro | if( providerName == null ) { |
386 | String msg = "Provider name can't be null."; |
||
387 | 44023 | jjdelcerro | LOGGER.warn(msg); |
388 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
389 | } |
||
390 | 44743 | jjdelcerro | if( arguments!=null && arguments.length>0 ) { |
391 | if( arguments.length == 1 ) { |
||
392 | // Desde jython entra por este metodo en lugar de los especificos
|
||
393 | // de DataStoreParameters o DynObject
|
||
394 | if( arguments[0] instanceof DataStoreParameters ) { |
||
395 | return this.createStoreParameters(providerName, (DataStoreParameters)(arguments[0])); |
||
396 | } else if( arguments[0] instanceof DynObject ) { |
||
397 | return this.createStoreParameters(providerName, (DynObject)(arguments[0])); |
||
398 | } |
||
399 | } |
||
400 | if( (arguments.length % 2)!= 0 ) { |
||
401 | throw new IllegalArgumentException("The number of arguments must be even."); |
||
402 | } |
||
403 | 44738 | jjdelcerro | } |
404 | if( providerName == null ) { |
||
405 | String msg = "Provider name can't be null."; |
||
406 | LOGGER.warn(msg); |
||
407 | throw new IllegalArgumentException(msg); |
||
408 | } |
||
409 | 43020 | jjdelcerro | DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
410 | 43503 | jjdelcerro | if( providerFactory == null ) { |
411 | String msg = "Can't locate provider factory for '"+providerName+"'."; |
||
412 | 44023 | jjdelcerro | LOGGER.warn(msg); |
413 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
414 | } |
||
415 | 44738 | jjdelcerro | DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
416 | 44743 | jjdelcerro | if( arguments!=null && arguments.length>0 ) { |
417 | for( int i=0; i<arguments.length; i+=2 ) { |
||
418 | String name = (String) arguments[i]; |
||
419 | if( name.endsWith("=") ) { |
||
420 | name = name.substring(0, name.length()-1); |
||
421 | } |
||
422 | Object value = arguments[i+1]; |
||
423 | parameters.setDynValue(name, value); |
||
424 | } |
||
425 | 44738 | jjdelcerro | } |
426 | return parameters;
|
||
427 | 43020 | jjdelcerro | } |
428 | |||
429 | @Override
|
||
430 | 45043 | jjdelcerro | public NewDataStoreParameters createNewStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
431 | String explorerName = this.getServerExplorerFromStore(providerName); |
||
432 | return createNewStoreParameters(explorerName, providerName);
|
||
433 | } |
||
434 | |||
435 | @Override
|
||
436 | 43020 | jjdelcerro | public NewDataStoreParameters createNewStoreParameters(String explorerName, String providerName) throws InitializeException, ProviderNotRegisteredException { |
437 | try {
|
||
438 | 43093 | jjdelcerro | DataServerExplorer explorer = this.openServerExplorer(explorerName, (DataServerExplorerParameters)null); |
439 | 43020 | jjdelcerro | return explorer.getAddParameters(providerName);
|
440 | } catch (Exception ex) { |
||
441 | throw new InitializeException(ex); |
||
442 | } |
||
443 | } |
||
444 | |||
445 | @Override
|
||
446 | public DataServerExplorerParameters createServerExplorerParameters(String explorerName) throws InitializeException, ProviderNotRegisteredException { |
||
447 | 43503 | jjdelcerro | if( explorerName == null ) { |
448 | String msg = "Explorer name can't be null."; |
||
449 | 44023 | jjdelcerro | LOGGER.warn(msg); |
450 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
451 | } |
||
452 | 45425 | jjdelcerro | JsonObject parameters_json = null;
|
453 | 43020 | jjdelcerro | DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
454 | 45425 | jjdelcerro | if( explorerFactory == null ) { |
455 | parameters_json = Json.createObject(explorerName); |
||
456 | if( parameters_json==null || |
||
457 | !parameters_json.containsKey(PROVIDER_PARAMTER_NAME) ) { |
||
458 | String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
||
459 | LOGGER.warn(msg); |
||
460 | throw new IllegalArgumentException(msg); |
||
461 | } |
||
462 | explorerName = parameters_json.getString(PROVIDER_PARAMTER_NAME); |
||
463 | explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
||
464 | if( explorerFactory == null ) { |
||
465 | String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
||
466 | LOGGER.warn(msg); |
||
467 | throw new IllegalArgumentException(msg); |
||
468 | } |
||
469 | 43488 | jjdelcerro | } |
470 | 43020 | jjdelcerro | DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
471 | 45425 | jjdelcerro | if( parameters_json!=null ) { |
472 | Json.addAll(params, parameters_json); |
||
473 | } |
||
474 | 43020 | jjdelcerro | return params;
|
475 | } |
||
476 | |||
477 | @Override
|
||
478 | public DataStoreParameters createMemoryStoreParameters(String autoOrderAttributeName) throws InitializeException { |
||
479 | try {
|
||
480 | DataStoreParameters parameters = createStoreParameters(MemoryStoreProvider.NAME); |
||
481 | if (autoOrderAttributeName != null) { |
||
482 | parameters.setDynValue( |
||
483 | MemoryStoreParameters.ORDER_PARAMETER_NAME, |
||
484 | autoOrderAttributeName); |
||
485 | } |
||
486 | return parameters;
|
||
487 | } catch (Exception ex) { |
||
488 | throw new InitializeException(ex); |
||
489 | } |
||
490 | } |
||
491 | |||
492 | @Override
|
||
493 | public DataServerExplorer openServerExplorer(String explorerName, DataServerExplorerParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
494 | 43503 | jjdelcerro | if( explorerName == null ) { |
495 | String msg = "Explorer name can't be null."; |
||
496 | 44023 | jjdelcerro | LOGGER.warn(msg); |
497 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
498 | } |
||
499 | 43020 | jjdelcerro | DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
500 | 43450 | jjdelcerro | if( explorerFactory == null ) { |
501 | String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
||
502 | 44023 | jjdelcerro | LOGGER.warn(msg); |
503 | 43450 | jjdelcerro | throw new IllegalArgumentException(msg); |
504 | } |
||
505 | 43020 | jjdelcerro | if (parameters == null) { |
506 | parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
||
507 | } |
||
508 | DataServerExplorer explorer = (DataServerExplorer) explorerFactory.create( |
||
509 | parameters, |
||
510 | new DefaultDataServerExplorerProviderServices()
|
||
511 | ); |
||
512 | return explorer;
|
||
513 | } |
||
514 | 43205 | fdiaz | |
515 | 43093 | jjdelcerro | @Override
|
516 | public DataServerExplorer openServerExplorer(String explorerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
517 | 43373 | jjdelcerro | if( arguments.length==1 && arguments[0] instanceof DataServerExplorerParameters ) { |
518 | 44669 | jjdelcerro | // Esto hace falta ya que desde scripting si se invoca a openServerExplorer con solo
|
519 | 43373 | jjdelcerro | // un parametro de tipo DataServerExplorerParameters llama ha este metodo en lugar de
|
520 | // llamar al que toca.
|
||
521 | return openServerExplorer(explorerName, (DataServerExplorerParameters)(arguments[0])); |
||
522 | } |
||
523 | 43503 | jjdelcerro | if( explorerName == null ) { |
524 | String msg = "Explorer name can't be null."; |
||
525 | 44023 | jjdelcerro | LOGGER.warn(msg); |
526 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
527 | } |
||
528 | 43093 | jjdelcerro | if( (arguments.length % 2)!= 0 ) { |
529 | throw new ValidateDataParametersException(); |
||
530 | } |
||
531 | DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
||
532 | DataServerExplorerParameters parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
||
533 | for( int i=0; i<arguments.length; i+=2 ) { |
||
534 | String name = (String) arguments[i]; |
||
535 | 44669 | jjdelcerro | if( name.endsWith("=") ) { |
536 | name = name.substring(0, name.length()-1); |
||
537 | } |
||
538 | 43093 | jjdelcerro | Object value = arguments[i+1]; |
539 | parameters.setDynValue(name, value); |
||
540 | } |
||
541 | return this.openServerExplorer(explorerName, parameters); |
||
542 | 43205 | fdiaz | |
543 | 43093 | jjdelcerro | } |
544 | 43205 | fdiaz | |
545 | 43020 | jjdelcerro | /**
|
546 | * @param parameters
|
||
547 | * @return
|
||
548 | * @throws org.gvsig.fmap.dal.exception.InitializeException
|
||
549 | * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
|
||
550 | * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
|
||
551 | * @deprecated see openServerExplorer
|
||
552 | */
|
||
553 | @Override
|
||
554 | public DataServerExplorer createServerExplorer(
|
||
555 | DataServerExplorerParameters parameters) throws InitializeException,
|
||
556 | ProviderNotRegisteredException, ValidateDataParametersException { |
||
557 | return openServerExplorer(parameters.getExplorerName(), parameters);
|
||
558 | } |
||
559 | |||
560 | 43045 | jjdelcerro | /**
|
561 | * @deprecated use openStore
|
||
562 | * @param parameters
|
||
563 | * @return
|
||
564 | * @throws InitializeException
|
||
565 | * @throws ProviderNotRegisteredException
|
||
566 | 43205 | fdiaz | * @throws ValidateDataParametersException
|
567 | 43045 | jjdelcerro | */
|
568 | 43020 | jjdelcerro | @Override
|
569 | 43045 | jjdelcerro | public DataStore createStore(DataStoreParameters parameters)
|
570 | throws InitializeException, ProviderNotRegisteredException,
|
||
571 | ValidateDataParametersException { |
||
572 | return openStore(parameters.getDataStoreName(), parameters);
|
||
573 | } |
||
574 | 43205 | fdiaz | |
575 | 43045 | jjdelcerro | @Override
|
576 | 47606 | fdiaz | public DataStore openStore(DataTransaction transaction, String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
577 | return this.openStore(transaction, providerName, parameters, false); |
||
578 | } |
||
579 | |||
580 | @Override
|
||
581 | 43020 | jjdelcerro | public DataStore openStore(String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
582 | 47606 | fdiaz | return this.openStore((DataTransaction)null, providerName, parameters, false); |
583 | 45966 | jjdelcerro | } |
584 | |||
585 | @Override
|
||
586 | public DataStore openStore(String providerName, DataStoreParameters parameters, boolean ignoreDALResource) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
587 | 47606 | fdiaz | return this.openStore((DataTransaction)null, providerName, parameters, ignoreDALResource); |
588 | } |
||
589 | |||
590 | @Override
|
||
591 | public DataStore openStore(DataTransaction transaction, String providerName, DataStoreParameters parameters, boolean ignoreDALResource) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
592 | 45966 | jjdelcerro | if (providerName == null) { |
593 | 43503 | jjdelcerro | String msg = "Provider name can't be null."; |
594 | 44023 | jjdelcerro | LOGGER.warn(msg); |
595 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
596 | } |
||
597 | 43020 | jjdelcerro | SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
598 | if (!identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, providerName)) {
|
||
599 | throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, providerName); |
||
600 | } |
||
601 | |||
602 | 43088 | jjdelcerro | parameters.validate(); |
603 | 43205 | fdiaz | |
604 | 43020 | jjdelcerro | String storeName = this.getStoreName(parameters); |
605 | 43450 | jjdelcerro | if( StringUtils.isEmpty(storeName) ) {
|
606 | String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
||
607 | 44023 | jjdelcerro | LOGGER.warn(msg); |
608 | 43450 | jjdelcerro | throw new IllegalArgumentException(msg); |
609 | } |
||
610 | 43020 | jjdelcerro | |
611 | DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
||
612 | 43450 | jjdelcerro | if( storeFactory == null ) { |
613 | String msg = "Can't locate store factory for '"+storeName+"'."; |
||
614 | 44023 | jjdelcerro | LOGGER.warn(msg); |
615 | 43450 | jjdelcerro | throw new IllegalArgumentException(msg); |
616 | } |
||
617 | 43020 | jjdelcerro | DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
618 | 43450 | jjdelcerro | if( providerFactory == null ) { |
619 | String msg = "Can't locate provider factory for '"+providerName+"'."; |
||
620 | 44023 | jjdelcerro | LOGGER.warn(msg); |
621 | 43450 | jjdelcerro | throw new IllegalArgumentException(msg); |
622 | } |
||
623 | 43020 | jjdelcerro | |
624 | DataStore store = (DataStore) storeFactory.create(parameters, this);
|
||
625 | 45966 | jjdelcerro | if( store instanceof DefaultFeatureStore ) { |
626 | ((DefaultFeatureStore)store).setIgnoreDALResource(ignoreDALResource); |
||
627 | 47606 | fdiaz | try {
|
628 | DataTransaction.add(transaction, (FeatureStore) store, false);
|
||
629 | } catch (Exception ex) { |
||
630 | throw new InitializeException(store.getFullName(), ex); |
||
631 | } |
||
632 | |||
633 | 45966 | jjdelcerro | } |
634 | 43020 | jjdelcerro | DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
635 | |||
636 | 45487 | fdiaz | if( provider == null ) { |
637 | String msg = "Can't create provider for '"+providerName+"'."; |
||
638 | LOGGER.trace(msg); |
||
639 | throw new IllegalArgumentException(msg); |
||
640 | } |
||
641 | |||
642 | 43020 | jjdelcerro | storeFactory.setProvider(store, provider); |
643 | 45425 | jjdelcerro | |
644 | addObservers(store); |
||
645 | if( store instanceof FeatureStoreProviderServices ) { |
||
646 | ((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
||
647 | } |
||
648 | return store;
|
||
649 | } |
||
650 | |||
651 | 46361 | jjdelcerro | @Override
|
652 | public DataFactory getStoreFactory(DataStoreParameters parameters) {
|
||
653 | String storeName = this.getStoreName(parameters); |
||
654 | if( StringUtils.isEmpty(storeName) ) {
|
||
655 | return null; |
||
656 | } |
||
657 | |||
658 | DataFactory storeFactory = this.getStoreRegister().getFactory(storeName);
|
||
659 | return storeFactory;
|
||
660 | } |
||
661 | |||
662 | 45425 | jjdelcerro | public void addObservers(DataStore store){ |
663 | 44871 | jjdelcerro | for (Observer storeObserver : storeObservers) { |
664 | if( storeObserver!=null) { |
||
665 | store.addObserver(storeObserver); |
||
666 | } |
||
667 | } |
||
668 | 43020 | jjdelcerro | } |
669 | |||
670 | 44871 | jjdelcerro | @Override
|
671 | 44253 | jjdelcerro | public DataStore openStore(DataStoreParameters parameters, DataStoreProvider provider) {
|
672 | String storeName = this.getStoreName(parameters); |
||
673 | if( StringUtils.isEmpty(storeName) ) {
|
||
674 | String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
||
675 | LOGGER.warn(msg); |
||
676 | throw new IllegalArgumentException(msg); |
||
677 | } |
||
678 | |||
679 | DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
||
680 | if( storeFactory == null ) { |
||
681 | String msg = "Can't locate store factory for '"+storeName+"'."; |
||
682 | LOGGER.warn(msg); |
||
683 | throw new IllegalArgumentException(msg); |
||
684 | } |
||
685 | DataStore store = (DataStore) storeFactory.create(parameters, this);
|
||
686 | storeFactory.setProvider(store, provider); |
||
687 | 44871 | jjdelcerro | for (Observer storeObserver : storeObservers) { |
688 | if( storeObserver!=null) { |
||
689 | store.addObserver(storeObserver); |
||
690 | } |
||
691 | } |
||
692 | if( store instanceof FeatureStoreProviderServices ) { |
||
693 | ((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
||
694 | } |
||
695 | 44253 | jjdelcerro | return store;
|
696 | } |
||
697 | |||
698 | 43020 | jjdelcerro | @Override
|
699 | public DataStore openStore(String provider, DynObject parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
700 | DataStoreParameters params = toDataStoreParameters(provider, parameters); |
||
701 | DataStore store = openStore(params.getDataStoreName(), params); |
||
702 | return store;
|
||
703 | } |
||
704 | |||
705 | @Override
|
||
706 | 43093 | jjdelcerro | public DataStore openStore(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
707 | 43239 | jjdelcerro | if( arguments.length == 1 ) { |
708 | // Desde jython entra por este metodo en lugar de los especificos
|
||
709 | // de DataStoreParameters o DynObject
|
||
710 | if( arguments[0] instanceof DataStoreParameters ) { |
||
711 | return this.openStore(providerName, (DataStoreParameters)(arguments[0])); |
||
712 | } else if( arguments[0] instanceof DynObject ) { |
||
713 | return this.openStore(providerName, (DynObject)(arguments[0])); |
||
714 | } |
||
715 | } |
||
716 | 45966 | jjdelcerro | if( arguments.length == 2 && arguments[0] instanceof DataStoreParameters && arguments[1] instanceof Boolean) { |
717 | return this.openStore(providerName, (DataStoreParameters)(arguments[0]), (boolean)(arguments[1])); |
||
718 | } |
||
719 | 43093 | jjdelcerro | if( (arguments.length % 2)!= 0 ) { |
720 | throw new ValidateDataParametersException(); |
||
721 | } |
||
722 | 43503 | jjdelcerro | if( providerName == null ) { |
723 | String msg = "Provider name can't be null."; |
||
724 | 44023 | jjdelcerro | LOGGER.warn(msg); |
725 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
726 | } |
||
727 | 43093 | jjdelcerro | DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
728 | DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
||
729 | for( int i=0; i<arguments.length; i+=2 ) { |
||
730 | String name = (String) arguments[i]; |
||
731 | 44669 | jjdelcerro | if( name.endsWith("=") ) { |
732 | name = name.substring(0, name.length()-1); |
||
733 | } |
||
734 | 43093 | jjdelcerro | Object value = arguments[i+1]; |
735 | parameters.setDynValue(name, value); |
||
736 | } |
||
737 | return this.openStore(providerName, parameters); |
||
738 | } |
||
739 | 43205 | fdiaz | |
740 | 43093 | jjdelcerro | @Override
|
741 | 43020 | jjdelcerro | public FeatureStore createMemoryStore(String autoOrderAttributeName) throws InitializeException { |
742 | try {
|
||
743 | DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
||
744 | DataStore store = openStore(MemoryStoreProvider.NAME, parameters); |
||
745 | return (FeatureStore) store;
|
||
746 | } catch (Exception ex) { |
||
747 | throw new InitializeException(ex); |
||
748 | } |
||
749 | } |
||
750 | |||
751 | @Override
|
||
752 | public DataStoreProviderFactory getStoreProviderFactory(String providerName) { |
||
753 | 43503 | jjdelcerro | if( providerName == null ) { |
754 | String msg = "Provider name can't be null."; |
||
755 | 44023 | jjdelcerro | LOGGER.warn(msg); |
756 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
757 | } |
||
758 | 43020 | jjdelcerro | DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
759 | return (DataStoreProviderFactory) providerFactory;
|
||
760 | } |
||
761 | |||
762 | @Override
|
||
763 | public List<String> getStoreProviders() { |
||
764 | return this.getStoreProviderRegister().getFactoryNames(); |
||
765 | } |
||
766 | |||
767 | @Override
|
||
768 | public List<String> getStoreProviders(String explorerName) { |
||
769 | 43503 | jjdelcerro | if( explorerName == null ) { |
770 | String msg = "Explorer name can't be null."; |
||
771 | 44023 | jjdelcerro | LOGGER.warn(msg); |
772 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
773 | } |
||
774 | 43020 | jjdelcerro | try {
|
775 | 43093 | jjdelcerro | DataServerExplorer explorer = openServerExplorer(explorerName, (DataServerExplorerParameters)null);
|
776 | 43020 | jjdelcerro | List names = explorer.getDataStoreProviderNames();
|
777 | return names;
|
||
778 | } catch (Exception ex) { |
||
779 | throw new RuntimeException("Can't get stores availables for explorer '" + explorerName + "'.", ex); |
||
780 | } |
||
781 | } |
||
782 | |||
783 | @Override
|
||
784 | public List<String> getExplorerProviders() { |
||
785 | List<String> names = this.getServerExplorerRegister().getFactoryNames(); |
||
786 | return names;
|
||
787 | } |
||
788 | |||
789 | @Override
|
||
790 | public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
||
791 | |||
792 | String providerName = parameters.getDataStoreName();
|
||
793 | DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
||
794 | if (providerFactory == null) { |
||
795 | throw new ProviderNotRegisteredException(providerName); |
||
796 | } |
||
797 | while (true) { |
||
798 | try {
|
||
799 | DataStoreProvider provider = (DataStoreProvider) providerFactory.create( |
||
800 | parameters, providerServices |
||
801 | ); |
||
802 | return provider;
|
||
803 | } catch (Exception e) { |
||
804 | if (openErrorHandler == null) { |
||
805 | throw new InitializeException(providerName, e); |
||
806 | } |
||
807 | boolean retry = openErrorHandler.canRetryOpen(e, parameters);
|
||
808 | if (!retry) {
|
||
809 | throw new InitializeException(providerName, e); |
||
810 | } |
||
811 | } |
||
812 | } |
||
813 | } |
||
814 | |||
815 | @Override
|
||
816 | public List<String> getFeatureIndexProviders() { |
||
817 | List<String> names = this.getFeatureIndexRegister().getFactoryNames(); |
||
818 | return names;
|
||
819 | } |
||
820 | |||
821 | @Override
|
||
822 | public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
||
823 | this.defaultDataIndexProviders.put(dataType, name);
|
||
824 | } |
||
825 | |||
826 | @Override
|
||
827 | public String getDefaultFeatureIndexProviderName(int dataType) { |
||
828 | return this.defaultDataIndexProviders.get(dataType); |
||
829 | } |
||
830 | |||
831 | @Override
|
||
832 | public FeatureIndexProviderServices createFeatureIndexProvider(
|
||
833 | String name,
|
||
834 | FeatureStore store, |
||
835 | FeatureType type, |
||
836 | String indexName,
|
||
837 | FeatureAttributeDescriptor attr |
||
838 | ) throws InitializeException, ProviderNotRegisteredException {
|
||
839 | |||
840 | if (name == null) { |
||
841 | name = getDefaultFeatureIndexProviderName(attr.getType()); |
||
842 | } |
||
843 | |||
844 | if (name == null) { |
||
845 | throw new InitializeException( |
||
846 | "There not any index provider registered.", null); |
||
847 | } |
||
848 | DataFactory indexfactory = this.getFeatureIndexRegister().getFactory(name);
|
||
849 | if (indexfactory == null) { |
||
850 | throw new InitializeException( |
||
851 | "There not any index provider registered with name '" + name + "'.", null); |
||
852 | |||
853 | } |
||
854 | FeatureIndexProvider provider = (FeatureIndexProvider) indexfactory.create(null, null); |
||
855 | |||
856 | FeatureIndexProviderServices services = new DefaultFeatureIndex(
|
||
857 | (FeatureStoreProviderServices) store, |
||
858 | type, |
||
859 | provider, |
||
860 | attr.getName(), |
||
861 | indexName |
||
862 | ); |
||
863 | services.initialize(); |
||
864 | return services;
|
||
865 | |||
866 | } |
||
867 | |||
868 | @Override
|
||
869 | public String getTemporaryDirectory() { |
||
870 | 43241 | jjdelcerro | FoldersManager manager = ToolsLocator.getFoldersManager(); |
871 | File folder = manager.getUniqueTemporaryFile("_daltmp_"); |
||
872 | return folder.getAbsolutePath();
|
||
873 | 43020 | jjdelcerro | } |
874 | |||
875 | @Override
|
||
876 | public DataStoreParameters createStoreParameters(DynStruct struct) throws InitializeException, ProviderNotRegisteredException { |
||
877 | if (!(struct instanceof DynStruct_v2)) { |
||
878 | throw new IllegalArgumentException("A DynStruct_v2 is required."); |
||
879 | } |
||
880 | Tags tags = ((DynStruct_v2) struct).getTags(); |
||
881 | return this.createStoreParameters(tags); |
||
882 | } |
||
883 | |||
884 | @Override
|
||
885 | public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException { |
||
886 | String providerName = (String) tags.get(TAG_DAL_OPENSTORE + "provider"); |
||
887 | if (providerName == null) { |
||
888 | throw new IllegalArgumentException("Tag DAL.OpenStore.provider is missing in struct."); |
||
889 | } |
||
890 | int prefixlen = TAG_DAL_OPENSTORE.length();
|
||
891 | DataStoreParameters parameters = this.createStoreParameters(providerName);
|
||
892 | for (String key : tags) { |
||
893 | if (key.startsWith(TAG_DAL_OPENSTORE)) {
|
||
894 | parameters.setDynValue(key.substring(prefixlen), tags.get(key)); |
||
895 | } |
||
896 | } |
||
897 | return parameters;
|
||
898 | } |
||
899 | |||
900 | @Override
|
||
901 | public DataStore openStore(DynStruct struct) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
||
902 | DataStoreParameters paramters = this.createStoreParameters(struct);
|
||
903 | DataStore store = this.openStore(paramters.getDataStoreName(), paramters);
|
||
904 | return store;
|
||
905 | } |
||
906 | |||
907 | @Override
|
||
908 | 45043 | jjdelcerro | public void newStore(String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
909 | String explorerName = this.getServerExplorerFromStore(providerName); |
||
910 | newStore(explorerName, providerName, parameters, overwrite); |
||
911 | } |
||
912 | |||
913 | @Override
|
||
914 | 43020 | jjdelcerro | public void newStore(String explorerName, String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
915 | 43503 | jjdelcerro | if( explorerName == null ) { |
916 | String msg = "Explorer name can't be null."; |
||
917 | 44023 | jjdelcerro | LOGGER.warn(msg); |
918 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
919 | } |
||
920 | if( providerName == null ) { |
||
921 | String msg = "Provider name can't be null."; |
||
922 | 44023 | jjdelcerro | LOGGER.warn(msg); |
923 | 43503 | jjdelcerro | throw new IllegalArgumentException(msg); |
924 | } |
||
925 | 43020 | jjdelcerro | |
926 | SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
||
927 | if (!identityManager.getCurrentIdentity().isAuthorized(CREATE_STORE_AUTHORIZATION, parameters, providerName)) {
|
||
928 | throw new UnauthorizedException(CREATE_STORE_AUTHORIZATION, parameters, providerName); |
||
929 | } |
||
930 | parameters.validate(); |
||
931 | try {
|
||
932 | DataServerExplorerParameters explorerParameters = this.createServerExplorerParameters(explorerName);
|
||
933 | DataServerExplorer server = this.openServerExplorer(explorerName, explorerParameters);
|
||
934 | server.add(providerName, parameters, overwrite); |
||
935 | } catch (Exception e) { |
||
936 | throw new InitializeException(e); |
||
937 | } |
||
938 | } |
||
939 | |||
940 | @Override
|
||
941 | 44023 | jjdelcerro | @Deprecated
|
942 | public Evaluator createExpresion(String expression) throws InitializeException { |
||
943 | Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
||
944 | exp.setPhrase(expression); |
||
945 | return this.createExpresion(exp); |
||
946 | 43020 | jjdelcerro | } |
947 | |||
948 | @Override
|
||
949 | 44023 | jjdelcerro | @Deprecated
|
950 | public Evaluator createExpresion(Expression expression) throws InitializeException { |
||
951 | 45366 | omartinez | DefaultFeatureExpressionEvaluator exp = new DefaultFeatureExpressionEvaluator(expression);
|
952 | 44023 | jjdelcerro | return exp;
|
953 | 43020 | jjdelcerro | } |
954 | |||
955 | 44023 | jjdelcerro | |
956 | 43020 | jjdelcerro | @Override
|
957 | 44023 | jjdelcerro | public Evaluator createFilter(String expression) throws InitializeException { |
958 | Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
||
959 | exp.setPhrase(expression); |
||
960 | return this.createFilter(exp); |
||
961 | } |
||
962 | |||
963 | @Override
|
||
964 | public Evaluator createFilter(Expression expression) throws InitializeException { |
||
965 | 45366 | omartinez | DefaultFeatureExpressionEvaluator exp = new DefaultFeatureExpressionEvaluator(expression);
|
966 | 43984 | jjdelcerro | return exp;
|
967 | } |
||
968 | |||
969 | @Override
|
||
970 | 43020 | jjdelcerro | public FeaturePagingHelper createFeaturePagingHelper(
|
971 | FeatureStore featureStore, int pageSize) throws BaseException { |
||
972 | return new FeaturePagingHelperImpl(featureStore, pageSize); |
||
973 | } |
||
974 | |||
975 | @Override
|
||
976 | public FeaturePagingHelper createFeaturePagingHelper(
|
||
977 | FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
||
978 | throws BaseException {
|
||
979 | return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
||
980 | } |
||
981 | |||
982 | @Override
|
||
983 | public void setOpenErrorHandler(OpenErrorHandler handler) { |
||
984 | openErrorHandler = handler; |
||
985 | } |
||
986 | |||
987 | @Override
|
||
988 | public OpenErrorHandler getOpenErrorHandler() {
|
||
989 | return this.openErrorHandler; |
||
990 | } |
||
991 | |||
992 | @Override
|
||
993 | public EditableFeatureType createFeatureType() {
|
||
994 | 43739 | jjdelcerro | return new DefaultEditableFeatureType(null); |
995 | 43020 | jjdelcerro | } |
996 | |||
997 | @Override
|
||
998 | 45043 | jjdelcerro | public EditableFeatureType createFeatureType(JsonObject json) {
|
999 | EditableFeatureType featureType = this.createFeatureType();
|
||
1000 | 45425 | jjdelcerro | featureType.fromJson(json); |
1001 | 45043 | jjdelcerro | return featureType;
|
1002 | } |
||
1003 | |||
1004 | @Override
|
||
1005 | 43020 | jjdelcerro | public DataServerExplorerPool getDataServerExplorerPool() {
|
1006 | if (this.dataServerExplorerPool == null) { |
||
1007 | 45425 | jjdelcerro | this.dataServerExplorerPool = new DataServerExplorerPoolImpl(); |
1008 | 43020 | jjdelcerro | } |
1009 | return this.dataServerExplorerPool; |
||
1010 | } |
||
1011 | |||
1012 | @Override
|
||
1013 | public void setDataServerExplorerPool(DataServerExplorerPool pool) { |
||
1014 | this.dataServerExplorerPool = pool;
|
||
1015 | } |
||
1016 | |||
1017 | public DataStoreParameters toDataStoreParameters(String provider, DynObject params) throws InitializeException, ProviderNotRegisteredException { |
||
1018 | if (params instanceof DataStoreParameters) { |
||
1019 | return (DataStoreParameters) params;
|
||
1020 | } |
||
1021 | String providerName;
|
||
1022 | try {
|
||
1023 | providerName = (String) params.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
|
||
1024 | } catch (Exception ex) { |
||
1025 | providerName = provider; |
||
1026 | } |
||
1027 | DataStoreParameters parameters = this.createStoreParameters(providerName);
|
||
1028 | ToolsLocator.getDynObjectManager().copy(params, parameters); |
||
1029 | return parameters;
|
||
1030 | } |
||
1031 | |||
1032 | @Override
|
||
1033 | public List<DataType> getDataTypes() { |
||
1034 | if (dataTypes == null) { |
||
1035 | DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
||
1036 | dataTypes = new ArrayList<>(); |
||
1037 | dataTypes.add(manager.get(DataTypes.STRING)); |
||
1038 | dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
||
1039 | dataTypes.add(manager.get(DataTypes.INT)); |
||
1040 | dataTypes.add(manager.get(DataTypes.DOUBLE)); |
||
1041 | dataTypes.add(manager.get(DataTypes.DATE)); |
||
1042 | dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
||
1043 | } |
||
1044 | return dataTypes;
|
||
1045 | } |
||
1046 | |||
1047 | @Override
|
||
1048 | public void setResourcesLoader(ClassLoader loader) { |
||
1049 | this.resourcesLoader = loader;
|
||
1050 | } |
||
1051 | |||
1052 | @Override
|
||
1053 | public void setResourcesLoader(File folder) { |
||
1054 | if (folder == null) { |
||
1055 | this.resourcesLoader = null; |
||
1056 | return;
|
||
1057 | } |
||
1058 | try {
|
||
1059 | URL[] urls = new URL[]{folder.toURI().toURL()}; |
||
1060 | this.resourcesLoader = new URLClassLoader(urls); |
||
1061 | } catch (Exception ex) { |
||
1062 | throw new IllegalArgumentException("Can't create a ClassLoader from '" + folder.toString() + "'.", ex); |
||
1063 | } |
||
1064 | } |
||
1065 | |||
1066 | @Override
|
||
1067 | public URL getResource(Object reourceLoader, String name) { |
||
1068 | URL x;
|
||
1069 | if (this.resourcesLoader != null) { |
||
1070 | x = this.resourcesLoader.getResource(name);
|
||
1071 | if (x != null) { |
||
1072 | return x;
|
||
1073 | } |
||
1074 | } |
||
1075 | x = reourceLoader.getClass().getResource(name); |
||
1076 | return x;
|
||
1077 | } |
||
1078 | |||
1079 | @Override
|
||
1080 | public InputStream getResourceAsStream(Object reourceLoader, String name) { |
||
1081 | InputStream x;
|
||
1082 | if (this.resourcesLoader != null) { |
||
1083 | x = this.resourcesLoader.getResourceAsStream(name);
|
||
1084 | if (x != null) { |
||
1085 | return x;
|
||
1086 | } |
||
1087 | } |
||
1088 | x = reourceLoader.getClass().getResourceAsStream(name); |
||
1089 | return x;
|
||
1090 | } |
||
1091 | 43205 | fdiaz | |
1092 | 43040 | jjdelcerro | @Override
|
1093 | public ExpressionBuilder createExpressionBuilder() {
|
||
1094 | 44042 | jjdelcerro | return ExpressionEvaluatorLocator.getManager().createExpressionBuilder();
|
1095 | 43040 | jjdelcerro | } |
1096 | 43056 | jjdelcerro | |
1097 | public void registerFeatureCacheProvider( |
||
1098 | FeatureCacheProviderFactory providerFactory) { |
||
1099 | ToolsLocator.getExtensionPointManager() |
||
1100 | .add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
||
1101 | .append(providerFactory.getName(), "", providerFactory);
|
||
1102 | } |
||
1103 | |||
1104 | public FeatureCacheProvider createFeatureCacheProvider(String name, |
||
1105 | DynObject parameters) throws DataException {
|
||
1106 | if (name == null) { |
||
1107 | throw new InitializeException( |
||
1108 | "It is necessary to provide a cache name", null); |
||
1109 | } |
||
1110 | if (parameters == null) { |
||
1111 | throw new InitializeException( |
||
1112 | "It is necessary to provide parameters to create the explorer",
|
||
1113 | null);
|
||
1114 | } |
||
1115 | FeatureCacheProviderFactory featureCacheProviderFactory; |
||
1116 | try {
|
||
1117 | featureCacheProviderFactory = |
||
1118 | (FeatureCacheProviderFactory) ToolsLocator |
||
1119 | .getExtensionPointManager().get(DATA_MANAGER_CACHE) |
||
1120 | .create(name); |
||
1121 | if (featureCacheProviderFactory == null) { |
||
1122 | throw new ProviderNotRegisteredException(name); |
||
1123 | } |
||
1124 | return featureCacheProviderFactory.createCacheProvider(parameters);
|
||
1125 | 45043 | jjdelcerro | } catch (Exception e) { |
1126 | 43056 | jjdelcerro | throw new InitializeException(e); |
1127 | } |
||
1128 | } |
||
1129 | |||
1130 | 43093 | jjdelcerro | @Override
|
1131 | 43056 | jjdelcerro | public List getFeatureCacheProviders() { |
1132 | ExtensionPoint extensionPoint = |
||
1133 | ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
||
1134 | if (extensionPoint != null) { |
||
1135 | return ToolsLocator.getExtensionPointManager()
|
||
1136 | .get(DATA_MANAGER_CACHE).getNames(); |
||
1137 | } else {
|
||
1138 | return new ArrayList(); |
||
1139 | } |
||
1140 | } |
||
1141 | |||
1142 | 43093 | jjdelcerro | @Override
|
1143 | 43056 | jjdelcerro | public DynObject createCacheParameters(String name) |
1144 | throws InitializeException, ProviderNotRegisteredException {
|
||
1145 | if (name == null) { |
||
1146 | throw new InitializeException( |
||
1147 | "It is necessary to provide a cache name", null); |
||
1148 | } |
||
1149 | FeatureCacheProviderFactory featureCacheProviderFactory; |
||
1150 | try {
|
||
1151 | featureCacheProviderFactory = |
||
1152 | (FeatureCacheProviderFactory) ToolsLocator |
||
1153 | .getExtensionPointManager().get(DATA_MANAGER_CACHE) |
||
1154 | .create(name); |
||
1155 | if (featureCacheProviderFactory == null) { |
||
1156 | throw new ProviderNotRegisteredException(name); |
||
1157 | } |
||
1158 | return featureCacheProviderFactory.createParameters();
|
||
1159 | 45043 | jjdelcerro | } catch (Exception e) { |
1160 | 43056 | jjdelcerro | throw new InitializeException(e); |
1161 | } |
||
1162 | } |
||
1163 | |||
1164 | 43205 | fdiaz | @Override
|
1165 | 43212 | jjdelcerro | public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException { |
1166 | 43205 | fdiaz | DataManagerProviderServices dataManager = DALSPILocator.getDataManagerProviderServices(); |
1167 | DataServerExplorerParameters eparams = null;
|
||
1168 | DataServerExplorer serverExplorer; |
||
1169 | try {
|
||
1170 | serverExplorer = dataManager.openServerExplorer(FILESYSTEM_EXPLORER_NAME, eparams); |
||
1171 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
1172 | throw new OpenException(FILESYSTEM_EXPLORER_NAME, e); |
||
1173 | } |
||
1174 | 43056 | jjdelcerro | |
1175 | 43205 | fdiaz | try {
|
1176 | serverExplorer.add(providerName, params, overwrite); |
||
1177 | } catch (DataException e) {
|
||
1178 | throw new CreateFileStoreException(e, providerName); |
||
1179 | } |
||
1180 | } |
||
1181 | 43983 | jjdelcerro | |
1182 | @Override
|
||
1183 | public FeatureSymbolTable createFeatureSymbolTable() {
|
||
1184 | 44738 | jjdelcerro | FeatureSymbolTable symbolTable = new FeatureSymbolTableImpl();
|
1185 | 43983 | jjdelcerro | return symbolTable;
|
1186 | } |
||
1187 | |||
1188 | @Override
|
||
1189 | 45739 | jjdelcerro | public FeatureSymbolTable createFeatureSymbolTable(String name) { |
1190 | FeatureSymbolTable symbolTable = new FeatureSymbolTableImpl(name);
|
||
1191 | return symbolTable;
|
||
1192 | } |
||
1193 | |||
1194 | @Override
|
||
1195 | 43989 | jjdelcerro | public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression) { |
1196 | FeatureAttributeEmulatorExpression emulator = new DefaultFeatureAttributeEmulatorExpression(type, expression);
|
||
1197 | return emulator;
|
||
1198 | } |
||
1199 | |||
1200 | 44128 | jjdelcerro | @Override
|
1201 | public void registerDataProfile(DataProfile profile) { |
||
1202 | if( profile==null ) { |
||
1203 | return;
|
||
1204 | } |
||
1205 | if( this.dataProfiles==null ) { |
||
1206 | 46419 | fdiaz | this.dataProfiles = new HashMap<>(); |
1207 | 44128 | jjdelcerro | } |
1208 | 46419 | fdiaz | this.dataProfiles.put(profile.getID().toLowerCase(), profile);
|
1209 | 44128 | jjdelcerro | } |
1210 | 43989 | jjdelcerro | |
1211 | 44128 | jjdelcerro | @Override
|
1212 | public List<DataProfile> getDataProfiles() { |
||
1213 | if( this.dataProfiles==null ) { |
||
1214 | return null; |
||
1215 | } |
||
1216 | 46419 | fdiaz | return Collections.unmodifiableList(new ArrayList<>(this.dataProfiles.values())); |
1217 | 44128 | jjdelcerro | } |
1218 | |||
1219 | @Override
|
||
1220 | public DataProfile getDataProfile(String name) { |
||
1221 | if( StringUtils.isBlank(name) ) {
|
||
1222 | return null; |
||
1223 | } |
||
1224 | 46419 | fdiaz | if(this.dataProfiles == null){ |
1225 | return null; |
||
1226 | 44128 | jjdelcerro | } |
1227 | 46419 | fdiaz | return this.dataProfiles.get(name.toLowerCase()); |
1228 | 44128 | jjdelcerro | } |
1229 | |||
1230 | 44253 | jjdelcerro | private StoresRepository storesRepository;
|
1231 | |||
1232 | @Override
|
||
1233 | public StoresRepository getStoresRepository() {
|
||
1234 | if( this.storesRepository==null ) { |
||
1235 | 44304 | jjdelcerro | this.storesRepository = new BaseStoresRepository("DAL"); |
1236 | 44253 | jjdelcerro | } |
1237 | return this.storesRepository; |
||
1238 | } |
||
1239 | 44304 | jjdelcerro | |
1240 | 44253 | jjdelcerro | @Override
|
1241 | 44304 | jjdelcerro | public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection) {
|
1242 | DatabaseWorkspaceManager workspace = new DefaultDatabaseWorkspaceManager(connection);
|
||
1243 | return workspace;
|
||
1244 | 44253 | jjdelcerro | } |
1245 | 44346 | jjdelcerro | |
1246 | @Override
|
||
1247 | 44821 | jjdelcerro | public void removeDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1248 | this.databaseWorkspaces.remove(databaseWorkspace.getId(),databaseWorkspace);
|
||
1249 | StoresRepository repo = databaseWorkspace.getStoresRepository(); |
||
1250 | this.getStoresRepository().removeRepository(repo.getID());
|
||
1251 | for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
||
1252 | if( listener!=null ) { |
||
1253 | try {
|
||
1254 | listener.onRemoveDatabaseWorkspace(databaseWorkspace); |
||
1255 | } catch(Throwable th) { |
||
1256 | LOGGER.warn("Problems calling databaseworkspace listener '"+listener.getName()+"'.",th); |
||
1257 | } |
||
1258 | } |
||
1259 | } |
||
1260 | try {
|
||
1261 | ResourcesStorage resources = databaseWorkspace.getResourcesStorage(); |
||
1262 | ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
||
1263 | Script script = scriptManager.loadScript(resources, "OnDisconnectToWorkspace.script");
|
||
1264 | if( script != null ) { |
||
1265 | script.invokeFunction("main", new Object[] {databaseWorkspace}); |
||
1266 | } |
||
1267 | } catch(Throwable th) { |
||
1268 | LOGGER.warn("Problems executing 'OnDisconnectToWorkspace.script' from workspace '"+databaseWorkspace.getId()+"'.",th); |
||
1269 | } |
||
1270 | } |
||
1271 | |||
1272 | @Override
|
||
1273 | 44346 | jjdelcerro | public void addDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1274 | this.databaseWorkspaces.put(databaseWorkspace.getId(),databaseWorkspace);
|
||
1275 | StoresRepository repo = databaseWorkspace.getStoresRepository(); |
||
1276 | this.getStoresRepository().addRepository(repo);
|
||
1277 | 44419 | jjdelcerro | |
1278 | 44821 | jjdelcerro | for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
1279 | 44419 | jjdelcerro | if( listener!=null ) { |
1280 | try {
|
||
1281 | listener.onAddDatabaseWorkspace(databaseWorkspace); |
||
1282 | } catch(Throwable th) { |
||
1283 | LOGGER.warn("Problems calling databaseworkspace listener '"+listener.getName()+"'.",th); |
||
1284 | } |
||
1285 | } |
||
1286 | } |
||
1287 | 47606 | fdiaz | LocalTransaction trans = new LocalTransaction(this,null); |
1288 | 44419 | jjdelcerro | try {
|
1289 | 47606 | fdiaz | trans.begin(); |
1290 | trans.add(databaseWorkspace); |
||
1291 | 44419 | jjdelcerro | ResourcesStorage resources = databaseWorkspace.getResourcesStorage(); |
1292 | ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
||
1293 | Script script = scriptManager.loadScript(resources, "OnConnectToWorkspace.script");
|
||
1294 | if( script != null ) { |
||
1295 | script.invokeFunction("main", new Object[] {databaseWorkspace}); |
||
1296 | } |
||
1297 | 47606 | fdiaz | trans.commit(); |
1298 | 44419 | jjdelcerro | } catch(Throwable th) { |
1299 | LOGGER.warn("Problems executing 'OnConnectToWorkspace.script' from workspace '"+databaseWorkspace.getId()+"'.",th); |
||
1300 | 47606 | fdiaz | trans.abortQuietly(); |
1301 | } finally {
|
||
1302 | trans.closeQuietly(); |
||
1303 | 44419 | jjdelcerro | } |
1304 | 44346 | jjdelcerro | } |
1305 | 44419 | jjdelcerro | |
1306 | @Override
|
||
1307 | 44821 | jjdelcerro | public void addDatabaseWorkspaceListener(DatabaseWorkspaceListener listener) { |
1308 | 44419 | jjdelcerro | this.addDatabaseWorkspaceListeners.put(listener.getName(), listener);
|
1309 | } |
||
1310 | 44346 | jjdelcerro | |
1311 | @Override
|
||
1312 | public DatabaseWorkspaceManager getDatabaseWorkspace(String name) { |
||
1313 | 44821 | jjdelcerro | if( StringUtils.isBlank(name) ) {
|
1314 | return null; |
||
1315 | } |
||
1316 | 44346 | jjdelcerro | return this.databaseWorkspaces.get(name); |
1317 | } |
||
1318 | 44328 | jjdelcerro | |
1319 | @Override
|
||
1320 | 44346 | jjdelcerro | public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params) {
|
1321 | for (DatabaseWorkspaceManager databaseWorkspace : this.databaseWorkspaces.values()) { |
||
1322 | if( databaseWorkspace.getStoresRepository().contains(params) ) {
|
||
1323 | return databaseWorkspace;
|
||
1324 | } |
||
1325 | } |
||
1326 | return null; |
||
1327 | } |
||
1328 | |||
1329 | @Override
|
||
1330 | 46338 | fdiaz | public DatabaseWorkspaceManager getDatabaseWorkspace(DataServerExplorerParameters params) {
|
1331 | for (DatabaseWorkspaceManager databaseWorkspace : this.databaseWorkspaces.values()) { |
||
1332 | DataServerExplorerParameters p = databaseWorkspace.getServerExplorerParameters(); |
||
1333 | if(p.isTheSameServerExplorer(params)){
|
||
1334 | return databaseWorkspace;
|
||
1335 | } |
||
1336 | } |
||
1337 | return null; |
||
1338 | } |
||
1339 | |||
1340 | @Override
|
||
1341 | 44328 | jjdelcerro | public void writeDALResource(ResourcesStorage resources, DataStore store) { |
1342 | ResourcesStorage.Resource resource = null;
|
||
1343 | try {
|
||
1344 | if( resources == null || resources.isReadOnly() ) { |
||
1345 | return;
|
||
1346 | } |
||
1347 | resource = resources.getResource("dal");
|
||
1348 | if( resource == null || resource.isReadOnly() ) { |
||
1349 | return;
|
||
1350 | } |
||
1351 | DALFile dalFile = DALFile.getDALFile(); |
||
1352 | dalFile.setStore((DefaultFeatureStore) store); |
||
1353 | if( !dalFile.isEmpty() ) {
|
||
1354 | dalFile.write(resource); |
||
1355 | } |
||
1356 | } catch (Throwable ex) { |
||
1357 | LOGGER.warn("Can't save DAL resource", ex);
|
||
1358 | } finally {
|
||
1359 | IOUtils.closeQuietly(resource); |
||
1360 | } |
||
1361 | |||
1362 | |||
1363 | } |
||
1364 | |||
1365 | @Override
|
||
1366 | public void writeDALResource(ResourcesStorage resources, FeatureType featureType) { |
||
1367 | ResourcesStorage.Resource resource = null;
|
||
1368 | try {
|
||
1369 | if( resources == null || resources.isReadOnly() ) { |
||
1370 | return;
|
||
1371 | } |
||
1372 | resource = resources.getResource("dal");
|
||
1373 | if( resource == null || resource.isReadOnly() ) { |
||
1374 | return;
|
||
1375 | } |
||
1376 | DALFile dalFile = DALFile.getDALFile(); |
||
1377 | dalFile.setFeatureType(featureType); |
||
1378 | if( !dalFile.isEmpty() ) {
|
||
1379 | dalFile.write(resource); |
||
1380 | } |
||
1381 | } catch (Throwable ex) { |
||
1382 | LOGGER.warn("Can't save DAL resource", ex);
|
||
1383 | } finally {
|
||
1384 | IOUtils.closeQuietly(resource); |
||
1385 | } |
||
1386 | } |
||
1387 | 44376 | jjdelcerro | |
1388 | @Override
|
||
1389 | 44719 | jjdelcerro | public void clearAvailableValuesCache() { |
1390 | 45772 | omartinez | //TODO
|
1391 | 44719 | jjdelcerro | } |
1392 | 45772 | omartinez | |
1393 | 44719 | jjdelcerro | @Override
|
1394 | 44409 | jjdelcerro | public String createUniqueID() { |
1395 | UUID x = UUID.randomUUID(); |
||
1396 | String s = x.toString();
|
||
1397 | return s;
|
||
1398 | } |
||
1399 | 44750 | jjdelcerro | |
1400 | 44753 | omartinez | @Override
|
1401 | 46012 | jjdelcerro | public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor(String name, int type) { |
1402 | 46104 | omartinez | return createEditableFeatureAttributeDescriptor(null, name,type, false); |
1403 | 46012 | jjdelcerro | } |
1404 | |||
1405 | 46104 | omartinez | public static DefaultEditableFeatureAttributeDescriptor createEditableFeatureAttributeDescriptor(FeatureType ftype, String name, int type) { |
1406 | return createEditableFeatureAttributeDescriptor(ftype, name,type, false); |
||
1407 | 46012 | jjdelcerro | } |
1408 | |||
1409 | 46104 | omartinez | public static DefaultEditableFeatureAttributeDescriptor createEditableFeatureAttributeDescriptor(FeatureType ftype, String name, int type, boolean strongChanges) { |
1410 | 46012 | jjdelcerro | switch (type) {
|
1411 | case DataTypes.DOUBLE:
|
||
1412 | case DataTypes.FLOAT:
|
||
1413 | case DataTypes.DECIMAL:
|
||
1414 | case DataTypes.BOOLEAN:
|
||
1415 | case DataTypes.BYTE:
|
||
1416 | case DataTypes.BYTEARRAY:
|
||
1417 | case DataTypes.CHAR:
|
||
1418 | case DataTypes.DATE:
|
||
1419 | case DataTypes.GEOMETRY:
|
||
1420 | case DataTypes.INT:
|
||
1421 | case DataTypes.LONG:
|
||
1422 | case DataTypes.OBJECT:
|
||
1423 | case DataTypes.LIST: // Solo para campos calculados ??? |
||
1424 | case DataTypes.STRING:
|
||
1425 | case DataTypes.TIME:
|
||
1426 | case DataTypes.TIMESTAMP:
|
||
1427 | case DataTypes.URI:
|
||
1428 | case DataTypes.URL:
|
||
1429 | case DataTypes.FILE:
|
||
1430 | break;
|
||
1431 | |||
1432 | default:
|
||
1433 | throw new UnsupportedDataTypeException(name, type); |
||
1434 | } |
||
1435 | 46104 | omartinez | DefaultEditableFeatureAttributeDescriptor edi = new DefaultEditableFeatureAttributeDescriptor(ftype, strongChanges);
|
1436 | 46012 | jjdelcerro | edi.setName(name); |
1437 | edi.setDataType(type); |
||
1438 | if (edi.getDataType().supportSize()) {
|
||
1439 | edi.setSize(edi.getDataType().getDefaultSize()); |
||
1440 | 46104 | omartinez | } |
1441 | 44753 | omartinez | return edi;
|
1442 | } |
||
1443 | |||
1444 | 44750 | jjdelcerro | @Override
|
1445 | public DALExpressionBuilder createDALExpressionBuilder() {
|
||
1446 | return new DefaultDALExpressionBuilder(); |
||
1447 | } |
||
1448 | |||
1449 | 44871 | jjdelcerro | @Override
|
1450 | public void addStoreObserver(Observer observer) { |
||
1451 | this.storeObservers.add(observer);
|
||
1452 | } |
||
1453 | |||
1454 | @Override
|
||
1455 | public void removeStoreObserver(Observer observer) { |
||
1456 | this.storeObservers.remove(observer);
|
||
1457 | } |
||
1458 | 45043 | jjdelcerro | |
1459 | @Override
|
||
1460 | public String getServerExplorerFromStore(String name) { |
||
1461 | Register r = this.getServerExplorerRegister();
|
||
1462 | for (DataFactory factory0 : r) {
|
||
1463 | DataServerExplorerFactory factory = (DataServerExplorerFactory) factory0; |
||
1464 | if( factory.isStoreSupported(name) ) {
|
||
1465 | return factory.getName();
|
||
1466 | } |
||
1467 | } |
||
1468 | return null; |
||
1469 | } |
||
1470 | 45426 | fdiaz | |
1471 | @Override
|
||
1472 | public void setMaxSizeForSmallFeatureSelection(long size){ |
||
1473 | this.maxSizeForSmallFeatureSelection = size;
|
||
1474 | } |
||
1475 | 45043 | jjdelcerro | |
1476 | 45426 | fdiaz | @Override
|
1477 | public long getMaxSizeForSmallFeatureSelection() { |
||
1478 | return this.maxSizeForSmallFeatureSelection; |
||
1479 | } |
||
1480 | |||
1481 | 45469 | jjdelcerro | @Override
|
1482 | 45461 | jjdelcerro | public void registerLargeMap(Factory factory) { |
1483 | this.largeMapFactory = factory;
|
||
1484 | } |
||
1485 | |||
1486 | 45469 | jjdelcerro | @Override
|
1487 | 45461 | jjdelcerro | public void registerLargeSet(Factory factory) { |
1488 | this.largeSetFactory = factory;
|
||
1489 | } |
||
1490 | |||
1491 | 45426 | fdiaz | @Override
|
1492 | public Map createLargeMap() { |
||
1493 | 45461 | jjdelcerro | return (Map) this.largeMapFactory.create(); |
1494 | 45426 | fdiaz | } |
1495 | |||
1496 | @Override
|
||
1497 | public Set createLargeSet() { |
||
1498 | 45461 | jjdelcerro | return (Set) this.largeSetFactory.create(); |
1499 | 45426 | fdiaz | } |
1500 | 45445 | jjdelcerro | |
1501 | @Override
|
||
1502 | public DataTransaction createTransaction() {
|
||
1503 | DefaultTransaction transaction = new DefaultTransaction();
|
||
1504 | return transaction;
|
||
1505 | } |
||
1506 | 45696 | jjdelcerro | |
1507 | @Override
|
||
1508 | public void putFeaturesInClipboard(FeatureSet set) { |
||
1509 | if( set==null ) { |
||
1510 | return;
|
||
1511 | } |
||
1512 | String s = set.toJson().toString();
|
||
1513 | ToolsSwingLocator.getToolsSwingManager().putInClipboard(s); |
||
1514 | } |
||
1515 | |||
1516 | @Override
|
||
1517 | public List<EditableFeature> getFeaturesFromClipboard(FeatureStore store, Predicate<FeatureAttributeDescriptor> attrFilter) throws DataException { |
||
1518 | if( store==null ) { |
||
1519 | return Collections.EMPTY_LIST; |
||
1520 | } |
||
1521 | String clipboard = ToolsSwingLocator.getToolsSwingManager().getFromClipboard();
|
||
1522 | if( StringUtils.isBlank(clipboard) ) {
|
||
1523 | return Collections.EMPTY_LIST; |
||
1524 | } |
||
1525 | JsonArray array = Json.createArray(clipboard); |
||
1526 | if (array == null) { |
||
1527 | return Collections.EMPTY_LIST; |
||
1528 | } |
||
1529 | List<EditableFeature> features = new ArrayList<>(); |
||
1530 | for (JsonValue jsonValue : array) {
|
||
1531 | EditableFeature f = store.createNewFeature(); |
||
1532 | f.copyFrom((JsonObject) jsonValue, attrFilter); |
||
1533 | features.add(f); |
||
1534 | } |
||
1535 | return features;
|
||
1536 | } |
||
1537 | 45739 | jjdelcerro | |
1538 | @Override
|
||
1539 | public FeatureRuleExpression createFeatureRuleExpression() {
|
||
1540 | FeatureRuleExpression rule = new DefaultFeatureRuleExpression();
|
||
1541 | return rule;
|
||
1542 | 46805 | jjdelcerro | } |
1543 | |||
1544 | @Override
|
||
1545 | public File getCacheResourcesFolder() { |
||
1546 | FoldersManager fm = ToolsLocator.getFoldersManager(); |
||
1547 | File f = fm.getTemporaryFile("resources-storage"); |
||
1548 | return f;
|
||
1549 | } |
||
1550 | 45739 | jjdelcerro | |
1551 | 46805 | jjdelcerro | @Override
|
1552 | public void clearAllCachedResources() { |
||
1553 | try {
|
||
1554 | File f = this.getCacheResourcesFolder(); |
||
1555 | FileUtils.deleteDirectory(f); |
||
1556 | } catch (Exception ex) { |
||
1557 | LOGGER.warn("Can't remove local cache for of resources.", ex);
|
||
1558 | } |
||
1559 | 47784 | jjdelcerro | // FIXME: deberia borrarse las caches de los featuretype del StoresRepository
|
1560 | 46805 | jjdelcerro | } |
1561 | 46996 | jjdelcerro | |
1562 | @Override
|
||
1563 | public LabelsCacheForFieldValues createLabelsCacheForFieldValues(Invocable labelFormulaProvider, SimpleTaskStatus status) {
|
||
1564 | LabelsCacheForFieldValuesImpl x = new LabelsCacheForFieldValuesImpl(labelFormulaProvider, status);
|
||
1565 | return x;
|
||
1566 | } |
||
1567 | 47080 | jjdelcerro | |
1568 | public List<FeatureType> getFeatureTypesFromDAL(byte[] daldata) { |
||
1569 | try {
|
||
1570 | BytesResource res = ResourcesStorage.createBytesResource(daldata); |
||
1571 | DALFile dalfile = DALFile.getDALFile(res); |
||
1572 | return dalfile.getFeatureTypes();
|
||
1573 | } catch (DataException ex) {
|
||
1574 | return null; |
||
1575 | } |
||
1576 | } |
||
1577 | |||
1578 | 47209 | jjdelcerro | @Override
|
1579 | 47080 | jjdelcerro | public byte[] getDALBytesFromFeatureType(FeatureType ftype) { |
1580 | try {
|
||
1581 | DALFile dalfile = DALFile.getDALFile(); |
||
1582 | dalfile.setFeatureType(ftype); |
||
1583 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
||
1584 | dalfile.write(bos); |
||
1585 | IOUtils.closeQuietly(bos); |
||
1586 | return bos.toByteArray();
|
||
1587 | } catch (DataException ex) {
|
||
1588 | return null; |
||
1589 | } |
||
1590 | } |
||
1591 | 47138 | jjdelcerro | |
1592 | private PropertiesSupportHelper propertiesSupportHelper;
|
||
1593 | |||
1594 | @Override
|
||
1595 | public Object getProperty(String name) { |
||
1596 | if( this.propertiesSupportHelper == null ) { |
||
1597 | return null; |
||
1598 | } |
||
1599 | return this.propertiesSupportHelper.getProperty(name); |
||
1600 | } |
||
1601 | |||
1602 | @Override
|
||
1603 | public void setProperty(String name, Object value) { |
||
1604 | if( this.propertiesSupportHelper == null ) { |
||
1605 | this.propertiesSupportHelper = new PropertiesSupportHelper(); |
||
1606 | } |
||
1607 | this.propertiesSupportHelper.setProperty(name,value);
|
||
1608 | } |
||
1609 | |||
1610 | @Override
|
||
1611 | public Map<String, Object> getProperties() { |
||
1612 | if( this.propertiesSupportHelper == null ) { |
||
1613 | return Collections.EMPTY_MAP; |
||
1614 | } |
||
1615 | return this.propertiesSupportHelper.getProperties(); |
||
1616 | } |
||
1617 | |||
1618 | 47209 | jjdelcerro | public DataTypeDetector createDataTypeDetector(Locale locale) { |
1619 | DataTypeDetector x = new DataTypeDetectorImpl(locale);
|
||
1620 | return x;
|
||
1621 | } |
||
1622 | 47861 | jjdelcerro | |
1623 | private File localResourcesFolder; |
||
1624 | |||
1625 | @Override
|
||
1626 | public File getLocalResourcesFolder() { |
||
1627 | if( this.localResourcesFolder==null ) { |
||
1628 | FoldersManager fm = ToolsLocator.getFoldersManager(); |
||
1629 | this.localResourcesFolder = FileUtils.getFile(fm.getTemporaryFolder(), "localresources"); |
||
1630 | } |
||
1631 | return this.localResourcesFolder; |
||
1632 | } |
||
1633 | |||
1634 | @Override
|
||
1635 | 47880 | jjdelcerro | public File getLocalResourcesFolder(DataServerExplorerParameters params) { |
1636 | if( !(params instanceof JDBCServerExplorerParameters) ) { |
||
1637 | return null; |
||
1638 | } |
||
1639 | try {
|
||
1640 | JDBCServerExplorerParameters parameters = (JDBCServerExplorerParameters) params; |
||
1641 | StringBuilder s = new StringBuilder(); |
||
1642 | s.append("r");
|
||
1643 | if( StringUtils.isNotBlank(parameters.getProviderName()) ) {
|
||
1644 | s.append("-");
|
||
1645 | s.append(parameters.getProviderName()); |
||
1646 | } |
||
1647 | if( StringUtils.isNotBlank(parameters.getHost()) ) {
|
||
1648 | s.append("-");
|
||
1649 | s.append(parameters.getHost()); |
||
1650 | } |
||
1651 | if( StringUtils.isNotBlank(parameters.getDBName()) ) {
|
||
1652 | s.append("-");
|
||
1653 | s.append(parameters.getDBName()); |
||
1654 | } |
||
1655 | // if( StringUtils.isNotBlank(parameters.getSchema()) ) {
|
||
1656 | // s.append("-");
|
||
1657 | // s.append(parameters.getSchema());
|
||
1658 | // }
|
||
1659 | s.append("-");
|
||
1660 | s.append(DigestUtils.md5Hex(parameters.getUrl())); |
||
1661 | File f = FileUtils.getFile(this.getLocalResourcesFolder(), s.toString()); |
||
1662 | return f;
|
||
1663 | } catch(Throwable ex) { |
||
1664 | LOGGER.debug("Can't get local resources folder.", ex);
|
||
1665 | } |
||
1666 | return null; |
||
1667 | } |
||
1668 | |||
1669 | @Override
|
||
1670 | 47861 | jjdelcerro | public void setLocalResourcesFolder(File resourcesFolder) { |
1671 | this.localResourcesFolder = resourcesFolder;
|
||
1672 | } |
||
1673 | |||
1674 | 43020 | jjdelcerro | } |