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 / LargeFeatureSelection.java @ 46078

History | View | Annotate | Download (21.9 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40559 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5 40435 jjdelcerro
 *
6 43089 jjdelcerro
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 40435 jjdelcerro
 *
11 43089 jjdelcerro
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 40435 jjdelcerro
 *
16 43089 jjdelcerro
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 40435 jjdelcerro
 *
20 43089 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 40435 jjdelcerro
 */
23
package org.gvsig.fmap.dal.feature.impl;
24
25
import java.util.HashMap;
26 42834 dmartinezizquierdo
import java.util.Iterator;
27 40435 jjdelcerro
import java.util.List;
28
import java.util.Map;
29
import org.gvsig.fmap.dal.exception.DataException;
30 42821 dmartinezizquierdo
import org.gvsig.fmap.dal.exception.DataRuntimeException;
31 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.EditableFeature;
32
import org.gvsig.fmap.dal.feature.Feature;
33 44113 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureQuery;
34 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureReference;
35
import org.gvsig.fmap.dal.feature.FeatureSelection;
36
import org.gvsig.fmap.dal.feature.FeatureSet;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38 44113 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
39 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureType;
40 43089 jjdelcerro
import org.gvsig.fmap.dal.feature.impl.featureset.AbstractFeatureSet;
41 44113 jjdelcerro
import org.gvsig.fmap.dal.feature.impl.featureset.DefaultFeatureSet;
42 40435 jjdelcerro
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dispose.DisposableIterator;
44 43088 jjdelcerro
import org.gvsig.tools.dispose.DisposeUtils;
45 40435 jjdelcerro
import org.gvsig.tools.dynobject.DynStruct;
46
import org.gvsig.tools.exception.BaseException;
47 43089 jjdelcerro
import org.gvsig.tools.observer.Observable;
48
import org.gvsig.tools.observer.Observer;
49 40435 jjdelcerro
import org.gvsig.tools.persistence.PersistenceManager;
50
import org.gvsig.tools.persistence.PersistentState;
51
import org.gvsig.tools.persistence.exception.PersistenceException;
52 43358 jjdelcerro
import org.gvsig.tools.visitor.Visitor;
53 42834 dmartinezizquierdo
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55 40435 jjdelcerro
56
/**
57
 * Default implementation of the FeatureSelection interface. Internally, only
58
 * FeatureReference values are stored.
59 42821 dmartinezizquierdo
 *
60 40435 jjdelcerro
 * This implementation performs better if used with the selection related
61
 * methods: select, deselect and isSelected ones.
62 42821 dmartinezizquierdo
 *
63 40435 jjdelcerro
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
64
 */
65 45426 fdiaz
public class LargeFeatureSelection extends AbstractFeatureSet
66 43089 jjdelcerro
        implements FeatureSelection {
67 45426 fdiaz
68
69
    private static final String DYNCLASS_PERSISTENT_NAME = "LargeFeatureSelection";
70 40435 jjdelcerro
71 43089 jjdelcerro
    public class RemoveFromFeatureSelectionException extends DataRuntimeException {
72 40435 jjdelcerro
73 43089 jjdelcerro
        /**
74
         *
75
         */
76
        private static final long serialVersionUID = 2636692469445838928L;
77
        private final static String MESSAGE_FORMAT = "Can't remove feature from reversed selection.";
78
        private final static String MESSAGE_KEY = "_RemoveFromFeatureSelectionException";
79 40435 jjdelcerro
80 43089 jjdelcerro
        public RemoveFromFeatureSelectionException(Throwable cause) {
81
            super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
82
            //setValue("store", store);
83
        }
84
    }
85 40435 jjdelcerro
86 43089 jjdelcerro
    /**
87
     * Facade over a Iterator of FeatureReferences, to return Features instead.
88
     *
89
     * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
90
     */
91
    private class FeatureIteratorFacade implements DisposableIterator {
92 40435 jjdelcerro
93 43089 jjdelcerro
        private final Logger LOGGER = LoggerFactory
94
                .getLogger(FeatureIteratorFacade.class);
95 40435 jjdelcerro
96 43089 jjdelcerro
        private java.util.Iterator refIterator;
97 40435 jjdelcerro
98 43089 jjdelcerro
        private FeatureStore featureStore;
99
        private Feature currentFeature = null;
100 40435 jjdelcerro
101 43089 jjdelcerro
        public FeatureIteratorFacade(java.util.Iterator iter,
102
                FeatureStore featureStore) {
103
            this.refIterator = iter;
104
            this.featureStore = featureStore;
105
        }
106 40435 jjdelcerro
107 43089 jjdelcerro
        @Override
108
        public boolean hasNext() {
109
            return refIterator.hasNext();
110
        }
111 40435 jjdelcerro
112 43089 jjdelcerro
        @Override
113
        public Object next() {
114
            FeatureReference ref = nextFeatureReference();
115
            try {
116
                currentFeature = featureStore.getFeatureByReference(ref);
117
                return currentFeature;
118
            } catch (DataException ex) {
119
                LOGGER.error(
120
                        "Error loading the Feature with FeatureReference: "
121
                        + ref, ex);
122
                return null;
123
            }
124
        }
125 42821 dmartinezizquierdo
126 43089 jjdelcerro
        /**
127
         * Returns the next FeatureReference.
128
         *
129
         * @return the next FeatureReference
130
         */
131
        public FeatureReference nextFeatureReference() {
132
            return (FeatureReference) refIterator.next();
133
        }
134 40435 jjdelcerro
135 43089 jjdelcerro
        @Override
136
        public void remove() {
137
            try {
138
                featureStore.delete(currentFeature);
139
                refIterator.remove();
140
            } catch (DataException e) {
141
                throw new RemoveFromFeatureSelectionException(e);
142
            }
143
        }
144 40435 jjdelcerro
145 43089 jjdelcerro
        public class RemoveFromFeatureSelectionException extends DataRuntimeException {
146 40435 jjdelcerro
147 43089 jjdelcerro
            /**
148
             *
149
             */
150
            private static final long serialVersionUID = 2636692469445838928L;
151
            private final static String MESSAGE_FORMAT = "Can't remove feature from selection.";
152
            private final static String MESSAGE_KEY = "_RemoveFromFeatureSelectionException";
153 40435 jjdelcerro
154 43089 jjdelcerro
            public RemoveFromFeatureSelectionException(Throwable cause) {
155
                super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
156
                //setValue("store", store);
157
            }
158
        }
159 40435 jjdelcerro
160 43089 jjdelcerro
        @Override
161
        public void dispose() {
162
            if (refIterator instanceof DisposableIterator) {
163
                ((DisposableIterator) refIterator).dispose();
164
            }
165
            refIterator = null;
166
            featureStore = null;
167
        }
168
    }
169 40435 jjdelcerro
170 45426 fdiaz
//    /**
171
//     * Facade over a Iterator of FeatureReferences, to return Features instead,
172
//     * when the Selection is reversed
173
//     *
174
//     * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
175
//     */
176
//    private class ReversedFeatureIteratorFacade implements DisposableIterator {
177
//
178
//        private SelectionData selectionData;
179
//
180
//        private DisposableIterator iterator;
181
//
182
//        private Feature nextFeature = null;
183
//        private Feature currentFeature = null;
184
//
185
//        private FeatureSet featureSet;
186
//
187
//        public ReversedFeatureIteratorFacade(SelectionData selectionData,
188
//                FeatureStore featureStore, boolean fastIterator) {
189
//            this.selectionData = selectionData;
190
//
191
//            // Load a Set with all the store features
192
//            try {
193
//                featureSet = new IgnoreInsertAndUpdateFeatureSet(
194
//                        (DefaultFeatureStore) featureStore,
195
//                        new DefaultFeatureQuery(featureStore.getDefaultFeatureType())
196
//                );
197
//                iterator = featureSet.fastIterator();
198
//            } catch (DataException ex) {
199
//                throw new ReversedSelectionIteratorException(ex);
200
//            }
201
//
202
//            // Filter the features not selected and position in the next
203
//            // selected feature
204
//            positionInNextElement();
205
//        }
206
//
207
//        @Override
208
//        public boolean hasNext() {
209
//            return nextFeature != null;
210
//        }
211
//
212
//        @Override
213
//        public Object next() {
214
//            featureIterators.remove(currentFeature);
215
//            currentFeature = nextFeature.getCopy();
216
//            featureIterators.put(currentFeature, this);
217
//            positionInNextElement();
218
//            return currentFeature;
219
//        }
220
//
221
//        @Override
222
//        public void remove() {
223
//            try {
224
//                featureSet.delete(currentFeature);
225
//            } catch (DataException e) {
226
//                throw new RemoveFromFeatureSelectionException(e);
227
//
228
//            }
229
//        }
230
//
231
//        private void positionInNextElement() {
232
//            nextFeature = null;
233
//            while (iterator.hasNext()) {
234
//                nextFeature = (Feature) iterator.next();
235
//                if (selectionData.contains(nextFeature.getReference())) {
236
//                    nextFeature = null;
237
//                } else {
238
//                    break;
239
//                }
240
//            }
241
//        }
242
//
243
//        @Override
244
//        public void dispose() {
245
//            this.featureSet.dispose();
246
//            this.iterator.dispose();
247
//            this.selectionData = null;
248
//            this.nextFeature = null;
249
//        }
250
//    }
251 40435 jjdelcerro
252 45426 fdiaz
//    private Map featureTypeCounts = new HashMap(1);
253 43089 jjdelcerro
    private final Map<Feature, Iterator> featureIterators = new HashMap<>();
254 45426 fdiaz
    private final LargeFeatureReferenceSelection featureReferenceSelection;
255 40435 jjdelcerro
256 43089 jjdelcerro
    /**
257
     * Creates a DefaultFeatureSelection, with a FeatureStore.
258
     *
259
     * @param featureStore the FeatureStore to load Features from
260
     * @throws DataException if there is an error while getting the total number
261
     * of Features of the Store.
262
     * @see AbstractSetBasedDataSelection#DefaultSelection(int)
263
     */
264 45426 fdiaz
    public LargeFeatureSelection(DefaultFeatureStore featureStore)
265 43089 jjdelcerro
            throws DataException {
266 45426 fdiaz
        this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore);
267 43089 jjdelcerro
    }
268 40435 jjdelcerro
269 43089 jjdelcerro
    /**
270
     * Creates a new Selection with the total size of Features from which the
271
     * selection will be performed.
272
     *
273
     * @param featureStore the FeatureStore of the selected FeatureReferences
274
     * @param helper to get some information of the Store
275
     * @throws DataException if there is an error while getting the total number
276
     * of Features of the Store.
277
     */
278 45426 fdiaz
    public LargeFeatureSelection(FeatureStore featureStore,
279 43089 jjdelcerro
            FeatureSelectionHelper helper) throws DataException {
280 45426 fdiaz
        this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore, helper);
281 43089 jjdelcerro
    }
