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

History | View | Annotate | Download (21.7 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 javax.json.JsonObject;
30
import org.gvsig.expressionevaluator.Expression;
31
import org.gvsig.expressionevaluator.ExpressionBuilder;
32

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

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

    
73
    public static final String CREATE_STORE_AUTHORIZATION = "dal-create-store";
74
    public static final String READ_STORE_AUTHORIZATION = "dal-read-store";
75
    public static final String WRITE_STORE_AUTHORIZATION = "dal-write-store";
76

    
77
    public static final String DAL_SYMBOL_TABLE = "DAL.SymbolTable.Global";
78
//    public static final String DAL_SYMBOL_TABLE_FEATURE = "DAL.SymbolTable.Feature";
79

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

    
101
    public static final int USE_LABELS_YES = 0;
102
    public static final int USE_LABELS_NO = 1;
103
    public static final int USE_LABELS_BOTH = 2;
104
    
105
    /**
106
     * 
107
     * Returns the default DAL's temporary directory
108
     *
109
     * @return Temporary directory name
110
     * @deprecated use FoldersManager of org.gvsig.tools
111
     */
112
    public String getTemporaryDirectory();
113

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

    
139
    public DataStoreParameters createStoreParameters(byte[] data);
140

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

    
157
    public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException;
158

    
159
    /**
160
     * Creates, initializes and returns an instance of NewDataStoreParameters
161
     * given the name with which their provider is registered.
162
     *
163
     * @param explorer
164
     * @param provider
165
     * @return
166
     *
167
     * @throws InitializeException
168
     * @throws ProviderNotRegisteredException
169
     */
170
    public NewDataStoreParameters createNewStoreParameters(String explorer, String provider)
171
            throws InitializeException, ProviderNotRegisteredException;
172

    
173
    public NewDataStoreParameters createNewStoreParameters(String provider)
174
            throws InitializeException, ProviderNotRegisteredException;
175

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

    
197
    public DataStore openStore(String provider, DataStoreParameters parameters)
198
            throws InitializeException, ProviderNotRegisteredException,
199
            ValidateDataParametersException;
200

    
201
    public DataStore openStore(
202
            String providerName,
203
            Object... arguments)
204
        throws
205
            InitializeException,
206
            ProviderNotRegisteredException,
207
            ValidateDataParametersException;
208

    
209
    public DataStore openStore(DynStruct struct)
210
            throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException;
211

    
212
    /**
213
     * Create a new physical store
214
     *
215
     * @param explorer
216
     * @param provider
217
     * @param parameters
218
     * @param overwrite
219
     *
220
     * @throws InitializeException
221
     * @throws ProviderNotRegisteredException
222
     * @throws ValidateDataParametersException
223
     */
224
    public void newStore(String explorer, String provider, NewDataStoreParameters parameters, boolean overwrite)
225
            throws InitializeException, ProviderNotRegisteredException,
226
            ValidateDataParametersException;
227

    
228
    public void newStore(String provider, NewDataStoreParameters parameters, boolean overwrite)
229
            throws InitializeException, ProviderNotRegisteredException,
230
            ValidateDataParametersException;
231

    
232
    /**
233
     * Returns a list of Strings containing the names of all available DataStore
234
     * providers.
235
     *
236
     * @return list of String containing available DataStore provider names
237
     */
238
    public List getStoreProviders();
239

    
240
    /**
241
     * Returns a list of Strings containing the names of all available DataStore
242
     * providers for an explorer.
243
     *
244
     * @param name
245
     * @return
246
     */
247
    public List<String> getStoreProviders(String name);
248

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

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

    
292
    public DataServerExplorer openServerExplorer(
293
            String explorerName,
294
            Object... arguments)
295
        throws
296
            InitializeException,
297
            ProviderNotRegisteredException,
298
            ValidateDataParametersException;
299
    /**
300
     * @param parameters
301
     * @return
302
     * @throws org.gvsig.fmap.dal.exception.InitializeException
303
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
304
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
305
     * @deprecated see openServerExplorer
306
     */
307
    public DataServerExplorer createServerExplorer(
308
            DataServerExplorerParameters parameters)
309
            throws InitializeException, ProviderNotRegisteredException,
310
            ValidateDataParametersException;
311

    
312
    /**
313
     * @param parameters
314
     * @return
315
     * @throws org.gvsig.fmap.dal.exception.InitializeException
316
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
317
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
318
     * @deprecated see openStore
319
     */
320
    public DataStore createStore(DataStoreParameters parameters)
321
            throws InitializeException, ProviderNotRegisteredException,
322
            ValidateDataParametersException;
323

    
324
    /**
325
     * Returns a list of String containing the names of the available
326
     * DataServerExplorer providers.
327
     *
328
     * @return list of String containing the names of the available
329
     * DataServerExplorer providers.
330
     */
331
    public List<String> getExplorerProviders();
332

    
333
    /**
334
     * Creates an instance of Evaluator that represents the given expression.
335
     *
336
     * @param expression String containing a CQL expression.
337
     * @return instance of Evaluator representing the given expression.
338
     * @throws InitializeException
339
     * @deprecated use createFilter
340
     */
341
    public Evaluator createExpresion(String expression)
342
            throws InitializeException;
343

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

    
355
    /**
356
     * Creates an instance of Evaluator that represents the given expression.
357
     *
358
     * @param expression String containing a CQL expression.
359
     * @return instance of Evaluator representing the given expression.
360
     * @throws InitializeException
361
     */
362
    public Evaluator createFilter(String expression)
363
            throws InitializeException;
364

    
365
    /**
366
     * Creates an instance of Evaluator that represents the given expression.
367
     *
368
     * @param expression a Expression with the filter
369
     * @return instance of Evaluator representing the given expression.
370
     * @throws InitializeException
371
     */
372
    public Evaluator createFilter(Expression expression)
373
            throws InitializeException;
374

    
375
    /*
376
     * ====================================================================
377
     *
378
     * Index related services
379
     */
380
    /**
381
     * Returns a list of String containing the names of the available index
382
     * providers.
383
     *
384
     * @return list of strings with the names of the available index providers
385
     */
386
    public List<String> getFeatureIndexProviders();
387

    
388
    /**
389
     * Sets the default DataIndexProvider for the given data type.
390
     *
391
     * @param dataType one of the data types defined in {@link DataTypes}.
392
     * @param name Provider's name
393
     */
394
    public void setDefaultFeatureIndexProviderName(int dataType, String name);
395

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

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

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

    
435
    /**
436
     * Creates a {@link FeaturePagingHelper} to paginate data from a
437
     * {@link FeatureStore}.
438
     *
439
     * @param featureStore to get the {@link Feature}s from
440
     * @param pageSize the page size
441
     * @return a {@link FeaturePagingHelper}
442
     * @throws BaseException if there is an error creating the helper
443
     */
444
    public FeaturePagingHelper createFeaturePagingHelper(
445
            FeatureStore featureStore, int pageSize) throws BaseException;
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 featureQuery to filter and/or order the data
453
     * @param pageSize the page size
454
     * @return a {@link FeaturePagingHelper}
455
     * @throws BaseException if there is an error creating the helper
456
     */
457
    public FeaturePagingHelper createFeaturePagingHelper(
458
            FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
459
            throws BaseException;
460

    
461
    public void setOpenErrorHandler(OpenErrorHandler handler);
462

    
463
    public OpenErrorHandler getOpenErrorHandler();
464

    
465
    public DataStoreProviderFactory getStoreProviderFactory(String name);
466

    
467
    public EditableFeatureType createFeatureType();
468
    
469
    public EditableFeatureType createFeatureType(JsonObject json);
470

    
471
    public DataServerExplorerPool getDataServerExplorerPool();
472

    
473
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
474

    
475
    public void setResourcesLoader(ClassLoader loader);
476

    
477
    public void setResourcesLoader(File folder);
478

    
479
    /**
480
     * Return a list of the DataTypes supported for the type of the feature
481
     * attributes. The list is only informative.
482
     *
483
     * @return
484
     */
485
    public List<DataType> getDataTypes();
486

    
487
    public Register getStoreRegister();
488

    
489
    public Register getStoreProviderRegister();
490

    
491
    public Register getServerExplorerRegister();
492

    
493
    public Register getFeatureIndexRegister();
494

    
495
    /**
496
     * Creates a default ExpressionBuilder.
497
     *
498
     * This ExpressionBuilder is not dependent on a data source,
499
     * and is not advisable to use it.
500
     *
501
     * @return the ExpressionBuilder
502
     * @deprecated use ExpressionEvaluatorManager.createExpressionBuilder()
503
     */
504
    public ExpressionBuilder createExpressionBuilder();
505

    
506
    /**
507
         * Returns a list of String containing the names of the available cache providers.
508
         *
509
         * @return
510
         *                 list of strings with the names of the available cache providers
511
         */
512
    public List getFeatureCacheProviders();
513

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

    
533
    /**
534
     * @param providerName
535
     * @param params
536
     * @param overwrite
537
     * @throws DataException
538
     */
539
    public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException;
540

    
541
    public FeatureSymbolTable createFeatureSymbolTable();
542

    
543
    public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor();
544
    
545
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
546

    
547
    public void registerDataProfile(DataProfile profile);
548

    
549
    public List<DataProfile> getDataProfiles();
550

    
551
    public DataProfile getDataProfile(String name);
552
    
553
    public StoresRepository getStoresRepository();
554
    
555
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
556
    
557
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
558

    
559
    public void removeDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
560

    
561
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.DatabaseWorkspaceListener listener);
562
    
563
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
564
    
565
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
566

    
567
    public void writeDALResource(ResourcesStorage resources, DataStore store);
568
    
569
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
570

    
571
    /**
572
     * Return a 35-40 characters unique identifier.
573
     * 
574
     * @return the unique identifier
575
     */
576
    public String createUniqueID();
577

    
578
    public void clearAvailableValuesCache();
579

    
580
    public DALExpressionBuilder createDALExpressionBuilder();
581
    
582
    public boolean isTheOldRasterRegistered();
583
    
584
    public void addStoreObserver(Observer observer);
585
    
586
    public void removeStoreObserver(Observer observer);
587

    
588
    public String getServerExplorerFromStore(String name);
589
    
590
    public void setMaxSizeForSmallFeatureSelection(long size);
591

    
592
    public long getMaxSizeForSmallFeatureSelection();
593
    
594
    public Map createLargeMap();
595
    
596
    public Set createLargeSet();
597
}