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 / impl / DefaultFeatureQuery.java @ 44393
History | View | Annotate | Download (19 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal.feature.impl; |
||
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.HashMap; |
||
28 | import java.util.List; |
||
29 | import java.util.Map; |
||
30 | 43358 | jjdelcerro | import org.apache.commons.lang3.ArrayUtils; |
31 | 43913 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
32 | 44023 | jjdelcerro | import org.gvsig.expressionevaluator.Expression; |
33 | 42971 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
34 | 43358 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
37 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureQuery; |
38 | import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
||
39 | 43358 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
40 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
41 | 44023 | jjdelcerro | import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultExpressionEvaluator; |
42 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
43 | import org.gvsig.tools.dynobject.DynStruct; |
||
44 | import org.gvsig.tools.evaluator.AndEvaluator; |
||
45 | import org.gvsig.tools.evaluator.Evaluator; |
||
46 | import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
||
47 | import org.gvsig.tools.persistence.PersistentState; |
||
48 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
49 | |||
50 | /**
|
||
51 | * Defines the properties of a collection of Features, as a result of a query
|
||
52 | * through a FeatureStore.
|
||
53 | * <p>
|
||
54 | * A FeatureQuery is always defined by a FeatureType, or by the list of
|
||
55 | * attribute names of the FeatureStore to return.
|
||
56 | * </p>
|
||
57 | * <p>
|
||
58 | * The filter allows to select Features whose properties have values with the
|
||
59 | * characteristics defined by the filter.
|
||
60 | * </p>
|
||
61 | * <p>
|
||
62 | * The order is used to set the order of the result FeatureCollection, based on
|
||
63 | * the values of the properties of the Features.
|
||
64 | * </p>
|
||
65 | * <p>
|
||
66 | * The scale parameter can be used by the FeatureStore as a hint about the
|
||
67 | * quality or resolution of the data needed to view or operate with the data
|
||
68 | * returned. As an example, the FeatureStore may use the scale to return only a
|
||
69 | * representative subset of the data, or maybe to return Features with less
|
||
70 | * detail, like a point or a line instead of a polygon.
|
||
71 | * </p>
|
||
72 | * <p>
|
||
73 | * If an implementation of FeatureStore is able to get other parameters to
|
||
74 | * customize the behavior of the getDataCollection methods, there is an option
|
||
75 | * to set more parameters through the setAttribute method.
|
||
76 | * </p>
|
||
77 | 42975 | jjdelcerro | *
|
78 | 40435 | jjdelcerro | * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
79 | */
|
||
80 | public class DefaultFeatureQuery implements FeatureQuery { |
||
81 | |||
82 | public static final String SCALE_PARAM_NAME = "Scale"; |
||
83 | |||
84 | private Map queryParameters = new HashMap(); |
||
85 | |||
86 | private String featureTypeId = null; |
||
87 | |||
88 | private List attributeNames = new ArrayList(); |
||
89 | |||
90 | 41212 | jjdelcerro | private List constantsAttributeNames = new ArrayList(); |
91 | |||
92 | 40435 | jjdelcerro | private Evaluator filter;
|
93 | |||
94 | /**
|
||
95 | * This boolean value is used to know if the current filter
|
||
96 | * has been added using the {@link FeatureQuery#addFilter(Evaluator)}
|
||
97 | * method or the {@link FeatureQuery#setFilter(Evaluator)} method.
|
||
98 | */
|
||
99 | 42798 | jjdelcerro | // private boolean isAddFilter = true;
|
100 | 40435 | jjdelcerro | |
101 | private FeatureQueryOrder order = new FeatureQueryOrder(); |
||
102 | |||
103 | private long limit; |
||
104 | |||
105 | private long pageSize; |
||
106 | |||
107 | 44374 | jjdelcerro | private boolean group = false; |
108 | 40435 | jjdelcerro | /**
|
109 | * Creates a FeatureQuery which will load all available Features of a type.
|
||
110 | 42975 | jjdelcerro | *
|
111 | 40435 | jjdelcerro | */
|
112 | public DefaultFeatureQuery() {
|
||
113 | super();
|
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * Creates a FeatureQuery which will load all available Features of a type.
|
||
118 | 42975 | jjdelcerro | *
|
119 | 40435 | jjdelcerro | * @param featureType
|
120 | * the type of Features of the query
|
||
121 | */
|
||
122 | public DefaultFeatureQuery(FeatureType featureType) {
|
||
123 | super();
|
||
124 | this.setFeatureType(featureType);
|
||
125 | } |
||
126 | |||
127 | /**
|
||
128 | * Creates a FeatureQuery with the type of features, a filter and the order
|
||
129 | * for the FeatureCollection.
|
||
130 | 42975 | jjdelcerro | *
|
131 | 40435 | jjdelcerro | * @param featureType
|
132 | * the type of Features of the query
|
||
133 | * @param filter
|
||
134 | * based on the properties of the Features
|
||
135 | */
|
||
136 | public DefaultFeatureQuery(FeatureType featureType, Evaluator filter) {
|
||
137 | super();
|
||
138 | this.setFeatureType(featureType);
|
||
139 | this.filter = filter;
|
||
140 | } |
||
141 | |||
142 | /**
|
||
143 | * Creates a FeatureQuery with the type of features, a filter, the order for
|
||
144 | * the FeatureCollection and the view scale.
|
||
145 | 42975 | jjdelcerro | *
|
146 | 40435 | jjdelcerro | * @param featureType
|
147 | * the type of Features of the query
|
||
148 | * @param filter
|
||
149 | * based on the properties of the Features
|
||
150 | * @param scale
|
||
151 | * to view the Features.
|
||
152 | */
|
||
153 | public DefaultFeatureQuery(FeatureType featureType, Evaluator filter,
|
||
154 | double scale) {
|
||
155 | this.setFeatureType(featureType);
|
||
156 | this.filter = filter;
|
||
157 | this.setScale(scale);
|
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * Creates a FeatureQuery which will load a list of attribute names of all
|
||
162 | * available Features.
|
||
163 | 42975 | jjdelcerro | *
|
164 | 40435 | jjdelcerro | * @param attributeNames
|
165 | * the list of attribute names to load
|
||
166 | */
|
||
167 | public DefaultFeatureQuery(String[] attributeNames) { |
||
168 | super();
|
||
169 | setAttributeNames(attributeNames); |
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * Creates a FeatureQuery with the list of attribute names of feature, a
|
||
174 | * filter and the order for the FeatureCollection.
|
||
175 | 42975 | jjdelcerro | *
|
176 | 40435 | jjdelcerro | * @param attributeNames
|
177 | * the list of attribute names to load
|
||
178 | * @param filter
|
||
179 | * based on the properties of the Features
|
||
180 | */
|
||
181 | public DefaultFeatureQuery(String[] attributeNames, Evaluator filter) { |
||
182 | super();
|
||
183 | setAttributeNames(attributeNames); |
||
184 | this.filter = filter;
|
||
185 | } |
||
186 | |||
187 | /**
|
||
188 | * Creates a FeatureQuery with the list of attribute names of feature, a
|
||
189 | * filter, the order for the FeatureCollection and the view scale.
|
||
190 | 42975 | jjdelcerro | *
|
191 | 40435 | jjdelcerro | * @param attributeNames
|
192 | * the list of attribute names to load
|
||
193 | * @param filter
|
||
194 | * based on the properties of the Features
|
||
195 | * @param scale
|
||
196 | * to view the Features.
|
||
197 | */
|
||
198 | public DefaultFeatureQuery(String[] attributeNames, Evaluator filter, |
||
199 | double scale) {
|
||
200 | setAttributeNames(attributeNames); |
||
201 | this.filter = filter;
|
||
202 | this.setScale(scale);
|
||
203 | } |
||
204 | |||
205 | 43358 | jjdelcerro | @Override
|
206 | 40435 | jjdelcerro | public double getScale() { |
207 | Double scale = (Double) this.getQueryParameter(SCALE_PARAM_NAME); |
||
208 | if (scale == null) { |
||
209 | return 0; |
||
210 | } |
||
211 | 43358 | jjdelcerro | return scale;
|
212 | 40435 | jjdelcerro | } |
213 | |||
214 | 43358 | jjdelcerro | @Override
|
215 | 40435 | jjdelcerro | public void setScale(double scale) { |
216 | 43358 | jjdelcerro | this.setQueryParameter(SCALE_PARAM_NAME, scale);
|
217 | 40435 | jjdelcerro | } |
218 | |||
219 | 43358 | jjdelcerro | @Override
|
220 | 40435 | jjdelcerro | public Object getQueryParameter(String name) { |
221 | return queryParameters.get(name);
|
||
222 | } |
||
223 | |||
224 | 43358 | jjdelcerro | @Override
|
225 | 40435 | jjdelcerro | public void setQueryParameter(String name, Object value) { |
226 | queryParameters.put(name, value); |
||
227 | } |
||
228 | |||
229 | 43358 | jjdelcerro | @Override
|
230 | 40435 | jjdelcerro | public void setFeatureType(FeatureType featureType) { |
231 | this.featureTypeId = featureType.getId();
|
||
232 | } |
||
233 | |||
234 | 43358 | jjdelcerro | @Override
|
235 | 40435 | jjdelcerro | public String[] getAttributeNames() { |
236 | return (String[])attributeNames.toArray(new String[attributeNames.size()]); |
||
237 | } |
||
238 | |||
239 | 43358 | jjdelcerro | @Override
|
240 | 40435 | jjdelcerro | public void setAttributeNames(String[] attributeNames) { |
241 | this.attributeNames.clear();
|
||
242 | if (attributeNames != null){ |
||
243 | for (int i=0 ; i<attributeNames.length ; i++){ |
||
244 | this.attributeNames.add(attributeNames[i]);
|
||
245 | 42975 | jjdelcerro | } |
246 | 40435 | jjdelcerro | } |
247 | } |
||
248 | 42975 | jjdelcerro | |
249 | 43358 | jjdelcerro | @Override
|
250 | 43558 | jjdelcerro | public void retrievesAllAttributes() { |
251 | this.attributeNames.clear();
|
||
252 | } |
||
253 | |||
254 | @Override
|
||
255 | 40435 | jjdelcerro | public void addAttributeName(String attributeName){ |
256 | //If the attribute exists finish the method
|
||
257 | for (int i=0 ; i<attributeNames.size() ; i++){ |
||
258 | if (attributeNames.get(i).equals(attributeName)){
|
||
259 | return;
|
||
260 | 42975 | jjdelcerro | } |
261 | } |
||
262 | 40435 | jjdelcerro | this.attributeNames.add(attributeName);
|
263 | } |
||
264 | |||
265 | 43358 | jjdelcerro | @Override
|
266 | public void addEssentialAttributeNames(FeatureStore store) { |
||
267 | FeatureType storeType; |
||
268 | try {
|
||
269 | storeType = store.getDefaultFeatureType(); |
||
270 | } catch (DataException ex) {
|
||
271 | throw new RuntimeException("Can't access to the default feature type of tghe store", ex); |
||
272 | } |
||
273 | FeatureAttributeDescriptor[] pks = storeType.getPrimaryKey();
|
||
274 | if( storeType.hasOID() || ArrayUtils.isEmpty(pks) ) {
|
||
275 | FeatureAttributeDescriptor attrInt = null;
|
||
276 | FeatureAttributeDescriptor attrStr = null;
|
||
277 | FeatureAttributeDescriptor attrNotGeom = null;
|
||
278 | for (FeatureAttributeDescriptor attr : storeType) {
|
||
279 | if( attrInt == null && (attr.getType()==DataTypes.INT || attr.getType()==DataTypes.LONG) ) { |
||
280 | attrInt = attr; |
||
281 | } else if( attrStr == null && attr.getType()==DataTypes.STRING ) { |
||
282 | attrStr = attr; |
||
283 | } else if( attrNotGeom == null && attr.getType()!=DataTypes.GEOMETRY ) { |
||
284 | attrNotGeom = attr; |
||
285 | } |
||
286 | } |
||
287 | if( attrInt != null ) { |
||
288 | this.addAttributeName(attrInt.getName());
|
||
289 | } else if( attrStr != null ) { |
||
290 | this.addAttributeName(attrStr.getName());
|
||
291 | } else if( attrNotGeom != null ) { |
||
292 | this.addAttributeName(attrNotGeom.getName());
|
||
293 | } else {
|
||
294 | this.addAttributeName(storeType.getAttributeDescriptor(0).getName()); |
||
295 | } |
||
296 | } else {
|
||
297 | for(FeatureAttributeDescriptor attr : pks ) {
|
||
298 | this.addAttributeName(attr.getName());
|
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | |||
303 | @Override
|
||
304 | public void addPrimaryKeyAttributeNames(FeatureStore store) { |
||
305 | FeatureType storeType; |
||
306 | try {
|
||
307 | storeType = store.getDefaultFeatureType(); |
||
308 | } catch (DataException ex) {
|
||
309 | throw new RuntimeException("Can't access to the default feature type of tghe store", ex); |
||
310 | } |
||
311 | for(FeatureAttributeDescriptor attr : storeType.getPrimaryKey() ) {
|
||
312 | this.addAttributeName(attr.getName());
|
||
313 | } |
||
314 | } |
||
315 | |||
316 | @Override
|
||
317 | 41212 | jjdelcerro | public boolean hasAttributeNames() { |
318 | return !this.attributeNames.isEmpty(); |
||
319 | } |
||
320 | |||
321 | 43358 | jjdelcerro | @Override
|
322 | 41212 | jjdelcerro | public void clearAttributeNames() { |
323 | this.attributeNames = new ArrayList(); |
||
324 | } |
||
325 | |||
326 | 43358 | jjdelcerro | @Override
|
327 | 40435 | jjdelcerro | public Evaluator getFilter() {
|
328 | return filter;
|
||
329 | } |
||
330 | 42975 | jjdelcerro | |
331 | 42971 | jjdelcerro | @Override
|
332 | 44023 | jjdelcerro | public void setFilter(Expression filter) { |
333 | 44259 | jjdelcerro | if( filter == null ) { |
334 | this.clearFilter();
|
||
335 | return;
|
||
336 | } |
||
337 | 44023 | jjdelcerro | Evaluator x = new DefaultExpressionEvaluator(filter);
|
338 | this.setFilter(x);
|
||
339 | } |
||
340 | |||
341 | @Override
|
||
342 | 42971 | jjdelcerro | public void setFilter(String filter) { |
343 | 43913 | jjdelcerro | if( StringUtils.isEmpty(filter) ) {
|
344 | this.clearFilter();
|
||
345 | return;
|
||
346 | } |
||
347 | 42971 | jjdelcerro | try {
|
348 | this.setFilter(DALLocator.getDataManager().createExpresion(filter));
|
||
349 | } catch (Exception ex) { |
||
350 | throw new RuntimeException("Can't create filter from '"+filter+"'",ex); |
||
351 | } |
||
352 | } |
||
353 | 40435 | jjdelcerro | |
354 | 43358 | jjdelcerro | @Override
|
355 | 40435 | jjdelcerro | public void setFilter(Evaluator filter) { |
356 | 43913 | jjdelcerro | if( filter == null ) { |
357 | this.clearFilter();
|
||
358 | return;
|
||
359 | } |
||
360 | 40435 | jjdelcerro | this.filter = filter;
|
361 | addFilterAttributes(filter); |
||
362 | } |
||
363 | |||
364 | 42795 | jjdelcerro | @Override
|
365 | 42971 | jjdelcerro | public void addFilter(String filter) { |
366 | 43913 | jjdelcerro | if( StringUtils.isEmpty(filter) ) {
|
367 | return;
|
||
368 | } |
||
369 | 42971 | jjdelcerro | try {
|
370 | 44393 | jjdelcerro | this.addFilter(DALLocator.getDataManager().createFilter(filter));
|
371 | 42971 | jjdelcerro | } catch (Exception ex) { |
372 | throw new RuntimeException("Can't create filter from '"+filter+"'",ex); |
||
373 | } |
||
374 | } |
||
375 | 42975 | jjdelcerro | |
376 | 42971 | jjdelcerro | @Override
|
377 | 44023 | jjdelcerro | public void addFilter(Expression filter) { |
378 | Evaluator x = new DefaultExpressionEvaluator(filter);
|
||
379 | this.addFilter(x);
|
||
380 | } |
||
381 | |||
382 | @Override
|
||
383 | 40435 | jjdelcerro | public void addFilter(Evaluator evaluator) { |
384 | 43913 | jjdelcerro | if (evaluator == null) { |
385 | 42795 | jjdelcerro | return;
|
386 | } |
||
387 | 43913 | jjdelcerro | if (this.filter == null) { |
388 | this.filter = evaluator;
|
||
389 | } else {
|
||
390 | if (this.filter instanceof AndEvaluator) { |
||
391 | ((AndEvaluator) this.filter).addEvaluator(evaluator);
|
||
392 | } else {
|
||
393 | this.filter = new AndEvaluator(this.filter); |
||
394 | ((AndEvaluator) this.filter).addEvaluator(evaluator);
|
||
395 | 40435 | jjdelcerro | } |
396 | 43913 | jjdelcerro | } |
397 | 40435 | jjdelcerro | addFilterAttributes(evaluator); |
398 | } |
||
399 | 42975 | jjdelcerro | |
400 | 43358 | jjdelcerro | @Override
|
401 | 42975 | jjdelcerro | public void clearFilter() { |
402 | this.filter = null; |
||
403 | } |
||
404 | |||
405 | 40435 | jjdelcerro | private void addFilterAttributes(Evaluator evaluator){ |
406 | if (evaluator != null){ |
||
407 | EvaluatorFieldsInfo fieldsInfo = evaluator.getFieldsInfo(); |
||
408 | if (fieldsInfo == null){ |
||
409 | // FieldsInfo is not available in this evaluator
|
||
410 | return;
|
||
411 | } |
||
412 | String[] fieldNames = fieldsInfo.getFieldNames(); |
||
413 | if (fieldNames== null){ |
||
414 | // fieldNames is not available in this evaluator
|
||
415 | return;
|
||
416 | } |
||
417 | 42975 | jjdelcerro | |
418 | 40435 | jjdelcerro | for (int i=0 ; i<fieldNames.length ; i++){ |
419 | addAttributeName(fieldNames[i]); |
||
420 | } |
||
421 | } |
||
422 | } |
||
423 | |||
424 | 43358 | jjdelcerro | @Override
|
425 | 40435 | jjdelcerro | public FeatureQueryOrder getOrder() {
|
426 | return order;
|
||
427 | } |
||
428 | |||
429 | 43358 | jjdelcerro | @Override
|
430 | 40435 | jjdelcerro | public void setOrder(FeatureQueryOrder order) { |
431 | this.order = order;
|
||
432 | } |
||
433 | |||
434 | 43358 | jjdelcerro | @Override
|
435 | 40435 | jjdelcerro | public boolean hasFilter() { |
436 | return this.filter != null; |
||
437 | } |
||
438 | |||
439 | 43358 | jjdelcerro | @Override
|
440 | 40435 | jjdelcerro | public boolean hasOrder() { |
441 | return this.order != null && this.order.size() > 0; |
||
442 | } |
||
443 | |||
444 | 43358 | jjdelcerro | @Override
|
445 | 40435 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
446 | DefaultFeatureQuery clone = (DefaultFeatureQuery) super.clone();
|
||
447 | |||
448 | // Clone attribute names array
|
||
449 | if (attributeNames != null) { |
||
450 | clone.attributeNames = new ArrayList(); |
||
451 | for (int i=0 ; i<attributeNames.size() ; i++){ |
||
452 | clone.attributeNames.add(attributeNames.get(i)); |
||
453 | 42975 | jjdelcerro | } |
454 | 40435 | jjdelcerro | } |
455 | |||
456 | // Clone order
|
||
457 | if (order != null) { |
||
458 | clone.order = (FeatureQueryOrder) order.clone(); |
||
459 | } |
||
460 | |||
461 | return clone;
|
||
462 | } |
||
463 | |||
464 | 43358 | jjdelcerro | @Override
|
465 | 40435 | jjdelcerro | public FeatureQuery getCopy() {
|
466 | try {
|
||
467 | return (FeatureQuery) clone();
|
||
468 | } catch (CloneNotSupportedException e) { |
||
469 | // TODO Auto-generated catch block
|
||
470 | e.printStackTrace(); |
||
471 | return null; |
||
472 | } |
||
473 | // DefaultFeatureQuery aCopy = new DefaultFeatureQuery();
|
||
474 | //
|
||
475 | // aCopy.featureTypeId = this.featureTypeId;
|
||
476 | //
|
||
477 | // if (this.attributeNames != null) {
|
||
478 | // aCopy.attributeNames = (String[]) Arrays
|
||
479 | // .asList(this.attributeNames).toArray(new String[0]);
|
||
480 | // }
|
||
481 | //
|
||
482 | // aCopy.filter = this.filter;
|
||
483 | //
|
||
484 | // if (this.order != null) {
|
||
485 | // aCopy.order = this.order.getCopy();
|
||
486 | // }
|
||
487 | //
|
||
488 | // return aCopy;
|
||
489 | } |
||
490 | |||
491 | 43358 | jjdelcerro | @Override
|
492 | 40435 | jjdelcerro | public String getFeatureTypeId() { |
493 | return featureTypeId;
|
||
494 | } |
||
495 | |||
496 | 43358 | jjdelcerro | @Override
|
497 | 40435 | jjdelcerro | public void setFeatureTypeId(String featureTypeId) { |
498 | this.featureTypeId = featureTypeId;
|
||
499 | } |
||
500 | |||
501 | 43358 | jjdelcerro | @Override
|
502 | 40435 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
503 | // FIXME: falta por terminar de implementar
|
||
504 | state.set("queryParameters", this.queryParameters); |
||
505 | state.set("featureTypeId", this.featureTypeId); |
||
506 | state.set("attributeNames", this.attributeNames); |
||
507 | // state.set("filter", this.filter);
|
||
508 | state.set("limit", this.limit); |
||
509 | state.set("pageSize", this.pageSize); |
||
510 | |||
511 | } |
||
512 | |||
513 | 43358 | jjdelcerro | @Override
|
514 | 40435 | jjdelcerro | public void loadFromState(PersistentState state) throws PersistenceException { |
515 | // FIXME: falta por terminar de implementar
|
||
516 | this.queryParameters = (Map) state.get("queryParameters"); |
||
517 | this.featureTypeId = state.getString("featureTypeId"); |
||
518 | this.attributeNames = state.getList("attributeNames"); |
||
519 | this.filter = (Evaluator) state.get("filter"); |
||
520 | this.limit = state.getLong("limit"); |
||
521 | this.pageSize = state.getLong("pageSize"); |
||
522 | |||
523 | } |
||
524 | |||
525 | /**
|
||
526 | * Register the class on PersistenceManager
|
||
527 | 42975 | jjdelcerro | *
|
528 | 40435 | jjdelcerro | */
|
529 | public static void registerPersistent() { |
||
530 | DynStruct definition = |
||
531 | ToolsLocator.getPersistenceManager() |
||
532 | .addDefinition(DefaultFeatureQuery.class, |
||
533 | "DefaultFeatureQuery",
|
||
534 | "DefaultFeatureQuery Persistent definition",
|
||
535 | null,
|
||
536 | null);
|
||
537 | |||
538 | definition.addDynFieldMap("queryParameters")
|
||
539 | .setClassOfItems(Object.class)
|
||
540 | .setMandatory(true);
|
||
541 | |||
542 | definition.addDynFieldString("featureTypeId").setMandatory(false); |
||
543 | |||
544 | definition.addDynFieldList("attributeNames")
|
||
545 | .setClassOfItems(String.class)
|
||
546 | .setMandatory(false);
|
||
547 | |||
548 | definition.addDynFieldObject("filter")
|
||
549 | .setClassOfValue(Evaluator.class) |
||
550 | .setMandatory(false);
|
||
551 | |||
552 | definition.addDynFieldObject("order")
|
||
553 | .setClassOfValue(FeatureQueryOrder.class) |
||
554 | .setMandatory(false);
|
||
555 | |||
556 | definition.addDynFieldLong("limit").setMandatory(false); |
||
557 | |||
558 | definition.addDynFieldLong("pageSize").setMandatory(false); |
||
559 | |||
560 | } |
||
561 | |||
562 | 43358 | jjdelcerro | @Override
|
563 | 40435 | jjdelcerro | public long getLimit() { |
564 | return limit;
|
||
565 | } |
||
566 | |||
567 | 43358 | jjdelcerro | @Override
|
568 | 40435 | jjdelcerro | public long getPageSize() { |
569 | return pageSize;
|
||
570 | } |
||
571 | |||
572 | 43358 | jjdelcerro | @Override
|
573 | 40435 | jjdelcerro | public void setLimit(long limit) { |
574 | this.limit = limit;
|
||
575 | } |
||
576 | |||
577 | 43358 | jjdelcerro | @Override
|
578 | 40435 | jjdelcerro | public void setPageSize(long pageSize) { |
579 | this.pageSize = pageSize;
|
||
580 | } |
||
581 | |||
582 | 43358 | jjdelcerro | @Override
|
583 | 41212 | jjdelcerro | public String[] getConstantsAttributeNames() { |
584 | return (String[])constantsAttributeNames.toArray(new String[constantsAttributeNames.size()]); |
||
585 | } |
||
586 | |||
587 | 43358 | jjdelcerro | @Override
|
588 | 41212 | jjdelcerro | public void setConstantsAttributeNames(String[] constantsAttributeNames) { |
589 | this.constantsAttributeNames.clear();
|
||
590 | if (constantsAttributeNames != null){ |
||
591 | for (int i=0 ; i<constantsAttributeNames.length ; i++){ |
||
592 | this.constantsAttributeNames.add(constantsAttributeNames[i]);
|
||
593 | 42975 | jjdelcerro | } |
594 | 41212 | jjdelcerro | } |
595 | } |
||
596 | 42975 | jjdelcerro | |
597 | 43358 | jjdelcerro | @Override
|
598 | 41212 | jjdelcerro | public void addConstantAttributeName(String attributeName) { |
599 | //If the attribute exists finish the method
|
||
600 | for (int i=0 ; i<constantsAttributeNames.size() ; i++){ |
||
601 | if (constantsAttributeNames.get(i).equals(attributeName)){
|
||
602 | return;
|
||
603 | 42975 | jjdelcerro | } |
604 | } |
||
605 | 41212 | jjdelcerro | this.constantsAttributeNames.add(attributeName);
|
606 | } |
||
607 | |||
608 | 43358 | jjdelcerro | @Override
|
609 | 41212 | jjdelcerro | public boolean hasConstantsAttributeNames() { |
610 | return !this.constantsAttributeNames.isEmpty(); |
||
611 | } |
||
612 | |||
613 | 43358 | jjdelcerro | @Override
|
614 | 41212 | jjdelcerro | public void clearConstantsAttributeNames() { |
615 | this.constantsAttributeNames = new ArrayList(); |
||
616 | } |
||
617 | |||
618 | 44374 | jjdelcerro | @Override
|
619 | public boolean isGrouped() { |
||
620 | return this.group; |
||
621 | } |
||
622 | |||
623 | @Override
|
||
624 | public void setGroup(boolean group) { |
||
625 | this.group = group;
|
||
626 | } |
||
627 | |||
628 | 40435 | jjdelcerro | } |