282 40435 jjdelcerro
283 43089 jjdelcerro
    /**
284
     * Constructor used by the persistence manager. Don't use directly. After to
285
     * invoke this method, the persistence manager calls the the method
286
     * {@link #loadFromState(PersistentState)} to set the values of the internal
287
     * attributes that this class needs to work.
288
     */
289 45426 fdiaz
    public LargeFeatureSelection() {
290
        this.featureReferenceSelection = new LargeFeatureReferenceSelection();
291 43089 jjdelcerro
    }
292 40435 jjdelcerro
293 43089 jjdelcerro
    @Override
294
    public FeatureStore getFeatureStore() {
295
        return this.featureReferenceSelection.getFeatureStore();
296
    }
297 40435 jjdelcerro
298 43089 jjdelcerro
    private void notifyObservers(String notificationType) {
299
        this.featureReferenceSelection.notifyObservers(notificationType);
300
    }
301 40435 jjdelcerro
302 43089 jjdelcerro
    @Override
303
    public void enableNotifications() {
304
        this.featureReferenceSelection.enableNotifications();
305
    }
306 40435 jjdelcerro
307 43089 jjdelcerro
    @Override
308
    public void disableNotifications() {
309
        this.featureReferenceSelection.disableNotifications();
310
    }
311 40435 jjdelcerro
312 45426 fdiaz
//    public boolean isReversed() {
313
//        return this.featureReferenceSelection.isReversed();
314
//    }
315 40435 jjdelcerro
316 43089 jjdelcerro
    @Override
