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

History | View | Annotate | Download (23 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.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 int RECOMENDED_SIZE_FOR_CLOB = 4096;
80
    
81
    public static final String CREATE_STORE_AUTHORIZATION = "dal-create-store";
82
    public static final String READ_STORE_AUTHORIZATION = "dal-read-store";
83
    public static final String WRITE_STORE_AUTHORIZATION = "dal-write-store";
84

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

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

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

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

    
149
    public DataStoreParameters createStoreParameters(byte[] data);
150

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

    
167
    public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException;
168

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

    
183
    public NewDataStoreParameters createNewStoreParameters(String provider)
184
            throws InitializeException, ProviderNotRegisteredException;
185

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

    
207
    public DataStore openStore(String provider, DataStoreParameters parameters)
208
            throws InitializeException, ProviderNotRegisteredException,
209
            ValidateDataParametersException;
210

    
211
    public DataStore openStore(String providerName, DataStoreParameters 
212
            parameters, boolean ignoreDALResource) 
213
            throws InitializeException, ProviderNotRegisteredException, 
214
            ValidateDataParametersException;
215

    
216
    public DataStore openStore(
217
            String providerName,
218
            Object... arguments)
219
        throws
220
            InitializeException,
221
            ProviderNotRegisteredException,
222
            ValidateDataParametersException;
223

    
224
    public DataStore openStore(DynStruct struct)
225
            throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException;
226

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

    
243
    public void newStore(String provider, NewDataStoreParameters parameters, boolean overwrite)
244
            throws InitializeException, ProviderNotRegisteredException,
245
            ValidateDataParametersException;
246

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
476
    public void setOpenErrorHandler(OpenErrorHandler handler);
477

    
478
    public OpenErrorHandler getOpenErrorHandler();
479

    
480
    public DataStoreProviderFactory getStoreProviderFactory(String name);
481

    
482
    public EditableFeatureType createFeatureType();
483
    
484
    public EditableFeatureType createFeatureType(JsonObject json);
485

    
486
    public DataServerExplorerPool getDataServerExplorerPool();
487

    
488
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
489

    
490
    public void setResourcesLoader(ClassLoader loader);
491

    
492
    public void setResourcesLoader(File folder);
493

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

    
502
    public Register getStoreRegister();
503

    
504
    public Register getStoreProviderRegister();
505

    
506
    public Register getServerExplorerRegister();
507

    
508
    public Register getFeatureIndexRegister();
509

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

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

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

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

    
556
    public FeatureSymbolTable createFeatureSymbolTable();
557
    
558
    public FeatureSymbolTable createFeatureSymbolTable(String name);
559

    
560
    public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor(String name, int type);
561
    
562
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
563

    
564
    public void registerDataProfile(DataProfile profile);
565

    
566
    public List<DataProfile> getDataProfiles();
567

    
568
    public DataProfile getDataProfile(String name);
569
    
570
    public StoresRepository getStoresRepository();
571
    
572
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
573
    
574
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
575

    
576
    public void removeDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
577

    
578
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.DatabaseWorkspaceListener listener);
579
    
580
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
581
    
582
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
583

    
584
    public void writeDALResource(ResourcesStorage resources, DataStore store);
585
    
586
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
587

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

    
595
    public void clearAvailableValuesCache();
596

    
597
    public DALExpressionBuilder createDALExpressionBuilder();
598
    
599
    public boolean isTheOldRasterRegistered();
600
    
601
    public void addStoreObserver(Observer observer);
602
    
603
    public void removeStoreObserver(Observer observer);
604

    
605
    public String getServerExplorerFromStore(String name);
606
    
607
    public void setMaxSizeForSmallFeatureSelection(long size);
608

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

    
628
    public FeatureRuleExpression createFeatureRuleExpression();
629
}