Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / DataManager.java @ 45696

History | View | Annotate | Download (22.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal;
24

    
25
import java.io.File;
26
import java.util.List;
27
import java.util.Map;
28
import java.util.Set;
29
import java.util.function.Predicate;
30
import javax.json.JsonObject;
31
import org.gvsig.expressionevaluator.Expression;
32
import org.gvsig.expressionevaluator.ExpressionBuilder;
33

    
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
39
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
40
import org.gvsig.fmap.dal.feature.EditableFeatureType;
41
import org.gvsig.fmap.dal.feature.Feature;
42
import org.gvsig.fmap.dal.feature.FeatureIndex;
43
import org.gvsig.fmap.dal.feature.FeatureQuery;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureType;
46
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
47
import org.gvsig.fmap.dal.resource.ResourceManager;
48
import org.gvsig.tools.dataTypes.DataType;
49
import org.gvsig.tools.dynobject.DynObject;
50
import org.gvsig.tools.dynobject.DynStruct;
51
import org.gvsig.tools.dynobject.Tags;
52
import org.gvsig.tools.evaluator.Evaluator;
53
import org.gvsig.tools.exception.BaseException;
54
import org.gvsig.tools.service.spi.Services;
55
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
56
import org.gvsig.fmap.dal.feature.DataProfile;
57
import org.gvsig.fmap.dal.feature.EditableFeature;
58
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
59
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
60
import org.gvsig.fmap.dal.feature.FeatureSet;
61
import org.gvsig.tools.observer.Observer;
62
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
63
import org.gvsig.tools.swing.api.ToolsSwingLocator;
64
import org.gvsig.tools.util.Factory;
65

    
66
/**
67
 * There are two top level management roles within DAL: data access and resource
68
 * management.
69
 *
70
 * This class is responsible of the data access management role. It provides
71
 * ways for registering and instantiating {@link DataServerExplorer}(s),
72
 * {@link DataStore}(s), {@link Evaluator}(s) and {@link FeatureIndex}(es).
73
 *
74
 * @see ResourceManager
75
 *
76
 */
77
public interface DataManager extends Services {
78

    
79
    public static final String CREATE_STORE_AUTHORIZATION = "dal-create-store";
80
    public static final String READ_STORE_AUTHORIZATION = "dal-read-store";
81
    public static final String WRITE_STORE_AUTHORIZATION = "dal-write-store";
82

    
83
    public static final String DAL_SYMBOL_TABLE = "DAL.SymbolTable.Global";
84
//    public static final String DAL_SYMBOL_TABLE_FEATURE = "DAL.SymbolTable.Feature";
85

    
86
    public static final String FUNCTION_FOREING_VALUE = "FOREING_VALUE";
87
    public static final String FUNCTION_SELECT = "SELECT";
88
    public static final String FUNCTION_UPDATE = "UPDATE";
89
    public static final String FUNCTION_SELECT_COUNT = "SELECT_COUNT";
90
    public static final String FUNCTION_EXISTS = "EXISTS";
91
    public static final String FUNCTION_EXISTS_TABLE = "EXISTS_TABLE";
92
    public static final String FUNCTION_ROW_TAG = "ROW_TAG";
93
    public static final String FUNCTION_SET_ROW_TAG = "SET_ROW_TAG";
94
    public static final String FUNCTION_CURRENT_ROW = "CURRENT_ROW";
95
    public static final String FUNCTION_CURRENT_STORE = "CURRENT_STORE";
96
    public static final String FUNCTION_ISSELECTED_CURRENT_ROW = "ISSELECTED_CURRENT_ROW";
97
    public static final String FUNCTION_GEOMETRY = "GEOMETRY";
98
    public static final String FUNCTION_CREATE_IN_MEMORY_TABLE = "CREATE_IN_MEMORY_TABLE";
99
    public static final String FUNCTION_INSERT_INTO_TABLE = "INSERT_INTO_TABLE";
100
    public static final String FUNCTION_CREATE_TABLE = "CREATE_TABLE";
101
    public static final String FUNCTION_CREATE_TABLE_STRUCTURE = "CREATE_TABLE_STRUCTURE";
102
    
103
    public static final String DAL_PREFERRED_COLUMNS = "DAL.Preferred.Columns";
104
    
105
    public static final String DAL_USE_LABELS = "DAL.useLabels";
106

    
107
    public static final int USE_LABELS_YES = 0;
108
    public static final int USE_LABELS_NO = 1;
109
    public static final int USE_LABELS_BOTH = 2;
110
    
111
    /**
112
     * 
113
     * Returns the default DAL's temporary directory
114
     *
115
     * @return Temporary directory name
116
     * @deprecated use FoldersManager of org.gvsig.tools
117
     */
118
    public String getTemporaryDirectory();
119

    
120
    /*
121
     * ====================================================================
122
     *
123
     * Store related services
124
     */
125
    /**
126
     * Creates, initializes and returns an instance of DataStoreParameters given
127
     * the name with which their provider is registered.
128
     *
129
     * @param name provider name
130
     * @param arguments
131
     * @return the data store parameters
132
     *
133
     * @throws ProviderNotRegisteredException if the memory provider is not
134
     * registered
135
     * @throws InitializeException if there is an error initializing the
136
     * parameters for the memory provider
137
     *
138
     */
139
    public DataStoreParameters createStoreParameters(String name, Object... arguments)
140
            throws InitializeException, ProviderNotRegisteredException;
141
    
142
    public DataStoreParameters createStoreParameters(String name)
143
            throws InitializeException, ProviderNotRegisteredException;
144

    
145
    public DataStoreParameters createStoreParameters(byte[] data);
146

    
147
    /**
148
     * Creates, initializes and fill an instance of DataStoreParameters from the
149
     * tags of the DynStruct passed as parameter.
150
     *
151
     * @param struct structure from which tags were created ths parameters.
152
     * @return the data store parameters
153
     *
154
     * @throws ProviderNotRegisteredException if the memory provider is not
155
     * registered
156
     * @throws InitializeException if there is an error initializing the
157
     * parameters for the memory provider
158
     *
159
     */
160
    public DataStoreParameters createStoreParameters(DynStruct struct)
161
            throws InitializeException, ProviderNotRegisteredException;
162

    
163
    public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException;
164

    
165
    /**
166
     * Creates, initializes and returns an instance of NewDataStoreParameters
167
     * given the name with which their provider is registered.
168
     *
169
     * @param explorer
170
     * @param provider
171
     * @return
172
     *
173
     * @throws InitializeException
174
     * @throws ProviderNotRegisteredException
175
     */
176
    public NewDataStoreParameters createNewStoreParameters(String explorer, String provider)
177
            throws InitializeException, ProviderNotRegisteredException;
178

    
179
    public NewDataStoreParameters createNewStoreParameters(String provider)
180
            throws InitializeException, ProviderNotRegisteredException;
181

    
182
    /**
183
     *
184
     * Creates, initializes and returns an instance of DataStore given the
185
     * DataStoreParameters.
186
     *
187
     * @param provider
188
     * @param parameters parameters used to instantiate and initialize the
189
     * DataStore
190
     * @return
191
     *
192
     * @throws ProviderNotRegisteredException if the memory provider is not
193
     * registered
194
     * @throws InitializeException if there is an error initializing the
195
     * parameters for the memory provider
196
     * @throws ValidateDataParametersException if the parameters to open the
197
     * memory based store are not valid
198
     */
199
    public DataStore openStore(String provider, DynObject parameters)
200
            throws InitializeException, ProviderNotRegisteredException,
201
            ValidateDataParametersException;
202

    
203
    public DataStore openStore(String provider, DataStoreParameters parameters)
204
            throws InitializeException, ProviderNotRegisteredException,
205
            ValidateDataParametersException;
206

    
207
    public DataStore openStore(
208
            String providerName,
209
            Object... arguments)
210
        throws
211
            InitializeException,
212
            ProviderNotRegisteredException,
213
            ValidateDataParametersException;
214

    
215
    public DataStore openStore(DynStruct struct)
216
            throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException;
217

    
218
    /**
219
     * Create a new physical store
220
     *
221
     * @param explorer
222
     * @param provider
223
     * @param parameters
224
     * @param overwrite
225
     *
226
     * @throws InitializeException
227
     * @throws ProviderNotRegisteredException
228
     * @throws ValidateDataParametersException
229
     */
230
    public void newStore(String explorer, String provider, NewDataStoreParameters parameters, boolean overwrite)
231
            throws InitializeException, ProviderNotRegisteredException,
232
            ValidateDataParametersException;
233

    
234
    public void newStore(String provider, NewDataStoreParameters parameters, boolean overwrite)
235
            throws InitializeException, ProviderNotRegisteredException,
236
            ValidateDataParametersException;
237

    
238
    /**
239
     * Returns a list of Strings containing the names of all available DataStore
240
     * providers.
241
     *
242
     * @return list of String containing available DataStore provider names
243
     */
244
    public List getStoreProviders();
245

    
246
    /**
247
     * Returns a list of Strings containing the names of all available DataStore
248
     * providers for an explorer.
249
     *
250
     * @param name
251
     * @return
252
     */
253
    public List<String> getStoreProviders(String name);
254

    
255
    /*
256
     * ====================================================================
257
     *
258
     * Explorer related services
259
     */
260
    /**
261
     * Returns an instance of {@link DataServerExplorerParameters} corresponding
262
     * to the given name.
263
     *
264
     * @param name name of a registered server explorer provider
265
     * @return
266
     *
267
     * @throws InitializeException if parameter initialization causes an error.
268
     *
269
     * @throws ProviderNotRegisteredException if could not find a provider by
270
     * the given name.
271
     *
272
     *
273
     */
274
    public DataServerExplorerParameters createServerExplorerParameters(
275
            String name)
276
            throws InitializeException, ProviderNotRegisteredException;
277

    
278
    /**
279
     * Returns an instance of {@link DataServerExplorer} given its parameters.
280
     *
281
     * @param name
282
     * @param parameters parameters used to instantiate and initialize the
283
     * {@link DataServerExplorer}.
284
     *
285
     * @return an instance of {@link DataServerExplorer}.
286
     *
287
     * @throws InitializeException
288
     *
289
     * @throws ProviderNotRegisteredException
290
     * @throws ValidateDataParametersException
291
     */
292
    public DataServerExplorer openServerExplorer(
293
            String name,
294
            DataServerExplorerParameters parameters)
295
            throws InitializeException, ProviderNotRegisteredException,
296
            ValidateDataParametersException;
297

    
298
    public DataServerExplorer openServerExplorer(
299
            String explorerName,
300
            Object... arguments)
301
        throws
302
            InitializeException,
303
            ProviderNotRegisteredException,
304
            ValidateDataParametersException;
305
    /**
306
     * @param parameters
307
     * @return
308
     * @throws org.gvsig.fmap.dal.exception.InitializeException
309
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
310
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
311
     * @deprecated see openServerExplorer
312
     */
313
    public DataServerExplorer createServerExplorer(
314
            DataServerExplorerParameters parameters)
315
            throws InitializeException, ProviderNotRegisteredException,
316
            ValidateDataParametersException;
317

    
318
    /**
319
     * @param parameters
320
     * @return
321
     * @throws org.gvsig.fmap.dal.exception.InitializeException
322
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
323
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
324
     * @deprecated see openStore
325
     */
326
    public DataStore createStore(DataStoreParameters parameters)
327
            throws InitializeException, ProviderNotRegisteredException,
328
            ValidateDataParametersException;
329

    
330
    /**
331
     * Returns a list of String containing the names of the available
332
     * DataServerExplorer providers.
333
     *
334
     * @return list of String containing the names of the available
335
     * DataServerExplorer providers.
336
     */
337
    public List<String> getExplorerProviders();
338

    
339
    /**
340
     * Creates an instance of Evaluator that represents the given expression.
341
     *
342
     * @param expression String containing a CQL expression.
343
     * @return instance of Evaluator representing the given expression.
344
     * @throws InitializeException
345
     * @deprecated use createFilter
346
     */
347
    public Evaluator createExpresion(String expression)
348
            throws InitializeException;
349

    
350
    /**
351
     * Creates an instance of Evaluator that represents the given expression.
352
     *
353
     * @param expression a Expression with the filter
354
     * @return instance of Evaluator representing the given expression.
355
     * @throws InitializeException
356
     * @deprecated use createFilter
357
     */
358
    public Evaluator createExpresion(Expression expression)
359
            throws InitializeException;
360

    
361
    /**
362
     * Creates an instance of Evaluator that represents the given expression.
363
     *
364
     * @param expression String containing a CQL expression.
365
     * @return instance of Evaluator representing the given expression.
366
     * @throws InitializeException
367
     */
368
    public Evaluator createFilter(String expression)
369
            throws InitializeException;
370

    
371
    /**
372
     * Creates an instance of Evaluator that represents the given expression.
373
     *
374
     * @param expression a Expression with the filter
375
     * @return instance of Evaluator representing the given expression.
376
     * @throws InitializeException
377
     */
378
    public Evaluator createFilter(Expression expression)
379
            throws InitializeException;
380

    
381
    /*
382
     * ====================================================================
383
     *
384
     * Index related services
385
     */
386
    /**
387
     * Returns a list of String containing the names of the available index
388
     * providers.
389
     *
390
     * @return list of strings with the names of the available index providers
391
     */
392
    public List<String> getFeatureIndexProviders();
393

    
394
    /**
395
     * Sets the default DataIndexProvider for the given data type.
396
     *
397
     * @param dataType one of the data types defined in {@link DataTypes}.
398
     * @param name Provider's name
399
     */
400
    public void setDefaultFeatureIndexProviderName(int dataType, String name);
401

    
402
    /**
403
     * Returns the default DataIndexProvider name, given a data type. Data types
404
     * are defined in {@link DataTypes}.
405
     *
406
     * @param dataType one of the constants in {@link DataTypes}.
407
     *
408
     * @return the name of the default {@link FeatureIndexProvider} if there is
409
     * anyone available for the given data type.
410
     */
411
    public String getDefaultFeatureIndexProviderName(int dataType);
412

    
413
    /**
414
     * Utility method to create the {@link DataStoreParameters} to create a
415
     * {@link FeatureStore} based on the {@link MemoryStoreProvider}.
416
     *
417
     * @param autoOrderAttributeName the name of the {@link Feature} attribute
418
     * to be used to order the store {@link Feature}s by default. Set to null if
419
     * you don't want any order by default
420
     * @return the parameters for the memory based store
421
     * @throws InitializeException if there is an error initializing the
422
     * parameters for the memory provider
423
     */
424
    public DataStoreParameters createMemoryStoreParameters(
425
            String autoOrderAttributeName) throws InitializeException;
426

    
427
    /**
428
     * Utility method to create the a {@link FeatureStore} based on the
429
     * {@link MemoryStoreProvider}.
430
     *
431
     * @param autoOrderAttributeName the name of the {@link Feature} attribute
432
     * to be used to order the store {@link Feature}s by default. Set to null if
433
     * you don't want any order by default
434
     * @return the the memory based store
435
     * @throws InitializeException if there is an error initializing the
436
     * parameters for the memory provider
437
     */
438
    public FeatureStore createMemoryStore(String autoOrderAttributeName)
439
            throws InitializeException;
440

    
441
    /**
442
     * Creates a {@link FeaturePagingHelper} to paginate data from a
443
     * {@link FeatureStore}.
444
     *
445
     * @param featureStore to get the {@link Feature}s from
446
     * @param pageSize the page size
447
     * @return a {@link FeaturePagingHelper}
448
     * @throws BaseException if there is an error creating the helper
449
     */
450
    public FeaturePagingHelper createFeaturePagingHelper(
451
            FeatureStore featureStore, int pageSize) throws BaseException;
452

    
453
    /**
454
     * Creates a {@link FeaturePagingHelper} to paginate data from a
455
     * {@link FeatureStore}.
456
     *
457
     * @param featureStore to get the {@link Feature}s from
458
     * @param featureQuery to filter and/or order the data
459
     * @param pageSize the page size
460
     * @return a {@link FeaturePagingHelper}
461
     * @throws BaseException if there is an error creating the helper
462
     */
463
    public FeaturePagingHelper createFeaturePagingHelper(
464
            FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
465
            throws BaseException;
466

    
467
    public void setOpenErrorHandler(OpenErrorHandler handler);
468

    
469
    public OpenErrorHandler getOpenErrorHandler();
470

    
471
    public DataStoreProviderFactory getStoreProviderFactory(String name);
472

    
473
    public EditableFeatureType createFeatureType();
474
    
475
    public EditableFeatureType createFeatureType(JsonObject json);
476

    
477
    public DataServerExplorerPool getDataServerExplorerPool();
478

    
479
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
480

    
481
    public void setResourcesLoader(ClassLoader loader);
482

    
483
    public void setResourcesLoader(File folder);
484

    
485
    /**
486
     * Return a list of the DataTypes supported for the type of the feature
487
     * attributes. The list is only informative.
488
     *
489
     * @return
490
     */
491
    public List<DataType> getDataTypes();
492

    
493
    public Register getStoreRegister();
494

    
495
    public Register getStoreProviderRegister();
496

    
497
    public Register getServerExplorerRegister();
498

    
499
    public Register getFeatureIndexRegister();
500

    
501
    /**
502
     * Creates a default ExpressionBuilder.
503
     *
504
     * This ExpressionBuilder is not dependent on a data source,
505
     * and is not advisable to use it.
506
     *
507
     * @return the ExpressionBuilder
508
     * @deprecated use ExpressionEvaluatorManager.createExpressionBuilder()
509
     */
510
    public ExpressionBuilder createExpressionBuilder();
511

    
512
    /**
513
         * Returns a list of String containing the names of the available cache providers.
514
         *
515
         * @return
516
         *                 list of strings with the names of the available cache providers
517
         */
518
    public List getFeatureCacheProviders();
519

    
520
        /**
521
         * Returns an instance of {@link DataServerExplorerParameters} corresponding
522
         * to the given name used by the cache to create a store to save the
523
         * retrieved data.
524
         *
525
         * @param name
526
         *            name of a registered feature cache provider
527
     * @return 
528
         *
529
         * @throws InitializeException
530
         *             if parameter initialization causes an error.
531
         *
532
         * @throws ProviderNotRegisteredException
533
         *             if could not find a cache provider by the given name.
534
         *
535
         */
536
        public DynObject createCacheParameters(String name)
537
                        throws InitializeException, ProviderNotRegisteredException;
538

    
539
    /**
540
     * @param providerName
541
     * @param params
542
     * @param overwrite
543
     * @throws DataException
544
     */
545
    public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException;
546

    
547
    public FeatureSymbolTable createFeatureSymbolTable();
548

    
549
    public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor();
550
    
551
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
552

    
553
    public void registerDataProfile(DataProfile profile);
554

    
555
    public List<DataProfile> getDataProfiles();
556

    
557
    public DataProfile getDataProfile(String name);
558
    
559
    public StoresRepository getStoresRepository();
560
    
561
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
562
    
563
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
564

    
565
    public void removeDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
566

    
567
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.DatabaseWorkspaceListener listener);
568
    
569
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
570
    
571
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
572

    
573
    public void writeDALResource(ResourcesStorage resources, DataStore store);
574
    
575
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
576

    
577
    /**
578
     * Return a 35-40 characters unique identifier.
579
     * 
580
     * @return the unique identifier
581
     */
582
    public String createUniqueID();
583

    
584
    public void clearAvailableValuesCache();
585

    
586
    public DALExpressionBuilder createDALExpressionBuilder();
587
    
588
    public boolean isTheOldRasterRegistered();
589
    
590
    public void addStoreObserver(Observer observer);
591
    
592
    public void removeStoreObserver(Observer observer);
593

    
594
    public String getServerExplorerFromStore(String name);
595
    
596
    public void setMaxSizeForSmallFeatureSelection(long size);
597

    
598
    public long getMaxSizeForSmallFeatureSelection();
599
    
600
    public void registerLargeMap(Factory factory);
601
    
602
    public void registerLargeSet(Factory factory);
603
    
604
    public Map createLargeMap();
605
    
606
    public Set createLargeSet();
607
    
608
    public DataTransaction createTransaction();
609
    
610
    public void putFeaturesInClipboard(FeatureSet set);
611
    
612
    public List<EditableFeature> getFeaturesFromClipboard(
613
            FeatureStore store, 
614
            Predicate<FeatureAttributeDescriptor> attrFilter
615
    ) throws DataException;
616
    
617
}