Revision 47642 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreProvider.java

View differences:

CSVStoreProvider.java
30 30
import java.util.List;
31 31
import org.apache.commons.io.FileUtils;
32 32
import org.apache.commons.io.FilenameUtils;
33
import org.apache.commons.lang3.StringUtils;
33 34
import org.gvsig.fmap.dal.DataStore;
35
import org.gvsig.fmap.dal.DataTypes;
34 36
import org.gvsig.fmap.dal.FileHelper;
35 37
import org.gvsig.fmap.dal.exception.DataException;
36 38
import org.gvsig.fmap.dal.exception.InitializeException;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37 40
import org.gvsig.fmap.dal.feature.FeatureSet;
38 41
import org.gvsig.fmap.dal.feature.FeatureType;
39 42
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
......
284 287
            LOGGER.warn("Not been able to end append '" + this.getFullName() + "'.", ex);
285 288
        }
286 289
    }
290
    
291
    @Override
292
    protected boolean mustFixFeatureType() {
293
        try {
294
            String param_types_def = CSVStoreParameters.getRawFieldTypes(this.getParameters());
295
            String[] pointDimensionNames = CSVStoreParameters.getPointDimensionNames(this.getParameters());
296
            String geometry_column = CSVStoreParameters.getGeometryColumn(this.getParameters());
297
            
298
            
299
            FeatureType dalFeatureType = this.getStoreServices().getDefaultFeatureType();
300
            if (StringUtils.isNotBlank(geometry_column)){
301
                FeatureAttributeDescriptor attr = dalFeatureType.getAttributeDescriptor(geometry_column);
302
                if(attr == null || attr.getType() !=  DataTypes.GEOMETRY){
303
                    return true;
304
                }
305
            }
306
            if (StringUtils.isNotBlank(param_types_def)
307
                    || pointDimensionNames != null) {
308
                for (FeatureAttributeDescriptor dalAttr : dalFeatureType) {
309
                    if(dalAttr.isComputed()){
310
                        continue;
311
                    }
312
                    FeatureAttributeDescriptor csvAttr = featureType.getAttributeDescriptor(dalAttr.getName());
313
                    if(csvAttr == null){
314
                        return true;
315
                    }
316
                    if(!dalAttr.get("all").equals(csvAttr.get("all"))){
317
                        return true;
318
                    }
319
                }
320
            }
321
        } catch (DataException ex) {
322
            LOGGER.warn("Can't check if should fix the feature type", ex);
323
        }
324
        return false;
325
    }
287 326

  
288 327
    @Override
289 328
    protected SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException {
......
303 342

  
304 343
    @Override
305 344
    public List<String> getRowByIndex(long index) {
306
        try {
307
            this.open();
308
        } catch(Exception ex) {
309
            throw new RuntimeException("Can't get row by index", ex);
310
        }
311
        if (this.virtualrows == null) {
312
            return null;
313
        }
314
        List<String> line = this.virtualrows.get64(index);
345
        List<String> line = super.getRowByIndex(index);
315 346
        if( line!=null ) {
316 347
            for (int i = 0; i < line.size(); i++) {
317 348
                String s = line.get(i);

Also available in: Unified diff