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

History | View | Annotate | Download (19.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 org.gvsig.expressionevaluator.Expression;
28
import org.gvsig.expressionevaluator.ExpressionBuilder;
29

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

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

    
67
    public static final String CREATE_STORE_AUTHORIZATION = "dal-create-store";
68
    public static final String READ_STORE_AUTHORIZATION = "dal-read-store";
69
    public static final String WRITE_STORE_AUTHORIZATION = "dal-write-store";
70

    
71
    public static final String DAL_SYMBOL_TABLE = "DAL.SymbolTable.Global";
72
    public static final String DAL_SYMBOL_TABLE_FEATURE = "DAL.SymbolTable.Feature";
73

    
74
    public static final String FUNCTION_FOREING_VALUE = "FOREING_VALUE";
75
    public static final String FUNCTION_SELECT = "SELECT";
76
    public static final String FUNCTION_SELECT_COUNT = "SELECT_COUNT";
77
    public static final String FUNCTION_EXISTS = "EXISTS";
78
    public static final String FUNCTION_CURRENT_ROW = "CURRENT_ROW";
79
    public static final String FUNCTION_CURRENT_STORE = "CURRENT_STORE";
80
    public static final String FUNCTION_ISSELECTED_CURRENT_ROW = "ISSELECTED_CURRENT_ROW";
81
    
82
    public static final String DAL_PREFERRED_COLUMNS = "DAL.Preferred.Columns";
83
    
84
    public static final String DAL_USE_LABELS = "DAL.useLabels";
85
    public static final int USE_LABELS_YES = 0;
86
    public static final int USE_LABELS_NO = 1;
87
    public static final int USE_LABELS_BOTH = 2;
88
    
89
    /**
90
     * 
91
     * Returns the default DAL's temporary directory
92
     *
93
     * @return Temporary directory name
94
     * @deprecated use FoldersManager of org.gvsig.tools
95
     */
96
    public String getTemporaryDirectory();
97

    
98
    /*
99
     * ====================================================================
100
     *
101
     * Store related services
102
     */
103
    /**
104
     * Creates, initializes and returns an instance of DataStoreParameters given
105
     * the name with which their provider is registered.
106
     *
107
     * @param name provider name
108
     * @return the data store parameters
109
     *
110
     * @throws ProviderNotRegisteredException if the memory provider is not
111
     * registered
112
     * @throws InitializeException if there is an error initializing the
113
     * parameters for the memory provider
114
     *
115
     */
116
    public DataStoreParameters createStoreParameters(String name, Object... arguments)
117
            throws InitializeException, ProviderNotRegisteredException;
118

    
119
    public DataStoreParameters createStoreParameters(byte[] data);
120

    
121
    /**
122
     * Creates, initializes and fill an instance of DataStoreParameters from the
123
     * tags of the DynStruct passed as parameter.
124
     *
125
     * @param struct structure from which tags were created ths parameters.
126
     * @return the data store parameters
127
     *
128
     * @throws ProviderNotRegisteredException if the memory provider is not
129
     * registered
130
     * @throws InitializeException if there is an error initializing the
131
     * parameters for the memory provider
132
     *
133
     */
134
    public DataStoreParameters createStoreParameters(DynStruct struct)
135
            throws InitializeException, ProviderNotRegisteredException;
136

    
137
    public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException;
138

    
139
    /**
140
     * Creates, initializes and returns an instance of NewDataStoreParameters
141
     * given the name with which their provider is registered.
142
     *
143
     * @param explorer
144
     * @param provider
145
     * @return
146
     *
147
     * @throws InitializeException
148
     * @throws ProviderNotRegisteredException
149
     */
150
    public NewDataStoreParameters createNewStoreParameters(String explorer, String provider)
151
            throws InitializeException, ProviderNotRegisteredException;
152

    
153
    /**
154
     *
155
     * Creates, initializes and returns an instance of DataStore given the
156
     * DataStoreParameters.
157
     *
158
     * @param provider
159
     * @param parameters parameters used to instantiate and initialize the
160
     * DataStore
161
     * @return
162
     *
163
     * @throws ProviderNotRegisteredException if the memory provider is not
164
     * registered
165
     * @throws InitializeException if there is an error initializing the
166
     * parameters for the memory provider
167
     * @throws ValidateDataParametersException if the parameters to open the
168
     * memory based store are not valid
169
     */
170
    public DataStore openStore(String provider, DynObject parameters)
171
            throws InitializeException, ProviderNotRegisteredException,
172
            ValidateDataParametersException;
173

    
174
    public DataStore openStore(String provider, DataStoreParameters parameters)
175
            throws InitializeException, ProviderNotRegisteredException,
176
            ValidateDataParametersException;
177

    
178
    public DataStore openStore(
179
            String providerName,
180
            Object... arguments)
181
        throws
182
            InitializeException,
183
            ProviderNotRegisteredException,
184
            ValidateDataParametersException;
185

    
186
    public DataStore openStore(DynStruct struct)
187
            throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException;
188

    
189
    /**
190
     * Create a new physical store
191
     *
192
     * @param explorer
193
     * @param provider
194
     * @param parameters
195
     * @param overwrite
196
     *
197
     * @throws InitializeException
198
     * @throws ProviderNotRegisteredException
199
     * @throws ValidateDataParametersException
200
     */
201
    public void newStore(String explorer, String provider, NewDataStoreParameters parameters, boolean overwrite)
202
            throws InitializeException, ProviderNotRegisteredException,
203
            ValidateDataParametersException;
204

    
205
    /**
206
     * Returns a list of Strings containing the names of all available DataStore
207
     * providers.
208
     *
209
     * @return list of String containing available DataStore provider names
210
     */
211
    public List getStoreProviders();
212

    
213
    /**
214
     * Returns a list of Strings containing the names of all available DataStore
215
     * providers for an explorer.
216
     *
217
     * @param name
218
     * @return
219
     */
220
    public List<String> getStoreProviders(String name);
221

    
222
    /*
223
     * ====================================================================
224
     *
225
     * Explorer related services
226
     */
227
    /**
228
     * Returns an instance of {@link DataServerExplorerParameters} corresponding
229
     * to the given name.
230
     *
231
     * @param name name of a registered server explorer provider
232
     * @return
233
     *
234
     * @throws InitializeException if parameter initialization causes an error.
235
     *
236
     * @throws ProviderNotRegisteredException if could not find a provider by
237
     * the given name.
238
     *
239
     *
240
     */
241
    public DataServerExplorerParameters createServerExplorerParameters(
242
            String name)
243
            throws InitializeException, ProviderNotRegisteredException;
244

    
245
    /**
246
     * Returns an instance of {@link DataServerExplorer} given its parameters.
247
     *
248
     * @param name
249
     * @param parameters parameters used to instantiate and initialize the
250
     * {@link DataServerExplorer}.
251
     *
252
     * @return an instance of {@link DataServerExplorer}.
253
     *
254
     * @throws InitializeException
255
     *
256
     * @throws ProviderNotRegisteredException
257
     * @throws ValidateDataParametersException
258
     */
259
    public DataServerExplorer openServerExplorer(
260
            String name,
261
            DataServerExplorerParameters parameters)
262
            throws InitializeException, ProviderNotRegisteredException,
263
            ValidateDataParametersException;
264

    
265
    public DataServerExplorer openServerExplorer(
266
            String explorerName,
267
            Object... arguments)
268
        throws
269
            InitializeException,
270
            ProviderNotRegisteredException,
271
            ValidateDataParametersException;
272
    /**
273
     * @param parameters
274
     * @return
275
     * @throws org.gvsig.fmap.dal.exception.InitializeException
276
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
277
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
278
     * @deprecated see openServerExplorer
279
     */
280
    public DataServerExplorer createServerExplorer(
281
            DataServerExplorerParameters parameters)
282
            throws InitializeException, ProviderNotRegisteredException,
283
            ValidateDataParametersException;
284

    
285
    /**
286
     * @param parameters
287
     * @return
288
     * @throws org.gvsig.fmap.dal.exception.InitializeException
289
     * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
290
     * @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
291
     * @deprecated see openStore
292
     */
293
    public DataStore createStore(DataStoreParameters parameters)
294
            throws InitializeException, ProviderNotRegisteredException,
295
            ValidateDataParametersException;
296

    
297
    /**
298
     * Returns a list of String containing the names of the available
299
     * DataServerExplorer providers.
300
     *
301
     * @return list of String containing the names of the available
302
     * DataServerExplorer providers.
303
     */
304
    public List<String> getExplorerProviders();
305

    
306
    /**
307
     * Creates an instance of Evaluator that represents the given expression.
308
     *
309
     * @param expression String containing a CQL expression.
310
     * @return instance of Evaluator representing the given expression.
311
     * @throws InitializeException
312
     * @deprecated use createFilter
313
     */
314
    public Evaluator createExpresion(String expression)
315
            throws InitializeException;
316

    
317
    /**
318
     * Creates an instance of Evaluator that represents the given expression.
319
     *
320
     * @param expression a Expression with the filter
321
     * @return instance of Evaluator representing the given expression.
322
     * @throws InitializeException
323
     * @deprecated use createFilter
324
     */
325
    public Evaluator createExpresion(Expression expression)
326
            throws InitializeException;
327

    
328
    /**
329
     * Creates an instance of Evaluator that represents the given expression.
330
     *
331
     * @param expression String containing a CQL expression.
332
     * @return instance of Evaluator representing the given expression.
333
     * @throws InitializeException
334
     */
335
    public Evaluator createFilter(String expression)
336
            throws InitializeException;
337

    
338
    /**
339
     * Creates an instance of Evaluator that represents the given expression.
340
     *
341
     * @param expression a Expression with the filter
342
     * @return instance of Evaluator representing the given expression.
343
     * @throws InitializeException
344
     */
345
    public Evaluator createFilter(Expression expression)
346
            throws InitializeException;
347

    
348
    /*
349
     * ====================================================================
350
     *
351
     * Index related services
352
     */
353
    /**
354
     * Returns a list of String containing the names of the available index
355
     * providers.
356
     *
357
     * @return list of strings with the names of the available index providers
358
     */
359
    public List<String> getFeatureIndexProviders();
360

    
361
    /**
362
     * Sets the default DataIndexProvider for the given data type.
363
     *
364
     * @param dataType one of the data types defined in {@link DataTypes}.
365
     * @param name Provider's name
366
     */
367
    public void setDefaultFeatureIndexProviderName(int dataType, String name);
368

    
369
    /**
370
     * Returns the default DataIndexProvider name, given a data type. Data types
371
     * are defined in {@link DataTypes}.
372
     *
373
     * @param dataType one of the constants in {@link DataTypes}.
374
     *
375
     * @return the name of the default {@link FeatureIndexProvider} if there is
376
     * anyone available for the given data type.
377
     */
378
    public String getDefaultFeatureIndexProviderName(int dataType);
379

    
380
    /**
381
     * Utility method to create the {@link DataStoreParameters} to create a
382
     * {@link FeatureStore} based on the {@link MemoryStoreProvider}.
383
     *
384
     * @param autoOrderAttributeName the name of the {@link Feature} attribute
385
     * to be used to order the store {@link Feature}s by default. Set to null if
386
     * you don't want any order by default
387
     * @return the parameters for the memory based store
388
     * @throws InitializeException if there is an error initializing the
389
     * parameters for the memory provider
390
     */
391
    public DataStoreParameters createMemoryStoreParameters(
392
            String autoOrderAttributeName) throws InitializeException;
393

    
394
    /**
395
     * Utility method to create the a {@link FeatureStore} based on the
396
     * {@link MemoryStoreProvider}.
397
     *
398
     * @param autoOrderAttributeName the name of the {@link Feature} attribute
399
     * to be used to order the store {@link Feature}s by default. Set to null if
400
     * you don't want any order by default
401
     * @return the the memory based store
402
     * @throws InitializeException if there is an error initializing the
403
     * parameters for the memory provider
404
     */
405
    public FeatureStore createMemoryStore(String autoOrderAttributeName)
406
            throws InitializeException;
407

    
408
    /**
409
     * Creates a {@link FeaturePagingHelper} to paginate data from a
410
     * {@link FeatureStore}.
411
     *
412
     * @param featureStore to get the {@link Feature}s from
413
     * @param pageSize the page size
414
     * @return a {@link FeaturePagingHelper}
415
     * @throws BaseException if there is an error creating the helper
416
     */
417
    public FeaturePagingHelper createFeaturePagingHelper(
418
            FeatureStore featureStore, int pageSize) throws BaseException;
419

    
420
    /**
421
     * Creates a {@link FeaturePagingHelper} to paginate data from a
422
     * {@link FeatureStore}.
423
     *
424
     * @param featureStore to get the {@link Feature}s from
425
     * @param featureQuery to filter and/or order the data
426
     * @param pageSize the page size
427
     * @return a {@link FeaturePagingHelper}
428
     * @throws BaseException if there is an error creating the helper
429
     */
430
    public FeaturePagingHelper createFeaturePagingHelper(
431
            FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
432
            throws BaseException;
433

    
434
    public void setOpenErrorHandler(OpenErrorHandler handler);
435

    
436
    public OpenErrorHandler getOpenErrorHandler();
437

    
438
    public DataStoreProviderFactory getStoreProviderFactory(String name);
439

    
440
    public EditableFeatureType createFeatureType();
441

    
442
    public DataServerExplorerPool getDataServerExplorerPool();
443

    
444
    public void setDataServerExplorerPool(DataServerExplorerPool pool);
445

    
446
    public void setResourcesLoader(ClassLoader loader);
447

    
448
    public void setResourcesLoader(File folder);
449

    
450
    /**
451
     * Return a list of the DataTypes supported for the type of the feature
452
     * attributes. The list is only informative.
453
     *
454
     * @return
455
     */
456
    public List<DataType> getDataTypes();
457

    
458
    public Register getStoreRegister();
459

    
460
    public Register getStoreProviderRegister();
461

    
462
    public Register getServerExplorerRegister();
463

    
464
    public Register getFeatureIndexRegister();
465

    
466
    /**
467
     * Creates a default ExpressionBuilder.
468
     *
469
     * This ExpressionBuilder is not dependent on a data source,
470
     * and is not advisable to use it.
471
     *
472
     * @return the ExpressionBuilder
473
     * @deprecated use ExpressionEvaluatorManager.createExpressionBuilder()
474
     */
475
    public ExpressionBuilder createExpressionBuilder();
476

    
477
    /**
478
         * Returns a list of String containing the names of the available cache providers.
479
         *
480
         * @return
481
         *                 list of strings with the names of the available cache providers
482
         */
483
    public List getFeatureCacheProviders();
484

    
485
        /**
486
         * Returns an instance of {@link DataServerExplorerParameters} corresponding
487
         * to the given name used by the cache to create a store to save the
488
         * retrieved data.
489
         *
490
         * @param name
491
         *            name of a registered feature cache provider
492
     * @return 
493
         *
494
         * @throws InitializeException
495
         *             if parameter initialization causes an error.
496
         *
497
         * @throws ProviderNotRegisteredException
498
         *             if could not find a cache provider by the given name.
499
         *
500
         */
501
        public DynObject createCacheParameters(String name)
502
                        throws InitializeException, ProviderNotRegisteredException;
503

    
504
    /**
505
     * @param providerName
506
     * @param params
507
     * @param overwrite
508
     * @throws DataException
509
     */
510
    public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException;
511

    
512
    public FeatureSymbolTable createFeatureSymbolTable();
513

    
514
    public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression);
515

    
516
    public void registerDataProfile(DataProfile profile);
517

    
518
    public List<DataProfile> getDataProfiles();
519

    
520
    public DataProfile getDataProfile(String name);
521
    
522
    public StoresRepository getStoresRepository();
523
    
524
    public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection);
525
    
526
    public void addDatabaseWorkspace(DatabaseWorkspaceManager DatabaseWorkspace);
527

    
528
    public void addDatabaseWorkspaceListener(DatabaseWorkspaceManager.AddDatabaseWorkspaceListener listener);
529
    
530
    public DatabaseWorkspaceManager getDatabaseWorkspace(String name);
531
    
532
    public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params);
533

    
534
    public void writeDALResource(ResourcesStorage resources, DataStore store);
535
    
536
    public void writeDALResource(ResourcesStorage resources, FeatureType featureType);
537

    
538
    /**
539
     * Return a 35-40 characters unique identifier.
540
     * 
541
     * @return the unique identifier
542
     */
543
    public String createUniqueID();
544

    
545
    public void clearAvailableValuesCache();
546

    
547

    
548
}