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

View differences:

DefaultFeatureQuery.java
29 29
import java.util.Map;
30 30
import java.util.logging.Level;
31 31
import java.util.logging.Logger;
32
import org.apache.commons.lang3.ArrayUtils;
32 33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.exception.DataException;
33 36
import org.gvsig.fmap.dal.exception.InitializeException;
37
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
34 38
import org.gvsig.fmap.dal.feature.FeatureQuery;
35 39
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
36 41
import org.gvsig.fmap.dal.feature.FeatureType;
37 42
import org.gvsig.tools.ToolsLocator;
38 43
import org.gvsig.tools.dynobject.DynStruct;
......
102 107
    /**
103 108
     * Creates a FeatureQuery which will load all available Features of a type.
104 109
     *
105
     * @param featureType
106
     *            the type of Features of the query
107 110
     */
108 111
    public DefaultFeatureQuery() {
109 112
        super();
......
128 131
     *            the type of Features of the query
129 132
     * @param filter
130 133
     *            based on the properties of the Features
131
     * @param order
132
     *            for the result
133 134
     */
134 135
    public DefaultFeatureQuery(FeatureType featureType, Evaluator filter) {
135 136
        super();
......
145 146
     *            the type of Features of the query
146 147
     * @param filter
147 148
     *            based on the properties of the Features
148
     * @param order
149
     *            for the result
150 149
     * @param scale
151 150
     *            to view the Features.
152 151
     */
......
177 176
     *            the list of attribute names to load
178 177
     * @param filter
179 178
     *            based on the properties of the Features
180
     * @param order
181
     *            for the result
182 179
     */
183 180
    public DefaultFeatureQuery(String[] attributeNames, Evaluator filter) {
184 181
        super();
......
194 191
     *            the list of attribute names to load
195 192
     * @param filter
196 193
     *            based on the properties of the Features
197
     * @param order
198
     *            for the result
199 194
     * @param scale
200 195
     *            to view the Features.
201 196
     */
......
206 201
        this.setScale(scale);
207 202
    }
208 203

  
204
    @Override
209 205
    public double getScale() {
210 206
        Double scale = (Double) this.getQueryParameter(SCALE_PARAM_NAME);
211 207
        if (scale == null) {
212 208
            return 0;
213 209
        }
214
        return scale.doubleValue();
210
        return scale;
215 211
    }
216 212

  
213
    @Override
217 214
    public void setScale(double scale) {
218
        this.setQueryParameter(SCALE_PARAM_NAME, new Double(scale));
215
        this.setQueryParameter(SCALE_PARAM_NAME, scale);
219 216
    }
220 217

  
218
    @Override
221 219
    public Object getQueryParameter(String name) {
222 220
        return queryParameters.get(name);
223 221
    }
224 222

  
223
    @Override
225 224
    public void setQueryParameter(String name, Object value) {
226 225
        queryParameters.put(name, value);
227 226
    }
228 227

  
228
    @Override
229 229
    public void setFeatureType(FeatureType featureType) {
230 230
        this.featureTypeId = featureType.getId();
231 231
    }
232 232

  
233
    @Override
233 234
    public String[] getAttributeNames() {
234 235
        return (String[])attributeNames.toArray(new String[attributeNames.size()]);
235 236
    }
236 237

  
238
    @Override
237 239
    public void setAttributeNames(String[] attributeNames) {
238 240
        this.attributeNames.clear();
239 241
        if (attributeNames != null){
......
243 245
        }
244 246
    }
245 247

  
248
    @Override
246 249
    public void addAttributeName(String attributeName){
247 250
        //If the attribute exists finish the method
248 251
        for (int i=0 ; i<attributeNames.size() ; i++){
......
253 256
        this.attributeNames.add(attributeName);
254 257
    }
255 258

  
259
    @Override
260
    public void addEssentialAttributeNames(FeatureStore store) {
261
        FeatureType storeType;
262
        try {
263
            storeType = store.getDefaultFeatureType();
264
        } catch (DataException ex) {
265
            throw new RuntimeException("Can't access to the default feature type of tghe store", ex);
266
        }
267
        FeatureAttributeDescriptor[] pks = storeType.getPrimaryKey();
268
        if( storeType.hasOID() || ArrayUtils.isEmpty(pks) ) {
269
            FeatureAttributeDescriptor attrInt = null;
270
            FeatureAttributeDescriptor attrStr = null;
271
            FeatureAttributeDescriptor attrNotGeom = null;
272
            for (FeatureAttributeDescriptor attr : storeType) {
273
                if( attrInt == null && (attr.getType()==DataTypes.INT || attr.getType()==DataTypes.LONG) ) {
274
                    attrInt = attr;
275
                } else if( attrStr == null && attr.getType()==DataTypes.STRING ) {
276
                    attrStr = attr;
277
                } else if( attrNotGeom == null && attr.getType()!=DataTypes.GEOMETRY ) {
278
                    attrNotGeom = attr;
279
                }
280
            }
281
            if( attrInt != null ) {
282
                this.addAttributeName(attrInt.getName());
283
            } else if( attrStr != null ) {
284
                this.addAttributeName(attrStr.getName());
285
            } else if( attrNotGeom != null ) {
286
                this.addAttributeName(attrNotGeom.getName());
287
            } else {
288
                this.addAttributeName(storeType.getAttributeDescriptor(0).getName());
289
            }
290
        } else {
291
            for(FeatureAttributeDescriptor attr : pks ) {
292
                this.addAttributeName(attr.getName());
293
            }
294
        }
295
    }
296
    
297
    @Override
298
    public void addPrimaryKeyAttributeNames(FeatureStore store) {
299
        FeatureType storeType;
300
        try {
301
            storeType = store.getDefaultFeatureType();
302
        } catch (DataException ex) {
303
            throw new RuntimeException("Can't access to the default feature type of tghe store", ex);
304
        }
305
        for(FeatureAttributeDescriptor attr : storeType.getPrimaryKey() ) {
306
            this.addAttributeName(attr.getName());
307
        }
308
    }
309

  
310
    @Override
256 311
    public boolean hasAttributeNames() {
257 312
        return !this.attributeNames.isEmpty();
258 313
    }
259 314

  
315
    @Override
260 316
    public void clearAttributeNames() {
261 317
        this.attributeNames = new ArrayList();
262 318
    }
263 319

  
320
    @Override
264 321
    public Evaluator getFilter() {
265 322
        return filter;
266 323
    }
......
274 331
        }
275 332
    }
276 333

  
334
    @Override
277 335
    public void setFilter(Evaluator filter) {
278 336
        this.filter = filter;
279 337
        addFilterAttributes(filter);
......
314 372
//        isAddFilter = true;
315 373
    }
316 374

  
375
    @Override
317 376
    public void clearFilter() {
318 377
      this.filter = null;
319 378
    }
......
337 396
        }
