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 / feature / FeatureStore.java @ 44346

History | View | Annotate | Download (43.4 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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature;
25

    
26
import java.util.Iterator;
27
import java.util.List;
28

    
29
import org.cresques.cts.IProjection;
30
import org.gvsig.expressionevaluator.Expression;
31
import org.gvsig.expressionevaluator.ExpressionBuilder;
32

    
33
import org.gvsig.fmap.dal.DataServerExplorer;
34
import org.gvsig.fmap.dal.DataStore;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.StoresRepository;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.exception.ReadException;
39
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
40
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
41
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.SpatialIndex;
43
import org.gvsig.fmap.geom.primitive.Envelope;
44
import org.gvsig.tools.dispose.DisposableIterator;
45
import org.gvsig.tools.dynobject.DynObject;
46
import org.gvsig.tools.lang.Cloneable;
47
import org.gvsig.tools.observer.Observer;
48
import org.gvsig.tools.undo.UndoRedoStack;
49
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
50
import org.gvsig.tools.util.UnmodifiableBasicList64;
51

    
52
/**
53
 * <p>
54
 * A FeatureStore is a type of store whose data consists on sets of
55
 * {@link Feature}(s). {@link Feature}(s) from the same FeatureStore can be of
56
 * different {@link FeatureType}(s) (as in GML format for instance).
57
 * </p>
58
 *
59
 * <p>
60
 * FeatureStore allows:
61
 * </p>
62
 * <ul>
63
 * <li>Obtaining the default {@link FeatureType}. A FeatureStore always has one
64
 * and only one default FeatureType.
65
 * <li>Obtaining the list of {@link FeatureType}(s) defined in the FeatureStore.
66
 * <li>Obtaining, filtering and sorting subsets of data ({@link FeatureSet})
67
 * through {@link FeatureQuery}, as well as background loading.
68
 * <li>Obtaining the total {@link Envelope} (AKA bounding box or extent) of the
69
 * store.
70
 * <li>Support for editing {@link FeatureType}(s).
71
 * <li>Obtaining information about contained {@link Geometry} types.
72
 * <li>Exporting to another store.
73
 * <li>Indexing.
74
 * <li>Selection.
75
 * <li>Locks management.
76
 * </ul>
77
 *
78
 */
79
public interface FeatureStore extends DataStore, UndoRedoStack, Cloneable {
80

    
81
    public static final String METADATA_DEFINITION_NAME = "FeatureStore";
82

    
83
    /** Indicates that this store is in query mode */
84
    final static int MODE_QUERY = 0;
85

    
86
    /** Indicates that this store is in full edit mode */
87
    final static int MODE_FULLEDIT = 1;
88

    
89
    /** Indicates that this store is in append mode */
90
    final static int MODE_APPEND = 2;
91

    
92
    /*
93
     * =============================================================
94
     *
95
     * information related services
96
     */
97

    
98
    /**
99
     * Indicates whether this store allows writing.
100
     *
101
     * @return
102
     *         true if this store can be written, false if not.
103
     */
104
    public boolean allowWrite();
105

    
106
    /**
107
     * Returns this store's default {@link FeatureType}.
108
     *
109
     * @return
110
     *         this store's default {@link FeatureType}.
111
     *
112
     * @throws DataException
113
     */
114
    public FeatureType getDefaultFeatureType() throws DataException;
115

    
116
    /**
117
     * Returns this store's featureType {@link FeatureType} matches with
118
     * featureTypeId.
119
     *
120
     * @param featureTypeId
121
     *
122
     * @return this store's default {@link FeatureType}.
123
     *
124
     * @throws DataException
125
     */
126
    public FeatureType getFeatureType(String featureTypeId)
127
        throws DataException;
128

    
129
    /**
130
     * Returns this store's {@link FeatureType}(s).
131
     *
132
     * @return a list with this store's {@link FeatureType}(s).
133
     *
134
     * @throws DataException
135
     */
136
    public List getFeatureTypes() throws DataException;
137

    
138
    /**
139
     * Returns this store's parameters.
140
     *
141
     * @return
142
     *         {@link DataStoreParameters} containing this store's parameters
143
     */
144
    public DataStoreParameters getParameters();
145

    
146
    /**
147
     *@throws DataException
148
     * @deprecated Mirar de cambiarlo a metadatos
149
     */
150
    public boolean canWriteGeometry(int gvSIGgeometryType) throws DataException;
151

    
152
    /**
153
     * Returns this store's total envelope (extent).
154
     *
155
     * @return this store's total envelope (extent) or <code>null</code> if
156
     *         store not have geometry information
157
     */
158
    public Envelope getEnvelope() throws DataException;
159

    
160
    /**
161
     *
162
     * @deprecated use getDefaultFeatureType().getDefaultSRS()
163
     * @return
164
     * @throws DataException
165
     */
166
    public IProjection getSRSDefaultGeometry() throws DataException;
167

    
168
    /**
169
     * Exports this store to another store.
170
     *
171
     * @param explorer
172
     *            {@link DataServerExplorer} target
173
     * @param params
174
     *            New parameters of this store that will be used on the target
175
     *            explorer
176
     *
177
     * @throws DataException
178
     *
179
     * @Deprecated this method is unstable
180
     */
181
    public void export(DataServerExplorer explorer, String provider,
182
        NewFeatureStoreParameters params) throws DataException;
183

    
184
    public void copyTo(FeatureStore target);
185

    
186
    /*
187
     * =============================================================
188
     *
189
     * Query related services
190
     */
191
    
192
    /** 
193
     * Create a {@link FeatureQuery} with the restrictions indicateds.
194
     * 
195
     * "filter" will be null or a valid filter expression for the store.
196
     * 
197
     * "sortBy" can be null to use the store's default order.
198
     * 
199
     * The parameter sortBy can be an attribute name or a comma separated list. 
200
     * Each attribute name can be preceded or followed by "+" or "-" to indicate 
201
     * the order to use to sort by that attribute. 
202
     * 
203
     * If no "+" or "-" is indicated, the "asc" parameter will be used to 
204
     * determine if the order is ascending, "true" or decent, "false".
205
     * 
206
     * @param filter an {@link String} expression used to filter the features in the store.
207
     * @param sortBy Attribute names separated by commas used to sort the list to return.
208
     * @param asc use order ascending, true, or descending, false.
209
     * @return a {@link FeatureQuery} with the restrictions.
210
     * @see {@link FeatureQuery}
211
     */
212
    public FeatureQuery createFeatureQuery(String filter, String sortBy, boolean asc);
213

    
214
    /** 
215
     * Create a {@link FeatureQuery} with the restrictions indicateds.
216
     * 
217
     * "filter" will be null or {@link Expression} valid for the store.
218
     * 
219
     * "sortBy" can be null to use the store's default order.
220
     * 
221
     * The parameter sortBy can be an attribute name or a comma separated list. 
222
     * Each attribute name can be preceded or followed by "+" or "-" to indicate 
223
     * the order to use to sort by that attribute. 
224
     * 
225
     * If no "+" or "-" is indicated, the "asc" parameter will be used to 
226
     * determine if the order is ascending, "true" or decent, "false".
227
     * 
228
     * @param filter an {@link String} expression used to filter the features in the store.
229
     * @param sortBy Attribute names separated by commas used to sort the list to return.
230
     * @param asc use order ascending, true, or descending, false.
231
     * @return a {@link FeatureQuery} with the restrictions.
232
     * @see {@link FeatureQuery}
233
     */
234
    public FeatureQuery createFeatureQuery(Expression filter, String sortBy, boolean asc);
235
        
236
    /**
237
     * Returns all available features in the store.
238
     *
239
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
240
     * 
241
     * @return the {@link FeatureSet} 
242
     * @throws ReadException if there is any error while reading the features
243
     * @see {@link #accept(org.gvsig.tools.visitor.Visitor)}, {@link #getFeatureSet(FeatureQuery)}
244
     */
245
    FeatureSet getFeatureSet() throws DataException;
246

    
247
    /**
248
     * Return a subset of features.
249
     * 
250
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
251
     * 
252
     * @param filter an {@link String} expression used to filter the features in the store.
253
     * @return the {@link FeatureSet} 
254
     * @throws ReadException if there is any error while reading the features
255
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
256
     */
257
    FeatureSet getFeatureSet(String filter) throws DataException;
258

    
259
    /**
260
     * Return a subset of features.
261
     * 
262
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
263
     * 
264
     * The sort order used is ascending.
265
     * 
266
     * @param filter an {@link String} expression used to filter the features in the store.
267
     * @param sortBy Attribute names separated by commas used to sort the list to return.
268
     * @return the {@link FeatureSet} 
269
     * @throws ReadException if there is any error while reading the features
270
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
271
     */
272
    FeatureSet getFeatureSet(String filter, String sortBy) throws DataException;
273

    
274
    /**
275
     * Return a subset of features.
276
     * 
277
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
278
     * 
279
     * @param filter an {@link String} expression used to filter the features in the store.
280
     * @param sortBy Attribute names separated by commas used to sort the list to return.
281
     * @param asc use order ascending, true, or descending, false.
282
     * @return the {@link FeatureSet} 
283
     * @throws ReadException if there is any error while reading the features
284
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
285
     */
286
    FeatureSet getFeatureSet(String filter, String sortBy, boolean asc) throws DataException;
287

    
288
    /**
289
     * Return a subset of features.
290
     * 
291
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
292
     * 
293
     * @param filter an {@link Expression} used to filter the features in the store.
294
     * @return the {@link FeatureSet} 
295
     * @throws DataException 
296
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
297
     */
298
    FeatureSet getFeatureSet(Expression filter) throws DataException;
299

    
300
    /**
301
     * Return a subset of features.
302
     * 
303
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
304
     * 
305
     * The sort order used is ascending.
306
     * 
307
     * @param filter an {@link Expression} used to filter the features in the store.
308
     * @param sortBy Attribute names separated by commas used to sort the list to return.
309
     * @return the {@link FeatureSet} 
310
     * @throws ReadException if there is any error while reading the features
311
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
312
     */
313
    FeatureSet getFeatureSet(Expression filter, String sortBy) throws DataException;
314

    
315
    /**
316
     * Return a subset of features.
317
     * 
318
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
319
     * 
320
     * @param filter an {@link Expression} used to filter the features in the store.
321
     * @param sortBy Attribute names separated by commas used to sort the list to return.
322
     * @param asc use order ascending, true, or descending, false.
323
     * @return the {@link FeatureSet} 
324
     * @throws DataException 
325
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
326
     */
327
    FeatureSet getFeatureSet(Expression filter, String sortBy, boolean asc) throws DataException;
328

    
329
    /**
330
     * Returns a subset of features taking into account the properties and
331
     * restrictions of the {@link FeatureQuery}.
332
     * 
333
     * If {@link FeatureQuery} is null, return al features in the store.
334
     * 
335
     * <p>
336
     * <em>
337
     * <strong>NOTE:</strong> if you use this method to get a
338
     * {@link FeatureSet}, you  must get sure it is disposed
339
     * (@see {@link DisposableIterator#dispose()}) in any case, even if an
340
     * error occurs while getting the data. It is recommended to use the
341
     * <code>accept</code> methods instead, which handle everything for you.
342
     * Take into account the accept methods may use a fast iterator to
343
     * get the features.
344
     * </em>
345
     * </p>
346
     *
347
     * @param featureQuery defines the characteristics of the features to return.
348
     * @return the {@link FeatureSet} 
349
     * @throws ReadException if there is any error while reading the features.
350
     * @see #accept(org.gvsig.tools.visitor.Visitor, org.gvsig.fmap.dal.DataQuery)
351
     */
352
    FeatureSet getFeatureSet(FeatureQuery featureQuery) throws DataException;
353

    
354
    /**
355
     * Loads a subset of features taking into account the properties and
356
     * restrictions of the FeatureQuery. 
357
     * When feature loading is finished call the Observer passing the
358
     * {@link FeatureSet}  loaded.
359
     *
360
     * @param featureQuery defines the characteristics of the features to return.
361
     * @param observer to be notified when loading is finished.
362
     * @throws DataException if there is any error while loading the features
363
     */
364
    void getFeatureSet(FeatureQuery featureQuery, Observer observer) throws DataException;
365

    
366
    /**
367
     * Loads all available feature in the store. The loading of Features is
368
     * performed by calling the Observer, once each loaded Feature.
369
     *
370
     * @param observer to be notified of each loaded Feature
371
     * @throws DataException if there is any error while loading the features
372
     */
373
    void getFeatureSet(Observer observer) throws DataException;
374

    
375
    /**
376
     * Return a paginated list of Features filtered by the query.
377
     * 
378
     * If the query  is null, return all features in the store sorteds 
379
     * by default order.
380
     * 
381
     * The return value implements {@link List} and {@link UnmodifiableBasicList64} 
382
     * to support large list of features.
383
     * 
384
     * The returned list of Features is paginated, and the page size
385
     * used is "pageSize". 
386
     * 
387
     * If the page size is less than or equal to 0, the default page size of 
388
     * 100 will be used.
389
     *
390
     * @param query to filter and sort the returned feature list
391
     * @param pageSize the page size of the list
392
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
393
     */
394
    public List<Feature> getFeatures(FeatureQuery query, int pageSize);
395

    
396
    /**
397
     * Return a paginated list of Features.
398
     * 
399
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
400
     * using the default page size.
401
     * 
402
     * @param query to filter and sort the returned feature list
403
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
404
     * @see {@link #getFeatures(FeatureQuery, int)}
405
     */
406
    public List<Feature> getFeatures(FeatureQuery query);
407

    
408
    /**
409
     * Return a paginated list with al Features in the store.
410
     * 
411
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
412
     * using the default page size.
413
     * 
414
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
415
     * @see {@link #getFeatures(FeatureQuery, int)}
416
     */
417
    public List<Feature> getFeatures();
418

    
419
    /**
420
     * Return a paginated list of Features
421
     * 
422
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
423
     * 
424
     * @param filter used to filter the features in the store.
425
     * @return the List of Features
426
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(String,String,boolean)}
427
     */
428
    public List<Feature> getFeatures(String filter);
429

    
430
    /**
431
     * Return a paginated list of Features.
432
     * 
433
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
434
     * using the default page size.
435
     * 
436
     * @param filter used to filter the features in the store.
437
     * @param sortBy Attribute names separated by commas used to sort the list to return.
438
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
439
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(String,String,boolean)}
440
     */
441
    public List<Feature> getFeatures(String filter, String sortBy);
442

    
443
    /**
444
     * Return a paginated list of Features.
445
     *  
446
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
447
     * using the default page size.
448
     * 
449
     * @param filter an {@link String} expression used to filter the features in the store.
450
     * @param sortBy Attribute names separated by commas used to sort the list to return.
451
     * @param asc use order ascending, true, or descending, false.
452
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
453
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(String,String,boolean)}
454
     */
455
    public List<Feature> getFeatures(String filter, String sortBy, boolean asc);
456

    
457
    /**
458
     * Return a paginated list of Features
459
     * 
460
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
461
     * using the default page size.
462
     * 
463
     * @param filter an {@link Expression} used to filter the features in the store.
464
     * @return the List of Features
465
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(Expression,String,boolean)}
466
     */
467
    public List<Feature> getFeatures(Expression filter);
468

    
469
    /**
470
     * Return a paginated list of Features
471
     * 
472
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
473
     * using the default page size.
474
     * 
475
     * @param filter an {@link Expression} used to filter the features in the store.
476
     * @param sortBy Attribute names separated by commas used to sort the list to return.
477
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
478
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(Expression,String,boolean)}
479
     */
480
    public List<Feature> getFeatures(Expression filter, String sortBy);
481

    
482
    /**
483
     * Return a paginated list of Features
484
     * 
485
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
486
     * using the default page size.
487
     * 
488
     * @param filter an {@link Expression} used to filter the features in the store.
489
     * @param sortBy Attribute names separated by commas used to sort the list to return.
490
     * @param asc use order ascending, true, or descending, false.
491
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
492
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(Expression,String,boolean)}
493
     */
494
    public List<Feature> getFeatures(Expression filter, String sortBy, boolean asc);
495

    
496
    /**
497
     * Return the first {@link Feature} of the store.
498
     * 
499
     * @return the first {@link Feature} or null if the store is empty.
500
     * @throws DataException 
501
     */
502
    public Feature first() throws DataException;
503

    
504
    /**
505
     * Returns the first {@link Feature} that meets the criteria indicated.
506
     * 
507
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
508
     * 
509
     * @param filter {@link String} expression used to filter the features.
510
     * @return the first {@link Feature} or null if the filter don't return any feature.
511
     * @throws DataException 
512
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(String,String,boolean)}
513
     */
514
    public Feature findFirst(String filter) throws DataException;
515

    
516
    /**
517
     * Returns the first {@link Feature} that meets the criteria indicated.
518
     * 
519
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
520
     * 
521
     * @param filter {@link String} expression used to filter the features.
522
     * @param sortBy Attribute names separated by commas used to sort the list to return.
523
     * @return the first {@link Feature} or null if the filter don't return any feature.
524
     * @throws DataException 
525
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(String,String,boolean)}
526
     */
527
    public Feature findFirst(String filter, String sortBy) throws DataException;
528

    
529
    /**
530
     * Returns the first {@link Feature} that meets the criteria indicated.
531
     * 
532
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
533
     * 
534
     * @param filter {@link String} expression used to filter the features.
535
     * @param sortBy Attribute names separated by commas used to sort the list to return.
536
     * @param asc use order ascending, true, or descending, false.
537
     * @return the first {@link Feature} or null if the filter don't return any feature.
538
     * @throws DataException 
539
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(String,String,boolean)}
540
     */
541
    public Feature findFirst(String filter, String sortBy, boolean asc) throws DataException;
542

    
543
    /**
544
     * Returns the first {@link Feature} that meets the criteria indicated.
545
     * 
546
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
547
     * 
548
     * @param filter {@link String} expression used to filter the features.
549
     * @return the first {@link Feature} or null if the filter don't return any feature.
550
     * @throws DataException 
551
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
552
     */
553
    public Feature findFirst(Expression filter) throws DataException;
554

    
555
    /**
556
     * Returns the first {@link Feature} that meets the criteria indicated.
557
     * 
558
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
559
     * 
560
     * @param filter {@link String} expression used to filter the features.
561
     * @param sortBy Attribute names separated by commas used to sort the list to return.
562
     * @return the first {@link Feature} or null if the filter don't return any feature.
563
     * @throws DataException 
564
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
565
     */
566
    public Feature findFirst(Expression filter, String sortBy) throws DataException;
567

    
568
    /**
569
     * Returns the first {@link Feature} that meets the criteria indicated.
570
     * 
571
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
572
     * 
573
     * @param filter {@link String} expression used to filter the features.
574
     * @param sortBy Attribute names separated by commas used to sort the list to return.
575
     * @param asc use order ascending, true, or descending, false.
576
     * @return the first {@link Feature} or null if the filter don't return any feature.
577
     * @throws DataException 
578
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
579
     */
580
    public Feature findFirst(Expression filter, String sortBy, boolean asc) throws DataException;
581

    
582
    /**
583
     * Returns the first {@link Feature} that meets the criteria indicated.
584
     * 
585
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
586
     * 
587
     * @param query to filter and sort the returned feature list
588
     * @return the first {@link Feature} or null if the filter don't return any feature.
589
     * @throws DataException 
590
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
591
     */
592
    public Feature findFirst(FeatureQuery query) throws DataException;
593

    
594
    /**
595
     * Returns the feature given its reference.
596
     *
597
     * @param reference a unique FeatureReference
598
     * @return 
599
     * @returnThe Feature
600
     * @throws DataException
601
     *
602
     */
603
    public Feature getFeatureByReference(FeatureReference reference) throws DataException;
604

    
605
    /**
606
     * Returns the feature given its reference and feature type.
607
     *
608
     * @param reference
609
     *            a unique FeatureReference
610
     *
611
     * @param featureType
612
     *            FeatureType to which the requested Feature belongs
613
     *
614
     * @return
615
     *         The Feature
616
     *
617
     * @throws DataException
618
     *
619
     */
620
    public Feature getFeatureByReference(FeatureReference reference,
621
        FeatureType featureType) throws DataException;
622

    
623
    /*
624
     * =============================================================
625
     *
626
     * Editing related services
627
     */
628

    
629
    /**
630
     * Enters editing state.
631
     */
632
    public void edit() throws DataException;
633

    
634
    /**
635
     * Enters editing state specifying the editing mode.
636
     *
637
     * @param mode
638
     *
639
     * @throws DataException
640
     */
641
    public void edit(int mode) throws DataException;
642

    
643
    /**
644
     * Cancels all editing since the last edit().
645
     *
646
     * @throws DataException
647
     */
648
    public void cancelEditing() throws DataException;
649

    
650
    /**
651
     * Exits editing state.
652
     *
653
     * @throws DataException
654
     */
655
    public void finishEditing() throws DataException;
656

    
657
    /**
658
     * Save changes in the provider without leaving the edit mode.
659
     * Do not call observers to communicate a change of ediding mode.
660
     * The operation's history is eliminated to prevent inconsistencies
661
     * in the data.
662
     *
663
     * @throws DataException
664
     */
665
    public void commitChanges() throws DataException ;
666

    
667
    /**
668
     *
669
     * Returns true if you can call CommitChanges method.
670
     * If not in editing or changes have been made in the structure
671
     * return false.
672
     *
673
     * @return true if can call commitChanges
674
     * @throws DataException
675
     */
676
    public boolean canCommitChanges() throws DataException;
677

    
678

    
679
    /**
680
     * Indicates whether this store is in editing state.
681
     *
682
     * @return
683
     *         true if this store is in editing state, false if not.
684
     */
685
    public boolean isEditing();
686

    
687
    /**
688
     * Indicates whether this store is in appending state. In this state the new
689
     * features are automatically inserted at the end of the {@link FeatureSet}.
690
     *
691
     * @return true if this store is in appending state.
692
     */
693
    public boolean isAppending();
694

    
695
    /**
696
     * Updates a {@link FeatureType} in the store with the changes in the
697
     * {@link EditableFeatureType}.<br>
698
     *
699
     * Any {@link FeatureSet} from this store that are used will be invalidated.
700
     *
701
     * @param featureType
702
     *            an {@link EditableFeatureType} with the changes.
703
     *
704
     * @throws DataException
705
     */
706
    public void update(EditableFeatureType featureType) throws DataException;
707

    
708
    /**
709
     * Updates a {@link Feature} in the store with the changes in the
710
     * {@link EditableFeature}.<br>
711
     *
712
     * Any {@link FeatureSet} from this store that was still in use will be
713
     * invalidated. You can override this using
714
     * {@link FeatureSet#update(EditableFeature)}.
715
     *
716
     * @param feature
717
     *            the feature to be updated
718
     *
719
     * @throws DataException
720
     */
721
    public void update(EditableFeature feature) throws DataException;
722

    
723
    /**
724
     * Deletes a {@link Feature} from the store.<br>
725
     *
726
     * Any {@link FeatureSet} from this store that was still in use will be
727
     * invalidated. You can override this using {@link Iterator#remove()} from
728
     * {@link FeatureSet}.
729
     *
730
     * @param feature
731
     *            The feature to be deleted.
732
     *
733
     * @throws DataException
734
     */
735
    public void delete(Feature feature) throws DataException;
736

    
737
    /**
738
     * Inserts a {@link Feature} in the store.<br>
739
     *
740
     * Any {@link FeatureSet} from this store that was still in use will be
741
     * invalidated. You can override this using
742
     * {@link FeatureSet#insert(EditableFeature)}.
743
     *
744
     * @param feature
745
     *            The feature to be inserted
746
     *
747
     * @throws DataException
748
     */
749
    public void insert(EditableFeature feature) throws DataException;
750

    
751
    /**
752
     * Creates a new feature using the default feature type and returns it as an
753
     * {@link EditableFeature}
754
     *
755
     * @return a new feature in editable state
756
     *
757
     * @throws DataException
758
     */
759
    public EditableFeature createNewFeature() throws DataException;
760

    
761
    /**
762
     * Creates a new feature of the given {@link FeatureType} and uses the given
763
     * {@link Feature} as default values to initialize it.
764
     *
765
     * @param type
766
     *            the new feature's feature type
767
     *
768
     * @param defaultValues
769
     *            a feature whose values are used as default values for the new
770
     *            feature.
771
     *
772
     * @return the new feature.
773
     *
774
     * @throws DataException
775
     */
776
    public EditableFeature createNewFeature(FeatureType type,
777
        Feature defaultValues) throws DataException;
778

    
779
    /**
780
     * Creates a new feature of the given {@link FeatureType}. The flag
781
     * defaultValues is used to indicate whether the new feature should be
782
     * initialized with default values or not.
783
     *
784
     * @param type
785
     *            the new feature's feature type
786
     *
787
     * @param defaultValues
788
     *            if true the new feature is initialized with each attribute's
789
     *            default value.
790
     *
791
     * @return
792
     *         the new feature
793
     *
794
     * @throws DataException
795
     */
796
    public EditableFeature createNewFeature(FeatureType type,
797
        boolean defaultValues) throws DataException;
798

    
799
    /**
800
     * Creates a new feature of default {@link FeatureType}. The flag
801
     * defaultValues is used to indicate whether the new feature should be
802
     * initialized with default values or not.
803
     *
804
     * @param defaultValues
805
     *            if true the new feature is initialized with each attribute's
806
     *            default value.
807
     *
808
     * @return
809
     *         the new feature
810
     *
811
     * @throws DataException
812
     */
813
    public EditableFeature createNewFeature(boolean defaultValues)
814
        throws DataException;
815

    
816
    /**
817
     * Creates a new feature of default {@link FeatureType}.
818
     * The new feature should be initialized with the values of the feature
819
     * passed as parameter.
820
     * Values are inicialiced by name from the feature specified. Error in
821
     * value assignement are ignoreds.
822
     *
823
     * @param defaultValues the values to initialize the new feature.
824
     * @return the new feature
825
     * @throws DataException
826
     */
827
    public EditableFeature createNewFeature(Feature defaultValues)
828
        throws DataException;
829

    
830
    /**
831
     * Applies the validation rules associated to the given mode to the active
832
     * {@link FeatureSet}.
833
     *
834
     * @param mode
835
     *            can be one of {MODE_QUERY, MODE_FULLEDIT, MODE_APPEND}
836
     *
837
     * @throws DataException
838
     */
839
    public void validateFeatures(int mode) throws DataException;
840

    
841
    /**
842
     * Indicates whether this store supports append mode.
843
     *
844
     * @return
845
     *         true if this store supports append mode.
846
     */
847
    public boolean isAppendModeSupported();
848

    
849
    /**
850
     * Initiates an editing group. This is typically used to group series of
851
     * store editing operations.
852
     *
853
     * @param description
854
     *            Description of the editing group.
855
     *
856
     * @throws NeedEditingModeException
857
     */
858
    public void beginEditingGroup(String description)
859
        throws NeedEditingModeException;
860

    
861
    /**
862
     * Finishes an editing group.
863
     *
864
     * @throws NeedEditingModeException
865
     */
866
    public void endEditingGroup() throws NeedEditingModeException;
867

    
868
    /*
869
     * =============================================================
870
     *
871
     * Index related services
872
     */
873

    
874
    /**
875
     * Creates an index which will be applied to the features of the given type,
876
     * by using the data of the given attribute.
877
     *
878
     * @param featureType
879
     *            The FeatureType to which the indexed attribute belongs.
880
     *
881
     * @param attributeName
882
     *            The name of the attributed to be indexed
883
     *
884
     * @param indexName
885
     *            The index name
886
     *
887
     * @return the resulting {@link FeatureIndex}
888
     *
889
     *
890
     * @throws FeatureIndexException
891
     *             if there is an error creating the index
892
     */
893
    public FeatureIndex createIndex(FeatureType featureType,
894
        String attributeName, String indexName) throws DataException;
895

    
896
    /**
897
     * Creates an index which will be applied to the features of the given type,
898
     * by using the data of the given attribute.
899
     *
900
     * @param indexTypeName
901
     *            the type of the index to be created. That name is
902
     *            related to one of the registered index providers
903
     * @param featureType
904
     *            The FeatureType to which the indexed attribute belongs.
905
     *
906
     * @param attributeName
907
     *            The name of the attributed to be indexed
908
     *
909
     * @param indexName
910
     *            The index name
911
     *
912
     * @return the resulting {@link FeatureIndex}
913
     *
914
     *
915
     * @throws FeatureIndexException
916
     *             if there is an error creating the index
917
     */
918
    public FeatureIndex createIndex(String indexTypeName,
919
        FeatureType featureType, String attributeName, String indexName)
920
        throws DataException;
921

    
922
    /**
923
     * Creates an index which will be applied to the features of the given type,
924
     * by using the data of the given attribute. This method will return without
925
     * waiting for the index to be filled, as that will be performed in
926
     * background. An optional {@link Observer} parameter is provided to be
927
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
928
     * when the index has finished filling with data and is available to be
929
     * used.
930
     *
931
     * @param featureType
932
     *            The FeatureType to which the indexed attribute belongs.
933
     *
934
     * @param attributeName
935
     *            The name of the attributed to be indexed
936
     *
937
     * @param indexName
938
     *            The index name
939
     *
940
     * @param observer
941
     *            to notify to when the created index has finished filling
942
     *            with data and is available to be used. The observer will
943
     *            receive then a
944
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
945
     *            notification, with the index object if it has finished
946
     *            successfully, or a
947
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
948
     *            notification with the exception object if there has been
949
     *            any error in the process. Optional.
950
     *
951
     * @return the resulting {@link FeatureIndex}
952
     *
953
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
954
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
955
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
956
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
957
     *
958
     * @throws FeatureIndexException
959
     *             if there is an error creating the index
960
     */
961
    public FeatureIndex createIndex(FeatureType featureType,
962
        String attributeName, String indexName, Observer observer)
963
        throws DataException;
964

    
965
    /**
966
     * Creates an index which will be applied to the features of the given type,
967
     * by using the data of the given attribute. This method will return without
968
     * waiting for the index to be filled, as that will be performed in
969
     * background. An optional {@link Observer} parameter is provided to be
970
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
971
     * when the index has finished filling with data and is available to be
972
     * used.
973
     *
974
     * @param indexTypeName
975
     *            the type of the index to be created. That name is
976
     *            related to one of the registered index providers
977
     * @param featureType
978
     *            The FeatureType to which the indexed attribute belongs.
979
     *
980
     * @param attributeName
981
     *            The name of the attributed to be indexed
982
     *
983
     * @param indexName
984
     *            The index name
985
     *
986
     * @param observer
987
     *            to notify to when the created index has finished filling
988
     *            with data and is available to be used. The observer will
989
     *            receive then a
990
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
991
     *            notification, with the index object if it has finished
992
     *            successfully, or a
993
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
994
     *            notification with the exception object if there has been
995
     *            any error in the process. Optional.
996
     *
997
     * @return the resulting {@link FeatureIndex}
998
     *
999
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
1000
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
1001
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
1002
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
1003
     *
1004
     * @throws FeatureIndexException
1005
     *             if there is an error creating the index
1006
     */
1007
    public FeatureIndex createIndex(String indexTypeName,
1008
        FeatureType featureType, String attributeName, String indexName,
1009
        Observer observer) throws DataException;
1010

    
1011
    /**
1012
     * Returns a FeatureIndexes structure containing all available indexes in
1013
     * the store.
1014
     *
1015
     * @return
1016
     */
1017
    public FeatureIndexes getIndexes();
1018

    
1019
    /*
1020
     * =============================================================
1021
     *
1022
     * Selection related services
1023
     */
1024

    
1025
    /**
1026
     * Sets the selection to the passed {@link FeatureSet}
1027
     *
1028
     * @param selection
1029
     *            A {@link FeatureSet} with the requested selection
1030
     */
1031
    public void setSelection(FeatureSet selection) throws DataException;
1032

    
1033
    /**
1034
     * Creates a {@link FeatureSelection}
1035
     *
1036
     * @return
1037
     *         a {@link FeatureSelection}
1038
     *
1039
     * @throws DataException
1040
     */
1041
    public FeatureSelection createFeatureSelection() throws DataException;
1042

    
1043
    /**
1044
     * Returns the current {@link FeatureSelection}.
1045
     * Create a empty selection if not exits.
1046
     * 
1047
     * Manage of the selection can be slow on some data sources. 
1048
     * Use with care.
1049
     * In data sources that do not support position access to records, 
1050
     * it may be slow to retrieve items from the selection. In some data 
1051
     * sources it may be necessary to access to this to retrieve each 
1052
     * item in the selection.
1053
     *
1054
     * @return
1055
     *         current {@link FeatureSelection}.
1056
     *
1057
     * @throws DataException
1058
     */
1059
    public FeatureSelection getFeatureSelection() throws DataException;
1060

    
1061
    /*
1062
     * =============================================================
1063
     *
1064
     * Lock related services
1065
     */
1066

    
1067
    /**
1068
     * Indicates whether this store supports locks.
1069
     *
1070
     * @return
1071
     *         true if this store supports locks, false if not.
1072
     */
1073
    public boolean isLocksSupported();
1074

    
1075
    /**
1076
     * Returns the set of locked features
1077
     *
1078
     * @return
1079
     *         set of locked features
1080
     *
1081
     * @throws DataException
1082
     */
1083
    public FeatureLocks getLocks() throws DataException;
1084

    
1085
    /*
1086
     * =============================================================
1087
     * Transforms related services
1088
     * =============================================================
1089
     */
1090

    
1091
    /**
1092
     * Returns this store transforms
1093
     *
1094
     * @return
1095
     *         this store transforms
1096
     */
1097
    public FeatureStoreTransforms getTransforms();
1098

    
1099
    /**
1100
     * Returns a new {@link FeatureQuery} associated to this store.
1101
     *
1102
     * @return
1103
     *         a new {@link FeatureQuery} associated to this store.
1104
     */
1105
    public FeatureQuery createFeatureQuery();
1106

    
1107
    /**
1108
     * Returns featue count of this store.
1109
     *
1110
     * @return
1111
     * @throws DataException
1112
     */
1113
    public long getFeatureCount() throws DataException;
1114

    
1115
//    /**
1116
//     * Creates a vectorial cache that is used to save and retrieve data.
1117
//     *
1118
//     * @param name
1119
//     *            the cache name.
1120
//     * @param parameters
1121
//     *            parameters to create the stores used to save data.
1122
//     * @throws DataException
1123
//     */
1124
//    public void createCache(String name, DynObject parameters)
1125
//        throws DataException;
1126
//
1127
//    /**
1128
//     * @return the vectorial cache
1129
//     */
1130
//    public FeatureCache getCache();
1131

    
1132
    /**
1133
     * Return if the provider knows the real envelope of a layer. If not,
1134
     * the {@link FeatureStoreProvider#getEnvelope()} method doesn't return
1135
     * the full envelope.
1136
     *
1137
     * @return
1138
     *         <true> if it knows the real envelope.
1139
     */
1140
    public boolean isKnownEnvelope();
1141

    
1142
    /**
1143
     * Return if the maximum number of features provided by the
1144
     * provider are limited.
1145
     *
1146
     * @return
1147
     *         <true> if there is a limit of features.
1148
     */
1149
    public boolean hasRetrievedFeaturesLimit();
1150

    
1151
    /**
1152
     * If the {@link FeatureStoreProvider#hasRetrievedFeaturesLimit()} returns
1153
     * true,
1154
     * it returns the limit of features retrieved from the provider.
1155
     *
1156
     * @return
1157
     *         The limit of the retrieved features.
1158
     */
1159
    public int getRetrievedFeaturesLimit();
1160

    
1161
    /**
1162
     * Return the associated feature to the dynobject.
1163
     * If the dynobject isn't associated to a feature of this store, return null.
1164
     *
1165
     * @param dynobject
1166
     * @return
1167
     */
1168
    public Feature getFeature(DynObject dynobject);
1169

    
1170
    public Iterator iterator();
1171

    
1172
    public ExpressionBuilder createExpressionBuilder();
1173

    
1174
    /**
1175
     * 
1176
     * @return 
1177
     * @deprecated use createExpressionBuilder
1178
     */
1179
    public ExpressionBuilder createExpression();
1180

    
1181
    public void createCache(String name, DynObject parameters)
1182
        throws DataException;
1183

    
1184
    public FeatureCache getCache();
1185

    
1186
    public boolean isBroken();
1187

    
1188
        public Throwable getBreakingsCause();
1189

    
1190
    /**
1191
     * @param index
1192
     * @return
1193
     */
1194
    public SpatialIndex wrapSpatialIndex(SpatialIndex index);
1195
    
1196
    public FeatureReference getFeatureReference(String code);
1197

    
1198
    /**
1199
     * Devuelbe el numero de operaciones pendientes de guardar en una sesion
1200
     * de edicion. Es un valor orientativo.
1201
     * Las operaciones pendientes son la suma de operaciones de borrado, insercion
1202
     * o modificacion de las features en una sesion de edicion.
1203
     * 
1204
     * Retorna 0 si no esta en edicion.
1205
     * 
1206
     * @return numero de operaciones pendientes. 
1207
     */
1208
    public long getPendingChangesCount();
1209
    
1210
    public Feature getSampleFeature();
1211
}