317
    public long getSelectedCount() {
318
        return this.featureReferenceSelection.getSelectedCount();
319
    }
320 40435 jjdelcerro
321 43089 jjdelcerro
    @Override
322
    public boolean select(FeatureReference reference) {
323
        return this.featureReferenceSelection.select(reference);
324
    }
325 40435 jjdelcerro
326 43089 jjdelcerro
    @Override
327
    public boolean deselect(FeatureReference reference) {
328
        return this.featureReferenceSelection.deselect(reference);
329
    }
330 40435 jjdelcerro
331 43089 jjdelcerro
    @Override
332
    public Iterator referenceIterator() {
333
        return this.featureReferenceSelection.referenceIterator();
334
    }
335 42834 dmartinezizquierdo
336 43089 jjdelcerro
    @Override
337
    public void selectAll() throws DataException {
338
        this.featureReferenceSelection.selectAll();
339
    }
340 42834 dmartinezizquierdo
341 43089 jjdelcerro
    @Override
342
    public void deselectAll() throws DataException {
343
        this.featureReferenceSelection.deselectAll();
344
    }
345
346
    @Override
347
    public boolean isSelected(FeatureReference reference) {
348
        return this.featureReferenceSelection.isSelected(reference);
349
    }
350 40435 jjdelcerro
351 43089 jjdelcerro
    @Override
