Statistics
| Revision:

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

History | View | Annotate | Download (24.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,
153
        NewFeatureStoreParameters params) 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) throws DataException;
208

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

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

    
235
    /**
236
     * Returns the feature given its reference.
237
     * 
238
     * @param reference
239
     *            a unique FeatureReference
240
     * @return
241
     *         The Feature
242
     * 
243
     * @throws DataException
244
     * 
245
     */
246
    public Feature getFeatureByReference(FeatureReference reference)
247
        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,
265
        FeatureType featureType) 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
411
     *            default value.
412
     * 
413
     * @return
414
     *         the new feature
415
     * 
416
     * @throws DataException
417
     */
418
    public EditableFeature createNewFeature(FeatureType type,
419
        boolean defaultValues) throws DataException;
420

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

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

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

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

    
469
    /**
470
     * Finishes an editing group.
471
     * 
472
     * @throws NeedEditingModeException
473
     */
474
    public void endEditingGroup() throws NeedEditingModeException;
475

    
476
    /*
477
     * =============================================================
478
     * 
479
     * Index related services
480
     */
481

    
482
    /**
483
     * Creates an index which will be applied to the features of the given type,
484
     * by using the data of the given attribute.
485
     * 
486
     * @param featureType
487
     *            The FeatureType to which the indexed attribute belongs.
488
     * 
489
     * @param attributeName
490
     *            The name of the attributed to be indexed
491
     * 
492
     * @param indexName
493
     *            The index name
494
     * 
495
     * @return the resulting {@link FeatureIndex}
496
     * 
497
     * 
498
     * @throws FeatureIndexException
499
     *             if there is an error creating the index
500
     */
501
    public FeatureIndex createIndex(FeatureType featureType,
502
        String attributeName, String indexName) throws DataException;
503

    
504
    /**
505
     * Creates an index which will be applied to the features of the given type,
506
     * by using the data of the given attribute.
507
     * 
508
     * @param indexTypeName
509
     *            the type of the index to be created. That name is
510
     *            related to one of the registered index providers
511
     * @param featureType
512
     *            The FeatureType to which the indexed attribute belongs.
513
     * 
514
     * @param attributeName
515
     *            The name of the attributed to be indexed
516
     * 
517
     * @param indexName
518
     *            The index name
519
     * 
520
     * @return the resulting {@link FeatureIndex}
521
     * 
522
     * 
523
     * @throws FeatureIndexException
524
     *             if there is an error creating the index
525
     */
526
    public FeatureIndex createIndex(String indexTypeName,
527
        FeatureType featureType, String attributeName, String indexName)
528
        throws DataException;
529

    
530
    /**
531
     * Creates an index which will be applied to the features of the given type,
532
     * by using the data of the given attribute. This method will return without
533
     * waiting for the index to be filled, as that will be performed in
534
     * background. An optional {@link Observer} parameter is provided to be
535
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
536
     * when the index has finished filling with data and is available to be
537
     * used.
538
     * 
539
     * @param featureType
540
     *            The FeatureType to which the indexed attribute belongs.
541
     * 
542
     * @param attributeName
543
     *            The name of the attributed to be indexed
544
     * 
545
     * @param indexName
546
     *            The index name
547
     * 
548
     * @param observer
549
     *            to notify to when the created index has finished filling
550
     *            with data and is available to be used. The observer will
551
     *            receive then a
552
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
553
     *            notification, with the index object if it has finished
554
     *            successfully, or a
555
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
556
     *            notification with the exception object if there has been
557
     *            any error in the process. Optional.
558
     * 
559
     * @return the resulting {@link FeatureIndex}
560
     * 
561
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
562
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
563
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
564
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
565
     * 
566
     * @throws FeatureIndexException
567
     *             if there is an error creating the index
568
     */
569
    public FeatureIndex createIndex(FeatureType featureType,
570
        String attributeName, String indexName, Observer observer)
571
        throws DataException;
572

    
573
    /**
574
     * Creates an index which will be applied to the features of the given type,
575
     * by using the data of the given attribute. This method will return without
576
     * waiting for the index to be filled, as that will be performed in
577
     * background. An optional {@link Observer} parameter is provided to be
578
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
579
     * when the index has finished filling with data and is available to be
580
     * used.
581
     * 
582
     * @param indexTypeName
583
     *            the type of the index to be created. That name is
584
     *            related to one of the registered index providers
585
     * @param featureType
586
     *            The FeatureType to which the indexed attribute belongs.
587
     * 
588
     * @param attributeName
589
     *            The name of the attributed to be indexed
590
     * 
591
     * @param indexName
592
     *            The index name
593
     * 
594
     * @param observer
595
     *            to notify to when the created index has finished filling
596
     *            with data and is available to be used. The observer will
597
     *            receive then a
598
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
599
     *            notification, with the index object if it has finished
600
     *            successfully, or a
601
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
602
     *            notification with the exception object if there has been
603
     *            any error in the process. Optional.
604
     * 
605
     * @return the resulting {@link FeatureIndex}
606
     * 
607
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
608
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
609
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
610
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
611
     * 
612
     * @throws FeatureIndexException
613
     *             if there is an error creating the index
614
     */
