Revision 27234 branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/paging/FeaturePagingHelperImpl.java
FeaturePagingHelperImpl.java | ||
---|---|---|
29 | 29 |
import java.util.Iterator; |
30 | 30 |
|
31 | 31 |
import org.gvsig.fmap.dal.exception.DataException; |
32 |
import org.gvsig.fmap.dal.feature.*; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
33 |
import org.gvsig.fmap.dal.feature.Feature; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
33 | 38 |
import org.slf4j.Logger; |
34 | 39 |
import org.slf4j.LoggerFactory; |
35 | 40 |
|
... | ... | |
37 | 42 |
* Helper class to access the values of a FeatureCollection by position. Handles |
38 | 43 |
* pagination automatically to avoid filling the memory in case of big |
39 | 44 |
* collections. |
40 |
*
|
|
45 |
* |
|
41 | 46 |
* TODO: evaluate if its more convenient to read values in the background when |
42 | 47 |
* the returned value is near the end of the page, instead of loading a page on |
43 | 48 |
* demand. |
44 |
*
|
|
49 |
* |
|
45 | 50 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
46 | 51 |
*/ |
47 | 52 |
public class FeaturePagingHelperImpl implements FeaturePagingHelper { |
... | ... | |
65 | 70 |
|
66 | 71 |
/** |
67 | 72 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore. |
68 |
*
|
|
73 |
* |
|
69 | 74 |
* @param featureStore |
70 | 75 |
* to extract data from |
71 | 76 |
* @throws DataException |
... | ... | |
78 | 83 |
|
79 | 84 |
/** |
80 | 85 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore. |
81 |
*
|
|
86 |
* |
|
82 | 87 |
* @param featureSet |
83 | 88 |
* to extract data from |
84 | 89 |
* @param pageSize |
... | ... | |
94 | 99 |
|
95 | 100 |
/** |
96 | 101 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore. |
97 |
*
|
|
102 |
* |
|
98 | 103 |
* @param featureSet |
99 | 104 |
* to extract data from |
100 | 105 |
* @throws DataException |
... | ... | |
107 | 112 |
|
108 | 113 |
/** |
109 | 114 |
* Constructs a FeaturePagingHelperImpl from data of a FeatureStore. |
110 |
*
|
|
115 |
* |
|
111 | 116 |
* @param featureSet |
112 | 117 |
* to extract data from |
113 | 118 |
* @param pageSize |
... | ... | |
189 | 194 |
} |
190 | 195 |
|
191 | 196 |
long positionForIndex = index |
192 |
- (getCurrentPage() * (long) getMaxPageSize());
|
|
197 |
- (getCurrentPage() * getMaxPageSize()); |
|
193 | 198 |
|
194 | 199 |
return values[(int) positionForIndex]; |
195 | 200 |
} |
... | ... | |
238 | 243 |
if (currentPage < (numPages - 1)) { |
239 | 244 |
currentPageSize = getMaxPageSize(); |
240 | 245 |
} else { |
241 |
currentPageSize = (int) (getTotalSize() - (currentPage * (long) getMaxPageSize()));
|
|
246 |
currentPageSize = (int) (getTotalSize() - (currentPage * getMaxPageSize())); |
|
242 | 247 |
} |
243 | 248 |
|
244 | 249 |
values = new Feature[currentPageSize]; |
... | ... | |
264 | 269 |
} |
265 | 270 |
featureSet = getFeatureStore().getFeatureSet(query); |
266 | 271 |
} |
272 |
|
|
273 |
public void delete(Feature feature) throws DataException { |
|
274 |
if(featureSet == null){ |
|
275 |
// FIXME change to RuntimeDalException |
|
276 |
throw new IllegalStateException(); |
|
277 |
} |
|
278 |
featureSet.delete(feature); |
|
279 |
reloadCurrentPage(); |
|
280 |
} |
|
281 |
|
|
282 |
public void insert(EditableFeature feature) throws DataException { |
|
283 |
if (featureSet == null) { |
|
284 |
// FIXME change to RuntimeDalException |
|
285 |
throw new IllegalStateException(); |
|
286 |
} |
|
287 |
featureSet.insert(feature); |
|
288 |
reloadCurrentPage(); |
|
289 |
} |
|
290 |
|
|
291 |
public void update(EditableFeature feature) throws DataException { |
|
292 |
if (featureSet == null) { |
|
293 |
// FIXME change to RuntimeDalException |
|
294 |
throw new IllegalStateException(); |
|
295 |
} |
|
296 |
featureSet.update(feature); |
|
297 |
reloadCurrentPage(); |
|
298 |
} |
|
299 |
|
|
300 |
public FeatureType getFeatureType() { |
|
301 |
return featureSet.getDefaultFeatureType(); |
|
302 |
} |
|
267 | 303 |
} |
Also available in: Unified diff