352
    public void reverse() {
353
        this.featureReferenceSelection.reverse();
354
    }
355 40435 jjdelcerro
356 43089 jjdelcerro
    @Override
357
    public void dispose() {
358
        this.featureReferenceSelection.dispose();
359
    }
360 40435 jjdelcerro
361 43089 jjdelcerro
    @Override
362
    public void update(Observable o, Object o1) {
363
        this.featureReferenceSelection.update(o, o1);
364
    }
365 40435 jjdelcerro
366 43089 jjdelcerro
    @Override
367
    public void addObserver(Observer obsrvr) {
368
        this.featureReferenceSelection.addObserver(obsrvr);
369
    }
370 40435 jjdelcerro
371 43089 jjdelcerro
    @Override
372
    public void deleteObserver(Observer obsrvr) {
373
        this.featureReferenceSelection.deleteObserver(obsrvr);
374
    }
375 40435 jjdelcerro
376 43089 jjdelcerro
    @Override
377
    public void deleteObservers() {
378
        this.featureReferenceSelection.deleteObservers();
379
    }
380 40435 jjdelcerro
381 43089 jjdelcerro
    @Override
382
    public void beginComplexNotification() {
383
        this.featureReferenceSelection.beginComplexNotification();
384
    }
385 40435 jjdelcerro
386 43089 jjdelcerro
    @Override
387
    public void endComplexNotification() {
388
        this.featureReferenceSelection.endComplexNotification();
389
    }
390 40435 jjdelcerro
391 43089 jjdelcerro
    @Override
392
    public void saveToState(PersistentState ps) throws PersistenceException {
393
        this.featureReferenceSelection.saveToState(ps);
394
    }
395 40435 jjdelcerro
396 43089 jjdelcerro
    @Override
397
    public boolean select(Feature feature) {
398 45426 fdiaz
        return this.featureReferenceSelection.select(feature.getReference());
399 43089 jjdelcerro
    }
400 40435 jjdelcerro
401 43089 jjdelcerro
    @Override
402
    public boolean select(FeatureSet features) throws DataException {
403
        boolean change = false;
404
        boolean inComplex = false;
405
        disableNotifications();
406
        DisposableIterator iter = null;
407
        try {
408
            for (iter = features.fastIterator(); iter.hasNext();) {
409 45426 fdiaz
                change |= this.featureReferenceSelection.select(((Feature) iter.next()).getReference());
410 42821 dmartinezizquierdo
            }
411 43089 jjdelcerro
        } finally {
412
            DisposeUtils.disposeQuietly(iter);
413
        }
414
        enableNotifications();
415
        return change;
416
    }
417 40435 jjdelcerro
418 43089 jjdelcerro
    @Override
419
    public boolean deselect(Feature feature) {
420 45426 fdiaz
        return this.featureReferenceSelection.deselect(feature.getReference()); //, true);
421 43089 jjdelcerro
    }
422 42821 dmartinezizquierdo
423 43089 jjdelcerro
    @Override
424
    public boolean deselect(FeatureSet features) throws DataException {
425
        boolean change = false;
426
        disableNotifications();
427
        DisposableIterator iter = null;
428
        try {
429
            for (iter = features.fastIterator(); iter.hasNext();) {
430 45426 fdiaz
                change |= deselect((Feature) iter.next());
431 43089 jjdelcerro
            }
432
        } finally {
433
            DisposeUtils.disposeQuietly(iter);
434
        }
435
        enableNotifications();
436
        return change;
437
    }
438 40435 jjdelcerro
439 43089 jjdelcerro
    @Override
440
    public boolean isSelected(Feature feature) {
441
        if (feature == null) {
442
            return false;
443
        }
444 43646 jjdelcerro
        if( this.featureReferenceSelection.isEmpty() ) {
445
            return false;
446
        }
447 45426 fdiaz
        return this.featureReferenceSelection.isSelected(feature.getReference());
448 42834 dmartinezizquierdo
    }
