Revision 23934

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/paging/FeaturePagingHelper.java
62 62
     *
63 63
     * @return the number of pages available
64 64
     */
65
    int getNumPages();
65
    long getNumPages();
66 66

  
67 67
    /**
68 68
     * Returns the number of the currently loaded page of Features (zero based).
69 69
     *
70 70
     * @return the current page number
71 71
     */
72
    int getCurrentPage();
72
    long getCurrentPage();
73 73

  
74 74
    /**
75 75
     * Sets the current page number, and loads the Features for that page.
......
79 79
     * @throws DataException
80 80
     *             if there is an error setting the current page
81 81
     */
82
    void setCurrentPage(int page) throws DataException;
82
    void setCurrentPage(long page) throws DataException;
83 83

  
84 84
    /**
85 85
     * Returns the number of elements of the entire Collection.
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/paging/FeaturePagingHelperImpl.java
30 30

  
31 31
import org.apache.log4j.Logger;
32 32
import org.gvsig.fmap.data.exceptions.DataException;
33
import org.gvsig.fmap.data.exceptions.ReadException;
34 33
import org.gvsig.fmap.data.feature.*;
35 34

  
36 35
/**
......
50 49

  
51 50
    private FeatureQuery query;
52 51

  
53
    private FeatureSet featureCollection;
52
    private FeatureSet featureSet;
54 53

  
55 54
    private FeatureStore featureStore;
56 55

  
57 56
    private int maxPageSize;
58 57

  
59
    private int numPages;
58
    private long numPages;
60 59

  
61
    private int currentPage = -1;
60
    private long currentPage = -1;
62 61

  
63 62
    private Feature[] values;
64 63

  
65 64
    /**
66
     * Constructs a FeatureCollectionPagingHelper from a FeatureCollection.
65
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
67 66
     * 
68
     * @param featureCollection
67
     * @param featureStore
69 68
     *            to extract data from
70
     * @throws ReadException
69
     * @throws DataException
70
     *             if there is an error initializing the helper
71 71
     */
72 72
    public FeaturePagingHelperImpl(FeatureStore featureStore)
73 73
            throws DataException {
......
75 75
    }
76 76

  
77 77
    /**
78
     * Constructs a FeatureCollectionPagingHelper from a FeatureCollection.
78
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
79 79
     * 
80
     * @param featureCollection
80
     * @param featureSet
81 81
     *            to extract data from
82 82
     * @param pageSize
83 83
     *            the number of elements per page data
84
     * @throws ReadException
84
     * @throws DataException
85
     *             if there is an error initializing the helper
85 86
     */
86 87
    public FeaturePagingHelperImpl(FeatureStore featureStore, int pageSize)
87 88
            throws DataException {
......
90 91
    }
91 92

  
92 93
    /**
93
     * Constructs a FeatureCollectionPagingHelper from a FeatureCollection.
94
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
94 95
     * 
95
     * @param featureCollection
96
     * @param featureSet
96 97
     *            to extract data from
97
     * @throws ReadException
98
     * @throws DataException
99
     *             if there is an error initializing the helper
98 100
     */
99 101
    public FeaturePagingHelperImpl(FeatureStore featureStore,
100 102
            FeatureQuery featureQuery) throws DataException {
......
102 104
    }
103 105

  
104 106
    /**
105
     * Constructs a FeatureCollectionPagingHelper from a FeatureCollection.
107
     * Constructs a FeaturePagingHelperImpl from data of a FeatureStore.
106 108
     * 
107
     * @param featureCollection
109
     * @param featureSet
108 110
     *            to extract data from
109 111
     * @param pageSize
110 112
     *            the number of elements per page data
111
     * @throws ReadException
113
     * @throws DataException
114
     *             if there is an error initializing the helper
112 115
     */
113 116
    public FeaturePagingHelperImpl(FeatureStore featureStore,
114 117
            FeatureQuery featureQuery, int pageSize) throws DataException {
......
128 131
        reloadCurrentPage();
129 132
    }
130 133

  
131
    public int getNumPages() {
134
    public long getNumPages() {
132 135
        return numPages;
133 136
    }
134 137

  
135 138
    /**
136 139
     * Sets the number of pages.
137 140
     */
138
    private void setNumPages(int numPages) {
141
    private void setNumPages(long numPages) {
139 142
        this.numPages = numPages;
140 143
    }
141 144

  
142
    public int getCurrentPage() {
145
    public long getCurrentPage() {
143 146
        return currentPage;
144 147
    }
145 148

  
146
    public void setCurrentPage(int page) throws DataException {
149
    public void setCurrentPage(long page) throws DataException {
147 150

  
148 151
        if (logger.isDebugEnabled()) {
149 152
            logger.debug("Current page: " + page);
......
171 174
    public Feature getFeatureAt(long index) throws DataException {
172 175
        // Check if we have currently loaded the viewed page data,
173 176
        // or we need to load a new one
174
        int pageForIndex = (int) Math.floor(index / getMaxPageSize());
177
        long pageForIndex = (long) Math.floor(index / getMaxPageSize());
175 178

  
176 179
        if (pageForIndex != getCurrentPage()) {
177 180
            setCurrentPage(pageForIndex);
178 181
        }
179 182

  
180 183
        long positionForIndex = index
181
                - (long) (getCurrentPage() * getMaxPageSize());
184
                - (getCurrentPage() * (long) getMaxPageSize());
182 185

  
183 186
        return values[(int) positionForIndex];
184 187
    }
......
188 191
    }
189 192

  
190 193
    public FeatureSet getFeatureCollection() {
191
        return featureCollection;
194
        return featureSet;
192 195
    }
193 196

  
194 197
    public void reloadCurrentPage() throws DataException {
......
214 217
    /**
215 218
     * Calculates the number of pages.
216 219
     */
217
    private int calculateNumPages() throws DataException {
218
        return ((int) Math.floor(getTotalSize() / getMaxPageSize())) + 1;
220
    private long calculateNumPages() throws DataException {
221
        return ((long) Math.floor(getTotalSize() / getMaxPageSize())) + 1;
219 222
    }
220 223

  
221 224
    /**
222 225
     * Loads all the Features of the current page.
223 226
     */
224 227
    private void loadCurrentPageData() throws DataException {
225
        int currentPage = getCurrentPage();
228
        long currentPage = getCurrentPage();
226 229
        int currentPageSize;
227 230
        if (currentPage < (numPages - 1)) {
228 231
            currentPageSize = getMaxPageSize();
229 232
        } else {
230
            currentPageSize = (int) (getTotalSize() - (long) (currentPage * getMaxPageSize()));
233
            currentPageSize = (int) (getTotalSize() - (currentPage * (long) getMaxPageSize()));
231 234
        }
232 235

  
233 236
        values = new Feature[currentPageSize];
......
243 246
    }
244 247

  
245 248
    private void loadFeatureCollection() throws DataException {
246
        if (featureCollection != null) {
247
            featureCollection.dispose();
249
        if (featureSet != null) {
250
            featureSet.dispose();
248 251
        }
249
        featureCollection = getFeatureStore().getFeatureSet(query);
252
        featureSet = getFeatureStore().getFeatureSet(query);
250 253
    }
251 254
}

Also available in: Unified diff