Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / featureset / DefaultFeatureSet.java @ 46277

History | View | Annotate | Download (24.8 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.impl.featureset;
25

    
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.Iterator;
29
import java.util.List;
30
import java.util.NoSuchElementException;
31

    
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.EditableFeature;
34
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureIndexes;
37
import org.gvsig.fmap.dal.feature.FeatureQuery;
38
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
39
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember;
40
import org.gvsig.fmap.dal.feature.FeatureSet;
41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
43
import org.gvsig.fmap.dal.feature.FeatureType;
44
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
45
import org.gvsig.fmap.dal.feature.exception.FeatureSetInitializeException;
46
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
47
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreTransforms;
48
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureType;
49
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
50
import org.gvsig.tools.ToolsLocator;
51
import org.gvsig.tools.dispose.DisposableIterator;
52
import org.gvsig.tools.dispose.DisposeUtils;
53
import org.gvsig.tools.evaluator.Evaluator;
54
import org.gvsig.tools.exception.BaseException;
55
import org.gvsig.tools.observer.Observable;
56
import org.gvsig.tools.observer.Observer;
57

    
58
public class DefaultFeatureSet extends AbstractFeatureSet implements
59
    FeatureSet, Observer {
60

    
61
    protected static final int NO_CHECKED = -1;
62
    protected static final int DEFAULT = 0;
63
    protected static final int FILTERED = 1;
64
    protected static final int ORDERED = 2;
65
    protected static final int ORDERED_FILTERED = 3;
66
    protected static final int EDITED = 4;
67
    protected static final int EDITED_FILTERED = 5;
68
    protected static final int ORDERD_EDITED = 6;
69
    protected static final int ORDERED_EDITED_FILTER = 7;
70

    
71
    protected Throwable sourceStoreModifiedCause;
72
    protected boolean sourceStoreModified;
73
    protected boolean ownFeaturesModified;
74
    protected DefaultFeatureStore store;
75
    protected List featureTypes;
76
    protected FeatureQuery query;
77
    protected FeatureSetProvider provider;
78
    protected long size;
79
    protected int iteratorMode;
80
    protected List orderedData;
81
    protected Feature featureToIgnoreNotification;
82
    protected DefaultFeatureStoreTransforms transform;
83
    protected FeatureQuery queryForProvider;
84
    protected FeatureType defaultFeatureType;
85
    protected FeatureType defatulFeatureTypeForProvider;
86
    protected boolean ignoreChanges;
87
    private boolean disposed = false;
88

    
89
    public DefaultFeatureSet(DefaultFeatureStore store, FeatureQuery query)
90
        throws DataException {
91
        DisposeUtils.bind(this);
92
        this.featureToIgnoreNotification = null;
93
        this.iteratorMode = NO_CHECKED;
94
        this.sourceStoreModified = false;
95
        this.ownFeaturesModified = false;
96
        this.size = -1;
97
        this.orderedData = null;
98
        this.store = store;
99
        DisposeUtils.bind(this.store);
100
        if (this.store.isEditing()) {
101
            this.transform = this.store.getFeatureTypeManager().getTransforms();
102
        } else {
103
            this.transform =
104
                (DefaultFeatureStoreTransforms) store.getTransforms();
105
        }
106
        this.query = query;
107
        try {
108
            this.queryForProvider = (FeatureQuery) query.clone();
109
        } catch (CloneNotSupportedException e) {
110
            throw new FeatureSetInitializeException(e);
111
        }
112

    
113
        this.featureTypes = new ArrayList();
114
        if (this.query.getFeatureTypeId() == null
115
            && this.query.getAttributeNames() == null) {
116
            this.defaultFeatureType = this.store.getDefaultFeatureType();
117
            this.featureTypes.addAll(this.store.getFeatureTypes());
118
        } else {
119
            this.defaultFeatureType = this.store.getFeatureType(this.query);
120
            List<EditableFeatureAttributeDescriptor> cols = this.query.getExtraColumn().getColumns();
121
            if (this.query!=null && cols!=null && !cols.isEmpty()) {
122
                DefaultFeatureType featureTypeExtraCols = (DefaultFeatureType) this.defaultFeatureType.getCopy();
123
                featureTypeExtraCols.setExtraColumn(this.query.getExtraColumn());
124
                this.defaultFeatureType = featureTypeExtraCols;
125
            }
126
            this.featureTypes.add(this.defaultFeatureType);
127
        }
128
        if (this.transform != null && !this.transform.isEmpty()) {
129
            this.fixQueryForProvider(this.queryForProvider, this.transform);
130
        } else {
131
            this.defatulFeatureTypeForProvider = this.defaultFeatureType;
132
        }
133

    
134
        FeatureIndexes indexes = store.getIndexes();
135
        if (this.queryForProvider.hasFilter() && indexes != null
136
            && indexes.areValid()) {
137
            this.provider =
138
                (FeatureSetProvider) indexes
139
                    .getFeatureSet(this.queryForProvider.getFilter());
140
        }
141
        if (this.provider == null) {
142
            this.provider =
143
                this.store.getProvider().createSet(this.queryForProvider,
144
                    this.defatulFeatureTypeForProvider);
145
        }
146
        this.store.addObserver(this);
147
    }
148

    
149
    private void fixQueryForProvider(FeatureQuery theQueryForProvider,
150
        DefaultFeatureStoreTransforms transformsToUse) throws DataException {
151
        theQueryForProvider.clearAttributeNames();
152
        FeatureType ftype =
153
            transformsToUse.getSourceFeatureTypeFrom(this.defaultFeatureType);
154
        theQueryForProvider.setFeatureTypeId(ftype.getId());
155
        this.defatulFeatureTypeForProvider = ftype;
156
        
157
        if (transformsToUse.isTransformsOriginalValues()) {
158
            theQueryForProvider.clearFilter();
159
            FeatureQueryOrder fqo = theQueryForProvider.getOrder();
160
            if (fqo != null) {
161
                fqo.clear();
162
            }
163
            return;
164

    
165
        }
166

    
167
        // Filter
168
        Evaluator filter = theQueryForProvider.getFilter();
169
        if (filter != null) {
170
            boolean canUseFilter;
171
            if (filter.getFieldsInfo() == null) {
172
                canUseFilter = false;
173
            } else {
174
                canUseFilter = areEvaluatorFieldsInAttributes(filter, ftype);
175
            }
176

    
177
            if (!canUseFilter) {
178
                theQueryForProvider.clearFilter();
179
            }
180

    
181
        }
182

    
183
        // Order
184
        if (theQueryForProvider.hasOrder()) {
185
            boolean canUseOrder = true;
186
            Iterator iter = theQueryForProvider.getOrder().iterator();
187
            FeatureQueryOrderMember item;
188
            while (iter.hasNext()) {
189
                item = (FeatureQueryOrderMember) iter.next();
190
                if (item.hasEvaluator()) {
191
                    if (!areEvaluatorFieldsInAttributes(item.getEvaluator(),
192
                        ftype)) {
193
                        canUseOrder = false;
194
                        break;
195
                    }
196
                } else {
197
                    if (ftype.get(item.getAttributeName()) == null) {
198
                        canUseOrder = false;
199
                        break;
200
                    }
201
                }
202
            }
203

    
204
            if (!canUseOrder) {
205
                theQueryForProvider.getOrder().clear();
206
            }
207
        }
208

    
209
    }
210

    
211
    private boolean areEvaluatorFieldsInAttributes(Evaluator evaluator,
212
        FeatureType fType) {
213
        if (evaluator.getFieldsInfo() == null) {
214
            return false;
215
        }
216
        String[] fieldNames = evaluator.getFieldsInfo().getFieldNames();
217
        if (fieldNames.length == 0) {
218
            return false;
219
        } else {
220
            for (String fieldName : fieldNames) {
221
                if (fType.get(fieldName) == null) {
222
                    return false;
223
                }
224
            }
225
        }
226
        return true;
227
    }
228

    
229
    @Override
230
    public FeatureType getDefaultFeatureType() {
231
        return this.defaultFeatureType;
232
    }
233

    
234
    @Override
235
    public List getFeatureTypes() {
236
        return Collections.unmodifiableList(this.featureTypes);
237
    }
238

    
239
    @Override
240
    public long getSize() throws DataException {
241
        this.checkSourceStoreModified();
242
        if (size < 0) {
243
            size = calculateSize();
244
        }
245
        return size;
246
    }
247

    
248
    private long calculateSize() throws DataException {
249
        boolean hasLimit = this.query.hasLimit();
250
        long limit = this.query.getLimit();
251
        long mySize = 0;
252
        
253
        int mode = this.getIteratorMode();
254
        DisposableIterator iter = null;
255
        switch (mode) {
256
        case DEFAULT:
257
        case ORDERED:
258
            if (this.provider.isEmpty()) {
259
                return 0;
260
            }
261
            mySize = provider.getSize();
262
            return (hasLimit && mySize>limit)? limit:mySize;
263

    
264
        case FILTERED:
265
        case ORDERED_FILTERED:
266
            try {
267
                iter = this.fastIterator();
268
                while ((hasLimit && (mySize<limit)) || !hasLimit ) {
269
                    iter.next();
270
                    mySize++;
271
                }
272
            } catch (NoSuchElementException e) {
273

    
274
            } finally {
275
                DisposeUtils.disposeQuietly(iter);
276
            }
277
            return (limit>=0 && mySize>limit)? limit:mySize;
278

    
279
        case EDITED:
280
        case ORDERD_EDITED:
281
            mySize = provider.getSize()
282
                + store.getFeatureManager().getDeltaSize();
283
            return (hasLimit && mySize>limit)? limit:mySize;
284

    
285
        case EDITED_FILTERED:
286
        case ORDERED_EDITED_FILTER:
287
            try {
288
                iter = this.fastIterator();
289
                while ((hasLimit && (mySize<limit)) || !hasLimit ) {
290
                    iter.next();
291
                    mySize++;
292
                }
293
            } catch (NoSuchElementException e) {
294

    
295
            } finally {
296
                DisposeUtils.disposeQuietly(iter);
297
            }
298
            return (hasLimit && mySize>limit)? limit:mySize;
299
            
300
        default:
301
            throw new IllegalArgumentException();
302
        }
303
    }
304
    
305
    @Override
306
    public synchronized final void dispose() {
307
        // Check if we have already been disposed, and don't do it again
308
        if (!disposed) {
309
            if (DisposeUtils.release(this)) {
310
                try {
311
                    doDispose();
312
                } catch (Exception ex) {
313
                    LOG.error("Error performing dispose", ex);
314
                } finally {
315
                    disposed = true;
316
                }
317
            }
318
        }
319
    }
320

    
321
    public void doDispose() {
322
        if( this.store!=null ) {
323
            this.store.deleteObserver(this);
324
            DisposeUtils.dispose(this.store);
325
            this.store = null;
326
        }
327
        if( this.provider!=null ) {
328
            this.provider.dispose();
329
            this.provider = null;
330
        }
331
        if (orderedData != null) {
332
            orderedData.clear();
333
            this.orderedData = null;
334
        }
335
        this.featureToIgnoreNotification = null;
336
        this.transform = null;
337
        this.query = null;
338
        this.queryForProvider = null;
339
        this.featureTypes = null;
340
        this.defaultFeatureType = null;
341
        this.defatulFeatureTypeForProvider = null;
342
    }
343

    
344
    public void update(Observable obsevable, Object notification) {
345
        if (sourceStoreModified) {
346
            return;
347
        }
348

    
349
        String type = ((FeatureStoreNotification) notification).getType();
350

    
351
        if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_INSERT)
352
            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_DELETE)
353
            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UPDATE)) {
354
            if (this.featureToIgnoreNotification == ((FeatureStoreNotification) notification)
355
                .getFeature()) {
356
                return;
357
            }
358
            sourceStoreModified = true;
359
            sourceStoreModifiedCause = new Throwable();
360
            return;
361
        }
