Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / FeatureStore.java @ 34112

History | View | Annotate | Download (18.1 KB)

1
package org.gvsig.fmap.dal.feature;
2

    
3
import java.util.Iterator;
4
import java.util.List;
5

    
6
import org.cresques.cts.IProjection;
7

    
8
import org.gvsig.fmap.dal.DataServerExplorer;
9
import org.gvsig.fmap.dal.DataStore;
10
import org.gvsig.fmap.dal.DataStoreParameters;
11
import org.gvsig.fmap.dal.exception.DataException;
12
import org.gvsig.fmap.dal.exception.ReadException;
13
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
14
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
15
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
16
import org.gvsig.fmap.geom.Geometry;
17
import org.gvsig.fmap.geom.primitive.Envelope;
18
import org.gvsig.tools.dispose.DisposableIterator;
19
import org.gvsig.tools.dynobject.DynObject;
20
import org.gvsig.tools.observer.Observer;
21
import org.gvsig.tools.undo.UndoRedoStack;
22

    
23
/**
24
 * <p>
25
 * A FeatureStore is a type of store whose data consists on sets of
26
 * {@link Feature}(s). {@link Feature}(s) from the same FeatureStore can be of
27
 * different {@link FeatureType}(s) (as in GML format for instance).
28
 * </p>
29
 *
30
 * <p>
31
 * FeatureStore allows:
32
 * </p>
33
 * <ul>
34
 * <li>Obtaining the default {@link FeatureType}. A FeatureStore always has one
35
 * and only one default FeatureType.
36
 * <li>Obtaining the list of {@link FeatureType}(s) defined in the FeatureStore.
37
 * <li>Obtaining, filtering and sorting subsets of data ({@link FeatureSet})
38
 * through {@link FeatureQuery}, as well as background loading.
39
 * <li>Obtaining the total {@link Envelope} (AKA bounding box or extent) of the
40
 * store.
41
 * <li>Support for editing {@link FeatureType}(s).
42
 * <li>Obtaining information about contained {@link Geometry} types.
43
 * <li>Exporting to another store.
44
 * <li>Indexing.
45
 * <li>Selection.
46
 * <li>Locks management.
47
 * </ul>
48
 *
49
 */