449 40435 jjdelcerro
450 43089 jjdelcerro
    @Override
451
    public FeatureType getDefaultFeatureType() {
452
        try {
453
            return getFeatureStore().getDefaultFeatureType();
454
        } catch (DataException ex) {
455
            LOG.error("Error getting the default feature type "
456
                    + "of the FeatureStore: " + getFeatureStore(), ex);
457
        }
458
        return null;
459 42834 dmartinezizquierdo
    }
460 40435 jjdelcerro
461 43089 jjdelcerro
    @Override
462
    public List getFeatureTypes() {
463 45426 fdiaz
        return this.featureReferenceSelection.getFeatureTypes();
464
//        // Go through the map of FeatureTypes, and return only the ones that
465
//        // have at least a Feature.
466
//        List types = new ArrayList();
467
//        for (java.util.Iterator iterator = featureTypeCounts.entrySet()
468
//                .iterator(); iterator.hasNext();) {
469
//            Map.Entry entry = (Entry) iterator.next();
470
//            FeatureType type = (FeatureType) entry.getKey();
471
//            Long count = (Long) entry.getValue();
472
//
473
//            if (count > 0) {
474
//                types.add(type);
475
//            }
476
//        }
477
//
478
//        return types;
479 43089 jjdelcerro
    }
480 40435 jjdelcerro
481 43089 jjdelcerro
    @Override
482
    public long getSize() throws DataException {
483
        return getSelectedCount();
484
    }
485 40435 jjdelcerro
486 43089 jjdelcerro
    /**
487
     * Returns the list of selected values, or the deselected ones if the
488
     * selection has been reversed.
489
     *
490
     * WARN: not very good performance implementation.
491
     */
492
    @Override
493 43358 jjdelcerro
        public DisposableIterator iterator(long index) {
494
                return iterator(index, 0, false);
495
        }
496 40435 jjdelcerro
497 43358 jjdelcerro
    @Override
498
        public DisposableIterator iterator(long index, long elements) {
499
                return iterator(index, elements, false);
500
        }
501
502 43089 jjdelcerro
    /**
503
     * Returns the list of selected values, or the deselected ones if the
504
     * selection has been reversed.
505
     *
506
     * WARN: not really a fast implementation.
507
     */
508
    @Override
509 43358 jjdelcerro
        public DisposableIterator fastIterator(long index) {
510
            return fastIterator(index, 0);
511
        }
512
513
    @Override
514
    public DisposableIterator fastIterator(long index, long elements) {
515
        return iterator(index, elements, true);
516 43089 jjdelcerro
    }
517 40435 jjdelcerro
518 43358 jjdelcerro
519 43089 jjdelcerro
    protected void clearFeatureReferences() {
520
        this.featureReferenceSelection.clearFeatureReferences();
521 45426 fdiaz
//        featureTypeCounts.clear();
522 43089 jjdelcerro
    }
523 40435 jjdelcerro
524 43089 jjdelcerro
    /**
525
     * Creates an iterator for the Selection.
526
     */
527 43358 jjdelcerro
    private DisposableIterator iterator(long index, long elements, boolean fastIterator) {
528 45426 fdiaz
        Iterator iter = this.featureReferenceSelection.referenceIterator();
529 43089 jjdelcerro
            for (long l = 0; l < index && iter.hasNext(); l++) {
530
                iter.next();
531
            }
532
            return new FeatureIteratorFacade(iter, getFeatureStore());
533 45426 fdiaz
//        if (isReversed()) {
534
//            DisposableIterator iter = new ReversedFeatureIteratorFacade(
535
//                    getData(), getFeatureStore(), fastIterator);
536
//            for (long l = 0; l < index && iter.hasNext(); l++) {
537
//                iter.next();
538
//            }
539
//            return iter;
540
//
541
//        } else {
542
//            // TODO: maybe we could add a new referenceIterator(int index)
543
//            // method that could be implemented in a more performant way
544
//
545
//            java.util.Iterator iter = getData().getSelected().iterator();
546
//            for (long l = 0; l < index && iter.hasNext(); l++) {
547
//                iter.next();
548
//            }
549
//            return new FeatureIteratorFacade(iter, getFeatureStore());
550
//        }
551 43089 jjdelcerro
    }