362
        if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UPDATE_TYPE)
363
            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_REDO)
364
            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UNDO)
365
            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_REFRESH)
366
            || type.equalsIgnoreCase(FeatureStoreNotification.COMPLEX_NOTIFICATION)
367
//            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_CLOSE)
368
//            || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_DISPOSE)
369
            || type.equalsIgnoreCase(FeatureStoreNotification.TRANSFORM_CHANGE)) {
370
            sourceStoreModified = true;
371
            sourceStoreModifiedCause = new Throwable();
372
            return;
373
        }
374
        if (type.equalsIgnoreCase(FeatureStoreNotification.RESOURCE_CHANGED)) {
375
            if(!this.ignoreChanges) {
376
                sourceStoreModified = true;
377
                sourceStoreModifiedCause = new Throwable();
378
                return;
379
            }
380
        }
381
        if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_CANCELEDITING)) {
382
            if (ownFeaturesModified) {
383
                sourceStoreModified = true;
384
                sourceStoreModifiedCause = new Throwable();
385
                return;
386
            }
387
        }
388
    }
389
  
390
    protected void checkSourceStoreModified() {
391
        if (sourceStoreModified) {
392
            ConcurrentDataModificationException ex = new ConcurrentDataModificationException(
393
                    store == null ? "": store.getName()
394
            );
395
            ex.initCause(sourceStoreModifiedCause);
396
            throw ex;
397
        }
398
    }
