Revision 41819 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
38 38
import org.gvsig.fmap.dal.feature.FeatureSet;
39 39
import org.gvsig.fmap.dal.feature.FeatureStore;
40 40
import org.gvsig.fmap.dal.feature.FeatureType;
41
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
41 42
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
42 43
import org.gvsig.fmap.dal.feature.impl.featureset.DynObjectFeatureFacade;
43 44
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
......
52 53
 * Helper class to access the values of a FeatureCollection by position. Handles
53 54
 * pagination automatically to avoid filling the memory in case of big
54 55
 * collections.
55
 * 
56
 *
56 57
 * TODO: evaluate if its more convenient to read values in the background when
57 58
 * the returned value is near the end of the page, instead of loading a page on
58 59
 * demand.
59
 * 
60
 *
60 61
 * @author gvSIG Team
61 62
 */
62 63
public class FeaturePagingHelperImpl extends DefaultDynObjectPagingHelper
......
80 81
    private boolean initialization_completed = false;
81 82
    /**
82 83
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
83
     * 
84
     *
84 85
     * @param featureStore
85 86
     *            to extract data from
86 87
     * @throws DataException
......
93 94

  
94 95
    /**
95 96
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
96
     * 
97
     *
97 98
     * @param featureStore
98 99
     *            to extract data from
99 100
     * @param pageSize
......
108 109

  
109 110
    /**
110 111
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
111
     * 
112
     *
112 113
     * @param featureStore
113 114
     *            to extract data from
114 115
     * @throws DataException
......
121 122

  
122 123
    /**
123 124
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
124
     * 
125
     *
125 126
     * @param featureSet
126 127
     *            to extract data from
127 128
     * @param pageSize
......
154 155
                }
155 156
            }
156 157
        }, pageSize);
157
        
158
        
158

  
159

  
159 160
        if (LOG.isDebugEnabled()) {
160
        	
161

  
161 162
            LOG.debug("FeaturePagingHelperImpl created with {} pages, "
162 163
                + "and a page size of {}", new Long(getCalculator()
163 164
                .getNumPages()), new Integer(pageSize));
......
218 219
            Feature feature = getCurrentPageFeatures()[(int) positionForIndex];
219 220
            return feature;
220 221
        }
221
        
222

  
222 223
    }
223 224

  
224 225
    public Feature[] getCurrentPageFeatures() {
......
244 245
     * has been added/removed)
245 246
     */