50
public interface FeatureStore extends DataStore, UndoRedoStack {
51

    
52
        public static final String METADATA_DEFINITION_NAME = "FeatureStore";
53

    
54
        /** Indicates that this store is in query mode */
55
        final static int MODE_QUERY = 0;
56

    
57
        /** Indicates that this store is in full edit mode */
58
        final static int MODE_FULLEDIT = 1;
59

    
60
        /** Indicates that this store is in append mode */
61
        final static int MODE_APPEND = 2;
62

    
63
        /*
64
         * =============================================================
65
         *
66
         * information related services
67
         */
68

    
69
        /**
70
         * Indicates whether this store allows writing.
71
         *
72
         * @return
73
         *                 true if this store can be written, false if not.
74
         */
75
        public boolean allowWrite();
76

    
77
        /**
78
         * Returns this store's default {@link FeatureType}.
79
         *
80
         * @return
81
         *                 this store's default {@link FeatureType}.
82
         *
83
         * @throws DataException
84
         */
85
        public FeatureType getDefaultFeatureType() throws DataException;
86

    
87
        /**
88
         * Returns this store's featureType {@link FeatureType} matches with
89
         * featureTypeId.
90
         *
91
         * @param featureTypeId
92
         *
93
         * @return this store's default {@link FeatureType}.
94
         *
95
         * @throws DataException
96
         */
97
        public FeatureType getFeatureType(String featureTypeId)
98
                        throws DataException;
99

    
100
        /**
101
         * Returns this store's {@link FeatureType}(s).
102
         *
103
         * @return a list with this store's {@link FeatureType}(s).
104
         *
105
         * @throws DataException
106
         */
107
        public List getFeatureTypes() throws DataException;
108

    
109
        /**
110
         * Returns this store's parameters.
111
         *
112
         * @return
113
         *                 {@link DataStoreParameters} containing this store's parameters
114
         */
115
        public DataStoreParameters getParameters();
116

    
117
        /**
118
         *@throws DataException
119
         * @deprecated Mirar de cambiarlo a metadatos
120
         */
121
        public boolean canWriteGeometry(int gvSIGgeometryType) throws DataException;
122

    
123
        /**
124
         * Returns this store's total envelope (extent).
125
         * 
126
         * @return this store's total envelope (extent) or <code>null</code> if
127
         *         store not have geometry information
128
         */
129
        public Envelope getEnvelope() throws DataException;
130

    
131
        /**
132
         *
133
         * @deprecated use getDefaultFeatureType().getDefaultSRS()
134
         * @return
135
         * @throws DataException
136
         */
137
        public IProjection getSRSDefaultGeometry() throws DataException;
138

    
139
        /**
140
         * Exports this store to another store.
141
         *
142
         * @param explorer
143
         *            {@link DataServerExplorer} target
144
         * @param params
145
         *            New parameters of this store that will be used on the target
146
         *            explorer
147
         *
148
         * @throws DataException
149
         *
150
         * @Deprecated this method is unstable
151
         */
152
        public void export(DataServerExplorer explorer, String provider, NewFeatureStoreParameters params)
153
                        throws DataException;
154

    
155
        /*
156
         * =============================================================
157
         *
158
         * Query related services
159
         */
160

    
161
        /**
162
         * Returns all available features in the store.
163
         * <p>
164
         * <em>
165
         * <strong>NOTE:</strong> if you use this method to get a 
166
         * {@link FeatureSet}, you  must get sure it is disposed 
167
         * (@see {@link DisposableIterator#dispose()}) in any case, even if an 
168
         * error occurs while getting the data. It is recommended to use the 
169
         * <code>accept</code> methods instead, which handle everything for you. 
170
         * Take into account the accept methods may use a fast iterator to 
171
         * get the features.
172
         * </em>
173
         * </p>
174
         * 
175
         * @see #accept(org.gvsig.tools.visitor.Visitor)
176
         * 
177
         * @return a collection of features
178
         * @throws ReadException
179
         *             if there is any error while reading the features
180
         */
181
        FeatureSet getFeatureSet() throws DataException;
182

    
183
        /**
184
         * Returns a subset of features taking into account the properties and
185
         * restrictions of the FeatureQuery.
186
         * <p>
187
         * <em>
188
         * <strong>NOTE:</strong> if you use this method to get a 
189
         * {@link FeatureSet}, you  must get sure it is disposed 
190
         * (@see {@link DisposableIterator#dispose()}) in any case, even if an 
191
         * error occurs while getting the data. It is recommended to use the 
192
         * <code>accept</code> methods instead, which handle everything for you. 
193
         * Take into account the accept methods may use a fast iterator to 
194
         * get the features.
195
         * </em>
196
         * </p>
197
         * 
198
         * @see #accept(org.gvsig.tools.visitor.Visitor,
199
         *      org.gvsig.fmap.dal.DataQuery)
200
         * 
201
         * @param featureQuery
202
         *            defines the characteristics of the features to return
203
         * @return a collection of features
204
         * @throws ReadException
205
         *             if there is any error while reading the features
206
         */
207
        FeatureSet getFeatureSet(FeatureQuery featureQuery)
208
         throws DataException;
209

    
210
        /**
211
         * Loads a subset of features taking into account the properties and
212
         * restrictions of the FeatureQuery. Feature loading is performed by calling
213
         * the Observer, once each loaded Feature.
214
         *
215
         * @param featureQuery
216
         *            defines the characteristics of the features to return
217
         * @param observer
218
         *            to be notified of each loaded Feature
219
         * @throws DataException
220
         *             if there is any error while loading the features
221
         */
222
        void getFeatureSet(FeatureQuery featureQuery, Observer observer)
223
        throws DataException;
224

    
225
        /**
226
         * Loads all available feature in the store. The loading of Features is
227
         * performed by calling the Observer, once each loaded Feature.
228
         *
229
         * @param observer
230
         *            to be notified of each loaded Feature
231
         * @throws DataException
232
         *             if there is any error while loading the features
233
         */
234
        void getFeatureSet(Observer observer) throws DataException;
235

    
236
        /**
237
         * Returns the feature given its reference.
238
         *
239
         * @param reference
240
         *            a unique FeatureReference
241
         * @return
242
         *                 The Feature
243
         *
244
         * @throws DataException
245
         *
246
         */
247
        public Feature getFeatureByReference(FeatureReference reference) throws DataException;
248

    
249
        /**
250
         * Returns the feature given its reference and feature type.
251
         *
252
         * @param reference
253
         *            a unique FeatureReference
254
         *
255
         * @param featureType
256
         *            FeatureType to which the requested Feature belongs
257
         *
258
         * @return
259
         *                 The Feature
260
         *
261
         * @throws DataException
262
         *
263
         */
264
        public Feature getFeatureByReference(FeatureReference reference, FeatureType featureType)
265
                        throws DataException;
266

    
267
        /*
268
         * =============================================================
269
         *
270
         * Editing related services
271
         */
272

    
273
        /**
274
         * Enters editing state.
275
         */
276
        public void edit() throws DataException;
277

    
278
        /**
279
         * Enters editing state specifying the editing mode.
280
         *
281
         * @param mode
282
         *
283
         * @throws DataException
284
         */
285
        public void edit(int mode) throws DataException;
286

    
287
        /**
288
         * Cancels all editing since the last edit().
289
         *
290
         * @throws DataException
291
         */
292
        public void cancelEditing() throws DataException;
293

    
294
        /**
295
         * Exits editing state.
296
         *
297
         * @throws DataException
298
         */
299
        public void finishEditing() throws DataException;
300

    
301
        /**
302
         * Indicates whether this store is in editing state.
303
         *
304
         * @return
305
         *                 true if this store is in editing state, false if not.
306
         */
307
        public boolean isEditing();
308

    
309
        /**
310
         * Indicates whether this store is in appending state. In this state the new
311
         * features are automatically inserted at the end of the {@link FeatureSet}.
312
         *
313
         * @return true if this store is in appending state.
314
         */
315
        public boolean isAppending();
316

    
317
        /**
318
         * Updates a {@link FeatureType} in the store with the changes in the
319
         * {@link EditableFeatureType}.<br>
320
         *
321
         * Any {@link FeatureSet} from this store that are used will be invalidated.
322
         *
323
         * @param featureType
324
         *            an {@link EditableFeatureType} with the changes.
325
         *
326
         * @throws DataException
327
         */
328
        public void update(EditableFeatureType featureType) throws DataException;
329

    
330
        /**
331
         * Updates a {@link Feature} in the store with the changes in the
332
         * {@link EditableFeature}.<br>
333
         *
334
         * Any {@link FeatureSet} from this store that was still in use will be
335
         * invalidated. You can override this using
336
         * {@link FeatureSet#update(EditableFeature)}.
337
         *
338
         * @param feature
339
         *            the feature to be updated
340
         *
341
         * @throws DataException
342
         */
343
        public void update(EditableFeature feature) throws DataException;
344

    
345
        /**
346
         * Deletes a {@link Feature} from the store.<br>
347
         *
348
         * Any {@link FeatureSet} from this store that was still in use will be
349
         * invalidated. You can override this using {@link Iterator#remove()} from
350
         * {@link FeatureSet}.
351
         *
352
         * @param feature
353
         *            The feature to be deleted.
354
         *
355
         * @throws DataException
356
         */
357
        public void delete(Feature feature) throws DataException;
358

    
359
        /**
360
         * Inserts a {@link Feature} in the store.<br>
361
         *
362
         * Any {@link FeatureSet} from this store that was still in use will be
363
         * invalidated. You can override this using
364
         * {@link FeatureSet#insert(EditableFeature)}.
365
         *
366
         * @param feature
367
         *            The feature to be inserted
368
         *
369
         * @throws DataException
370
         */
371
        public void insert(EditableFeature feature) throws DataException;
372

    
373
        /**
374
         * Creates a new feature using the default feature type and returns it as an
375
         * {@link EditableFeature}
376
         *
377
         * @return a new feature in editable state
378
         *
379
         * @throws DataException
380
         */
381
        public EditableFeature createNewFeature() throws DataException;
382

    
383
        /**
384
         * Creates a new feature of the given {@link FeatureType} and uses the given
385
         * {@link Feature} as default values to initialize it.
386
         *
387
         * @param type
388
         *            the new feature's feature type
389
         *
390
         * @param defaultValues
391
         *            a feature whose values are used as default values for the new
392
         *            feature.
393
         *
394
         * @return the new feature.
395
         *
396
         * @throws DataException
397
         */
398
        public EditableFeature createNewFeature(FeatureType type,
399
                        Feature defaultValues) throws DataException;
400

    
401
        /**
402
         * Creates a new feature of the given {@link FeatureType}. The flag
403
         * defaultValues is used to indicate whether the new feature should be
404
         * initialized with default values or not.
405
         *
406
         * @param type
407
         *            the new feature's feature type
408
         *
409
         * @param defaultValues
410
         *                         if true the new feature is initialized with each attribute's default value.
411
         *
412
         * @return
413
         *                 the new feature
414
         *
415
         * @throws DataException
416
         */
417
        public EditableFeature createNewFeature(FeatureType type,
418
                        boolean defaultValues) throws DataException;
419

    
420
        /**
421
         * Creates a new feature of default {@link FeatureType}. The flag
422
         * defaultValues is used to indicate whether the new feature should be
423
         * initialized with default values or not.
424
         *
425
         * @param defaultValues
426
         *                                 if true the new feature is initialized with each attribute's default value.
427
         *
428
         * @return
429
         *                 the new feature
430
         *
431
         * @throws DataException
432
         */
433
        public EditableFeature createNewFeature(boolean defaultValues)
434
                        throws DataException;
435

    
436
        /**
437
         * Applies the validation rules associated to the given mode to the active {@link FeatureSet}.
438
         *
439
         * @param mode
440
         *            can be one of {MODE_QUERY, MODE_FULLEDIT, MODE_APPEND}
441
         *
442
         * @throws DataException
443
         */
444
        public void validateFeatures(int mode) throws DataException;
445

    
446
        /**
447
         * Indicates whether this store supports append mode.
448
         *
449
         * @return
450
         *                 true if this store supports append mode.
451
         */
452
        public boolean isAppendModeSupported();
453

    
454
        /**
455
         * Initiates an editing group. This is typically used to group series of
456
         * store editing operations.
457
         *
458
         * @param description
459
         *            Description of the editing group.
460
         *
461
         * @throws NeedEditingModeException
462
         */
463
        public void beginEditingGroup(String description)
464
                        throws NeedEditingModeException;
465

    
466
        /**
467
         * Finishes an editing group.
468
         *
469
         * @throws NeedEditingModeException
470
         */
471
        public void endEditingGroup() throws NeedEditingModeException;
472

    
473
        /*
474
         * =============================================================
475
         *
476
         * Index related services
477
         */
478

    
479
        /**
480
         * Creates a FeatureIndex with name indexName, given the attributeName and
481
         * its featureType.
482
         *
483
         * @param featureType
484
         *            The FeatureType to which the indexed attribute belongs.
485
         *
486
         * @param attributeName
487
         *            The name of the attributed to be indexed
488
         *
489
         * @param indexName
490
         *            The index name
491
         *
492
         * @return the resulting FeatureIndex
493
         *
494
         *
495
         * @throws FeatureIndexException
496
         */
497
        public FeatureIndex createIndex(FeatureType featureType,
498
                        String attributeName, String indexName) throws DataException;
499

    
500
        /**
501
         * Creates a FeatureIndex with name indexName, given the attributeName and
502
         * its featureType. This method is intended for background indexing. It
503
         * receives an observer that will be notified by the process.
504
         *
505
         * @param featureType
506
         *            The FeatureType to which the indexed attribute belongs.
507
         *
508
         * @param attributeName
509
         *            The name of the attributed to be indexed
510
         *
511
         * @param indexName
512
         *            The index name
513
         *
514
         * @param observer
515
         *            an observer that will be notified of the indexing process
516
         *            progress.
517
         *
518
         * @return the resulting FeatureIndex
519
         *
520
         *
521
         * @throws FeatureIndexException
522
         */
523
        public FeatureIndex createIndex(FeatureType featureType,
524
                        String attributeName, String indexName, Observer observer) throws DataException;
525
        /**
526
         * Returns a FeatureIndexes structure containing all available indexes in
527
         * the store.
528
         *
529
         * @return
530
         */
531
        public FeatureIndexes getIndexes();
532

    
533
        /*
534
         * =============================================================
535
         *
536
         * Selection related services
537
         */
538

    
539
        /**
540
         * Sets the selection to the passed {@link FeatureSet}
541
         *
542
         * @param selection
543
         *            A {@link FeatureSet} with the requested selection
544
         */
545
        public void setSelection(FeatureSet selection) throws DataException;
546

    
547
        /**
548
         * Creates a {@link FeatureSelection}
549
         *
550
         * @return
551
         *                 a {@link FeatureSelection}
552
         *
553
         * @throws DataException
554
         */
555
        public FeatureSelection createFeatureSelection() throws DataException;
556

    
557
        /**
558
         * Returns the current {@link FeatureSelection}.
559
         *
560
         * @return
561
         *                 current {@link FeatureSelection}.
562
         *
563
         * @throws DataException
564
         */
565
        public FeatureSelection getFeatureSelection() throws DataException;
566

    
567
        /*
568
         * =============================================================
569
         *
570
         * Lock related services
571
         */
572

    
573
        /**
574
         * Indicates whether this store supports locks.
575
         *
576
         * @return
577
         *                 true if this store supports locks, false if not.
578
         */
579
        public boolean isLocksSupported();
580

    
581
        /**
582
         * Returns the set of locked features
583
         *
584
         * @return
585
         *                 set of locked features
586
         *
587
         * @throws DataException
588
         */
589
        public FeatureLocks getLocks() throws DataException;
590

    
591
        /*
592
         * =============================================================
593
         * Transforms related services
594
         * =============================================================
595
         */
596

    
597
        /**
598
         * Returns this store transforms
599
         *
600
         * @return
601
         *                 this store transforms
602
         */
603
        public FeatureStoreTransforms getTransforms();
604

    
605
        /**
606
         * Returns a new {@link FeatureQuery} associated to this store.
607
         *
608
         * @return
609
         *                 a new {@link FeatureQuery} associated to this store.
610
         */
611
        public FeatureQuery createFeatureQuery();
612

    
613
        /**
614
         * Returns featue count of this store.
615
         *
616
         * @return
617
         * @throws DataException
618
         */
619
        public long getFeatureCount() throws DataException;
620
        
621
        /**
622
         * Creates a vectorial cache that is used to save and retrieve data.
623
         * @param name the cache name.
624
         * @param parameters parameters to create the stores used to save data.
625
         * @throws DataException
626
         */
627
        public void createCache(String name, DynObject parameters) throws DataException;
628

    
629
        
630
        /**
631
         * @return the vectorial cache
632
         */
633
        public FeatureCache getCache();
634
        
635
         /**
636
     * Return if the provider knows the real envelope of a layer. If not,
637
     * the {@link FeatureStoreProvider#getEnvelope()} method doesn't return
638
     * the full envelope.
639
     * 
640
     * @return
641
     * <true> if it knows the real envelope.
642
     */
643
    public boolean isKnownEnvelope(); 
644
    
645
    /**
646
     * Return if the maximum number of features provided by the
647
     * provider are limited.
648
     * 
649
     * @return
650
     * <true> if there is a limit of features.
651
     */
652
    public boolean hasRetrievedFeaturesLimit();
653
    
654
    /**
655
     * If the {@link FeatureStoreProvider#hasRetrievedFeaturesLimit()} returns true,
656
     * it returns the limit of features retrieved from the provider.
657
     * @return
658
     * The limit of the retrieved features.
659
     */
660
    public int getRetrievedFeaturesLimit();
661
}
662