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

History | View | Annotate | Download (22.1 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 46309 jjdelcerro
    public Iterator<FeatureReference> referenceIterator() {
333 43089 jjdelcerro
        return this.featureReferenceSelection.referenceIterator();
334
    }
335 42834 dmartinezizquierdo
336 43089 jjdelcerro
    @Override
337 46309 jjdelcerro
    public Iterable<FeatureReference> referenceIterable() {
338
        return this.featureReferenceSelection.referenceIterable();
339
    }
340
341
    @Override
342 43089 jjdelcerro
    public void selectAll() throws DataException {
343
        this.featureReferenceSelection.selectAll();
344
    }
345 42834 dmartinezizquierdo
346 43089 jjdelcerro
    @Override
347
    public void deselectAll() throws DataException {
348
        this.featureReferenceSelection.deselectAll();
349
    }
350
351
    @Override
352
    public boolean isSelected(FeatureReference reference) {
353
        return this.featureReferenceSelection.isSelected(reference);
354
    }
355 40435 jjdelcerro
356 43089 jjdelcerro
    @Override
357
    public void reverse() {
358
        this.featureReferenceSelection.reverse();
359
    }
360 40435 jjdelcerro
361 43089 jjdelcerro
    @Override
362
    public void dispose() {
363
        this.featureReferenceSelection.dispose();
364
    }
365 40435 jjdelcerro
366 43089 jjdelcerro
    @Override
367
    public void update(Observable o, Object o1) {
368
        this.featureReferenceSelection.update(o, o1);
369
    }
370 40435 jjdelcerro
371 43089 jjdelcerro
    @Override
372
    public void addObserver(Observer obsrvr) {
373
        this.featureReferenceSelection.addObserver(obsrvr);
374
    }
375 40435 jjdelcerro
376 43089 jjdelcerro
    @Override
377
    public void deleteObserver(Observer obsrvr) {
378
        this.featureReferenceSelection.deleteObserver(obsrvr);
379
    }
380 40435 jjdelcerro
381 43089 jjdelcerro
    @Override
382
    public void deleteObservers() {
383
        this.featureReferenceSelection.deleteObservers();
384
    }
385 40435 jjdelcerro
386 43089 jjdelcerro
    @Override
387
    public void beginComplexNotification() {
388
        this.featureReferenceSelection.beginComplexNotification();
389
    }
390 40435 jjdelcerro
391 43089 jjdelcerro
    @Override
392
    public void endComplexNotification() {
393
        this.featureReferenceSelection.endComplexNotification();
394
    }
395 40435 jjdelcerro
396 43089 jjdelcerro
    @Override
397
    public void saveToState(PersistentState ps) throws PersistenceException {
398
        this.featureReferenceSelection.saveToState(ps);
399
    }
400 40435 jjdelcerro
401 43089 jjdelcerro
    @Override
402
    public boolean select(Feature feature) {
403 45426 fdiaz
        return this.featureReferenceSelection.select(feature.getReference());
404 43089 jjdelcerro
    }
405 40435 jjdelcerro
406 43089 jjdelcerro
    @Override
407
    public boolean select(FeatureSet features) throws DataException {
408
        boolean change = false;
409
        boolean inComplex = false;
410
        disableNotifications();
411
        DisposableIterator iter = null;
412
        try {
413
            for (iter = features.fastIterator(); iter.hasNext();) {
414 45426 fdiaz
                change |= this.featureReferenceSelection.select(((Feature) iter.next()).getReference());
415 42821 dmartinezizquierdo
            }
416 43089 jjdelcerro
        } finally {
417
            DisposeUtils.disposeQuietly(iter);
418
        }
419
        enableNotifications();
420
        return change;
421
    }
422 40435 jjdelcerro
423 43089 jjdelcerro
    @Override
424
    public boolean deselect(Feature feature) {
425 45426 fdiaz
        return this.featureReferenceSelection.deselect(feature.getReference()); //, true);
426 43089 jjdelcerro
    }
427 42821 dmartinezizquierdo
428 43089 jjdelcerro
    @Override
429
    public boolean deselect(FeatureSet features) throws DataException {
430
        boolean change = false;
431
        disableNotifications();
432
        DisposableIterator iter = null;
433
        try {
434
            for (iter = features.fastIterator(); iter.hasNext();) {
435 45426 fdiaz
                change |= deselect((Feature) iter.next());
436 43089 jjdelcerro
            }
437
        } finally {
438
            DisposeUtils.disposeQuietly(iter);
439
        }
440
        enableNotifications();
441
        return change;
442
    }
443 40435 jjdelcerro
444 43089 jjdelcerro
    @Override
445
    public boolean isSelected(Feature feature) {
446
        if (feature == null) {
447
            return false;
448
        }
449 43646 jjdelcerro
        if( this.featureReferenceSelection.isEmpty() ) {
450
            return false;
451
        }
452 45426 fdiaz
        return this.featureReferenceSelection.isSelected(feature.getReference());
453 42834 dmartinezizquierdo
    }
454 40435 jjdelcerro
455 43089 jjdelcerro
    @Override
456
    public FeatureType getDefaultFeatureType() {
457
        try {
458
            return getFeatureStore().getDefaultFeatureType();
459
        } catch (DataException ex) {
460
            LOG.error("Error getting the default feature type "
461
                    + "of the FeatureStore: " + getFeatureStore(), ex);
462
        }
463
        return null;
464 42834 dmartinezizquierdo
    }
465 40435 jjdelcerro
466 43089 jjdelcerro
    @Override
467
    public List getFeatureTypes() {
468 45426 fdiaz
        return this.featureReferenceSelection.getFeatureTypes();
469
//        // Go through the map of FeatureTypes, and return only the ones that
470
//        // have at least a Feature.
471
//        List types = new ArrayList();
472
//        for (java.util.Iterator iterator = featureTypeCounts.entrySet()
473
//                .iterator(); iterator.hasNext();) {
474
//            Map.Entry entry = (Entry) iterator.next();
475
//            FeatureType type = (FeatureType) entry.getKey();
476
//            Long count = (Long) entry.getValue();
477
//
478
//            if (count > 0) {
479
//                types.add(type);
480
//            }
481
//        }
482
//
483
//        return types;
484 43089 jjdelcerro
    }
485 40435 jjdelcerro
486 43089 jjdelcerro
    @Override
487
    public long getSize() throws DataException {
488
        return getSelectedCount();
489
    }
490 40435 jjdelcerro
491 43089 jjdelcerro
    /**
492
     * Returns the list of selected values, or the deselected ones if the
493
     * selection has been reversed.
494
     *
495
     * WARN: not very good performance implementation.
496
     */
497
    @Override
498 43358 jjdelcerro
        public DisposableIterator iterator(long index) {
499
                return iterator(index, 0, false);
500
        }
501 40435 jjdelcerro
502 43358 jjdelcerro
    @Override
503
        public DisposableIterator iterator(long index, long elements) {
504
                return iterator(index, elements, false);
505
        }
506
507 43089 jjdelcerro
    /**
508
     * Returns the list of selected values, or the deselected ones if the
509
     * selection has been reversed.
510
     *
511
     * WARN: not really a fast implementation.
512
     */
513
    @Override
514 43358 jjdelcerro
        public DisposableIterator fastIterator(long index) {
515
            return fastIterator(index, 0);
516
        }
517
518
    @Override
519
    public DisposableIterator fastIterator(long index, long elements) {
520
        return iterator(index, elements, true);
521 43089 jjdelcerro
    }
522 40435 jjdelcerro
523 43358 jjdelcerro
524 43089 jjdelcerro
    protected void clearFeatureReferences() {
525
        this.featureReferenceSelection.clearFeatureReferences();
526 45426 fdiaz
//        featureTypeCounts.clear();
527 43089 jjdelcerro
    }
528 40435 jjdelcerro
529 43089 jjdelcerro
    /**
530
     * Creates an iterator for the Selection.
531
     */
532 43358 jjdelcerro
    private DisposableIterator iterator(long index, long elements, boolean fastIterator) {
533 45426 fdiaz
        Iterator iter = this.featureReferenceSelection.referenceIterator();
534 43089 jjdelcerro
            for (long l = 0; l < index && iter.hasNext(); l++) {
535
                iter.next();
536
            }
537
            return new FeatureIteratorFacade(iter, getFeatureStore());
538 45426 fdiaz
//        if (isReversed()) {
539
//            DisposableIterator iter = new ReversedFeatureIteratorFacade(
540
//                    getData(), getFeatureStore(), fastIterator);
541
//            for (long l = 0; l < index && iter.hasNext(); l++) {
542
//                iter.next();
543
//            }
544
//            return iter;
545
//
546
//        } else {
547
//            // TODO: maybe we could add a new referenceIterator(int index)
548
//            // method that could be implemented in a more performant way
549
//
550
//            java.util.Iterator iter = getData().getSelected().iterator();
551
//            for (long l = 0; l < index && iter.hasNext(); l++) {
552
//                iter.next();
553
//            }
554
//            return new FeatureIteratorFacade(iter, getFeatureStore());
555
//        }
556 43089 jjdelcerro
    }
557 40435 jjdelcerro
558 45426 fdiaz
//    private Long removeFeatureTypeCount(FeatureType featureType) {
559
//        Long count = (Long) featureTypeCounts.get(featureType);
560
//        if (count == null) {
561
//            count = new Long(-1);
562
//        } else {
563
//            count = count - 1;
564
//        }
565
//        featureTypeCounts.put(featureType, count);
566
//        return count;
567
//    }
568
//
569
//    private Long addFeatureTypeCount(FeatureType featureType) {
570
//        Long count = (Long) featureTypeCounts.get(featureType);
571
//        if (count == null) {
572
//            count = new Long(1);
573
//        } else {
574
//            count = count + 1;
575
//        }
576
//        featureTypeCounts.put(featureType, count);
577
//        return count;
578
//    }
579 40435 jjdelcerro
580 43089 jjdelcerro
    @Override
581
    public void delete(Feature feature) throws DataException {
582
        Iterator it = this.featureIterators.get(feature);
583
        if (it != null) {
584
            it.remove();
585
            return;
586
        }
587
        feature.getStore().delete(feature);
588 40435 jjdelcerro
    }
589
590 43089 jjdelcerro
    @Override
591
    public void insert(EditableFeature feature) throws DataException {
592
        feature.getStore().insert(feature);
593
    }
594
595
    @Override
596
    public void update(EditableFeature feature) throws DataException {
597
        feature.getStore().update(feature);
598
    }
599 44097 omartinez
600
601
    @Override
602
    public void commitChanges() throws DataException {
603
    }
604 43089 jjdelcerro
605
    /*
606
     * (non-Javadoc)
607
     *
608
     * @seeorg.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection#
609
     * loadFromState(org.gvsig.tools.persistence.PersistentState)
610
     */
611
    @Override
612
    public void loadFromState(PersistentState state)
613
            throws PersistenceException {
614
        this.featureReferenceSelection.loadFromState(state);
615
    }
616
617
    protected void doDispose() throws BaseException {
618
        this.featureReferenceSelection.doDispose();
619 45426 fdiaz
//        featureTypeCounts.clear();
620 43089 jjdelcerro
    }
621
622
    public static void registerPersistent() {
623
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
624 45426 fdiaz
        DynStruct definition = manager.addDefinition(LargeFeatureSelection.class, DYNCLASS_PERSISTENT_NAME,
625
                "LargeFeatureSelection Persistent definition", null, null);
626 43089 jjdelcerro
627 45426 fdiaz
        definition.extend(manager.getDefinition(LargeFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME));
628
//        definition.addDynFieldMap("featureTypeCounts")
629
//                .setClassOfItems(Long.class).setMandatory(false);
630 43089 jjdelcerro
631
    }
632
633
    @Override
634
    public Object clone() throws CloneNotSupportedException {
635 45426 fdiaz
        LargeFeatureSelection clone = (LargeFeatureSelection) super.clone();
636
//        clone.featureTypeCounts = new HashMap(featureTypeCounts);
637 43089 jjdelcerro
        return clone;
638
    }
639
640 43358 jjdelcerro
    @Override
641
    protected void doAccept(Visitor visitor, long firstValueIndex, long elements) throws BaseException {
642 43646 jjdelcerro
        if( this.featureReferenceSelection.isEmpty() ) {
643
            return;
644
        }
645 43358 jjdelcerro
        DisposableIterator iterator = fastIterator(firstValueIndex, elements);
646
        if (iterator != null) {
647
            try {
648
                while (iterator.hasNext()) {
649
                    Feature feature = (Feature) iterator.next();
650
                    visitor.visit(feature);
651
                }
652
            } finally {
653
                iterator.dispose();
654
            }
655
        }
656
    }
657
658 44113 jjdelcerro
    private static class IgnoreInsertAndUpdateFeatureSet extends DefaultFeatureSet {
659
660
        public IgnoreInsertAndUpdateFeatureSet(DefaultFeatureStore store, FeatureQuery query) throws DataException {
661
            super(store, query);
662
        }
663
664 45426 fdiaz
        @Override
665 44113 jjdelcerro
        public void update(Observable obsevable, Object notification) {
666
            String type = ((FeatureStoreNotification) notification).getType();
667
            if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_INSERT)
668
                    || type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UPDATE)) {
669
                return;
670
            }
671
            super.update(obsevable, notification);
672
        }
673
674
    }
675
676 44435 jjdelcerro
    @Override
677
    public boolean isAvailable() {
678
        return this.featureReferenceSelection.isAvailable();
679
    }
680 44113 jjdelcerro
681 40767 jjdelcerro
}