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

History | View | Annotate | Download (44 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.UnmodifiableBasicList64;
50

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
183
    public void copyTo(FeatureStore target);
184

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
677

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

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

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

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

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

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

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

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

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

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

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

    
829
    public EditableFeature createNewFeature(JsonObject defaultValues)
830
        throws DataException;
831

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

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

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

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

    
870
    /*
871
     * =============================================================
872
     *
873
     * Index related services
874
     */
875

    
876
    /**
877
     * Creates an index which will be applied to the features of the given type,
878
     * by using the data of the given attribute.
879
     *
880
     * @param featureType
881
     *            The FeatureType to which the indexed attribute belongs.
882
     *
883
     * @param attributeName
884
     *            The name of the attributed to be indexed
885
     *
886
     * @param indexName
887
     *            The index name
888
     *
889
     * @return the resulting {@link FeatureIndex}
890
     *
891
     *
892
     * @throws FeatureIndexException
893
     *             if there is an error creating the index
894
     */
895
    public FeatureIndex createIndex(FeatureType featureType,
896
        String attributeName, String indexName) throws DataException;
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 indexTypeName
903
     *            the type of the index to be created. That name is
904
     *            related to one of the registered index providers
905
     * @param featureType
906
     *            The FeatureType to which the indexed attribute belongs.
907
     *
908
     * @param attributeName
909
     *            The name of the attributed to be indexed
910
     *
911
     * @param indexName
912
     *            The index name
913
     *
914
     * @return the resulting {@link FeatureIndex}
915
     *
916
     *
917
     * @throws FeatureIndexException
918
     *             if there is an error creating the index
919
     */
920
    public FeatureIndex createIndex(String indexTypeName,
921
        FeatureType featureType, String attributeName, String indexName)
922
        throws DataException;
923

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

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

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

    
1021
    /*
1022
     * =============================================================
1023
     *
1024
     * Selection related services
1025
     */
1026

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

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

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

    
1063
    /*
1064
     * =============================================================
1065
     *
1066
     * Lock related services
1067
     */
1068

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

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

    
1087
    /*
1088
     * =============================================================
1089
     * Transforms related services
1090
     * =============================================================
1091
     */
1092

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

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

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

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

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

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

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

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

    
1172
    public Iterator iterator();
1173

    
1174
    public ExpressionBuilder createExpressionBuilder();
1175

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

    
1183
    public void createCache(String name, DynObject parameters)
1184
        throws DataException;
1185

    
1186
    @Override
1187
    public FeatureCache getCache();
1188

    
1189
    public boolean isBroken();
1190

    
1191
    public Throwable getBreakingsCause();
1192

    
1193
    /**
1194
     * Indicates if the storage is temporary.
1195
     * There is no guarantee that a temporary store can be recovered from 
1196
     * its parameters. In general these will not be persistent.
1197
     * 
1198
     * @return true if the store is temporary, otherwise false.
1199
     */
1200
    public boolean isTemporary();
1201
    
1202
    /**
1203
     * @param index
1204
     * @return
1205
     */
1206
    public SpatialIndex wrapSpatialIndex(SpatialIndex index);
1207
    
1208
    public FeatureReference getFeatureReference(String code);
1209

    
1210
    /**
1211
     * Devuelbe el numero de operaciones pendientes de guardar en una sesion
1212
     * de edicion. Es un valor orientativo.
1213
     * Las operaciones pendientes son la suma de operaciones de borrado, insercion
1214
     * o modificacion de las features en una sesion de edicion.
1215
     * 
1216
     * Retorna 0 si no esta en edicion.
1217
     * 
1218
     * @return numero de operaciones pendientes. 
1219
     */
1220
    public long getPendingChangesCount();
1221
    
1222
    public Feature getSampleFeature();
1223
    
1224
    /**
1225
     * Return true when the default feature type of the store 
1226
     * support references.
1227
     * 
1228
     * @return true when support references.
1229
     */
1230
    public boolean supportReferences();
1231
}