Revision 47665 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/store/simplereader/SimpleReaderStoreProvider.java

View differences:

SimpleReaderStoreProvider.java
110 110

  
111 111
    protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleReaderStoreProvider.class);
112 112

  
113
//    public static final String NAME = DataStore.CSV_PROVIDER_NAME;
114
//    public static final String DESCRIPTION = "CSV file";
115
//
116
//    public static final String METADATA_DEFINITION_NAME = NAME;
117

  
118 113
    protected final ResourceProvider resource;
119 114

  
120 115
    protected long counterNewsOIDs = 0;
......
138 133
                metadata
139 134
        );
140 135
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
141
        this.taskStatus = manager.createDefaultSimpleTaskStatus("CSV");
136
        this.taskStatus = manager.createDefaultSimpleTaskStatus(this.getProviderName());
142 137
        this.taskStatus.setAutoremove(true);
143 138

  
144 139
        this.envelopes = new HashMap<>();
......
189 184
        try {
190 185
            loadFeatures();
191 186
        } catch (RuntimeException e) {
192
            LOGGER.debug("Can't load features from CSV '" + getFullFileName() + "'.", e);
187
            LOGGER.debug("Can't load features from '" + getFullFileName() + "'.", e);
193 188
            throw e;
194 189
        } catch (Exception e) {
195
            LOGGER.debug("Can't load features from CSV '" + getFullFileName() + "'.", e);
190
            LOGGER.debug("Can't load features from '" + getFullFileName() + "'.", e);
196 191
            throw new RuntimeException(e);
197 192
        }
198 193
    }
......
272 267
        }
273 268
    }
274 269

  
275
    @Override
276
    @SuppressWarnings("Convert2Lambda")
277
    public Envelope getEnvelope() throws DataException {
270
    public Envelope getEnvelope(String geomName) throws DataException {
278 271
        this.open();
279
        FeatureAttributeDescriptor geomdesc = this.featureType.getDefaultGeometryAttribute();
280
        String geomName = geomdesc.getName();
272
        if(geomName == null){
273
            FeatureAttributeDescriptor geomdesc = this.featureType.getDefaultGeometryAttribute();
274
            geomName = geomdesc.getName();
275
        }
281 276
        Envelope env = this.envelopes.get(geomName);
282 277
        if (env != null) {
283 278
            return env;
284 279
        }
285
        env = bboxFileLoad("_"+geomName);
286
        if (env != null) {
287
            this.envelopes.put(geomName, env);
288
            return env;
280

  
281
        File data_file = SimpleReaderStoreParameters.getFile(this.getSimpleReaderParameters());
282
        File bboxfile = this.getAuxFile("_"+geomName, "bbox");
283
        if (bboxfile.exists() && SimpleReaderUtils.isFileNewer(bboxfile, data_file)) {
284
            env = bboxFileLoad(bboxfile);
285
            if (env != null) {
286
                this.envelopes.put(geomName, env);
287
                return env;
288
            }
289 289
        }
290 290
        if (!this.need_calculate_envelope) {
291 291
            return null;
......
331 331

  
332 332
        this.need_calculate_envelope = false;
333 333
        return env;
334
        
334 335
    }
336
    
337
    @Override
338
    public Envelope getEnvelope() throws DataException {
339
        return getEnvelope(null);
340
    }
335 341

  
336 342
    @Override
337 343
    public Object getDynValue(String name) throws DynFieldNotFoundException {
......
425 431
                return point;
426 432
            } catch (Exception ex) {
427 433
                if (++errorcount < 5) {
428
                    logger.warn("[" + errorcount + "] Can't create point in CSV provider. XNAME='"
434
                    logger.warn("[" + errorcount + "] Can't create point. XNAME='"
429 435
                            + xname + "', YNAME='" + yname + "', ZNAME='" + zname + "', data=" + data.toString());
430 436
                }
431 437
                return null;
......
529 535
        InputStreamReader in = null;
530 536
        SimpleReader reader = null;
531 537
        try {
532
            taskStatus.setTitle("CSV "+this.getName());
538
            taskStatus.setTitle(this.getProviderName()+" "+this.getName());
533 539
            taskStatus.add();
534
//            boolean ignore_errors = CSVStoreParameters.getIgnoreErrors(getCSVParameters());
535 540

  
536 541
            // Initialize the feature types
537 542
            EditableFeatureType edftype = getStoreServices().createFeatureType(this.getName());
......
598 603
                }
599 604
                for (int i = 0; i < ftype.size(); i++) {
600 605
                    if (this.rowToFeatureTranslator.getColumnSize(i) > 0) {
601
//                    if (sizes[i] > 0) {
602 606
                        EditableFeatureAttributeDescriptor efad = ((EditableFeatureAttributeDescriptor) edftype.getAttributeDescriptor(i));
603
//                        efad.setSize(sizes[i]);
604 607
                        efad.setSize(this.rowToFeatureTranslator.getColumnSize(i));
605 608
                    }
606 609
                }
......
654 657
    }
655 658
    
656 659
    protected boolean mustFixFeatureType() {
660
        FeatureStore theStore = this.getStoreServices().getFeatureStore();
661
        FeatureType ft = theStore.getDefaultFeatureTypeQuietly();
662
        String geomName = ft.getDefaultGeometryAttributeName();
663
        if(StringUtils.isNotBlank(geomName)){
664
            if(this.featureType.getAttributeDescriptor(geomName)==null){
665
                return true;
666
            }
667
        }
657 668
        return false;
658 669
    }
659 670

  
......
804 815
                String geomName = geomdesc.getName();
805 816
                Envelope env = bboxFileLoad("_"+geomName);
806 817
                File indexfile = this.getAuxFile("_"+geomName, extname);
807
                boolean createIndex = !indexfile.exists();
808 818

  
819
                File data_file = SimpleReaderStoreParameters.getFile(this.getSimpleReaderParameters());
820
                boolean createIndex = !indexfile.exists() || SimpleReaderUtils.isFileNewer(data_file, indexfile);
821

  
809 822
                GeometryManager geomManager = GeometryLocator.getGeometryManager();
810 823
                SpatialIndexFactory indexfactory = geomManager.getSpatialIndexFactory(indexTypeName);
811 824
                DynObject params = indexfactory.createParameters();
......
884 897
        return index_file;
885 898
    }
886 899

  
900
    public SpatialIndex getSpatialIndex(String geomName) {
901
        if(spatialIndexes == null){
902
            return null;
903
        }
904
        return spatialIndexes.get(geomName);
905
    }
906

  
887 907
    public SpatialIndex getSpatialIndex() {
888 908
        if(spatialIndexes == null){
889 909
            return null;
......
949 969
        return null;
950 970
    }
951 971
    
952
    protected abstract SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException ;//{
953
//        return CSVUtils.getSimpleReader(getSimpleReaderParameters(), in);
954
//    }
972
    protected abstract SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException ;
955 973
    
956 974
}

Also available in: Unified diff