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

History | View | Annotate | Download (44.7 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
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
import javax.json.JsonObject;
29

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

    
34
import org.gvsig.fmap.dal.DataServerExplorer;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.DataStoreParameters;
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.util.Size64;
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, Iterable<Feature>, Size64 {
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
    public FeatureType getDefaultFeatureTypeQuietly();
117

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

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

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

    
148
    /**
149
     * @param gvSIGgeometryType
150
     * @return 
151
     * @throws DataException
152
     * @deprecated Mirar de cambiarlo a metadatos
153
     */
154
    public boolean canWriteGeometry(int gvSIGgeometryType) throws DataException;
155

    
156
    /**
157
     * Returns this store's total envelope (extent).
158
     *
159
     * @return this store's total envelope (extent) or <code>null</code> if
160
     *         store not have geometry information
161
     * @throws org.gvsig.fmap.dal.exception.DataException
162
     */
163
    public Envelope getEnvelope() throws DataException;
164

    
165
    /**
166
     *
167
     * @deprecated use getDefaultFeatureType().getDefaultSRS()
168
     * @return
169
     * @throws DataException
170
     */
171
    public IProjection getSRSDefaultGeometry() throws DataException;
172

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

    
190
    public void copyTo(FeatureStore target);
191

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

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

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

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

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

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

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

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

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

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

    
372
    /**
373
     * Loads all available feature in the store. The loading of Features is
374
     * performed by calling the Observer, once each loaded Feature.
375
     *
376
     * @param observer to be notified of each loaded Feature
377
     * @throws DataException if there is any error while loading the features
378
     */
379
    void getFeatureSet(Observer observer) throws DataException;
380

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

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

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

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

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

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

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

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

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

    
502
    /**
503
     * Return the first {@link Feature} of the store.
504
     * 
505
     * @return the first {@link Feature} or null if the store is empty.
506
     * @throws DataException 
507
     */
508
    public Feature first() throws DataException;
509

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

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

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

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

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

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

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

    
600
    /**
601
     * Returns the feature given its reference.
602
     *
603
     * @param reference a unique FeatureReference
604
     * @return 
605
     * @returnThe Feature
606
     * @throws DataException
607
     *
608
     */
609
    public Feature getFeatureByReference(FeatureReference reference) throws DataException;
610

    
611
    /**
612
     * Returns the feature given its reference and feature type.
613
     *
614
     * @param reference
615
     *            a unique FeatureReference
616
     *
617
     * @param featureType
618
     *            FeatureType to which the requested Feature belongs
619
     *
620
     * @return
621
     *         The Feature
622
     *
623
     * @throws DataException
624
     *
625
     */
626
    public Feature getFeatureByReference(FeatureReference reference,
627
        FeatureType featureType) throws DataException;
628

    
629
    /*
630
     * =============================================================
631
     *
632
     * Editing related services
633
     */
634

    
635
    /**
636
     * Enters editing state.
637
     * @throws org.gvsig.fmap.dal.exception.DataException
638
     */
639
    public void edit() throws DataException;
640

    
641
    /**
642
     * Enters editing state specifying the editing mode.
643
     *
644
     * @param mode
645
     *
646
     * @throws DataException
647
     */
648
    public void edit(int mode) throws DataException;
649

    
650
    /**
651
     * Cancels all editing since the last edit().
652
     *
653
     * @throws DataException
654
     */
655
    public void cancelEditing() throws DataException;
656

    
657
    /**
658
     * Exits editing state.
659
     *
660
     * @throws DataException
661
     */
662
    public void finishEditing() throws DataException;
663

    
664
    /**
665
     * Save changes in the provider without leaving the edit mode.
666
     * Do not call observers to communicate a change of ediding mode.
667
     * The operation's history is eliminated to prevent inconsistencies
668
     * in the data.
669
     *
670
     * @throws DataException
671
     */
672
    public void commitChanges() throws DataException ;
673

    
674
    /**
675
     *
676
     * Returns true if you can call CommitChanges method.
677
     * If not in editing or changes have been made in the structure
678
     * return false.
679
     *
680
     * @return true if can call commitChanges
681
     * @throws DataException
682
     */
683
    public boolean canCommitChanges() throws DataException;
684

    
685

    
686
    /**
687
     * Indicates whether this store is in editing state.
688
     *
689
     * @return
690
     *         true if this store is in editing state, false if not.
691
     */
692
    public boolean isEditing();
693

    
694
    /**
695
     * Indicates whether this store is in appending state. In this state the new
696
     * features are automatically inserted at the end of the {@link FeatureSet}.
697
     *
698
     * @return true if this store is in appending state.
699
     */
700
    public boolean isAppending();
701

    
702
    /**
703
     * Updates a {@link FeatureType} in the store with the changes in the
704
     * {@link EditableFeatureType}.<br>
705
     *
706
     * Any {@link FeatureSet} from this store that are used will be invalidated.
707
     *
708
     * @param featureType
709
     *            an {@link EditableFeatureType} with the changes.
710
     *
711
     * @throws DataException
712
     */
713
    public void update(EditableFeatureType featureType) throws DataException;
714

    
715
    /**
716
     * Updates a {@link Feature} in the store with the changes in the
717
     * {@link EditableFeature}.<br>
718
     *
719
     * Any {@link FeatureSet} from this store that was still in use will be
720
     * invalidated. You can override this using
721
     * {@link FeatureSet#update(EditableFeature)}.
722
     *
723
     * @param feature
724
     *            the feature to be updated
725
     *
726
     * @throws DataException
727
     */
728
    public void update(EditableFeature feature) throws DataException;
729

    
730
    /**
731
     * Deletes a {@link Feature} from the store.<br>
732
     *
733
     * Any {@link FeatureSet} from this store that was still in use will be
734
     * invalidated. You can override this using {@link Iterator#remove()} from
735
     * {@link FeatureSet}.
736
     *
737
     * @param feature
738
     *            The feature to be deleted.
739
     *
740
     * @throws DataException
741
     */
742
    public void delete(Feature feature) throws DataException;
743

    
744
    /**
745
     * Inserts a {@link Feature} in the store.<br>
746
     *
747
     * Any {@link FeatureSet} from this store that was still in use will be
748
     * invalidated. You can override this using
749
     * {@link FeatureSet#insert(EditableFeature)}.
750
     *
751
     * @param feature
752
     *            The feature to be inserted
753
     *
754
     * @throws DataException
755
     */
756
    public void insert(EditableFeature feature) throws DataException;
757

    
758
    /**
759
     * Inserts a set of {@link Feature} in the store.
760
     * 
761
     * The attributes of the feature are copied from the features of the set 
762
     * by name, forcing the conversion of types if necessary.
763
     *
764
     * Any {@link FeatureSet} from this store that was still in use will be
765
     * invalidated.
766
     *
767
     * @param set, set with the source features.
768
     * @throws DataException
769
     */
770
    public void insert(FeatureSet set) throws DataException;
771
    
772
    /**
773
     * Creates a new feature using the default feature type and returns it as an
774
     * {@link EditableFeature}
775
     *
776
     * @return a new feature in editable state
777
     *
778
     * @throws DataException
779
     */
780
    public EditableFeature createNewFeature() throws DataException;
781

    
782
    /**
783
     * Creates a new feature of the given {@link FeatureType} and uses the given
784
     * {@link Feature} as default values to initialize it.
785
     *
786
     * @param type
787
     *            the new feature's feature type
788
     *
789
     * @param defaultValues
790
     *            a feature whose values are used as default values for the new
791
     *            feature.
792
     *
793
     * @return the new feature.
794
     *
795
     * @throws DataException
796
     */
797
    public EditableFeature createNewFeature(FeatureType type,
798
        Feature defaultValues) throws DataException;
799

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

    
820
    /**
821
     * Creates a new feature of default {@link FeatureType}. The flag
822
     * defaultValues is used to indicate whether the new feature should be
823
     * initialized with default values or not.
824
     *
825
     * @param defaultValues
826
     *            if true the new feature is initialized with each attribute's
827
     *            default value.
828
     *
829
     * @return
830
     *         the new feature
831
     *
832
     * @throws DataException
833
     */
834
    public EditableFeature createNewFeature(boolean defaultValues)
835
        throws DataException;
836

    
837
    /**
838
     * Creates a new feature of default {@link FeatureType}.
839
     * The new feature should be initialized with the values of the feature
840
     * passed as parameter.
841
     * Values are inicialiced by name from the feature specified. Error in
842
     * value assignement are ignoreds.
843
     *
844
     * @param defaultValues the values to initialize the new feature.
845
     * @return the new feature
846
     * @throws DataException
847
     */
848
    public EditableFeature createNewFeature(Feature defaultValues)
849
        throws DataException;
850

    
851
    public EditableFeature createNewFeature(JsonObject defaultValues)
852
        throws DataException;
853

    
854
    /**
855
     * Applies the validation rules associated to the given mode to the active
856
     * {@link FeatureSet}.
857
     *
858
     * @param mode
859
     *            can be one of {MODE_QUERY, MODE_FULLEDIT, MODE_APPEND}
860
     *
861
     * @throws DataException
862
     */
863
    public void validateFeatures(int mode) throws DataException;
864

    
865
    /**
866
     * Indicates whether this store supports append mode.
867
     *
868
     * @return
869
     *         true if this store supports append mode.
870
     */
871
    public boolean isAppendModeSupported();
872

    
873
    /**
874
     * Initiates an editing group. This is typically used to group series of
875
     * store editing operations.
876
     *
877
     * @param description
878
     *            Description of the editing group.
879
     *
880
     * @throws NeedEditingModeException
881
     */
882
    public void beginEditingGroup(String description)
883
        throws NeedEditingModeException;
884

    
885
    /**
886
     * Finishes an editing group.
887
     *
888
     * @throws NeedEditingModeException
889
     */
890
    public void endEditingGroup() throws NeedEditingModeException;
891

    
892
    /*
893
     * =============================================================
894
     *
895
     * Index related services
896
     */
897

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

    
920
    /**
921
     * Creates an index which will be applied to the features of the given type,
922
     * by using the data of the given attribute.
923
     *
924
     * @param indexTypeName
925
     *            the type of the index to be created. That name is
926
     *            related to one of the registered index providers
927
     * @param featureType
928
     *            The FeatureType to which the indexed attribute belongs.
929
     *
930
     * @param attributeName
931
     *            The name of the attributed to be indexed
932
     *
933
     * @param indexName
934
     *            The index name
935
     *
936
     * @return the resulting {@link FeatureIndex}
937
     *
938
     *
939
     * @throws FeatureIndexException
940
     *             if there is an error creating the index
941
     */
942
    public FeatureIndex createIndex(String indexTypeName,
943
        FeatureType featureType, String attributeName, String indexName)
944
        throws DataException;
945

    
946
    /**
947
     * Creates an index which will be applied to the features of the given type,
948
     * by using the data of the given attribute. This method will return without
949
     * waiting for the index to be filled, as that will be performed in
950
     * background. An optional {@link Observer} parameter is provided to be
951
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
952
     * when the index has finished filling with data and is available to be
953
     * used.
954
     *
955
     * @param featureType
956
     *            The FeatureType to which the indexed attribute belongs.
957
     *
958
     * @param attributeName
959
     *            The name of the attributed to be indexed
960
     *
961
     * @param indexName
962
     *            The index name
963
     *
964
     * @param observer
965
     *            to notify to when the created index has finished filling
966
     *            with data and is available to be used. The observer will
967
     *            receive then a
968
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
969
     *            notification, with the index object if it has finished
970
     *            successfully, or a
971
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
972
     *            notification with the exception object if there has been
973
     *            any error in the process. Optional.
974
     *
975
     * @return the resulting {@link FeatureIndex}
976
     *
977
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
978
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
979
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
980
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
981
     *
982
     * @throws FeatureIndexException
983
     *             if there is an error creating the index
984
     */
985
    public FeatureIndex createIndex(FeatureType featureType,
986
        String attributeName, String indexName, Observer observer)
987
        throws DataException;
988

    
989
    /**
990
     * Creates an index which will be applied to the features of the given type,
991
     * by using the data of the given attribute. This method will return without
992
     * waiting for the index to be filled, as that will be performed in
993
     * background. An optional {@link Observer} parameter is provided to be
994
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
995
     * when the index has finished filling with data and is available to be
996
     * used.
997
     *
998
     * @param indexTypeName
999
     *            the type of the index to be created. That name is
1000
     *            related to one of the registered index providers
1001
     * @param featureType
1002
     *            The FeatureType to which the indexed attribute belongs.
1003
     *
1004
     * @param attributeName
1005
     *            The name of the attributed to be indexed
1006
     *
1007
     * @param indexName
1008
     *            The index name
1009
     *
1010
     * @param observer
1011
     *            to notify to when the created index has finished filling
1012
     *            with data and is available to be used. The observer will
1013
     *            receive then a
1014
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
1015
     *            notification, with the index object if it has finished
1016
     *            successfully, or a
1017
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
1018
     *            notification with the exception object if there has been
1019
     *            any error in the process. Optional.
1020
     *
1021
     * @return the resulting {@link FeatureIndex}
1022
     *
1023
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
1024
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
1025
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
1026
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
1027
     *
1028
     * @throws FeatureIndexException
1029
     *             if there is an error creating the index
1030
     */
1031
    public FeatureIndex createIndex(String indexTypeName,
1032
        FeatureType featureType, String attributeName, String indexName,
1033
        Observer observer) throws DataException;
1034

    
1035
    /**
1036
     * Returns a FeatureIndexes structure containing all available indexes in
1037
     * the store.
1038
     *
1039
     * @return
1040
     */
1041
    public FeatureIndexes getIndexes();
1042

    
1043
    /*
1044
     * =============================================================
1045
     *
1046
     * Selection related services
1047
     */
1048

    
1049
    /**
1050
     * Sets the selection to the passed {@link FeatureSet}
1051
     *
1052
     * @param selection
1053
     *            A {@link FeatureSet} with the requested selection
1054
     * @throws org.gvsig.fmap.dal.exception.DataException
1055
     */
1056
    public void setSelection(FeatureSet selection) throws DataException;
1057

    
1058
    /**
1059
     * Creates a {@link FeatureSelection}
1060
     *
1061
     * @return
1062
     *         a {@link FeatureSelection}
1063
     *
1064
     * @throws DataException
1065
     */
1066
    public FeatureSelection createFeatureSelection() throws DataException;
1067

    
1068
    /**
1069
     * Returns the current {@link FeatureSelection}.
1070
     * Create a empty selection if not exits.
1071
     * 
1072
     * Manage of the selection can be slow on some data sources. 
1073
     * Use with care.
1074
     * In data sources that do not support position access to records, 
1075
     * it may be slow to retrieve items from the selection. In some data 
1076
     * sources it may be necessary to access to this to retrieve each 
1077
     * item in the selection.
1078
     *
1079
     * @return
1080
     *         current {@link FeatureSelection}.
1081
     *
1082
     * @throws DataException
1083
     */
1084
    public FeatureSelection getFeatureSelection() throws DataException;
1085

    
1086
    /*
1087
     * =============================================================
1088
     *
1089
     * Lock related services
1090
     */
1091

    
1092
    /**
1093
     * Indicates whether this store supports locks.
1094
     *
1095
     * @return
1096
     *         true if this store supports locks, false if not.
1097
     */
1098
    public boolean isLocksSupported();
1099

    
1100
    /**
1101
     * Returns the set of locked features
1102
     *
1103
     * @return
1104
     *         set of locked features
1105
     *
1106
     * @throws DataException
1107
     */
1108
    public FeatureLocks getLocks() throws DataException;
1109

    
1110
    /*
1111
     * =============================================================
1112
     * Transforms related services
1113
     * =============================================================
1114
     */
1115

    
1116
    /**
1117
     * Returns this store transforms
1118
     *
1119
     * @return
1120
     *         this store transforms
1121
     */
1122
    public FeatureStoreTransforms getTransforms();
1123

    
1124
    /**
1125
     * Returns a new {@link FeatureQuery} associated to this store.
1126
     *
1127
     * @return
1128
     *         a new {@link FeatureQuery} associated to this store.
1129
     */
1130
    public FeatureQuery createFeatureQuery();
1131

    
1132
    /**
1133
     * Returns featue count of this store.
1134
     *
1135
     * @return
1136
     * @throws DataException
1137
     */
1138
    public long getFeatureCount() throws DataException;
1139

    
1140
//    /**
1141
//     * Creates a vectorial cache that is used to save and retrieve data.
1142
//     *
1143
//     * @param name
1144
//     *            the cache name.
1145
//     * @param parameters
1146
//     *            parameters to create the stores used to save data.
1147
//     * @throws DataException
1148
//     */
1149
//    public void createCache(String name, DynObject parameters)
1150
//        throws DataException;
1151
//
1152
//    /**
1153
//     * @return the vectorial cache
1154
//     */
1155
//    public FeatureCache getCache();
1156

    
1157
    /**
1158
     * Return if the provider knows the real envelope of a layer. If not,
1159
     * the {@link FeatureStoreProvider#getEnvelope()} method doesn't return
1160
     * the full envelope.
1161
     *
1162
     * @return true if it knows the real envelope.
1163
     */
1164
    public boolean isKnownEnvelope();
1165

    
1166
    /**
1167
     * Return if the maximum number of features provided by the
1168
     * provider are limited.
1169
     *
1170
     * @return true if there is a limit of features.
1171
     */
1172
    public boolean hasRetrievedFeaturesLimit();
1173

    
1174
    /**
1175
     * If the {@link FeatureStoreProvider#hasRetrievedFeaturesLimit()} returns
1176
     * true,
1177
     * it returns the limit of features retrieved from the provider.
1178
     *
1179
     * @return
1180
     *         The limit of the retrieved features.
1181
     */
1182
    public int getRetrievedFeaturesLimit();
1183

    
1184
    /**
1185
     * Return the associated feature to the dynobject.
1186
     * If the dynobject isn't associated to a feature of this store, return null.
1187
     *
1188
     * @param dynobject
1189
     * @return
1190
     */
1191
    public Feature getFeature(DynObject dynobject);
1192

    
1193

    
1194
    public ExpressionBuilder createExpressionBuilder();
1195

    
1196
    /**
1197
     * 
1198
     * @return 
1199
     * @deprecated use createExpressionBuilder
1200
     */
1201
    public ExpressionBuilder createExpression();
1202

    
1203
    public void createCache(String name, DynObject parameters)
1204
        throws DataException;
1205

    
1206
    @Override
1207
    public FeatureCache getCache();
1208

    
1209
    public boolean isBroken();
1210

    
1211
    public Throwable getBreakingsCause();
1212

    
1213
    /**
1214
     * Indicates if the storage is temporary.
1215
     * There is no guarantee that a temporary store can be recovered from 
1216
     * its parameters. In general these will not be persistent.
1217
     * 
1218
     * @return true if the store is temporary, otherwise false.
1219
     */
1220
    public boolean isTemporary();
1221
    
1222
    /**
1223
     * @param index
1224
     * @return
1225
     */
1226
    public SpatialIndex wrapSpatialIndex(SpatialIndex index);
1227
    
1228
    public FeatureReference getFeatureReference(String code);
1229

    
1230
    /**
1231
     * Devuelbe el numero de operaciones pendientes de guardar en una sesion
1232
     * de edicion. Es un valor orientativo.
1233
     * Las operaciones pendientes son la suma de operaciones de borrado, insercion
1234
     * o modificacion de las features en una sesion de edicion.
1235
     * 
1236
     * Retorna 0 si no esta en edicion.
1237
     * 
1238
     * @return numero de operaciones pendientes. 
1239
     */
1240
    public long getPendingChangesCount();
1241
    
1242
    public Feature getSampleFeature();
1243
    
1244
    /**
1245
     * Return true when the default feature type of the store 
1246
     * support references.
1247
     * 
1248
     * @return true when support references.
1249
     */
1250
    public boolean supportReferences();
1251
}