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 / paging / impl / FeaturePagingHelperImpl.java @ 43691
History | View | Annotate | Download (27.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
|
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.paging.impl; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Collection; |
28 |
import java.util.Date; |
29 |
import java.util.Iterator; |
30 |
import java.util.List; |
31 |
import java.util.ListIterator; |
32 |
import org.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
36 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
37 |
import org.gvsig.fmap.dal.feature.Feature; |
38 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
39 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
40 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
43 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
44 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
45 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade; |
46 |
import org.gvsig.fmap.dal.feature.paging.FacadeOfAFeaturePagingHelper; |
47 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
48 |
import org.gvsig.tools.dynobject.DynObject; |
49 |
import org.gvsig.tools.dynobject.DynObjectSet; |
50 |
import org.gvsig.tools.dynobject.impl.DefaultDynObjectPagingHelper; |
51 |
import org.gvsig.tools.exception.BaseException; |
52 |
import org.gvsig.tools.visitor.VisitCanceledException; |
53 |
import org.gvsig.tools.visitor.Visitor; |
54 |
|
55 |
/**
|
56 |
* Helper class to access the values of a FeatureCollection by position. Handles
|
57 |
* pagination automatically to avoid filling the memory in case of big
|
58 |
* collections.
|
59 |
*
|
60 |
* TODO: evaluate if its more convenient to read values in the background when
|
61 |
* the returned value is near the end of the page, instead of loading a page on
|
62 |
* demand.
|
63 |
*
|
64 |
* @author gvSIG Team
|
65 |
*/
|
66 |
public class FeaturePagingHelperImpl extends DefaultDynObjectPagingHelper |
67 |
implements FeaturePagingHelper {
|
68 |
|
69 |
private static final Logger LOG = LoggerFactory.getLogger(FeaturePagingHelperImpl.class); |
70 |
|
71 |
private static class Page { |
72 |
|
73 |
private Feature[] features; |
74 |
private final long number; |
75 |
private final int size; |
76 |
private long lastaccess; |
77 |
|
78 |
public Page(long number, int size) { |
79 |
this.size = size;
|
80 |
this.number = number;
|
81 |
this.features = new Feature[size]; |
82 |
this.lastaccess = 0; |
83 |
} |
84 |
|
85 |
public void setFeature(int i, Feature copy) { |
86 |
this.features[i] = copy;
|
87 |
} |
88 |
|
89 |
public Feature[] getFeatures() { |
90 |
this.lastaccess = (new Date()).getTime(); |
91 |
return this.features; |
92 |
} |
93 |
|
94 |
public long getPageNumber() { |
95 |
return this.number; |
96 |
} |
97 |
|
98 |
public long getLastAccess() { |
99 |
return this.lastaccess; |
100 |
} |
101 |
|
102 |
public int size() { |
103 |
return this.size; |
104 |
} |
105 |
|
106 |
public void dispose() { |
107 |
for (int i = 0; i < features.length; i++) { |
108 |
features[i] = null;
|
109 |
} |
110 |
this.features = null; |
111 |
this.lastaccess = 0; |
112 |
} |
113 |
} |
114 |
|
115 |
private static class PageCache { |
116 |
|
117 |
private final int maxpages; |
118 |
private List<Page> pages; |
119 |
|
120 |
public PageCache(int maxpages) { |
121 |
this.maxpages = maxpages;
|
122 |
this.pages = new ArrayList<>(); |
123 |
} |
124 |
|
125 |
public void clear() { |
126 |
for (Page page : pages) {
|
127 |
page.dispose(); |
128 |
} |
129 |
this.pages = new ArrayList<>(); |
130 |
} |
131 |
|
132 |
public Page get(long pageNumber) { |
133 |
for( Page page : pages ) {
|
134 |
if( page.getPageNumber() == pageNumber ) {
|
135 |
return page;
|
136 |
} |
137 |
} |
138 |
return null; |
139 |
} |
140 |
|
141 |
public void add(Page page) { |
142 |
if( this.pages.size()< this.maxpages ) { |
143 |
this.pages.add(page);
|
144 |
return;
|
145 |
} |
146 |
int toDrop = 0; |
147 |
for( int i=0; i<this.pages.size(); i++ ) { |
148 |
if( this.pages.get(i).getLastAccess()<this.pages.get(toDrop).getLastAccess() ) { |
149 |
toDrop = i; |
150 |
} |
151 |
} |
152 |
this.pages.set(toDrop, page);
|
153 |
} |
154 |
} |
155 |
|
156 |
private FeatureQuery query;
|
157 |
|
158 |
private FeatureStore featureStore;
|
159 |
|
160 |
/** If the selected Features must be returned as the first ones. **/
|
161 |
private boolean selectionUp = false; |
162 |
|
163 |
private FeatureSet featSet = null; |
164 |
private FeatureSelection initialSelection = null; |
165 |
|
166 |
private Feature[] features = null; |
167 |
private PageCache cachedPages = null; |
168 |
|
169 |
private boolean initialization_completed = false; |
170 |
|
171 |
private FeatureSelection selection = null; |
172 |
/**
|
173 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
|
174 |
*
|
175 |
* @param featureStore
|
176 |
* to extract data from
|
177 |
* @throws DataException
|
178 |
* if there is an error initializing the helper
|
179 |
*/
|
180 |
public FeaturePagingHelperImpl(FeatureStore featureStore)
|
181 |
throws BaseException {
|
182 |
this(featureStore, DEFAULT_PAGE_SIZE);
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
|
187 |
*
|
188 |
* @param featureStore
|
189 |
* to extract data from
|
190 |
* @param pageSize
|
191 |
* the number of elements per page data
|
192 |
* @throws DataException
|
193 |
* if there is an error initializing the helper
|
194 |
*/
|
195 |
public FeaturePagingHelperImpl(FeatureStore featureStore, int pageSize) |
196 |
throws BaseException {
|
197 |
this(featureStore, null, pageSize); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
|
202 |
*
|
203 |
* @param featureStore
|
204 |
* to extract data from
|
205 |
* @throws DataException
|
206 |
* if there is an error initializing the helper
|
207 |
*/
|
208 |
public FeaturePagingHelperImpl(FeatureStore featureStore,
|
209 |
FeatureQuery featureQuery) throws BaseException {
|
210 |
this(featureStore, featureQuery, DEFAULT_PAGE_SIZE);
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
|
215 |
*
|
216 |
* @param featureSet
|
217 |
* to extract data from
|
218 |
* @param pageSize
|
219 |
* the number of elements per page data
|
220 |
* @throws DataException
|
221 |
* if there is an error initializing the helper
|
222 |
*/
|
223 |
public FeaturePagingHelperImpl(FeatureStore featureStore,
|
224 |
FeatureQuery featureQuery, int pageSize) throws BaseException { |
225 |
super();
|
226 |
this.cachedPages = new PageCache(3); |
227 |
FeatureQuery query = featureQuery; |
228 |
if (featureQuery == null) { |
229 |
query = featureStore.createFeatureQuery(); |
230 |
query.setFeatureType(featureStore.getDefaultFeatureType()); |
231 |
} |
232 |
|
233 |
this.featureStore = featureStore;
|
234 |
this.query = query;
|
235 |
this.query.setPageSize(pageSize);
|
236 |
|
237 |
setDefaultCalculator(new Sizeable() {
|
238 |
public long getSize() { |
239 |
FeatureSet featureSet = getFeatureSet(false);
|
240 |
try {
|
241 |
return featureSet.getSize();
|
242 |
} catch (BaseException e) {
|
243 |
LOG.error("Error getting the size of the FeatureSet: "
|
244 |
+ featureSet, e); |
245 |
return 0l; |
246 |
} |
247 |
} |
248 |
}, pageSize); |
249 |
|
250 |
|
251 |
if (LOG.isDebugEnabled()) {
|
252 |
|
253 |
LOG.debug("FeaturePagingHelperImpl created with {} pages, "
|
254 |
+ "and a page size of {}", new Long(getCalculator() |
255 |
.getNumPages()), new Integer(pageSize)); |
256 |
} |
257 |
this.initialization_completed = true; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @return the selectionUp status
|
262 |
*/
|
263 |
public boolean isSelectionUp() { |
264 |
return selectionUp;
|
265 |
} |
266 |
|
267 |
public FeatureSelection getSelection() {
|
268 |
if (selection == null) { |
269 |
try {
|
270 |
return getFeatureStore().getFeatureSelection();
|
271 |
} catch (Exception e) { |
272 |
LOG.warn("Error getting the selection", e);
|
273 |
} |
274 |
} |
275 |
return selection;
|
276 |
} |
277 |
|
278 |
public void setSelection(FeatureSelection selection) { |
279 |
this.selection = selection;
|
280 |
} |
281 |
|
282 |
@Override
|
283 |
public void setSelectionUp(boolean selectionUp) { |
284 |
this.selectionUp = selectionUp;
|
285 |
try {
|
286 |
FeatureSelection currentSelection = getSelection(); |
287 |
if (selectionUp && !currentSelection.isEmpty()) {
|
288 |
initialSelection =(FeatureSelection) currentSelection.clone(); |
289 |
setCalculator(new OneSubsetOneSetPagingCalculator(
|
290 |
new FeatureSetSizeableDelegate(initialSelection),
|
291 |
new FeatureSetSizeableDelegate(getFeatureSet(false)), |
292 |
getMaxPageSize())); |
293 |
} else {
|
294 |
if (initialSelection != null) { |
295 |
initialSelection.dispose(); |
296 |
initialSelection = null;
|
297 |
} |
298 |
setDefaultCalculator(new FeatureSetSizeableDelegate(
|
299 |
getFeatureSet(false)), getMaxPageSize());
|
300 |
} |
301 |
} catch (BaseException e) {
|
302 |
LOG.error("Error setting the selection up setting to: "
|
303 |
+ selectionUp, e); |
304 |
} catch (CloneNotSupportedException e) { |
305 |
LOG.error("Error cloning the selection "
|
306 |
+ "while setting the selection up", e);
|
307 |
} |
308 |
} |
309 |
|
310 |
public synchronized Feature getFeatureAt(long index) throws BaseException { |
311 |
// Check if we have currently loaded the viewed page data,
|
312 |
// or we need to load a new one
|
313 |
int maxPageSize = getMaxPageSize();
|
314 |
long currentPage = getCurrentPage();
|
315 |
long currentPage2 = currentPage;
|
316 |
|
317 |
|
318 |
long pageForIndex = (long) Math.floor(index / maxPageSize); |
319 |
|
320 |
if (pageForIndex != currentPage) {
|
321 |
setCurrentPage(pageForIndex); |
322 |
currentPage2 = getCurrentPage(); |
323 |
} |
324 |
|
325 |
long positionForIndex = index - (currentPage2 * maxPageSize);
|
326 |
|
327 |
if (positionForIndex >= getCurrentPageFeatures().length) {
|
328 |
throw new FeatureIndexException( |
329 |
new IndexOutOfBoundsException("positionForIndex too big: " |
330 |
+ positionForIndex)); |
331 |
} else {
|
332 |
Feature feature = getCurrentPageFeatures()[(int) positionForIndex];
|
333 |
return feature;
|
334 |
} |
335 |
|
336 |
} |
337 |
|
338 |
public Feature[] getCurrentPageFeatures() { |
339 |
if( this.features==null ) { |
340 |
try {
|
341 |
this.loadCurrentPageData();
|
342 |
} catch (BaseException ex) {
|
343 |
// Do nothing
|
344 |
} |
345 |
if( this.features == null ) { |
346 |
String msg = "Can't retrieve the features from current page."; |
347 |
LOG.warn(msg); |
348 |
throw new RuntimeException(msg); |
349 |
} |
350 |
} |
351 |
return features;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* Gets the feature set.
|
356 |
* The boolean tells whether we must create the featureset
|
357 |
* again (for example perhaps we need it after a feature
|
358 |
* has been added/removed)
|
359 |
*/
|
360 |
private FeatureSet getFeatureSet(boolean reset) { |
361 |
|
362 |
if (featSet == null || reset) { |
363 |
|
364 |
if (featSet != null) { |
365 |
try {
|
366 |
featSet.dispose(); |
367 |
} catch (Exception ex) { |
368 |
LOG.info("Error while disposing featset.", ex);
|
369 |
} |
370 |
} |
371 |
|
372 |
try {
|
373 |
FeatureStore featureStore = getFeatureStore(); |
374 |
synchronized (featureStore) {
|
375 |
featSet = featureStore.getFeatureSet(getFeatureQuery()); |
376 |
} |
377 |
} catch (DataException e) {
|
378 |
throw new RuntimeException("Error getting a feature set with the query " + getFeatureQuery()); |
379 |
} |
380 |
} |
381 |
return featSet;
|
382 |
} |
383 |
|
384 |
@Override
|
385 |
public DynObjectSet getDynObjectSet() {
|
386 |
return getFeatureSet(false).getDynObjectSet(); |
387 |
} |
388 |
|
389 |
@Override
|
390 |
public void reloadCurrentPage() throws BaseException { |
391 |
|
392 |
boolean sel_up = this.isSelectionUp(); |
393 |
|
394 |
setSelectionUp(false);
|
395 |
if (getCalculator().getCurrentPage() > -1) { |
396 |
this.cachedPages.clear();
|
397 |
loadCurrentPageData(); |
398 |
} |
399 |
|
400 |
if (sel_up) {
|
401 |
setSelectionUp(true);
|
402 |
} |
403 |
} |
404 |
|
405 |
@Override
|
406 |
public void reload() throws BaseException { |
407 |
|
408 |
/*
|
409 |
* Force re-creation of feature set
|
410 |
*/
|
411 |
this.getFeatureSet(true); |
412 |
|
413 |
|
414 |
setDefaultCalculator(new Sizeable() {
|
415 |
public long getSize() { |
416 |
FeatureSet featureSet = getFeatureSet(false);
|
417 |
try {
|
418 |
return featureSet.getSize();
|
419 |
} catch (BaseException e) {
|
420 |
LOG.error("Error getting the size of the FeatureSet: "
|
421 |
+ featureSet, e); |
422 |
return 0l; |
423 |
} |
424 |
} |
425 |
}, getCalculator().getMaxPageSize()); |
426 |
reloadCurrentPage(); |
427 |
} |
428 |
|
429 |
public FeatureStore getFeatureStore() {
|
430 |
return featureStore;
|
431 |
} |
432 |
|
433 |
public FeatureQuery getFeatureQuery() {
|
434 |
return query;
|
435 |
} |
436 |
|
437 |
/**
|
438 |
* Loads all the Features of the current page.
|
439 |
* @throws org.gvsig.tools.exception.BaseException
|
440 |
*/
|
441 |
@Override
|
442 |
protected synchronized void loadCurrentPageData() throws BaseException { |
443 |
if( !initialization_completed ) {
|
444 |
return;
|
445 |
} |
446 |
final int currentPageSize = getCalculator().getCurrentPageSize(); |
447 |
final long currentPage = getCalculator().getCurrentPage(); |
448 |
Page page = this.cachedPages.get(currentPage);
|
449 |
if( page==null ) { |
450 |
page = new Page(currentPage, currentPageSize);
|
451 |
|
452 |
long t1 = 0; |
453 |
if (LOG.isTraceEnabled()) {
|
454 |
t1 = System.currentTimeMillis();
|
455 |
} |
456 |
|
457 |
if (selectionUp) {
|
458 |
loadCurrentPageDataWithSelectionUp(page); |
459 |
} else {
|
460 |
loadCurrentPageDataNoSelection(page); |
461 |
} |
462 |
|
463 |
if (LOG.isTraceEnabled()) {
|
464 |
long t2 = System.currentTimeMillis(); |
465 |
LOG.trace("Time to load {} features: {} ms", currentPageSize, t2 - t1);
|
466 |
} |
467 |
this.cachedPages.add(page);
|
468 |
} |
469 |
this.features = page.getFeatures();
|
470 |
} |
471 |
|
472 |
private void loadCurrentPageDataWithSelectionUp(final Page page) |
473 |
throws BaseException {
|
474 |
FeatureSelection selection = initialSelection; |
475 |
if (selection == null) { |
476 |
loadCurrentPageDataNoSelection(page); |
477 |
} else {
|
478 |
FeatureSet set = getFeatureSet(false);
|
479 |
try {
|
480 |
OneSubsetOneSetPagingCalculator twoSetsCalculator = null;
|
481 |
if (getCalculator() instanceof OneSubsetOneSetPagingCalculator) { |
482 |
twoSetsCalculator |
483 |
= (OneSubsetOneSetPagingCalculator) getCalculator(); |
484 |
} else {
|
485 |
twoSetsCalculator |
486 |
= new OneSubsetOneSetPagingCalculator(
|
487 |
new FeatureSetSizeableDelegate(selection),
|
488 |
new FeatureSetSizeableDelegate(set),
|
489 |
getMaxPageSize(), getCalculator().getCurrentPage()); |
490 |
setCalculator(twoSetsCalculator); |
491 |
} |
492 |
|
493 |
// First load values from the selection, if the current page has
|
494 |
// elements from it
|
495 |
if (twoSetsCalculator.hasCurrentPageAnyValuesInFirstSet()) {
|
496 |
loadDataFromFeatureSet(page, 0, selection,
|
497 |
twoSetsCalculator.getFirstSetInitialIndex(), |
498 |
twoSetsCalculator.getFirstSetHowMany(), null);
|
499 |
} |
500 |
// Next, load values from the FeatureSet if the current page has values
|
501 |
// from it
|
502 |
if (twoSetsCalculator.hasCurrentPageAnyValuesInSecondSet()) {
|
503 |
loadDataFromFeatureSet( |
504 |
page, |
505 |
// The cast will work as that size will be <= maxpagesize,
|
506 |
// which is an int
|
507 |
(int) twoSetsCalculator.getFirstSetHowMany(), set,
|
508 |
twoSetsCalculator.getSecondSetInitialIndex(), |
509 |
twoSetsCalculator.getSecondSetHowMany(), selection); |
510 |
} |
511 |
} finally {
|
512 |
/*
|
513 |
* This is the feature set
|
514 |
* we dont want to lose it
|
515 |
*/
|
516 |
// set.dispose();
|
517 |
} |
518 |
} |
519 |
} |
520 |
|
521 |
private void loadCurrentPageDataNoSelection(final Page page) |
522 |
throws BaseException {
|
523 |
|
524 |
long firstPosition = getCalculator().getInitialIndex();
|
525 |
|
526 |
if (LOG.isDebugEnabled()) {
|
527 |
LOG.debug("Loading {} Features starting at position {}",
|
528 |
getCalculator().getCurrentPageSize(), firstPosition |
529 |
); |
530 |
} |
531 |
|
532 |
FeatureSet featureSet = getFeatureSet(false);
|
533 |
try {
|
534 |
loadDataFromFeatureSet(page, 0, featureSet, firstPosition,
|
535 |
getCalculator().getCurrentPageSize(), null);
|
536 |
} catch(DataException ex) {
|
537 |
throw ex;
|
538 |
// } finally {
|
539 |
// featureSet.dispose();
|
540 |
} |
541 |
|
542 |
} |
543 |
|
544 |
private void loadDataFromFeatureSet(final Page page, |
545 |
final int valuesPosition, FeatureSet set, long initialIndex, |
546 |
final long howMany, final FeatureSelection selectedFeaturesToSkip) |
547 |
throws DataException {
|
548 |
|
549 |
try {
|
550 |
set.accept(new Visitor() {
|
551 |
private int i = valuesPosition; |
552 |
|
553 |
@Override
|
554 |
public void visit(Object obj) throws VisitCanceledException, |
555 |
BaseException { |
556 |
if (i >= valuesPosition + howMany) {
|
557 |
throw new VisitCanceledException(); |
558 |
} |
559 |
Feature current = (Feature) obj; |
560 |
// Add the current Feature only if we don't skip selected
|
561 |
// features or the feature is not selected
|
562 |
if (selectedFeaturesToSkip == null |
563 |
|| !selectedFeaturesToSkip.isSelected(current)) { |
564 |
try {
|
565 |
page.setFeature(i,current.getCopy()); |
566 |
i++; |
567 |
} catch(Exception ex) { |
568 |
// Aqui no deberia petar, pero...
|
569 |
// me he encontrado un caso que tenia una referencia a
|
570 |
// una feature seleccionada que ya no existia. No se como
|
571 |
// habia pasado, se habia quedado de antes guardada en el
|
572 |
// proyecto pero la feature ya no existia, y eso hacia que
|
573 |
// petase al intentar leer de disco la feature a partir
|
574 |
// de una referencia no valida.
|
575 |
} |
576 |
} |
577 |
} |
578 |
}, initialIndex, howMany); |
579 |
} catch(VisitCanceledException ex) {
|
580 |
// Do nothing
|
581 |
} catch (BaseException e) {
|
582 |
if (e instanceof DataException) { |
583 |
throw ((DataException) e);
|
584 |
} else {
|
585 |
LOG.error("Error loading the data starting at position {}",
|
586 |
new Long(initialIndex), e); |
587 |
} |
588 |
} |
589 |
} |
590 |
|
591 |
public void delete(Feature feature) throws BaseException { |
592 |
featureStore.delete(feature); |
593 |
/*
|
594 |
* Force re-creation of feature set
|
595 |
*/
|
596 |
this.getFeatureSet(true); |
597 |
|
598 |
reloadCurrentPage(); |
599 |
} |
600 |
|
601 |
public void insert(EditableFeature feature) throws BaseException { |
602 |
featureStore.insert(feature); |
603 |
/*
|
604 |
* Force re-creation of feature set
|
605 |
*/
|
606 |
this.getFeatureSet(true); |
607 |
|
608 |
reloadCurrentPage(); |
609 |
} |
610 |
|
611 |
public void update(EditableFeature feature) throws BaseException { |
612 |
featureStore.update(feature); |
613 |
/*
|
614 |
* Force re-creation of feature set
|
615 |
*/
|
616 |
this.getFeatureSet(true); |
617 |
|
618 |
reloadCurrentPage(); |
619 |
} |
620 |
|
621 |
public FeatureType getFeatureType() {
|
622 |
|
623 |
FeatureType ft = null;
|
624 |
|
625 |
try {
|
626 |
ft = featureStore.getDefaultFeatureType(); |
627 |
} catch (DataException e) {
|
628 |
LOG.error("Error while getting feature type: " +
|
629 |
e.getMessage(), e); |
630 |
} |
631 |
return ft;
|
632 |
|
633 |
/*
|
634 |
*
|
635 |
FeatureSet featureSet = getFeatureSet();
|
636 |
try {
|
637 |
return featureSet.getDefaultFeatureType();
|
638 |
} finally {
|
639 |
featureSet.dispose();
|
640 |
}
|
641 |
*/
|
642 |
|
643 |
|
644 |
} |
645 |
|
646 |
protected void doDispose() throws BaseException { |
647 |
initialSelection.dispose(); |
648 |
if (featSet != null) { |
649 |
try {
|
650 |
featSet.dispose(); |
651 |
} catch (Exception ex) { |
652 |
LOG.info("Error while disposing featset.", ex);
|
653 |
} |
654 |
} |
655 |
} |
656 |
|
657 |
public DynObject[] getCurrentPageDynObjects() { |
658 |
Feature[] features = getCurrentPageFeatures();
|
659 |
DynObject[] dynobjects = new DynObject[features.length]; |
660 |
for (int i = 0; i < dynobjects.length; i++) { |
661 |
dynobjects[i] = new DynObjectFeatureFacade(features[i]);
|
662 |
} |
663 |
return dynobjects;
|
664 |
} |
665 |
|
666 |
public DynObject getDynObjectAt(long index) throws BaseException { |
667 |
return new DynObjectFeatureFacade(getFeatureAt(index)); |
668 |
} |
669 |
|
670 |
public List asList() { |
671 |
return new FeaturePagingHelperList(); |
672 |
} |
673 |
|
674 |
public List asListOfDynObjects() { |
675 |
return new DynObjectPagingHelperList(); |
676 |
} |
677 |
|
678 |
private class FeaturePagingHelperList extends PagingHelperList { |
679 |
public Object get(int i) { |
680 |
try {
|
681 |
return getFeatureAt(i);
|
682 |
} catch (BaseException ex) {
|
683 |
throw new RuntimeException(ex); |
684 |
} |
685 |
} |
686 |
} |
687 |
|
688 |
private class DynObjectPagingHelperList extends PagingHelperList { |
689 |
public Object get(int i) { |
690 |
try {
|
691 |
return getDynObjectAt(i);
|
692 |
} catch (BaseException ex) {
|
693 |
throw new RuntimeException(ex); |
694 |
} |
695 |
} |
696 |
|
697 |
} |
698 |
|
699 |
private abstract class PagingHelperList implements List, FacadeOfAFeaturePagingHelper { |
700 |
|
701 |
@Override
|
702 |
public FeaturePagingHelper getFeaturePagingHelper() {
|
703 |
return FeaturePagingHelperImpl.this;
|
704 |
} |
705 |
|
706 |
public int size() { |
707 |
try {
|
708 |
return (int) getFeatureSet(false).getSize(); |
709 |
} catch (DataException ex) {
|
710 |
throw new RuntimeException(ex); |
711 |
} |
712 |
} |
713 |
|
714 |
public boolean isEmpty() { |
715 |
try {
|
716 |
return getFeatureSet(false).isEmpty(); |
717 |
} catch (DataException ex) {
|
718 |
throw new RuntimeException(ex); |
719 |
} catch (ConcurrentDataModificationException ex) {
|
720 |
LOG.warn( |
721 |
"Error to asking about the emptiness of the store. Retrying reloading data.",
|
722 |
ex); |
723 |
try {
|
724 |
reload(); |
725 |
} catch (BaseException e) {
|
726 |
LOG.warn("Error reloading data.", e);
|
727 |
throw new RuntimeException(e); |
728 |
} |
729 |
try {
|
730 |
return getFeatureSet(false).isEmpty(); |
731 |
} catch (DataException e) {
|
732 |
LOG.warn( |
733 |
"Error to asking about the emptiness of the store after reloading data.",
|
734 |
e); |
735 |
throw new RuntimeException(e); |
736 |
} |
737 |
} |
738 |
} |
739 |
|
740 |
public Iterator iterator() { |
741 |
try {
|
742 |
return getFeatureSet(false).fastIterator(); |
743 |
} catch (DataException ex) {
|
744 |
throw new RuntimeException(ex); |
745 |
} |
746 |
} |
747 |
|
748 |
public boolean contains(Object o) { |
749 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
750 |
} |
751 |
|
752 |
public Object[] toArray() { |
753 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
754 |
} |
755 |
|
756 |
public Object[] toArray(Object[] ts) { |
757 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
758 |
} |
759 |
|
760 |
public boolean add(Object e) { |
761 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
762 |
} |
763 |
|
764 |
public boolean remove(Object o) { |
765 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
766 |
} |
767 |
|
768 |
public boolean containsAll(Collection clctn) { |
769 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
770 |
} |
771 |
|
772 |
public boolean addAll(Collection clctn) { |
773 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
774 |
} |
775 |
|
776 |
public boolean addAll(int i, Collection clctn) { |
777 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
778 |
} |
779 |
|
780 |
public boolean removeAll(Collection clctn) { |
781 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
782 |
} |
783 |
|
784 |
public boolean retainAll(Collection clctn) { |
785 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
786 |
} |
787 |
|
788 |
public void clear() { |
789 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
790 |
} |
791 |
|
792 |
public Object set(int i, Object e) { |
793 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
794 |
} |
795 |
|
796 |
public void add(int i, Object e) { |
797 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
798 |
} |
799 |
|
800 |
public Object remove(int i) { |
801 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
802 |
} |
803 |
|
804 |
public int indexOf(Object o) { |
805 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
806 |
} |
807 |
|
808 |
public int lastIndexOf(Object o) { |
809 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
810 |
} |
811 |
|
812 |
public ListIterator listIterator() { |
813 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
814 |
} |
815 |
|
816 |
public ListIterator listIterator(int i) { |
817 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
818 |
} |
819 |
|
820 |
public List subList(int i, int i1) { |
821 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
822 |
} |
823 |
|
824 |
} |
825 |
} |