246 247
    private FeatureSet getFeatureSet(boolean reset) {
247
        
248

  
248 249
        if (featSet == null || reset) {
249
            
250

  
250 251
            if (featSet != null) {
251 252
                try {
252 253
                    featSet.dispose();
......
254 255
                    LOG.info("Error while disposing featset.", ex);
255 256
                }
256 257
            }
257
            
258

  
258 259
            try {
259
                FeatureStore featureStore = getFeatureStore();          
260
                FeatureStore featureStore = getFeatureStore();
260 261
                synchronized (featureStore) {
261
                    featSet = featureStore.getFeatureSet(getFeatureQuery());               
262
                    featSet = featureStore.getFeatureSet(getFeatureQuery());
262 263
                }
263 264
            } catch (DataException e) {
264 265
                throw new RuntimeException("Error getting a feature set with the query " + getFeatureQuery());
......
266 267
        }
267 268
        return featSet;
268 269
    }
269
    
270

  
270 271
    public DynObjectSet getDynObjectSet() {
271 272
    	return getFeatureSet(false).getDynObjectSet();
272 273
    }
273 274

  
274 275
    public void reloadCurrentPage() throws BaseException {
275
        
276

  
276 277
        boolean sel_up = this.isSelectionUp();
277 278

  
278 279
        setSelectionUp(false);
279 280
        if (getCalculator().getCurrentPage() > -1) {
280 281
            loadCurrentPageData();
281 282
        }
282
        
283

  
283 284
        if (sel_up) {
284 285
            setSelectionUp(true);
285 286
        }
286 287
    }
287 288

  
288 289
    public void reload() throws BaseException {
289
        
290

  
290 291
        /*
291 292
         * Force re-creation of feature set
292 293
         */
293 294
        this.getFeatureSet(true);
294 295

  
295
        
296

  
296 297
        setDefaultCalculator(new Sizeable() {
297 298
            public long getSize() {
298 299
            	FeatureSet featureSet = getFeatureSet(false);
......
345 346

  
346 347
        this.features = values;
347 348
    }
348
    
349

  
349 350
    private void loadCurrentPageDataWithSelectionUp(final Feature[] values)
350 351
            throws BaseException {
351 352
        FeatureSelection selection = initialSelection;
......
415 416
            // } finally {
416 417
        	// featureSet.dispose();
417 418
        }
418
        
419

  
419 420
    }
420 421

  
421 422
    private void loadDataFromFeatureSet(final Feature[] values,
......
444 445
                        } catch(Exception ex) {
445 446
                            // Aqui no deberia petar, pero...
446 447
                            // me he encontrado un caso que tenia una referencia a
447
                            // una feature seleccionada que ya no existia. No se como 
448
                            // una feature seleccionada que ya no existia. No se como
448 449
                            // habia pasado, se habia quedado de antes guardada en el
449 450
                            // proyecto pero la feature ya no existia, y eso hacia que
450 451
                            // petase al intentar leer de disco la feature a partir
......
494 495
    }
495 496

  
496 497
    public FeatureType getFeatureType() {
497
        
498

  
498 499
        FeatureType ft = null;
499
        
500

  
500 501
        try {
501 502
            ft = featureStore.getDefaultFeatureType();
502 503
        } catch (DataException e) {
......
504 505
                e.getMessage(), e);
505 506
        }
506 507
        return ft;
507
        
508

  
508 509
        /*
509
         * 
510
         *
510 511
        FeatureSet featureSet = getFeatureSet();
511 512
        try {
512 513
            return featureSet.getDefaultFeatureType();
......
515 516
        }
516 517
        */
517 518

  
518
        
519

  
519 520
    }
520 521

  
521 522
    protected void doDispose() throws BaseException {
......
545 546
    public List asList() {
546 547
        return new FeaturePagingHelperList();
547 548
    }
548
    
549

  
549 550
    public List asListOfDynObjects() {
550 551
        return new DynObjectPagingHelperList();
551
    }    
552
    
552
    }
553

  
553 554
    private class FeaturePagingHelperList extends PagingHelperList {
554 555
        public Object get(int i) {
555 556
            try {
......
559 560
            }
560 561
        }
561 562
    }
562
    
563

  
563 564
    private class DynObjectPagingHelperList extends PagingHelperList {
564 565
        public Object get(int i) {
565 566
            try {
......
569 570
            }
570 571
        }
571 572
    }
572
    
573

  
573 574
    private abstract class PagingHelperList implements List {
574 575

  
575 576
        public int size() {
......
585 586
                return getFeatureSet(false).isEmpty();
586 587
            } catch (DataException ex) {
587 588
                throw  new RuntimeException(ex);
589
            } catch (ConcurrentDataModificationException ex) {
590
                LOG.warn(
591
                    "Error to asking about the emptiness of the store. Retrying reloading data.",
592
                    ex);
593
                try {
594
                    reload();
595
                } catch (BaseException e) {
596
                    LOG.warn("Error reloading data.", e);
597
                    throw new RuntimeException(e);
598
                }
599
                try {
600
                    return getFeatureSet(false).isEmpty();
601
                } catch (DataException e) {
602
                    LOG.warn(
603
                        "Error to asking about the emptiness of the store after reloading data.",
604
                        e);
605
                    throw new RuntimeException(e);
606
                }
588 607
            }
589 608
        }
590 609

  
......
671 690
        public List subList(int i, int i1) {
672 691
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
673 692
        }
674
        
693

  
675 694
    }
676 695
}

Also available in: Unified diff