399

    
400
    @Override
401
    public DisposableIterator fastIterator(long index) throws DataException {
402
        return fastIterator(index, 0);
403
    }
404
    
405
    @Override
406
    public DisposableIterator fastIterator(long index, long elements) throws DataException {
407
        if (index < 0) {
408
            throw new IndexOutOfBoundsException("The index (" + index
409
                + ") is less than 0");
410
        }
411
        DisposableIterator it;
412
        int mode = this.getIteratorMode();
413

    
414
        switch (mode) {
415
        case DEFAULT:
416
            it = new FastDefaultIterator(this, index, elements);
417
            break;
418

    
419
        case FILTERED:
420
            it = new FastFilteredIterator(this, index, elements);
421
            break;
422

    
423
        case ORDERED:
424
            if(this.provider.canOrder() && this.provider.canIterateFromIndex()){
425
                it = new FastDefaultIterator(this, index, elements);
426
            } else {
427
                if (this.orderedData != null) {
428
                    it = new FastOrderedIterator(this, index);
429
                } else {
430
                    it = new FastOrderedIterator(this, new FastDefaultIterator(this, 0, -1), index);
431
                }
432
            }
433
            break;
434
            
435
        case ORDERED_FILTERED:
436
            if(this.provider.canOrder() && this.provider.canFilter() && this.provider.canIterateFromIndex()){
437
                it = new FastFilteredIterator(this, index, elements);
438
            } else {
439
                if (this.orderedData != null) {
440
                    it = new FastOrderedIterator(this, index);
441
                } else {
442
                    it = new FastOrderedIterator(this, new FastFilteredIterator(
443
                        this, 0, -1), index);
444
                }
445
            }
446

    
447
            break;
448

    
449
        case EDITED:
450
            it = new FastEditedIterator(this, index, elements);
451
            break;
452

    
453
        case EDITED_FILTERED:
454
            it = new FastEditedFilteredIterator(this, index, elements);
455
            break;
456

    
457
        case ORDERD_EDITED:
458
            if(this.provider.canOrder() && this.provider.canIterateFromIndex() && !this.store.getFeatureManager().hasDeleteds()){
459
                it = new FastEditedIterator(this, index, elements);
460
            } else {
461
                if (this.orderedData != null) {
462
                    it = new FastOrderedIterator(this, index);
463
                } else {
464
                    it = new FastOrderedIterator(this, new FastEditedIterator(
465
                        this, 0, -1), index);
466
                }
467
            }
468
            break;
469

    
470
        case ORDERED_EDITED_FILTER:
471
            if(this.provider.canOrder() && this.provider.canFilter() && this.provider.canIterateFromIndex() && !this.store.getFeatureManager().hasDeleteds()){
472
                it = new FastEditedFilteredIterator(this, index, elements);
473
            } else {
474
                if (this.orderedData != null) {
475
                    it = new FastOrderedIterator(this, index);
476
                } else {
477
                    it = new FastOrderedIterator(this,
478
                        new FastEditedFilteredIterator(this, 0, -1), index);
479
                }
480
            }
481
            break;
482
            
483
        default:
484
            throw new IllegalArgumentException();
485
        }
486
        if( this.query!=null && this.query.getLimit()>0 ) {
487
            it = new LimitIterator(it,this.query.getLimit());
488
        }
489
        return it;
490
    }