615
    public FeatureIndex createIndex(String indexTypeName,
616
        FeatureType featureType, String attributeName, String indexName,
617
        Observer observer) throws DataException;
618

    
619
    /**
620
     * Returns a FeatureIndexes structure containing all available indexes in
621
     * the store.
622
     * 
623
     * @return
624
     */
625
    public FeatureIndexes getIndexes();
626

    
627
    /*
628
     * =============================================================
629
     * 
630
     * Selection related services
631
     */
632

    
633
    /**
634
     * Sets the selection to the passed {@link FeatureSet}
635
     * 
636
     * @param selection
637
     *            A {@link FeatureSet} with the requested selection
638
     */
639
    public void setSelection(FeatureSet selection) throws DataException;
640

    
641
    /**
642
     * Creates a {@link FeatureSelection}
643
     * 
644
     * @return
645
     *         a {@link FeatureSelection}
646
     * 
647
     * @throws DataException
648
     */
649
    public FeatureSelection createFeatureSelection() throws DataException;
650

    
651
    /**
652
     * Returns the current {@link FeatureSelection}.
653
     * 
654
     * @return
655
     *         current {@link FeatureSelection}.
656
     * 
657
     * @throws DataException
658
     */
659
    public FeatureSelection getFeatureSelection() throws DataException;
660

    
661
    /*
662
     * =============================================================
663
     * 
664
     * Lock related services
665
     */
666

    
667
    /**
668
     * Indicates whether this store supports locks.
669
     * 
670
     * @return
671
     *         true if this store supports locks, false if not.
672
     */
673
    public boolean isLocksSupported();
674

    
675
    /**
676
     * Returns the set of locked features
677
     * 
678
     * @return
679
     *         set of locked features
680
     * 
681
     * @throws DataException
682
     */
683
    public FeatureLocks getLocks() throws DataException;
684

    
685
    /*
686
     * =============================================================
687
     * Transforms related services
688
     * =============================================================
689
     */
690

    
691
    /**
692
     * Returns this store transforms
693
     * 
694
     * @return
695
     *         this store transforms
696
     */
697
    public FeatureStoreTransforms getTransforms();
698

    
699
    /**
700
     * Returns a new {@link FeatureQuery} associated to this store.
701
     * 
702
     * @return
703
     *         a new {@link FeatureQuery} associated to this store.
704
     */
705
    public FeatureQuery createFeatureQuery();
706

    
707
    /**
708
     * Returns featue count of this store.
709
     * 
710
     * @return
711
     * @throws DataException
712
     */
713
    public long getFeatureCount() throws DataException;
714

    
715
    /**
716
     * Creates a vectorial cache that is used to save and retrieve data.
717
     * 
718
     * @param name
719
     *            the cache name.
720
     * @param parameters
721
     *            parameters to create the stores used to save data.
722
     * @throws DataException
723
     */
724
    public void createCache(String name, DynObject parameters)
725
        throws DataException;
726

    
727
    /**
728
     * @return the vectorial cache
729
     */
730
    public FeatureCache getCache();
731

    
732
    /**
733
     * Return if the provider knows the real envelope of a layer. If not,
734
     * the {@link FeatureStoreProvider#getEnvelope()} method doesn't return
735
     * the full envelope.
736
     * 
737
     * @return
738
     *         <true> if it knows the real envelope.
739
     */
740
    public boolean isKnownEnvelope();
741

    
742
    /**
743
     * Return if the maximum number of features provided by the
744
     * provider are limited.
745
     * 
746
     * @return
747
     *         <true> if there is a limit of features.
748
     */
749
    public boolean hasRetrievedFeaturesLimit();
750

    
751
    /**
752
     * If the {@link FeatureStoreProvider#hasRetrievedFeaturesLimit()} returns
753
     * true,
754
     * it returns the limit of features retrieved from the provider.
755
     * 
756
     * @return
757
     *         The limit of the retrieved features.
758
     */
759
    public int getRetrievedFeaturesLimit();
760
}