552 40435 jjdelcerro
553 45426 fdiaz
//    private Long removeFeatureTypeCount(FeatureType featureType) {
554
//        Long count = (Long) featureTypeCounts.get(featureType);
555
//        if (count == null) {
556
//            count = new Long(-1);
557
//        } else {
558
//            count = count - 1;
559
//        }
560
//        featureTypeCounts.put(featureType, count);
561
//        return count;
562
//    }
563
//
564
//    private Long addFeatureTypeCount(FeatureType featureType) {
565
//        Long count = (Long) featureTypeCounts.get(featureType);
566
//        if (count == null) {
567
//            count = new Long(1);
568
//        } else {
569
//            count = count + 1;
570
//        }
571
//        featureTypeCounts.put(featureType, count);
572
//        return count;
573
//    }
574 40435 jjdelcerro
575 43089 jjdelcerro
    @Override
576
    public void delete(Feature feature) throws DataException {
577
        Iterator it = this.featureIterators.get(feature);
578
        if (it != null) {
579
            it.remove();
580
            return;
581
        }
582
        feature.getStore().delete(feature);
583 40435 jjdelcerro
    }
584
585 43089 jjdelcerro
    @Override
586
    public void insert(EditableFeature feature) throws DataException {
587
        feature.getStore().insert(feature);
588
    }
589
590
    @Override
591
    public void update(EditableFeature feature) throws DataException {
592
        feature.getStore().update(feature);
593
    }
594 44097 omartinez
595
596
    @Override
597
    public void commitChanges() throws DataException {
598
    }
599 43089 jjdelcerro
600
    /*
601
     * (non-Javadoc)
602
     *
603
     * @seeorg.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection#
604
     * loadFromState(org.gvsig.tools.persistence.PersistentState)
605
     */
606
    @Override
607
    public void loadFromState(PersistentState state)
608
            throws PersistenceException {
609
        this.featureReferenceSelection.loadFromState(state);
610
    }
611
612
    protected void doDispose() throws BaseException {
613
        this.featureReferenceSelection.doDispose();
614 45426 fdiaz
//        featureTypeCounts.clear();
615 43089 jjdelcerro
    }
616
617
    public static void registerPersistent() {
618
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
619 45426 fdiaz
        DynStruct definition = manager.addDefinition(LargeFeatureSelection.class, DYNCLASS_PERSISTENT_NAME,
620
                "LargeFeatureSelection Persistent definition", null, null);
621 43089 jjdelcerro
622 45426 fdiaz
        definition.extend(manager.getDefinition(LargeFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME));
623
//        definition.addDynFieldMap("featureTypeCounts")
624
//                .setClassOfItems(Long.class).setMandatory(false);
625 43089 jjdelcerro
626
    }
627
628
    @Override
629
    public Object clone() throws CloneNotSupportedException {
630 45426 fdiaz
        LargeFeatureSelection clone = (LargeFeatureSelection) super.clone();
631
//        clone.featureTypeCounts = new HashMap(featureTypeCounts);
632 43089 jjdelcerro
        return clone;
633
    }
634
635 43358 jjdelcerro
    @Override
636
    protected void doAccept(Visitor visitor, long firstValueIndex, long elements) throws BaseException {
637 43646 jjdelcerro
        if( this.featureReferenceSelection.isEmpty() ) {
638
            return;
639
        }
640 43358 jjdelcerro
        DisposableIterator iterator = fastIterator(firstValueIndex, elements);
641
        if (iterator != null) {
642
            try {
643
                while (iterator.hasNext()) {
644
                    Feature feature = (Feature) iterator.next();
645
                    visitor.visit(feature);
646
                }
647
            } finally {
648
                iterator.dispose();
649
            }
650
        }
651
    }
652
653 44113 jjdelcerro
    private static class IgnoreInsertAndUpdateFeatureSet extends DefaultFeatureSet {
654
655
        public IgnoreInsertAndUpdateFeatureSet(DefaultFeatureStore store, FeatureQuery query) throws DataException {
656
            super(store, query);
657
        }
658
659 45426 fdiaz
        @Override
660 44113 jjdelcerro
        public void update(Observable obsevable, Object notification) {
661
            String type = ((FeatureStoreNotification) notification).getType();
662
            if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_INSERT)
663
                    || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UPDATE)) {
664
                return;
665
            }
666
            super.update(obsevable, notification);
667
        }
668
669
    }
670
671 44435 jjdelcerro
    @Override
672
    public boolean isAvailable() {
673
        return this.featureReferenceSelection.isAvailable();
674
    }
675 44113 jjdelcerro
676 40767 jjdelcerro
}