491

    
492
    private class LimitIterator implements DisposableIterator {
493

    
494
        private final DisposableIterator it;
495
        private final long limit;
496
        private int count;
497

    
498
        private LimitIterator(DisposableIterator it, long limit) {
499
            this.it = it;
500
            this.limit = limit;
501
            this.count = 0;
502
        }
503

    
504
        @Override
505
        public void dispose() {
506
            this.it.dispose();
507
        }
508

    
509
        @Override
510
        public boolean hasNext() {
511
            if( this.count>=this.limit ) {
512
                return false;
513
            }
514
            return this.it.hasNext();
515
        }
516

    
517
        @Override
518
        public Object next() {
519
            if( this.count>=this.limit ) {
520
                return null;
521
            }
522
            this.count++;
523
            return this.it.next();
524
        }
525

    
526
        @Override
527
        public void remove() {
528
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
529
        }
530
        
531
    }
532

    
533
    @Override
534
    public DisposableIterator iterator(long index) throws DataException {
535
        return iterator(index,0);
536
    }
537
    
538
    @Override
539
    public DisposableIterator iterator(long index, long elements) throws DataException {        
540
        if (index < 0) {
541
            throw new IndexOutOfBoundsException("The index (" + index
542
                + ") is less than 0");
543
        }
544
        DisposableIterator it;
545
        int mode = this.getIteratorMode();
546

    
547
        switch (mode) {
548
        case DEFAULT:
549
            it = new DefaultIterator(this, index, elements);
550
            break;
551

    
552
        case FILTERED:
553
            it = new FilteredIterator(this, index, elements);
554
            break;
555

    
556
        case ORDERED:
557
            if(this.provider.canOrder() && this.provider.canIterateFromIndex()){
558
                it = new DefaultIterator(this, index, elements);
559
            } else {
560
                if (orderedData != null) {
561
                    it = new OrderedIterator(this, index);
562

    
563
                } else {
564
                    it = new OrderedIterator(this, new DefaultIterator(this, 0, elements),index);
565
                }
566
            }
567
            break;
568

    
569
        case ORDERED_FILTERED:
570
            if(this.provider.canOrder() && this.provider.canFilter() && this.provider.canIterateFromIndex()){
571
                it = new FilteredIterator(this, index, elements);
572
            } else {
573
                if (orderedData != null) {
574
                    it = new OrderedIterator(this, index);
575
                } else {
576
                    it = new OrderedIterator(this, new FilteredIterator(this, 0, -1),index);
577
                }
578
            }
579
            break;
580

    
581
        case EDITED:
582
            it = new EditedIterator(this, index, elements);
583
            break;
584

    
585
        case EDITED_FILTERED:
586
            it = new EditedFilteredIterator(this, index, elements);
587
            break;
588

    
589
        case ORDERD_EDITED:
590
            if(this.provider.canOrder() && this.provider.canIterateFromIndex() && !this.store.getFeatureManager().hasDeleteds()){
591
                it = new EditedIterator(this, index, elements);
592
            } else {
593
                if (orderedData != null) {
594
                    it = new OrderedIterator(this, index);
595
                } else {
596
                    it = new OrderedIterator(this,
597
                        new EditedIterator(this, 0, -1), index);
598
                }
599
            }
600
            break;
601

    
602
        case ORDERED_EDITED_FILTER:
603
            if(this.provider.canOrder() && this.providerCanFilter() && this.provider.canIterateFromIndex() && !this.store.getFeatureManager().hasDeleteds()){
604
                it = new EditedFilteredIterator(this, index, elements);
605
            } else {
606
                if (orderedData != null) {
607
                    it = new OrderedIterator(this, index);
608
                } else {
609
                    it = new OrderedIterator(this,
610
                        new EditedFilteredIterator(this, 0, -1), index);
611
                }
612
            }
613
            break;
614

    
615
        default:
616
            throw new IllegalArgumentException();
617
        }
618

    
619
        if( this.query!=null && this.query.getLimit()>0 ) {
620
            it = new LimitIterator(it,this.query.getLimit());
621
        }
622
        return it;
623
    }
