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

History | View | Annotate | Download (22.8 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(String providerName, DataStoreParameters 
209
            parameters, boolean ignoreDALResource) 
210
            throws InitializeException, ProviderNotRegisteredException, 
211
            ValidateDataParametersException;
212

    
213
    public DataStore openStore(
214
            String providerName,
215
            Object... arguments)
216
        throws
217
            InitializeException,
218
            ProviderNotRegisteredException,
219
            ValidateDataParametersException;
220

    
221
    public DataStore openStore(DynStruct struct)
222
            throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException;
223

    
224
    /**
225
     * Create a new physical store
226
     *
227
     * @param explorer
228
     * @param provider
229
     * @param parameters
230
     * @param overwrite
231
     *
232
     * @throws InitializeException
233
     * @throws ProviderNotRegisteredException
234
     * @throws ValidateDataParametersException
235
     */
236
    public void newStore(String explorer, String provider, NewDataStoreParameters parameters, boolean overwrite)
237
            throws InitializeException, ProviderNotRegisteredException,
238
            ValidateDataParametersException;
239

    
240
    public void newStore(String provider, NewDataStoreParameters parameters, boolean overwrite)
241
            throws InitializeException, ProviderNotRegisteredException,
242
            ValidateDataParametersException;
243

    
244
    /**
245
     * Returns a list of Strings containing the names of all available DataStore
246
     * providers.
247
     *
248
     * @return list of String containing available DataStore provider names
249
     */
250
    public List getStoreProviders();
251

    
252
    /**
253
     * Returns a list of Strings containing the names of all available DataStore
254
     * providers for an explorer.
255
     *
256
     * @param name
257
     * @return
258
     */
259
    public List<String> getStoreProviders(String name);
260

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

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

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

    
324
    /**
325
     * @param parameters
326
     * @return
327
     * @throws org.gvsig.fmap.dal.exception.InitializeException
328
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
329
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
330
     * @deprecated see openStore
331
     */
332
    public DataStore createStore(DataStoreParameters parameters)
333
            throws InitializeException, ProviderNotRegisteredException,
334
            ValidateDataParametersException;
335

    
336
    /**
337
     * Returns a list of String containing the names of the available
338
     * DataServerExplorer providers.
339
     *
340
     * @return list of String containing the names of the available
341
     * DataServerExplorer providers.
342
     */
343
    public List<String> getExplorerProviders();
344

    
345
    /**
346
     * Creates an instance of Evaluator that represents the given expression.
347
     *
348
     * @param expression String containing a CQL expression.
349
     * @return instance of Evaluator representing the given expression.
350
     * @throws InitializeException
351
     * @deprecated use createFilter
352
     */
353
    public Evaluator createExpresion(String expression)
354
            throws InitializeException;
355

    
356
    /**
357
     * Creates an instance of Evaluator that represents the given expression.
358
     *
359
     * @param expression a Expression with the filter
360
     * @return instance of Evaluator representing the given expression.
361
     * @throws InitializeException
362
     * @deprecated use createFilter
363
     */
364
    public Evaluator createExpresion(Expression expression)
365
            throws InitializeException;
366

    
367
    /**
368
     * Creates an instance of Evaluator that represents the given expression.
369
     *
370
     * @param expression String containing a CQL expression.
371
     * @return instance of Evaluator representing the given expression.
372
     * @throws InitializeException
373
     */
374
    public Evaluator createFilter(String expression)
375
            throws InitializeException;
376

    
377
    /**
378
     * Creates an instance of Evaluator that represents the given expression.
379
     *
380
     * @param expression a Expression with the filter
381
     * @return instance of Evaluator representing the given expression.
382
     * @throws InitializeException
383
     */
384
    public Evaluator createFilter(Expression expression)
385
            throws InitializeException;
386

    
387
    /*
388
     * ====================================================================
389
     *
390
     * Index related services
391
     */
392
    /**
393
     * Returns a list of String containing the names of the available index
394
     * providers.
395
     *
396
     * @return list of strings with the names of the available index providers
397
     */
398
    public List<String> getFeatureIndexProviders();
399

    
400
    /**
401
     * Sets the default DataIndexProvider for the given data type.
402
     *
403
     * @param dataType one of the data types defined in {@link DataTypes}.
404
     * @param name Provider's name
405
     */
406
    public void setDefaultFeatureIndexProviderName(int dataType, String name);
407

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

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

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

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

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

    
473
    public void setOpenErrorHandler(OpenErrorHandler handler);
474

    
475
    public OpenErrorHandler getOpenErrorHandler();
476

    
477
    public DataStoreProviderFactory getStoreProviderFactory(String name);
478

    
479
    public EditableFeatureType createFeatureType();
480
    
481
    public EditableFeatureType createFeatureType(JsonObject json);
482

    
483
    public DataServerExplorerPool getDataServerExplorerPool();
484

    
485
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
486

    
487
    public void setResourcesLoader(ClassLoader loader);
488

    
489
    public void setResourcesLoader(File folder);
490

    
491
    /**
492
     * Return a list of the DataTypes supported for the type of the feature
493
     * attributes. The list is only informative.
494
     *
495
     * @return
496
     */
497
    public List<DataType> getDataTypes();
498

    
499
    public Register getStoreRegister();
500

    
501
    public Register getStoreProviderRegister();
502

    
503
    public Register getServerExplorerRegister();
504

    
505
    public Register getFeatureIndexRegister();
506

    
507
    /**
508
     * Creates a default ExpressionBuilder.
509
     *
510
     * This ExpressionBuilder is not dependent on a data source,
511
     * and is not advisable to use it.
512
     *
513
     * @return the ExpressionBuilder
514
     * @deprecated use ExpressionEvaluatorManager.createExpressionBuilder()
515
     */
516
    public ExpressionBuilder createExpressionBuilder();
517

    
518
    /**
519
         * Returns a list of String containing the names of the available cache providers.
520
         *
521
         * @return
522
         *                 list of strings with the names of the available cache providers
523
         */
524
    public List getFeatureCacheProviders();
525

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

    
545
    /**
546
     * @param providerName
547
     * @param params
548
     * @param overwrite
549
     * @throws DataException
550
     */
551
    public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException;
552

    
553
    public FeatureSymbolTable createFeatureSymbolTable();
554
    
555
    public FeatureSymbolTable createFeatureSymbolTable(String name);
556

    
557
    public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor(String name, int type);
558
    
559
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
560

    
561
    public void registerDataProfile(DataProfile profile);
562

    
563
    public List<DataProfile> getDataProfiles();
564

    
565
    public DataProfile getDataProfile(String name);
566
    
567
    public StoresRepository getStoresRepository();
568
    
569
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
570
    
571
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
572

    
573
    public void removeDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
574

    
575
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.DatabaseWorkspaceListener listener);
576
    
577
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
578
    
579
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
580

    
581
    public void writeDALResource(ResourcesStorage resources, DataStore store);
582
    
583
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
584

    
585
    /**
586
     * Return a 35-40 characters unique identifier.
587
     * 
588
     * @return the unique identifier
589
     */
590
    public String createUniqueID();
591

    
592
    public void clearAvailableValuesCache();
593

    
594
    public DALExpressionBuilder createDALExpressionBuilder();
595
    
596
    public boolean isTheOldRasterRegistered();
597
    
598
    public void addStoreObserver(Observer observer);
599
    
600
    public void removeStoreObserver(Observer observer);
601

    
602
    public String getServerExplorerFromStore(String name);
603
    
604
    public void setMaxSizeForSmallFeatureSelection(long size);
605

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

    
625
    public FeatureRuleExpression createFeatureRuleExpression();
626
}