Revision 44977 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

View differences:

FeaturePagingHelperImpl.java
1 1
/**
2 2
 * gvSIG. Desktop Geographic Information System.
3 3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
4
 * Copyright (C) 2007-2020 gvSIG Association.
5 5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
......
29 29
import java.util.Iterator;
30 30
import java.util.List;
31 31
import java.util.ListIterator;
32
import java.util.logging.Level;
33 32
import org.apache.commons.lang3.mutable.MutableBoolean;
34 33
import org.slf4j.Logger;
35 34
import org.slf4j.LoggerFactory;
......
67 66
 *
68 67
 * @author gvSIG Team
69 68
 */
69
@SuppressWarnings("UseSpecificCatch")
70 70
public class FeaturePagingHelperImpl extends DefaultDynObjectPagingHelper
71
    implements FeaturePagingHelper {
71
        implements FeaturePagingHelper {
72 72

  
73 73
    private static final Logger LOG = LoggerFactory.getLogger(FeaturePagingHelperImpl.class);
74 74

  
......
78 78
        private final long number;
79 79
        private final int size;
80 80
        private long lastaccess;
81
        
81

  
82 82
        public Page(long number, int size) {
83 83
            this.size = size;
84 84
            this.number = number;
......
89 89
        public void setFeature(int i, Feature copy) {
90 90
            this.features[i] = copy;
91 91
        }
92
        
92

  
93 93
        public Feature[] getFeatures() {
94 94
            this.lastaccess = (new Date()).getTime();
95 95
            return this.features;
96 96
        }
97
        
97

  
98 98
        public long getPageNumber() {
99 99
            return this.number;
100 100
        }
101
        
101

  
102 102
        public long getLastAccess() {
103 103
            return this.lastaccess;
104 104
        }
105
        
105

  
106 106
        public int size() {
107 107
            return this.size;
108 108
        }
109
        
109

  
110 110
        public void dispose() {
111 111
            for (int i = 0; i < features.length; i++) {
112 112
                features[i] = null;
......
114 114
            this.features = null;
115 115
            this.lastaccess = 0;
116 116
        }
117
    } 
118
    
117
    }
118

  
119 119
    private static class PageCache {
120 120

  
121 121
        private final int maxpages;
122 122
        private List<Page> pages;
123
        
123

  
124 124
        public PageCache(int maxpages) {
125 125
            this.maxpages = maxpages;
126 126
            this.pages = new ArrayList<>();
127 127
        }
128
        
128

  
129 129
        public void clear() {
130
            for (Page page : pages) {
130
            pages.forEach((page) -> {
131 131
                page.dispose();
132
            }
133
            this.pages = new ArrayList<>();    
132
            });
133
            this.pages = new ArrayList<>();
134 134
        }
135
        
135

  
136 136
        public Page get(long pageNumber) {
137
            for( Page page : pages ) {
138
                if( page.getPageNumber() == pageNumber ) {
137
            for (Page page : pages) {
138
                if (page.getPageNumber() == pageNumber) {
139 139
                    return page;
140 140
                }
141 141
            }
142 142
            return null;
143 143
        }
144
        
144

  
145 145
        public void add(Page page) {
146
            if( this.pages.size()< this.maxpages ) {
146
            if (this.pages.size() < this.maxpages) {
147 147
                this.pages.add(page);
148 148
                return;
149 149
            }
150 150
            int toDrop = 0;
151
            for( int i=0; i<this.pages.size(); i++ ) {
152
                if( this.pages.get(i).getLastAccess()<this.pages.get(toDrop).getLastAccess() ) {
151
            for (int i = 0; i < this.pages.size(); i++) {
152
                if (this.pages.get(i).getLastAccess() < this.pages.get(toDrop).getLastAccess()) {
153 153
                    toDrop = i;
154 154
                }
155 155
            }
156 156
            this.pages.set(toDrop, page);
157 157
        }
158 158
    }
159
    
159

  
160 160
    private FeatureQuery query;
161 161

  
162 162
    private FeatureStore featureStore;
163 163

  
164
    /** If the selected Features must be returned as the first ones. **/
164
    /**
165
     * If the selected Features must be returned as the first ones. *
166
     */
165 167
    private boolean selectionUp = false;
166 168

  
167 169
    private FeatureSet featSet = null;
168
    private FeatureSelection initialSelection = null;
169 170

  
170 171
    private Feature[] features = null;
171 172
    private PageCache cachedPages = null;
......
173 174
    private boolean initialization_completed = false;
174 175

  
175 176
    private FeatureSelection selection = null;
177

  
176 178
    /**
177 179
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
178 180
     *
179
     * @param featureStore
180
     *            to extract data from
181
     * @throws DataException
182
     *             if there is an error initializing the helper
181
     * @param featureStore to extract data from
182
     * @throws DataException if there is an error initializing the helper
183 183
     */
184 184
    public FeaturePagingHelperImpl(FeatureStore featureStore)
185
        throws BaseException {
185
            throws BaseException {
186 186
        this(featureStore, DEFAULT_PAGE_SIZE);
187 187
    }
188 188

  
189 189
    /**
190 190
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
191 191
     *
192
     * @param featureStore
193
     *            to extract data from
194
     * @param pageSize
195
     *            the number of elements per page data
196
     * @throws DataException
197
     *             if there is an error initializing the helper
192
     * @param featureStore to extract data from
193
     * @param pageSize the number of elements per page data
194
     * @throws DataException if there is an error initializing the helper
198 195
     */
199 196
    public FeaturePagingHelperImpl(FeatureStore featureStore, int pageSize)
200
        throws BaseException {
197
            throws BaseException {
201 198
        this(featureStore, null, pageSize);
202 199
    }
203 200

  
204 201
    /**
205 202
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
206 203
     *
207
     * @param featureStore
208
     *            to extract data from
209
     * @throws DataException
210
     *             if there is an error initializing the helper
204
     * @param featureStore to extract data from
205
     * @param featureQuery
206
     * @throws DataException if there is an error initializing the helper
211 207
     */
212 208
    public FeaturePagingHelperImpl(FeatureStore featureStore,
213
        FeatureQuery featureQuery) throws BaseException {
209
            FeatureQuery featureQuery) throws BaseException {
214 210
        this(featureStore, featureQuery, DEFAULT_PAGE_SIZE);
215 211
    }
216 212

  
217 213
    /**
218 214
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
219 215
     *
220
     * @param featureSet
221
     *            to extract data from
222
     * @param pageSize
223
     *            the number of elements per page data
224
     * @throws DataException
225
     *             if there is an error initializing the helper
216
     * @param featureStore
217
     * @param featureQuery
218
     * @param pageSize the number of elements per page data
219
     * @throws DataException if there is an error initializing the helper
226 220
     */
227 221
    public FeaturePagingHelperImpl(FeatureStore featureStore,
228
        FeatureQuery featureQuery, int pageSize) throws BaseException {
222
            FeatureQuery featureQuery, int pageSize) throws BaseException {
229 223
        super();
230 224
        this.cachedPages = new PageCache(3);
231
        FeatureQuery query = featureQuery;
225
        FeatureQuery theQuery = featureQuery;
232 226
        if (featureQuery == null) {
233
            query = featureStore.createFeatureQuery();
234
            query.setFeatureType(featureStore.getDefaultFeatureType());
227
            theQuery = featureStore.createFeatureQuery();
228
            theQuery.setFeatureType(featureStore.getDefaultFeatureType());
235 229
        }
236 230

  
237 231
        this.featureStore = featureStore;
238
        this.query = query;
232
        this.query = theQuery;
239 233
        this.query.setPageSize(pageSize);
240 234

  
241
        setDefaultCalculator(new Sizeable() {
242
            public long getSize() {
243
            	FeatureSet featureSet = getFeatureSet(false);
244
                try {
245
					return featureSet.getSize();
246
                } catch (BaseException e) {
247
                    LOG.error("Error getting the size of the FeatureSet: "
248
                        + featureSet, e);
249
                    return 0l;
250
                }
235
        setDefaultCalculator(() -> {
236
            FeatureSet featureSet = getFeatureSet(false);
237
            try {
238
                return featureSet.getSize();
239
            } catch (BaseException e) {
240
                LOG.warn("Error getting the size of the FeatureSet: " + featureSet, e);
241
                return 0l;
251 242
            }
252 243
        }, pageSize);
253

  
254

  
255 244
        if (LOG.isDebugEnabled()) {
256

  
257
            LOG.debug("FeaturePagingHelperImpl created with {} pages, "
258
                + "and a page size of {}", new Long(getCalculator()
259
                .getNumPages()), new Integer(pageSize));
245
            LOG.debug("FeaturePagingHelperImpl created with {} pages, and a page size of {}",
246
                    getCalculator().getNumPages(), pageSize
247
            );
260 248
        }
261 249
        this.initialization_completed = true;
262 250
    }
......
264 252
    /**
265 253
     * @return the selectionUp status
266 254
     */
255
    @Override
267 256
    public boolean isSelectionUp() {
268 257
        return selectionUp;
269 258
    }
270
    
259

  
260
    @Override
271 261
    public FeatureSelection getSelection() {
272 262
        if (selection == null) {
273 263
            try {
......
278 268
        }
279 269
        return selection;
280 270
    }
281
    
271

  
272
    @Override
282 273
    public void setSelection(FeatureSelection selection) {
283 274
        this.selection = selection;
284 275
    }
285
    
276

  
286 277
    @Override
287 278
    public void setSelectionUp(boolean selectionUp) {
288 279
        this.selectionUp = selectionUp;
......
290 281
            this.cachedPages.clear();
291 282
            FeatureSelection currentSelection = getSelection();
292 283
            if (selectionUp && !currentSelection.isEmpty()) {
293
                initialSelection =(FeatureSelection) currentSelection.clone();
284
//                initialSelection =(FeatureSelection) currentSelection.clone();
294 285
                setCalculator(new OneSubsetOneSetPagingCalculator(
295
                    new FeatureSetSizeableDelegate(initialSelection),
296
                    new FeatureSetSizeableDelegate(getFeatureSet(false)),
297
                    getMaxPageSize()));
286
                        new FeatureSetSizeableDelegate(currentSelection),
287
                        new FeatureSetSizeableDelegate(getFeatureSet(false)),
288
                        getMaxPageSize()));
298 289
            } else {
299
                if (initialSelection != null) {
300
                    initialSelection.dispose();
301
                    initialSelection = null;
302
                }
303 290
                setDefaultCalculator(new FeatureSetSizeableDelegate(
304
                    getFeatureSet(false)), getMaxPageSize());
291
                        getFeatureSet(false)), getMaxPageSize()
292
                );
305 293
            }
306 294
        } catch (BaseException e) {
307
            LOG.error("Error setting the selection up setting to: "
308
                + selectionUp, e);
309
        } catch (CloneNotSupportedException e) {
310
            LOG.error("Error cloning the selection "
311
                + "while setting the selection up", e);
295
            LOG.warn("Error setting the selection up setting to: " + selectionUp, e);
312 296
        }
313 297
    }
314 298

  
299
    @Override
315 300
    public synchronized Feature getFeatureAt(long index) throws BaseException {
316 301
        // Check if we have currently loaded the viewed page data,
317 302
        // or we need to load a new one
318
    	int maxPageSize = getMaxPageSize();
319
    	long currentPage = getCurrentPage();
320
    	long currentPage2 = currentPage;
321
    	
322
    	
303
        int maxPageSize = getMaxPageSize();
304
        long currentPage = getCurrentPage();
305
        long currentPage2 = currentPage;
306

  
323 307
        long pageForIndex = (long) Math.floor(index / maxPageSize);
324 308

  
325 309
        if (pageForIndex != currentPage) {
......
331 315

  
332 316
        if (positionForIndex >= getCurrentPageFeatures().length) {
333 317
            throw new FeatureIndexException(
334
                new IndexOutOfBoundsException("positionForIndex too big: "
335
                    + positionForIndex));
318
                    new IndexOutOfBoundsException("positionForIndex too big: "
319
                            + positionForIndex));
336 320
        } else {
337 321
            Feature feature = getCurrentPageFeatures()[(int) positionForIndex];
338 322
            return feature;
......
340 324

  
341 325
    }
342 326

  
327
    @Override
343 328
    public Feature[] getCurrentPageFeatures() {
344
        if( this.features==null ) {
329
        if (this.features == null) {
345 330
            try {
346 331
                this.loadCurrentPageData();
347 332
            } catch (BaseException ex) {
348 333
                // Do nothing
349 334
            }
350
            if( this.features == null ) {
335
            if (this.features == null) {
351 336
                String msg = "Can't retrieve the features from current page.";
352 337
                LOG.warn(msg);
353 338
                throw new RuntimeException(msg);
......
355 340
        }
356 341
        return features;
357 342
    }
358
    
343

  
359 344
    @Override
360 345
    public FeatureSet getFeatureSet() {
361 346
        return this.getFeatureSet(false);
362 347
    }
363 348

  
364 349
    /**
365
     * Gets the feature set.
366
     * The boolean tells whether we must create the featureset
367
     * again (for example perhaps we need it after a feature
368
     * has been added/removed)
350
     * Gets the feature set. The boolean tells whether we must create the
351
     * featureset again (for example perhaps we need it after a feature has been
352
     * added/removed)
369 353
     */
370 354
    private FeatureSet getFeatureSet(boolean reset) {
371 355

  
......
393 377

  
394 378
    @Override
395 379
    public DynObjectSet getDynObjectSet() {
396
    	return getFeatureSet(false).getDynObjectSet();
380
        return getFeatureSet(false).getDynObjectSet();
397 381
    }
398 382

  
399 383
    @Override
400 384
    public void reloadCurrentPage() throws BaseException {
401

  
402 385
        boolean sel_up = this.isSelectionUp();
403

  
404
        setSelectionUp(false);
405
        if (getCalculator().getCurrentPage() > -1) {
406
            this.cachedPages.clear();
407
            loadCurrentPageData();
386
        try {
387
            setSelectionUp(false);
388
            if (getCalculator().getCurrentPage() > -1) {
389
                this.cachedPages.clear();
390
                loadCurrentPageData();
391
            }
392
        } finally {
393
            if (sel_up) {
394
                setSelectionUp(true);
395
            }
408 396
        }
409

  
410
        if (sel_up) {
411
            setSelectionUp(true);
412
        }
413 397
    }
414 398

  
415 399
    @Override
......
421 405
         */
422 406
        this.getFeatureSet(true);
423 407

  
424

  
425
        setDefaultCalculator(new Sizeable() {
426
            public long getSize() {
427
            	FeatureSet featureSet = getFeatureSet(false);
428
                try {
429
					return featureSet.getSize();
430
                } catch (BaseException e) {
431
                    LOG.error("Error getting the size of the FeatureSet: "
432
                        + featureSet, e);
433
                    return 0l;
434
                }
408
        setDefaultCalculator(() -> {
409
            FeatureSet featureSet = getFeatureSet(false);
410
            try {
411
                return featureSet.getSize();
412
            } catch (BaseException e) {
413
                LOG.warn("Error getting the size of the FeatureSet: "+ featureSet, e);
414
                return 0l;
435 415
            }
436 416
        }, getCalculator().getMaxPageSize());
437 417
        reloadCurrentPage();
438 418
    }
439 419

  
420
    @Override
440 421
    public FeatureStore getFeatureStore() {
441 422
        return featureStore;
442 423
    }
443 424

  
425
    @Override
444 426
    public FeatureQuery getFeatureQuery() {
445 427
        return query;
446 428
    }
447 429

  
448 430
    /**
449 431
     * Loads all the Features of the current page.
432
     *
450 433
     * @throws org.gvsig.tools.exception.BaseException
451 434
     */
452 435
    @Override
453 436
    protected synchronized void loadCurrentPageData() throws BaseException {
454
        if( !initialization_completed ) {
437
        if (!initialization_completed) {
455 438
            return;
456 439
        }
457 440
        final int currentPageSize = getCalculator().getCurrentPageSize();
458 441
        final long currentPage = getCalculator().getCurrentPage();
459 442
        Page page = this.cachedPages.get(currentPage);
460
        if( page==null ) {
443
        if (page == null) {
461 444
            page = new Page(currentPage, currentPageSize);
462 445

  
463 446
            long t1 = 0;
......
482 465

  
483 466
    private void loadCurrentPageDataWithSelectionUp(final Page page)
484 467
            throws BaseException {
485
        FeatureSelection selection = initialSelection;
486
        if (selection == null) {
468
        FeatureSelection theSelection = getSelection();
469
        if (theSelection == null) {
487 470
            loadCurrentPageDataNoSelection(page);
488 471
        } else {
489 472
            FeatureSet set = getFeatureSet(false);
490 473
            try {
491 474
                OneSubsetOneSetPagingCalculator twoSetsCalculator = null;
492 475
                if (getCalculator() instanceof OneSubsetOneSetPagingCalculator) {
493
                    twoSetsCalculator
494
                            = (OneSubsetOneSetPagingCalculator) getCalculator();
476
                    twoSetsCalculator = (OneSubsetOneSetPagingCalculator) getCalculator();
495 477
                } else {
496
                    twoSetsCalculator
497
                            = new OneSubsetOneSetPagingCalculator(
498
                                    new FeatureSetSizeableDelegate(selection),
478
                    twoSetsCalculator = new OneSubsetOneSetPagingCalculator(
479
                                    new FeatureSetSizeableDelegate(theSelection),
499 480
                                    new FeatureSetSizeableDelegate(set),
500
                                    getMaxPageSize(), getCalculator().getCurrentPage());
481
                                    getMaxPageSize(), getCalculator().getCurrentPage()
482
                    );
501 483
                    setCalculator(twoSetsCalculator);
502 484
                }
503

  
504
	        // First load values from the selection, if the current page has
485
                // First load values from the selection, if the current page has
505 486
                // elements from it
506 487
                if (twoSetsCalculator.hasCurrentPageAnyValuesInFirstSet()) {
507
                    loadDataFromFeatureSet(page, 0, selection,
488
                    loadDataFromFeatureSet(page, 0, theSelection,
508 489
                            twoSetsCalculator.getFirstSetInitialIndex(),
509
                            twoSetsCalculator.getFirstSetHowMany(), null);
490
                            twoSetsCalculator.getFirstSetHowMany(), null
491
                    );
510 492
                }
511
	        // Next, load values from the FeatureSet if the current page has values
493
                // Next, load values from the FeatureSet if the current page has values
512 494
                // from it
513 495
                if (twoSetsCalculator.hasCurrentPageAnyValuesInSecondSet()) {
514 496
                    loadDataFromFeatureSet(
......
517 499
                            // which is an int
518 500
                            (int) twoSetsCalculator.getFirstSetHowMany(), set,
519 501
                            twoSetsCalculator.getSecondSetInitialIndex(),
520
                            twoSetsCalculator.getSecondSetHowMany(), selection);
502
                            twoSetsCalculator.getSecondSetHowMany(), theSelection
503
                    );
521 504
                }
522 505
            } finally {
523
                /*
524
                 * This is the feature set
525
                 * we dont want to lose it
526
                 */
506
                // This is the feature set we dont want to lose it
527 507
                // set.dispose();
528 508
            }
529 509
        }
530 510
    }
531 511

  
532 512
    private void loadCurrentPageDataNoSelection(final Page page)
533
        throws BaseException {
513
            throws BaseException {
534 514

  
535 515
        long firstPosition = getCalculator().getInitialIndex();
536 516

  
537 517
        if (LOG.isDebugEnabled()) {
538
            LOG.debug("Loading {} Features starting at position {}", 
539
                getCalculator().getCurrentPageSize(), firstPosition
518
            LOG.debug("Loading {} Features starting at position {}",
519
                    getCalculator().getCurrentPageSize(), firstPosition
540 520
            );
541 521
        }
542 522

  
543 523
        FeatureSet featureSet = getFeatureSet(false);
544 524
        try {
545
        	loadDataFromFeatureSet(page, 0, featureSet, firstPosition,
546
        			getCalculator().getCurrentPageSize(), null);
547
        } catch(DataException ex) {
525
            loadDataFromFeatureSet(page, 0, featureSet, firstPosition,
526
                    getCalculator().getCurrentPageSize(), null);
527
        } catch (DataException ex) {
548 528
            throw ex;
549
            // } finally {
550
        	// featureSet.dispose();
529
        } finally {
530
            // This is the feature set we dont want to lose it
531
            // featureSet.dispose();
551 532
        }
552

  
553 533
    }
554 534

  
555 535
    private void loadDataFromFeatureSet(final Page page,
556
        final int valuesPosition, FeatureSet set, long initialIndex,
557
        final long howMany, final FeatureSelection selectedFeaturesToSkip)
558
        throws DataException {
536
            final int valuesPosition, FeatureSet set, long initialIndex,
537
            final long howMany, final FeatureSelection selectedFeaturesToSkip)
538
            throws DataException {
559 539

  
560 540
        try {
561 541
            final MutableBoolean errorReported = new MutableBoolean(false);
......
564 544

  
565 545
                @Override
566 546
                public void visit(Object obj) throws VisitCanceledException,
567
                    BaseException {
547
                        BaseException {
568 548
                    if (i >= valuesPosition + howMany) {
569 549
                        throw new VisitCanceledException();
570 550
                    }
......
572 552
                    // Add the current Feature only if we don't skip selected
573 553
                    // features or the feature is not selected
574 554
                    if (selectedFeaturesToSkip == null
575
                        || !selectedFeaturesToSkip.isSelected(current)) {
555
                            || !selectedFeaturesToSkip.isSelected(current)) {
576 556
                        try {
577
                            page.setFeature(i,current.getCopy());
557
                            page.setFeature(i, current.getCopy());
578 558
                            i++;
579
                        } catch(Exception ex) {
559
                        } catch (Exception ex) {
580 560
                            // Aqui no deberia petar, pero...
581 561
                            // me he encontrado un caso que tenia una referencia a
582 562
                            // una feature seleccionada que ya no existia. No se como
......
584 564
                            // proyecto pero la feature ya no existia, y eso hacia que
585 565
                            // petase al intentar leer de disco la feature a partir
586 566
                            // de una referencia no valida.
587
                            if( !errorReported.booleanValue() ) {
588
                              // Solo sacamos un error por pagina de datos.
589
                              LOG.warn("Problemas recuperando feature.",ex);
590
                              errorReported.setTrue();
567
                            if (!errorReported.booleanValue()) {
568
                                // Solo sacamos un error por pagina de datos.
569
                                LOG.warn("Problemas recuperando feature.", ex);
570
                                errorReported.setTrue();
591 571
                            }
592 572
                        }
593 573
                    }
594 574
                }
595 575
            }, initialIndex, howMany);
596
        } catch(VisitCanceledException ex) {
576
        } catch (VisitCanceledException ex) {
597 577
            // Do nothing
598 578
        } catch (BaseException e) {
599 579
            if (e instanceof DataException) {
600 580
                throw ((DataException) e);
601 581
            } else {
602
                LOG.warn("Error loading the data starting at position {}",
603
                    new Long(initialIndex), e);
582
                LOG.warn("Error loading the data starting at position {}", initialIndex, e);
604 583
            }
605 584
        }
606 585
    }
607 586

  
587
    @Override
608 588
    public void delete(Feature feature) throws BaseException {
609 589
        featureStore.delete(feature);
610 590
        /*
......
615 595
        reloadCurrentPage();
616 596
    }
617 597

  
598
    @Override
618 599
    public void insert(EditableFeature feature) throws BaseException {
619
    	featureStore.insert(feature);
600
        featureStore.insert(feature);
620 601
        /*
621 602
         * Force re-creation of feature set
622 603
         */
......
624 605

  
625 606
        reloadCurrentPage();
626 607
    }
627
    
608

  
609
    @Override
628 610
    public boolean isEmpty() {
629 611
        try {
630 612
            return getFeatureSet(false).isEmpty();
......
639 621
            try {
640 622
                return getFeatureSet(false).isEmpty();
641 623
            } catch (DataException e) {
642
                LOG.warn("Error asking about the emptiness of the list after reloading data.",e);
624
                LOG.warn("Error asking about the emptiness of the list after reloading data.", e);
643 625
                throw new RuntimeException(e);
644 626
            }
645 627
        } catch (DataException ex) {
646
            throw  new RuntimeException(ex);
628
            throw new RuntimeException(ex);
647 629
        }
648 630
    }
649 631

  
632
    @Override
650 633
    public void update(EditableFeature feature) throws BaseException {
651
    	featureStore.update(feature);
634
        featureStore.update(feature);
652 635
        /*
653 636
         * Force re-creation of feature set
654 637
         */
......
657 640
        reloadCurrentPage();
658 641
    }
659 642

  
643
    @Override
660 644
    public FeatureType getFeatureType() {
661 645

  
662 646
        FeatureType ft = null;
......
664 648
        try {
665 649
            ft = featureStore.getDefaultFeatureType();
666 650
        } catch (DataException e) {
667
            LOG.error("Error while getting feature type: " +
668
                e.getMessage(), e);
651
            LOG.warn("Error while getting feature type: "+ e.getMessage(), e);
669 652
        }
670 653
        return ft;
671

  
672
        /*
673
         *
674
        FeatureSet featureSet = getFeatureSet();
675
        try {
676
            return featureSet.getDefaultFeatureType();
677
        } finally {
678
            featureSet.dispose();
679
        }
680
        */
681

  
682

  
683 654
    }
684 655

  
656
    @Override
685 657
    protected void doDispose() throws BaseException {
686
        initialSelection.dispose();
687 658
        if (featSet != null) {
688 659
            try {
689 660
                featSet.dispose();
......
693 664
        }
694 665
    }
695 666

  
667
    @Override
696 668
    public DynObject[] getCurrentPageDynObjects() {
697
        Feature[] features = getCurrentPageFeatures();
698
        DynObject[] dynobjects = new DynObject[features.length];
669
        Feature[] theFeatures = getCurrentPageFeatures();
670
        DynObject[] dynobjects = new DynObject[theFeatures.length];
699 671
        for (int i = 0; i < dynobjects.length; i++) {
700
            dynobjects[i] = new DynObjectFeatureFacade(features[i]);
672
            dynobjects[i] = new DynObjectFeatureFacade(theFeatures[i]);
701 673
        }
702 674
        return dynobjects;
703 675
    }
......
718 690
    }
719 691

  
720 692
    private class FeaturePagingHelperList extends PagingHelperList {
693

  
721 694
        @Override
722 695
        public Object get(int i) {
723 696
            return this.get64(i);
......
728 701
            try {
729 702
                return getFeatureAt(i);
730 703
            } catch (ConcurrentDataModificationException ex) {
731
                LOG.warn("ConcurrentDataModification error getting feature "+i+" of the list. Retrying reloading data.");
704
                LOG.warn("ConcurrentDataModification error getting feature " + i + " of the list. Retrying reloading data.");
732 705
                try {
733 706
                    reload();
734 707
                } catch (BaseException e) {
......
738 711
                try {
739 712
                    return getFeatureAt(i);
740 713
                } catch (Exception e) {
741
                    LOG.warn("Error getting feature "+i+" of the list after reloading data.",e);
714
                    LOG.warn("Error getting feature " + i + " of the list after reloading data.", e);
742 715
                    throw new RuntimeException(e);
743 716
                }
744 717
            } catch (BaseException ex) {
745
                throw  new RuntimeException(ex);
718
                throw new RuntimeException(ex);
746 719
            }
747 720
        }
748 721

  
749 722
        @Override
750 723
        public Object set(int i, Object e) {
751
//            Feature newFeature = (Feature) e;
752
//            EditableFeature oldFeature = ((Feature) this.get(i)).getEditable();
753
//            oldFeature.copyFrom(newFeature);
754
//            update(oldFeature);
755 724
            return super.set(i, e);
756 725
        }
757 726

  
758 727
        @Override
759 728
        public Object remove(int i) {
760
//            Feature feature = (Feature) this.get(i);
761
//            delete(feature);
762 729
            return super.remove(i);
763 730
        }
764 731

  
765 732
        @Override
766 733
        public boolean add(Object e) {
767
//            EditableFeature feature = (EditableFeature) e;
768
//            insert(feature);
769 734
            return super.add(e);
770 735
        }
771 736
    }
772 737

  
773 738
    private class DynObjectPagingHelperList extends PagingHelperList {
739

  
774 740
        @Override
775 741
        public Object get(int i) {
776 742
            return this.get64(i);
......
781 747
            try {
782 748
                return getDynObjectAt(position);
783 749
            } catch (ConcurrentDataModificationException ex) {
784
                LOG.warn("ConcurrentDataModification error getting element "+position+" of the list. Retrying reloading data.");
750
                LOG.warn("ConcurrentDataModification error getting element " + position + " of the list. Retrying reloading data.");
785 751
                try {
786 752
                    reload();
787 753
                } catch (BaseException e) {
......
791 757
                try {
792 758
                    return getDynObjectAt(position);
793 759
                } catch (Exception e) {
794
                    LOG.warn("Error getting element "+position+" of the list after reloading data.",e);
760
                    LOG.warn("Error getting element " + position + " of the list after reloading data.", e);
795 761
                    throw new RuntimeException(e);
796 762
                }
797 763
            } catch (BaseException ex) {
798
                throw  new RuntimeException(ex);
764
                throw new RuntimeException(ex);
799 765
            }
800 766
        }
801 767

  
......
812 778
        public String toString() {
813 779
            return String.format("..(%d %ss)...", this.size(), featureStore.getName());
814 780
        }
815
        
781

  
816 782
        @Override
817 783
        public long size64() {
818 784
            try {
......
828 794
                try {
829 795
                    return getFeatureSet(false).getSize();
830 796
                } catch (DataException e) {
831
                    LOG.warn("Error asking the size of the list after reloading data.",e);
797
                    LOG.warn("Error asking the size of the list after reloading data.", e);
832 798
                    throw new RuntimeException(e);
833 799
                }
834 800
            } catch (DataException ex) {
835
                throw  new RuntimeException(ex);
801
                throw new RuntimeException(ex);
836 802
            }
837 803
        }
838 804

  
839 805
        @Override
840 806
        public int size() {
841 807
            long sz = this.size64();
842
            if( sz>Integer.MAX_VALUE ) {
808
            if (sz > Integer.MAX_VALUE) {
843 809
                sz = Integer.MAX_VALUE;
844 810
            }
845 811
            return (int) sz;
......
860 826
                try {
861 827
                    return getFeatureSet(false).isEmpty();
862 828
                } catch (DataException e) {
863
                    LOG.warn("Error asking about the emptiness of the list after reloading data.",e);
829
                    LOG.warn("Error asking about the emptiness of the list after reloading data.", e);
864 830
                    throw new RuntimeException(e);
865 831
                }
866 832
            } catch (DataException ex) {
867
                throw  new RuntimeException(ex);
833
                throw new RuntimeException(ex);
868 834
            }
869 835
        }
870 836

  
......
883 849
                try {
884 850
                    return getFeatureSet(false).fastIterator();
885 851
                } catch (DataException e) {
886
                    LOG.warn("Error getting iterator of the list after reloading data.",e);
852
                    LOG.warn("Error getting iterator of the list after reloading data.", e);
887 853
                    throw new RuntimeException(e);
888 854
                }
889 855
            } catch (DataException ex) {
890
                throw  new RuntimeException(ex);
856
                throw new RuntimeException(ex);
891 857
            }
892 858
        }
893 859

  

Also available in: Unified diff