624

    
625
    private boolean providerCanOrder() {
626
        return this.provider.canOrder();
627
    }
628

    
629
    private boolean providerCanFilter() {
630
        return this.provider.canFilter();
631
    }
632

    
633
    private int getIteratorMode() {
634

    
635
        if (this.iteratorMode != NO_CHECKED) {
636
            return this.iteratorMode;
637
        }
638

    
639
        // TODO Tener en cuenta las transformaciones ???
640

    
641
        if (store.isEditing() && (store.getFeatureTypeManager().hasChanges() || store.getFeatureManager().hasChanges())) {
642
            if (this.query.hasOrder()) { // En edicion siempre ordeno yo.
643
                if (this.query.hasFilter()) {
644
                    return ORDERED_EDITED_FILTER;
645
                } else {
646
                    return ORDERD_EDITED;
647
                }
648
            } else {
649
                if (this.query.hasFilter()) {
650
                    return EDITED_FILTERED;
651
                } else {
652
                    return EDITED;
653
                }
654
            }
655
        } else {
656
            boolean useMyFilter = this.query.hasFilter();
657
            boolean useMyOrder = this.query.hasOrder();
658
            if (this.providerCanOrder() && this.transform.isEmpty()) {
659
                useMyOrder = false;
660
            }
661
            if (this.providerCanFilter() && this.transform.isEmpty()) {
662
                useMyFilter = false;
663
            }
664

    
665
            if (useMyOrder) {
666
                if (useMyFilter) {
667
                    return ORDERED_FILTERED;
668
                } else {
669
                    return ORDERED;
670
                }
671
            } else {
672
                if (useMyFilter) {
673
                    return FILTERED;
674
                } else {
675
                    return DEFAULT;
676
                }
677
            }
678
        }
679

    
680
    }
