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 @ 45739

History | View | Annotate | Download (22.6 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.FeatureRuleExpression;
61
import org.gvsig.fmap.dal.feature.FeatureSet;
62
import org.gvsig.tools.observer.Observer;
63
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
64
import org.gvsig.tools.swing.api.ToolsSwingLocator;
65
import org.gvsig.tools.util.Factory;
66

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
468
    public void setOpenErrorHandler(OpenErrorHandler handler);
469

    
470
    public OpenErrorHandler getOpenErrorHandler();
471

    
472
    public DataStoreProviderFactory getStoreProviderFactory(String name);
473

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

    
478
    public DataServerExplorerPool getDataServerExplorerPool();
479

    
480
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
481

    
482
    public void setResourcesLoader(ClassLoader loader);
483

    
484
    public void setResourcesLoader(File folder);
485

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

    
494
    public Register getStoreRegister();
495

    
496
    public Register getStoreProviderRegister();
497

    
498
    public Register getServerExplorerRegister();
499

    
500
    public Register getFeatureIndexRegister();
501

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

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

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

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

    
548
    public FeatureSymbolTable createFeatureSymbolTable();
549
    
550
    public FeatureSymbolTable createFeatureSymbolTable(String name);
551

    
552
    public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor();
553
    
554
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
555

    
556
    public void registerDataProfile(DataProfile profile);
557

    
558
    public List<DataProfile> getDataProfiles();
559

    
560
    public DataProfile getDataProfile(String name);
561
    
562
    public StoresRepository getStoresRepository();
563
    
564
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
565
    
566
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
567

    
568
    public void removeDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
569

    
570
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.DatabaseWorkspaceListener listener);
571
    
572
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
573
    
574
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
575

    
576
    public void writeDALResource(ResourcesStorage resources, DataStore store);
577
    
578
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
579

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

    
587
    public void clearAvailableValuesCache();
588

    
589
    public DALExpressionBuilder createDALExpressionBuilder();
590
    
591
    public boolean isTheOldRasterRegistered();
592
    
593
    public void addStoreObserver(Observer observer);
594
    
595
    public void removeStoreObserver(Observer observer);
596

    
597
    public String getServerExplorerFromStore(String name);
598
    
599
    public void setMaxSizeForSmallFeatureSelection(long size);
600

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

    
620
    public FeatureRuleExpression createFeatureRuleExpression();
621
}