338 397
    }
339 398

  
399
    @Override
340 400
    public FeatureQueryOrder getOrder() {
341 401
        return order;
342 402
    }
343 403

  
404
    @Override
344 405
    public void setOrder(FeatureQueryOrder order) {
345 406
        this.order = order;
346 407
    }
347 408

  
409
    @Override
348 410
    public boolean hasFilter() {
349 411
        return this.filter != null;
350 412
    }
351 413

  
414
    @Override
352 415
    public boolean hasOrder() {
353 416
        return this.order != null && this.order.size() > 0;
354 417
    }
355 418

  
419
    @Override
356 420
    public Object clone() throws CloneNotSupportedException {
357 421
        DefaultFeatureQuery clone = (DefaultFeatureQuery) super.clone();
358 422

  
......
372 436
        return clone;
373 437
    }
374 438

  
439
    @Override
375 440
    public FeatureQuery getCopy() {
376 441
        try {
377 442
            return (FeatureQuery) clone();
......
398 463
        // return aCopy;
399 464
    }
400 465

  
466
    @Override
401 467
    public String getFeatureTypeId() {
402 468
        return featureTypeId;
403 469
    }
404 470

  
471
    @Override
405 472
    public void setFeatureTypeId(String featureTypeId) {
406 473
        this.featureTypeId = featureTypeId;
407 474
    }
408 475

  
476
    @Override
409 477
    public void saveToState(PersistentState state) throws PersistenceException {
410 478
        // FIXME: falta por terminar de implementar
411 479
        state.set("queryParameters", this.queryParameters);
......
417 485

  
418 486
    }
419 487

  
488
    @Override
420 489
    public void loadFromState(PersistentState state) throws PersistenceException {
421 490
        // FIXME: falta por terminar de implementar
422 491
        this.queryParameters = (Map) state.get("queryParameters");
......
465 534

  
466 535
    }
467 536

  
537
    @Override
468 538
    public long getLimit() {
469 539
        return limit;
470 540
    }
471 541

  
542
    @Override
472 543
    public long getPageSize() {
473 544
        return pageSize;
474 545
    }
475 546

  
547
    @Override
476 548
    public void setLimit(long limit) {
477 549
        this.limit = limit;
478 550
    }
479 551

  
552
    @Override
480 553
    public void setPageSize(long pageSize) {
481 554
        this.pageSize = pageSize;
482 555
    }
483 556

  
557
    @Override
484 558
    public String[] getConstantsAttributeNames() {
485 559
        return (String[])constantsAttributeNames.toArray(new String[constantsAttributeNames.size()]);
486 560
    }
487 561

  
562
    @Override
488 563
    public void setConstantsAttributeNames(String[] constantsAttributeNames) {
489 564
        this.constantsAttributeNames.clear();
490 565
        if (constantsAttributeNames != null){
......
494 569
        }
495 570
    }
496 571

  
572
    @Override
497 573
    public void addConstantAttributeName(String attributeName) {
498 574
        //If the attribute exists finish the method
499 575
        for (int i=0 ; i<constantsAttributeNames.size() ; i++){
......
504 580
        this.constantsAttributeNames.add(attributeName);
505 581
    }
506 582

  
583
    @Override
507 584
    public boolean hasConstantsAttributeNames() {
508 585
        return !this.constantsAttributeNames.isEmpty();
509 586
    }
510 587

  
588
    @Override
511 589
    public void clearConstantsAttributeNames() {
512 590
        this.constantsAttributeNames = new ArrayList();
513 591
    }

Also available in: Unified diff