Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-cvsgis1 / 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 @ 45277

History | View | Annotate | Download (45.5 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.GetItemWithSizeAndIterator64;
50
import org.gvsig.tools.util.PropertiesSupport;
51
import org.gvsig.tools.util.Size64;
52
import org.gvsig.tools.util.UnmodifiableBasicList64;
53

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

    
86
    public static final String METADATA_DEFINITION_NAME = "FeatureStore";
87

    
88
    /** Indicates that this store is in query mode */
89
    final static int MODE_QUERY = 0;
90

    
91
    /** Indicates that this store is in full edit mode */
92
    final static int MODE_FULLEDIT = 1;
93

    
94
    /** Indicates that this store is in append mode */
95
    final static int MODE_APPEND = 2;
96
    
97
    final static int MODE_PASS_THROUGH = MODE_FULLEDIT;
98

    
99
    /*
100
     * =============================================================
101
     *
102
     * information related services
103
     */
104

    
105
    /**
106
     * Indicates whether this store allows writing.
107
     *
108
     * @return
109
     *         true if this store can be written, false if not.
110
     */
111
    public boolean allowWrite();
112

    
113
    /**
114
     * Returns this store's default {@link FeatureType}.
115
     *
116
     * @return
117
     *         this store's default {@link FeatureType}.
118
     *
119
     * @throws DataException
120
     */
121
    public FeatureType getDefaultFeatureType() throws DataException;
122
    
123
    public FeatureType getDefaultFeatureTypeQuietly();
124

    
125
    /**
126
     * Returns this store's featureType {@link FeatureType} matches with
127
     * featureTypeId.
128
     *
129
     * @param featureTypeId
130
     *
131
     * @return this store's default {@link FeatureType}.
132
     *
133
     * @throws DataException
134
     */
135
    public FeatureType getFeatureType(String featureTypeId)
136
        throws DataException;
137

    
138
    /**
139
     * Returns this store's {@link FeatureType}(s).
140
     *
141
     * @return a list with this store's {@link FeatureType}(s).
142
     *
143
     * @throws DataException
144
     */
145
    public List getFeatureTypes() throws DataException;
146

    
147
    /**
148
     * Returns this store's parameters.
149
     *
150
     * @return
151
     *         {@link DataStoreParameters} containing this store's parameters
152
     */
153
    public DataStoreParameters getParameters();
154

    
155
    /**
156
     * @param gvSIGgeometryType
157
     * @return 
158
     * @throws DataException
159
     * @deprecated Mirar de cambiarlo a metadatos
160
     */
161
    public boolean canWriteGeometry(int gvSIGgeometryType) throws DataException;
162

    
163
    /**
164
     * Returns this store's total envelope (extent).
165
     *
166
     * @return this store's total envelope (extent) or <code>null</code> if
167
     *         store not have geometry information
168
     * @throws org.gvsig.fmap.dal.exception.DataException
169
     */
170
    public Envelope getEnvelope() throws DataException;
171

    
172
    /**
173
     *
174
     * @deprecated use getDefaultFeatureType().getDefaultSRS()
175
     * @return
176
     * @throws DataException
177
     */
178
    public IProjection getSRSDefaultGeometry() throws DataException;
179

    
180
    /**
181
     * Exports this store to another store.
182
     *
183
     * @param explorer
184
     *            {@link DataServerExplorer} target
185
     * @param provider
186
     * @param params
187
     *            New parameters of this store that will be used on the target
188
     *            explorer
189
     *
190
     * @throws DataException
191
     *
192
     * @Deprecated this method is unstable
193
     */
194
    public void export(DataServerExplorer explorer, String provider,
195
        NewFeatureStoreParameters params) throws DataException;
196

    
197
    public void copyTo(FeatureStore target);
198

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

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

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

    
272
    /**
273
     * Return a subset of features.
274
     * 
275
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
276
     * 
277
     * The sort order used is ascending.
278
     * 
279
     * @param filter an {@link String} expression used to filter the features in the store.
280
     * @param sortBy Attribute names separated by commas used to sort the list to return.
281
     * @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) 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 String} expression used to filter the features in the store.
293
     * @param sortBy Attribute names separated by commas used to sort the list to return.
294
     * @param asc use order ascending, true, or descending, false.
295
     * @return the {@link FeatureSet} 
296
     * @throws ReadException if there is any error while reading the features
297
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
298
     */
299
    FeatureSet getFeatureSet(String filter, String sortBy, boolean asc) throws DataException;
300

    
301
    /**
302
     * Return a subset of features.
303
     * 
304
     * It is a utility method that calls {@link #getFeatureSet(FeatureQuery)}
305
     * 
306
     * @param filter an {@link Expression} used to filter the features in the store.
307
     * @return the {@link FeatureSet} 
308
     * @throws DataException 
309
     * @see {@link #createFeatureQuery(Expression,String,boolean)}, {@link #getFeatureSet(FeatureQuery)}
310
     */
311
    FeatureSet getFeatureSet(Expression filter) throws DataException;
312

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

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

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

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

    
379
    /**
380
     * Loads all available feature in the store. The loading of Features is
381
     * performed by calling the Observer, once each loaded Feature.
382
     *
383
     * @param observer to be notified of each loaded Feature
384
     * @throws DataException if there is any error while loading the features
385
     */
386
    void getFeatureSet(Observer observer) throws DataException;
387

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

    
409
    /**
410
     * Return a paginated list of Features.
411
     * 
412
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
413
     * using the default page size.
414
     * 
415
     * @param query to filter and sort the returned feature list
416
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
417
     * @see {@link #getFeatures(FeatureQuery, int)}
418
     */
419
    public List<Feature> getFeatures(FeatureQuery query);
420

    
421
    /**
422
     * Return a paginated list with al Features in the store.
423
     * 
424
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
425
     * using the default page size.
426
     * 
427
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
428
     * @see {@link #getFeatures(FeatureQuery, int)}
429
     */
430
    public List<Feature> getFeatures();
431

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

    
443
    /**
444
     * Return a paginated list of Features.
445
     * 
446
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
447
     * using the default page size.
448
     * 
449
     * @param filter used to filter the features in the store.
450
     * @param sortBy Attribute names separated by commas used to sort the list to return.
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);
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 String} expression used to filter the features in the store.
463
     * @param sortBy Attribute names separated by commas used to sort the list to return.
464
     * @param asc use order ascending, true, or descending, false.
465
     * @return the {@link List}/{@link UnmodifiableBasicList64} of features
466
     * @see {@link #getFeatures(FeatureQuery, int)}, {@link #createFeatureQuery(String,String,boolean)}
467
     */
468
    public List<Feature> getFeatures(String filter, String sortBy, boolean asc);
469

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

    
482
    /**
483
     * Return a paginated list of Features
484
     * 
485
     * It is a utility method that calls {@link #getFeatures(FeatureQuery, int)}
486
     * using the default page size.
487
     * 
488
     * @param filter an {@link Expression} used to filter the features in the store.
489
     * @param sortBy Attribute names separated by commas used to sort the list to return.
490
     * @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);
494

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

    
509
    public GetItemWithSizeAndIterator64<Feature> getFeatures64();
510

    
511
    public GetItemWithSizeAndIterator64<Feature> getFeatures64(String filter);
512
    
513
    public GetItemWithSizeAndIterator64<Feature> getFeatures64(String filter, String sortBy, boolean asc);
514
    
515
    public GetItemWithSizeAndIterator64<Feature> getFeatures64(FeatureQuery query, int pageSize);
516
    
517
    /**
518
     * Return the first {@link Feature} of the store.
519
     * 
520
     * @return the first {@link Feature} or null if the store is empty.
521
     * @throws DataException 
522
     */
523
    public Feature first() throws DataException;
524

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

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

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

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

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

    
589
    /**
590
     * Returns the first {@link Feature} that meets the criteria indicated.
591
     * 
592
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
593
     * 
594
     * @param filter {@link String} expression used to filter the features.
595
     * @param sortBy Attribute names separated by commas used to sort the list to return.
596
     * @param asc use order ascending, true, or descending, false.
597
     * @return the first {@link Feature} or null if the filter don't return any feature.
598
     * @throws DataException 
599
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
600
     */
601
    public Feature findFirst(Expression filter, String sortBy, boolean asc) throws DataException;
602

    
603
    /**
604
     * Returns the first {@link Feature} that meets the criteria indicated.
605
     * 
606
     * It is a utility method that calls {@link #findFirst(FeatureQuery)}.
607
     * 
608
     * @param query to filter and sort the returned feature list
609
     * @return the first {@link Feature} or null if the filter don't return any feature.
610
     * @throws DataException 
611
     * @see {@link #findFirst(FeatureQuery)}, {@link #createFeatureQuery(Expession,String,boolean)}
612
     */
613
    public Feature findFirst(FeatureQuery query) throws DataException;
614

    
615
    /**
616
     * Returns the feature given its reference.
617
     *
618
     * @param reference a unique FeatureReference
619
     * @return 
620
     * @returnThe Feature
621
     * @throws DataException
622
     *
623
     */
624
    public Feature getFeatureByReference(FeatureReference reference) throws DataException;
625

    
626
    /**
627
     * Returns the feature given its reference and feature type.
628
     *
629
     * @param reference
630
     *            a unique FeatureReference
631
     *
632
     * @param featureType
633
     *            FeatureType to which the requested Feature belongs
634
     *
635
     * @return
636
     *         The Feature
637
     *
638
     * @throws DataException
639
     *
640
     */
641
    public Feature getFeatureByReference(FeatureReference reference,
642
        FeatureType featureType) throws DataException;
643

    
644
    /*
645
     * =============================================================
646
     *
647
     * Editing related services
648
     */
649

    
650
    /**
651
     * Enters editing state.
652
     * @throws org.gvsig.fmap.dal.exception.DataException
653
     */
654
    public void edit() throws DataException;
655

    
656
    /**
657
     * Enters editing state specifying the editing mode.
658
     *
659
     * @param mode
660
     *
661
     * @throws DataException
662
     */
663
    public void edit(int mode) throws DataException;
664

    
665
    /**
666
     * Cancels all editing since the last edit().
667
     *
668
     * @throws DataException
669
     */
670
    public void cancelEditing() throws DataException;
671

    
672
    public boolean cancelEditingQuietly();
673

    
674
    /**
675
     * Exits editing state.
676
     *
677
     * @throws DataException
678
     */
679
    public void finishEditing() throws DataException;
680

    
681
    public boolean finishEditingQuietly();
682
    
683
    /**
684
     * Save changes in the provider without leaving the edit mode.
685
     * Do not call observers to communicate a change of ediding mode.
686
     * The operation's history is eliminated to prevent inconsistencies
687
     * in the data.
688
     *
689
     * @throws DataException
690
     */
691
    public void commitChanges() throws DataException ;
692

    
693
    /**
694
     *
695
     * Returns true if you can call CommitChanges method.
696
     * If not in editing or changes have been made in the structure
697
     * return false.
698
     *
699
     * @return true if can call commitChanges
700
     * @throws DataException
701
     */
702
    public boolean canCommitChanges() throws DataException;
703

    
704

    
705
    /**
706
     * Indicates whether this store is in editing state.
707
     *
708
     * @return
709
     *         true if this store is in editing state, false if not.
710
     */
711
    public boolean isEditing();
712

    
713
    /**
714
     * Indicates whether this store is in appending state. In this state the new
715
     * features are automatically inserted at the end of the {@link FeatureSet}.
716
     *
717
     * @return true if this store is in appending state.
718
     */
719
    public boolean isAppending();
720

    
721
    /**
722
     * Updates a {@link FeatureType} in the store with the changes in the
723
     * {@link EditableFeatureType}.<br>
724
     *
725
     * Any {@link FeatureSet} from this store that are used will be invalidated.
726
     *
727
     * @param featureType
728
     *            an {@link EditableFeatureType} with the changes.
729
     *
730
     * @throws DataException
731
     */
732
    public void update(EditableFeatureType featureType) throws DataException;
733

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

    
749
    /**
750
     * Deletes a {@link Feature} from the store.<br>
751
     *
752
     * Any {@link FeatureSet} from this store that was still in use will be
753
     * invalidated. You can override this using {@link Iterator#remove()} from
754
     * {@link FeatureSet}.
755
     *
756
     * @param feature
757
     *            The feature to be deleted.
758
     *
759
     * @throws DataException
760
     */
761
    public void delete(Feature feature) throws DataException;
762
    
763
    public void delete(String filter);
764
    
765
    public void delete(Expression filter);
766

    
767
    /**
768
     * Inserts a {@link Feature} in the store.<br>
769
     *
770
     * Any {@link FeatureSet} from this store that was still in use will be
771
     * invalidated. You can override this using
772
     * {@link FeatureSet#insert(EditableFeature)}.
773
     *
774
     * @param feature
775
     *            The feature to be inserted
776
     *
777
     * @throws DataException
778
     */
779
    public void insert(EditableFeature feature) throws DataException;
780

    
781
    /**
782
     * Inserts a set of {@link Feature} in the store.
783
     * 
784
     * The attributes of the feature are copied from the features of the set 
785
     * by name, forcing the conversion of types if necessary.
786
     *
787
     * Any {@link FeatureSet} from this store that was still in use will be
788
     * invalidated.
789
     *
790
     * @param set, set with the source features.
791
     * @throws DataException
792
     */
793
    public void insert(FeatureSet set) throws DataException;
794
    
795
    /**
796
     * Creates a new feature using the default feature type and returns it as an
797
     * {@link EditableFeature}
798
     *
799
     * @return a new feature in editable state
800
     *
801
     * @throws DataException
802
     */
803
    public EditableFeature createNewFeature() throws DataException;
804

    
805
    /**
806
     * Creates a new feature of the given {@link FeatureType} and uses the given
807
     * {@link Feature} as default values to initialize it.
808
     *
809
     * @param type
810
     *            the new feature's feature type
811
     *
812
     * @param defaultValues
813
     *            a feature whose values are used as default values for the new
814
     *            feature.
815
     *
816
     * @return the new feature.
817
     *
818
     * @throws DataException
819
     */
820
    public EditableFeature createNewFeature(FeatureType type,
821
        Feature defaultValues) throws DataException;
822

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

    
843
    /**
844
     * Creates a new feature of default {@link FeatureType}. The flag
845
     * defaultValues is used to indicate whether the new feature should be
846
     * initialized with default values or not.
847
     *
848
     * @param defaultValues
849
     *            if true the new feature is initialized with each attribute's
850
     *            default value.
851
     *
852
     * @return
853
     *         the new feature
854
     *
855
     * @throws DataException
856
     */
857
    public EditableFeature createNewFeature(boolean defaultValues)
858
        throws DataException;
859

    
860
    /**
861
     * Creates a new feature of default {@link FeatureType}.
862
     * The new feature should be initialized with the values of the feature
863
     * passed as parameter.
864
     * Values are inicialiced by name from the feature specified. Error in
865
     * value assignement are ignoreds.
866
     *
867
     * @param defaultValues the values to initialize the new feature.
868
     * @return the new feature
869
     * @throws DataException
870
     */
871
    public EditableFeature createNewFeature(Feature defaultValues)
872
        throws DataException;
873

    
874
    public EditableFeature createNewFeature(JsonObject defaultValues)
875
        throws DataException;
876

    
877
    /**
878
     * Applies the validation rules associated to the given mode to the active
879
     * {@link FeatureSet}.
880
     *
881
     * @param mode
882
     *            can be one of {MODE_QUERY, MODE_FULLEDIT, MODE_APPEND}
883
     *
884
     * @throws DataException
885
     */
886
    public void validateFeatures(int mode) throws DataException;
887

    
888
    /**
889
     * Indicates whether this store supports append mode.
890
     *
891
     * @return
892
     *         true if this store supports append mode.
893
     */
894
    public boolean isAppendModeSupported();
895

    
896
    /**
897
     * Initiates an editing group. This is typically used to group series of
898
     * store editing operations.
899
     *
900
     * @param description
901
     *            Description of the editing group.
902
     *
903
     * @throws NeedEditingModeException
904
     */
905
    public void beginEditingGroup(String description)
906
        throws NeedEditingModeException;
907

    
908
    /**
909
     * Finishes an editing group.
910
     *
911
     * @throws NeedEditingModeException
912
     */
913
    public void endEditingGroup() throws NeedEditingModeException;
914

    
915
    /*
916
     * =============================================================
917
     *
918
     * Index related services
919
     */
920

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

    
943
    /**
944
     * Creates an index which will be applied to the features of the given type,
945
     * by using the data of the given attribute.
946
     *
947
     * @param indexTypeName
948
     *            the type of the index to be created. That name is
949
     *            related to one of the registered index providers
950
     * @param featureType
951
     *            The FeatureType to which the indexed attribute belongs.
952
     *
953
     * @param attributeName
954
     *            The name of the attributed to be indexed
955
     *
956
     * @param indexName
957
     *            The index name
958
     *
959
     * @return the resulting {@link FeatureIndex}
960
     *
961
     *
962
     * @throws FeatureIndexException
963
     *             if there is an error creating the index
964
     */
965
    public FeatureIndex createIndex(String indexTypeName,
966
        FeatureType featureType, String attributeName, String indexName)
967
        throws DataException;
968

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

    
1012
    /**
1013
     * Creates an index which will be applied to the features of the given type,
1014
     * by using the data of the given attribute. This method will return without
1015
     * waiting for the index to be filled, as that will be performed in
1016
     * background. An optional {@link Observer} parameter is provided to be
1017
     * notified ( {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS} )
1018
     * when the index has finished filling with data and is available to be
1019
     * used.
1020
     *
1021
     * @param indexTypeName
1022
     *            the type of the index to be created. That name is
1023
     *            related to one of the registered index providers
1024
     * @param featureType
1025
     *            The FeatureType to which the indexed attribute belongs.
1026
     *
1027
     * @param attributeName
1028
     *            The name of the attributed to be indexed
1029
     *
1030
     * @param indexName
1031
     *            The index name
1032
     *
1033
     * @param observer
1034
     *            to notify to when the created index has finished filling
1035
     *            with data and is available to be used. The observer will
1036
     *            receive then a
1037
     *            {@link FeatureStoreNotification#INDEX_FILLING_SUCCESS}
1038
     *            notification, with the index object if it has finished
1039
     *            successfully, or a
1040
     *            {@link FeatureStoreNotification#INDEX_FILLING_ERROR}
1041
     *            notification with the exception object if there has been
1042
     *            any error in the process. Optional.
1043
     *
1044
     * @return the resulting {@link FeatureIndex}
1045
     *
1046
     * @see FeatureStoreNotification#INDEX_FILLING_STARTED
1047
     * @see FeatureStoreNotification#INDEX_FILLING_SUCCESS
1048
     * @see FeatureStoreNotification#INDEX_FILLING_CANCELLED
1049
     * @see FeatureStoreNotification#INDEX_FILLING_ERROR
1050
     *
1051
     * @throws FeatureIndexException
1052
     *             if there is an error creating the index
1053
     */
1054
    public FeatureIndex createIndex(String indexTypeName,
1055
        FeatureType featureType, String attributeName, String indexName,
1056
        Observer observer) throws DataException;
1057

    
1058
    /**
1059
     * Returns a FeatureIndexes structure containing all available indexes in
1060
     * the store.
1061
     *
1062
     * @return
1063
     */
1064
    public FeatureIndexes getIndexes();
1065

    
1066
    /*
1067
     * =============================================================
1068
     *
1069
     * Selection related services
1070
     */
1071

    
1072
    /**
1073
     * Sets the selection to the passed {@link FeatureSet}
1074
     *
1075
     * @param selection
1076
     *            A {@link FeatureSet} with the requested selection
1077
     * @throws org.gvsig.fmap.dal.exception.DataException
1078
     */
1079
    public void setSelection(FeatureSet selection) throws DataException;
1080

    
1081
    /**
1082
     * Creates a {@link FeatureSelection}
1083
     *
1084
     * @return
1085
     *         a {@link FeatureSelection}
1086
     *
1087
     * @throws DataException
1088
     */
1089
    public FeatureSelection createFeatureSelection() throws DataException;
1090

    
1091
    /**
1092
     * Returns the current {@link FeatureSelection}.
1093
     * Create a empty selection if not exits.
1094
     * 
1095
     * Manage of the selection can be slow on some data sources. 
1096
     * Use with care.
1097
     * In data sources that do not support position access to records, 
1098
     * it may be slow to retrieve items from the selection. In some data 
1099
     * sources it may be necessary to access to this to retrieve each 
1100
     * item in the selection.
1101
     *
1102
     * @return
1103
     *         current {@link FeatureSelection}.
1104
     *
1105
     * @throws DataException
1106
     */
1107
    public FeatureSelection getFeatureSelection() throws DataException;
1108

    
1109
    /*
1110
     * =============================================================
1111
     *
1112
     * Lock related services
1113
     */
1114

    
1115
    /**
1116
     * Indicates whether this store supports locks.
1117
     *
1118
     * @return
1119
     *         true if this store supports locks, false if not.
1120
     */
1121
    public boolean isLocksSupported();
1122

    
1123
    /**
1124
     * Returns the set of locked features
1125
     *
1126
     * @return
1127
     *         set of locked features
1128
     *
1129
     * @throws DataException
1130
     */
1131
    public FeatureLocks getLocks() throws DataException;
1132

    
1133
    /*
1134
     * =============================================================
1135
     * Transforms related services
1136
     * =============================================================
1137
     */
1138

    
1139
    /**
1140
     * Returns this store transforms
1141
     *
1142
     * @return
1143
     *         this store transforms
1144
     */
1145
    public FeatureStoreTransforms getTransforms();
1146

    
1147
    /**
1148
     * Returns a new {@link FeatureQuery} associated to this store.
1149
     *
1150
     * @return
1151
     *         a new {@link FeatureQuery} associated to this store.
1152
     */
1153
    public FeatureQuery createFeatureQuery();
1154

    
1155
    /**
1156
     * Returns featue count of this store.
1157
     *
1158
     * @return
1159
     * @throws DataException
1160
     */
1161
    public long getFeatureCount() throws DataException;
1162

    
1163
//    /**
1164
//     * Creates a vectorial cache that is used to save and retrieve data.
1165
//     *
1166
//     * @param name
1167
//     *            the cache name.
1168
//     * @param parameters
1169
//     *            parameters to create the stores used to save data.
1170
//     * @throws DataException
1171
//     */
1172
//    public void createCache(String name, DynObject parameters)
1173
//        throws DataException;
1174
//
1175
//    /**
1176
//     * @return the vectorial cache
1177
//     */
1178
//    public FeatureCache getCache();
1179

    
1180
    /**
1181
     * Return if the provider knows the real envelope of a layer. If not,
1182
     * the {@link FeatureStoreProvider#getEnvelope()} method doesn't return
1183
     * the full envelope.
1184
     *
1185
     * @return true if it knows the real envelope.
1186
     */
1187
    public boolean isKnownEnvelope();
1188

    
1189
    /**
1190
     * Return if the maximum number of features provided by the
1191
     * provider are limited.
1192
     *
1193
     * @return true if there is a limit of features.
1194
     */
1195
    public boolean hasRetrievedFeaturesLimit();
1196

    
1197
    /**
1198
     * If the {@link FeatureStoreProvider#hasRetrievedFeaturesLimit()} returns
1199
     * true,
1200
     * it returns the limit of features retrieved from the provider.
1201
     *
1202
     * @return
1203
     *         The limit of the retrieved features.
1204
     */
1205
    public int getRetrievedFeaturesLimit();
1206

    
1207
    /**
1208
     * Return the associated feature to the dynobject.
1209
     * If the dynobject isn't associated to a feature of this store, return null.
1210
     *
1211
     * @param dynobject
1212
     * @return
1213
     */
1214
    public Feature getFeature(DynObject dynobject);
1215

    
1216

    
1217
    public ExpressionBuilder createExpressionBuilder();
1218

    
1219
    /**
1220
     * 
1221
     * @return 
1222
     * @deprecated use createExpressionBuilder
1223
     */
1224
    public ExpressionBuilder createExpression();
1225

    
1226
    public void createCache(String name, DynObject parameters)
1227
        throws DataException;
1228

    
1229
    @Override
1230
    public FeatureCache getCache();
1231

    
1232
    public boolean isBroken();
1233

    
1234
    public Throwable getBreakingsCause();
1235

    
1236
    /**
1237
     * Indicates if the storage is temporary.
1238
     * There is no guarantee that a temporary store can be recovered from 
1239
     * its parameters. In general these will not be persistent.
1240
     * 
1241
     * @return true if the store is temporary, otherwise false.
1242
     */
1243
    public boolean isTemporary();
1244
    
1245
    /**
1246
     * @param index
1247
     * @return
1248
     */
1249
    public SpatialIndex wrapSpatialIndex(SpatialIndex index);
1250
    
1251
    public FeatureReference getFeatureReference(String code);
1252

    
1253
    /**
1254
     * Devuelbe el numero de operaciones pendientes de guardar en una sesion
1255
     * de edicion. Es un valor orientativo.
1256
     * Las operaciones pendientes son la suma de operaciones de borrado, insercion
1257
     * o modificacion de las features en una sesion de edicion.
1258
     * 
1259
     * Retorna 0 si no esta en edicion.
1260
     * 
1261
     * @return numero de operaciones pendientes. 
1262
     */
1263
    public long getPendingChangesCount();
1264
    
1265
    public Feature getSampleFeature();
1266
    
1267
    /**
1268
     * Return true when the default feature type of the store 
1269
     * support references.
1270
     * 
1271
     * @return true when support references.
1272
     */
1273
    public boolean supportReferences();
1274
}