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 @ 46195
History | View | Annotate | Download (21.9 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 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 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.feature.impl; |
24 |
|
25 |
import java.util.HashMap; |
26 |
import java.util.Iterator; |
27 |
import java.util.List; |
28 |
import java.util.Map; |
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.exception.DataRuntimeException; |
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
32 |
import org.gvsig.fmap.dal.feature.Feature; |
33 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
34 |
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 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
40 |
import org.gvsig.fmap.dal.feature.impl.featureset.AbstractFeatureSet; |
41 |
import org.gvsig.fmap.dal.feature.impl.featureset.DefaultFeatureSet; |
42 |
import org.gvsig.tools.ToolsLocator; |
43 |
import org.gvsig.tools.dispose.DisposableIterator; |
44 |
import org.gvsig.tools.dispose.DisposeUtils; |
45 |
import org.gvsig.tools.dynobject.DynStruct; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
import org.gvsig.tools.observer.Observable; |
48 |
import org.gvsig.tools.observer.Observer; |
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
50 |
import org.gvsig.tools.persistence.PersistentState; |
51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
52 |
import org.gvsig.tools.visitor.Visitor; |
53 |
import org.slf4j.Logger; |
54 |
import org.slf4j.LoggerFactory; |
55 |
|
56 |
/**
|
57 |
* Default implementation of the FeatureSelection interface. Internally, only
|
58 |
* FeatureReference values are stored.
|
59 |
*
|
60 |
* This implementation performs better if used with the selection related
|
61 |
* methods: select, deselect and isSelected ones.
|
62 |
*
|
63 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
64 |
*/
|
65 |
public class LargeFeatureSelection extends AbstractFeatureSet |
66 |
implements FeatureSelection {
|
67 |
|
68 |
|
69 |
private static final String DYNCLASS_PERSISTENT_NAME = "LargeFeatureSelection"; |
70 |
|
71 |
public class RemoveFromFeatureSelectionException extends DataRuntimeException { |
72 |
|
73 |
/**
|
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 |
|
80 |
public RemoveFromFeatureSelectionException(Throwable cause) { |
81 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
82 |
//setValue("store", store);
|
83 |
} |
84 |
} |
85 |
|
86 |
/**
|
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 |
|
93 |
private final Logger LOGGER = LoggerFactory |
94 |
.getLogger(FeatureIteratorFacade.class); |
95 |
|
96 |
private java.util.Iterator refIterator;
|
97 |
|
98 |
private FeatureStore featureStore;
|
99 |
private Feature currentFeature = null; |
100 |
|
101 |
public FeatureIteratorFacade(java.util.Iterator iter,
|
102 |
FeatureStore featureStore) { |
103 |
this.refIterator = iter;
|
104 |
this.featureStore = featureStore;
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public boolean hasNext() { |
109 |
return refIterator.hasNext();
|
110 |
} |
111 |
|
112 |
@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 |
|
126 |
/**
|
127 |
* Returns the next FeatureReference.
|
128 |
*
|
129 |
* @return the next FeatureReference
|
130 |
*/
|
131 |
public FeatureReference nextFeatureReference() {
|
132 |
return (FeatureReference) refIterator.next();
|
133 |
} |
134 |
|
135 |
@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 |
|
145 |
public class RemoveFromFeatureSelectionException extends DataRuntimeException { |
146 |
|
147 |
/**
|
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 |
|
154 |
public RemoveFromFeatureSelectionException(Throwable cause) { |
155 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
156 |
//setValue("store", store);
|
157 |
} |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public void dispose() { |
162 |
if (refIterator instanceof DisposableIterator) { |
163 |
((DisposableIterator) refIterator).dispose(); |
164 |
} |
165 |
refIterator = null;
|
166 |
featureStore = null;
|
167 |
} |
168 |
} |
169 |
|
170 |
// /**
|
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 |
|
252 |
// private Map featureTypeCounts = new HashMap(1);
|
253 |
private final Map<Feature, Iterator> featureIterators = new HashMap<>(); |
254 |
private final LargeFeatureReferenceSelection featureReferenceSelection; |
255 |
|
256 |
/**
|
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 |
public LargeFeatureSelection(DefaultFeatureStore featureStore)
|
265 |
throws DataException {
|
266 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore); |
267 |
} |
268 |
|
269 |
/**
|
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 |
public LargeFeatureSelection(FeatureStore featureStore,
|
279 |
FeatureSelectionHelper helper) throws DataException {
|
280 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore, helper); |
281 |
} |
282 |
|
283 |
/**
|
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 |
public LargeFeatureSelection() {
|
290 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(); |
291 |
} |
292 |
|
293 |
@Override
|
294 |
public FeatureStore getFeatureStore() {
|
295 |
return this.featureReferenceSelection.getFeatureStore(); |
296 |
} |
297 |
|
298 |
private void notifyObservers(String notificationType) { |
299 |
this.featureReferenceSelection.notifyObservers(notificationType);
|
300 |
} |
301 |
|
302 |
@Override
|
303 |
public void enableNotifications() { |
304 |
this.featureReferenceSelection.enableNotifications();
|
305 |
} |
306 |
|
307 |
@Override
|
308 |
public void disableNotifications() { |
309 |
this.featureReferenceSelection.disableNotifications();
|
310 |
} |
311 |
|
312 |
// public boolean isReversed() {
|
313 |
// return this.featureReferenceSelection.isReversed();
|
314 |
// }
|
315 |
|
316 |
@Override
|
317 |
public long getSelectedCount() { |
318 |
return this.featureReferenceSelection.getSelectedCount(); |
319 |
} |
320 |
|
321 |
@Override
|
322 |
public boolean select(FeatureReference reference) { |
323 |
return this.featureReferenceSelection.select(reference); |
324 |
} |
325 |
|
326 |
@Override
|
327 |
public boolean deselect(FeatureReference reference) { |
328 |
return this.featureReferenceSelection.deselect(reference); |
329 |
} |
330 |
|
331 |
@Override
|
332 |
public Iterator referenceIterator() { |
333 |
return this.featureReferenceSelection.referenceIterator(); |
334 |
} |
335 |
|
336 |
@Override
|
337 |
public void selectAll() throws DataException { |
338 |
this.featureReferenceSelection.selectAll();
|
339 |
} |
340 |
|
341 |
@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 |
|
351 |
@Override
|
352 |
public void reverse() { |
353 |
this.featureReferenceSelection.reverse();
|
354 |
} |
355 |
|
356 |
@Override
|
357 |
public void dispose() { |
358 |
this.featureReferenceSelection.dispose();
|
359 |
} |
360 |
|
361 |
@Override
|
362 |
public void update(Observable o, Object o1) { |
363 |
this.featureReferenceSelection.update(o, o1);
|
364 |
} |
365 |
|
366 |
@Override
|
367 |
public void addObserver(Observer obsrvr) { |
368 |
this.featureReferenceSelection.addObserver(obsrvr);
|
369 |
} |
370 |
|
371 |
@Override
|
372 |
public void deleteObserver(Observer obsrvr) { |
373 |
this.featureReferenceSelection.deleteObserver(obsrvr);
|
374 |
} |
375 |
|
376 |
@Override
|
377 |
public void deleteObservers() { |
378 |
this.featureReferenceSelection.deleteObservers();
|
379 |
} |
380 |
|
381 |
@Override
|
382 |
public void beginComplexNotification() { |
383 |
this.featureReferenceSelection.beginComplexNotification();
|
384 |
} |
385 |
|
386 |
@Override
|
387 |
public void endComplexNotification() { |
388 |
this.featureReferenceSelection.endComplexNotification();
|
389 |
} |
390 |
|
391 |
@Override
|
392 |
public void saveToState(PersistentState ps) throws PersistenceException { |
393 |
this.featureReferenceSelection.saveToState(ps);
|
394 |
} |
395 |
|
396 |
@Override
|
397 |
public boolean select(Feature feature) { |
398 |
return this.featureReferenceSelection.select(feature.getReference()); |
399 |
} |
400 |
|
401 |
@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 |
change |= this.featureReferenceSelection.select(((Feature) iter.next()).getReference());
|
410 |
} |
411 |
} finally {
|
412 |
DisposeUtils.disposeQuietly(iter); |
413 |
} |
414 |
enableNotifications(); |
415 |
return change;
|
416 |
} |
417 |
|
418 |
@Override
|
419 |
public boolean deselect(Feature feature) { |
420 |
return this.featureReferenceSelection.deselect(feature.getReference()); //, true); |
421 |
} |
422 |
|
423 |
@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 |
change |= deselect((Feature) iter.next()); |
431 |
} |
432 |
} finally {
|
433 |
DisposeUtils.disposeQuietly(iter); |
434 |
} |
435 |
enableNotifications(); |
436 |
return change;
|
437 |
} |
438 |
|
439 |
@Override
|
440 |
public boolean isSelected(Feature feature) { |
441 |
if (feature == null) { |
442 |
return false; |
443 |
} |
444 |
if( this.featureReferenceSelection.isEmpty() ) { |
445 |
return false; |
446 |
} |
447 |
return this.featureReferenceSelection.isSelected(feature.getReference()); |
448 |
} |
449 |
|
450 |
@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 |
} |
460 |
|
461 |
@Override
|
462 |
public List getFeatureTypes() { |
463 |
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 |
} |
480 |
|
481 |
@Override
|
482 |
public long getSize() throws DataException { |
483 |
return getSelectedCount();
|
484 |
} |
485 |
|
486 |
/**
|
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 |
public DisposableIterator iterator(long index) { |
494 |
return iterator(index, 0, false); |
495 |
} |
496 |
|
497 |
@Override
|
498 |
public DisposableIterator iterator(long index, long elements) { |
499 |
return iterator(index, elements, false); |
500 |
} |
501 |
|
502 |
/**
|
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 |
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 |
} |
517 |
|
518 |
|
519 |
protected void clearFeatureReferences() { |
520 |
this.featureReferenceSelection.clearFeatureReferences();
|
521 |
// featureTypeCounts.clear();
|
522 |
} |
523 |
|
524 |
/**
|
525 |
* Creates an iterator for the Selection.
|
526 |
*/
|
527 |
private DisposableIterator iterator(long index, long elements, boolean fastIterator) { |
528 |
Iterator iter = this.featureReferenceSelection.referenceIterator(); |
529 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
530 |
iter.next(); |
531 |
} |
532 |
return new FeatureIteratorFacade(iter, getFeatureStore()); |
533 |
// 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 |
} |
552 |
|
553 |
// 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 |
|
575 |
@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 |
} |
584 |
|
585 |
@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 |
|
595 |
|
596 |
@Override
|
597 |
public void commitChanges() throws DataException { |
598 |
} |
599 |
|
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 |
// featureTypeCounts.clear();
|
615 |
} |
616 |
|
617 |
public static void registerPersistent() { |
618 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
619 |
DynStruct definition = manager.addDefinition(LargeFeatureSelection.class, DYNCLASS_PERSISTENT_NAME, |
620 |
"LargeFeatureSelection Persistent definition", null, null); |
621 |
|
622 |
definition.extend(manager.getDefinition(LargeFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME)); |
623 |
// definition.addDynFieldMap("featureTypeCounts")
|
624 |
// .setClassOfItems(Long.class).setMandatory(false);
|
625 |
|
626 |
} |
627 |
|
628 |
@Override
|
629 |
public Object clone() throws CloneNotSupportedException { |
630 |
LargeFeatureSelection clone = (LargeFeatureSelection) super.clone();
|
631 |
// clone.featureTypeCounts = new HashMap(featureTypeCounts);
|
632 |
return clone;
|
633 |
} |
634 |
|
635 |
@Override
|
636 |
protected void doAccept(Visitor visitor, long firstValueIndex, long elements) throws BaseException { |
637 |
if( this.featureReferenceSelection.isEmpty() ) { |
638 |
return;
|
639 |
} |
640 |
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 |
private static class IgnoreInsertAndUpdateFeatureSet extends DefaultFeatureSet { |
654 |
|
655 |
public IgnoreInsertAndUpdateFeatureSet(DefaultFeatureStore store, FeatureQuery query) throws DataException { |
656 |
super(store, query);
|
657 |
} |
658 |
|
659 |
@Override
|
660 |
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 |
@Override
|
672 |
public boolean isAvailable() { |
673 |
return this.featureReferenceSelection.isAvailable(); |
674 |
} |
675 |
|
676 |
} |