681

    
682
    @Override
683
    public void delete(Feature feature) throws DataException {
684
        this.featureToIgnoreNotification = feature;
685
        this.store.delete(feature);
686
        if (this.size > 0) {
687
            this.size--;
688
        }
689
        this.featureToIgnoreNotification = null;
690
        this.ownFeaturesModified = true;
691
    }
692

    
693
    @Override
694
    public void insert(EditableFeature feature) throws DataException {
695
        this.featureToIgnoreNotification = feature;
696
        this.store.insert(feature);
697
        if (this.size >= 0) {
698
            this.size++;
699
        }
700
        this.featureToIgnoreNotification = null;
701
        this.ownFeaturesModified = true;
702
    }
703

    
704
    @Override
705
    public void update(EditableFeature feature) throws DataException {
706
        this.featureToIgnoreNotification = feature;
707
        this.store.update(feature);
708
        this.featureToIgnoreNotification = null;
709
        this.ownFeaturesModified = true;
710
    }
711
    
712
    @Override
713
    public void commitChanges() throws DataException {
714
        this.ignoreChanges = true;
715
        this.store.commitChanges();
716
        this.ignoreChanges = false;
717
        
718
    }
719

    
720
    @Override
721
    public FeatureStore getFeatureStore() {
722
        return store;
723
    }
724

    
725
}