Revision 44669 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/feature/spi/simpleprovider/AutomaticDetectionOfTypes.java

View differences:

AutomaticDetectionOfTypes.java
8 8
import java.util.Objects;
9 9
import org.gvsig.fmap.dal.DataTypes;
10 10
import org.gvsig.tools.ToolsLocator;
11
import org.gvsig.tools.dataTypes.Coercion;
12
import org.gvsig.tools.dataTypes.CoercionContext;
13
import org.gvsig.tools.dataTypes.DataTypeUtils;
11 14
import org.gvsig.tools.dataTypes.DataTypesManager;
12 15

  
13 16
/**
......
25 28
        public boolean possibleInt = true;
26 29
        public boolean possibleFloat = true;
27 30
        public boolean possibleDouble = true;
31
        public boolean possibleDecimal = true;
28 32
        public boolean possibleLong = true;
29 33
        public boolean possibleURL = true;
30 34
        public boolean possibleDate = true;
......
64 68
                locale = Locale.getDefault();
65 69
            }
66 70
            DataTypesManager typeManager = ToolsLocator.getDataTypesManager();
67
            DataTypesManager.CoercionWithLocale toDouble = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DOUBLE);
68
            DataTypesManager.CoercionWithLocale toFloat = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.FLOAT);
69
            DataTypesManager.CoercionWithLocale toDate = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DATE);
70
            DataTypesManager.CoercionWithLocale toInt = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.INT);
71
            DataTypesManager.CoercionWithLocale toLong = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.LONG);
72
            DataTypesManager.Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY);
73

  
71
            Coercion toDecimal = typeManager.getCoercion(DataTypes.DECIMAL);
72
            Coercion toDouble = typeManager.getCoercion(DataTypes.DOUBLE);
73
            Coercion toFloat = typeManager.getCoercion(DataTypes.FLOAT);
74
            Coercion toDate = typeManager.getCoercion(DataTypes.DATE);
75
            Coercion toInt = typeManager.getCoercion(DataTypes.INT);
76
            Coercion toLong = typeManager.getCoercion(DataTypes.LONG);
77
            Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY);
78
            CoercionContext coercionContext = DataTypeUtils.coerceContextLocale(locale);
79
            
74 80
            List<Object> row = rows.read();
75 81
            lineno++;
76 82

  
......
81 87
                    }
82 88
                    String rawvalue = Objects.toString(row.get(i),null);
83 89
                    PossibleDataType possibleDataType = possibleDataTypes.get(i);
90
                    if (possibleDataType.possibleDecimal) {
91
                        try {
92
                            toDecimal.coerce(rawvalue, coercionContext);
93
                            possibleDataType.possibleDecimal = true;
94
                        } catch (Exception ex) {
95
                            possibleDataType.possibleDecimal = false;
96
                        }
97
                    }
84 98
                    if (possibleDataType.possibleDouble) {
85 99
                        try {
86
                            toDouble.coerce(rawvalue, locale);
100
                            toDouble.coerce(rawvalue, coercionContext);
87 101
                            possibleDataType.possibleDouble = true;
88 102
                        } catch (Exception ex) {
89 103
                            possibleDataType.possibleDouble = false;
......
91 105
                    }
92 106
                    if (possibleDataType.possibleFloat) {
93 107
                        try {
94
                            toFloat.coerce(rawvalue, locale);
108
                            toFloat.coerce(rawvalue, coercionContext);
95 109
                            possibleDataType.possibleFloat = true;
96 110
                        } catch (Exception ex) {
97 111
                            possibleDataType.possibleFloat = false;
......
105 119
                    }
106 120
                    if (possibleDataType.possibleDate) {
107 121
                        try {
108
                            toDate.coerce(rawvalue, locale);
122
                            toDate.coerce(rawvalue, coercionContext);
109 123
                            possibleDataType.possibleDate = true;
110 124
                        } catch (Exception ex) {
111 125
                            possibleDataType.possibleDate = false;
......
141 155
                    types[n++] = DataTypes.LONG;
142 156
                    continue;
143 157
                }
158
                if (possibleDataType.possibleDecimal) {
159
                    types[n++] = DataTypes.DECIMAL;
160
                    continue;
161
                }
144 162
                if (possibleDataType.possibleFloat) {
145 163
                    // Forzamos los float a double para evitar perder precision
146 164
                    types[n++] = DataTypes.DOUBLE;

Also available in: Unified diff