Revision 44895

View differences:

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/indexes/memorybasictypes/MemoryFloatIndexProviderFactory.java
23 23
    
24 24
    @Override
25 25
    public DataFactoryUnit create(DynObject parameters, Services services) {
26
        return new MemoryBasicTypesIndexProvider<String>();
26
        return new MemoryBasicTypesIndexProvider<String>(String.class);
27 27
    }
28 28

  
29 29
    @Override
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/indexes/memorybasictypes/MemoryStringIndexProviderFactory.java
23 23
    
24 24
    @Override
25 25
    public DataFactoryUnit create(DynObject parameters, Services services) {
26
        return new MemoryBasicTypesIndexProvider<String>();
26
        return new MemoryBasicTypesIndexProvider<String>(String.class);
27 27
    }
28 28

  
29 29
    @Override
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/indexes/memorybasictypes/MemoryDoubleIndexProviderFactory.java
23 23
    
24 24
    @Override
25 25
    public DataFactoryUnit create(DynObject parameters, Services services) {
26
        return new MemoryBasicTypesIndexProvider<Double>();
26
        return new MemoryBasicTypesIndexProvider<Double>(Double.class);
27 27
    }
28 28

  
29 29
    @Override
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/indexes/memorybasictypes/MemoryIntIndexProviderFactory.java
23 23
    
24 24
    @Override
25 25
    public DataFactoryUnit create(DynObject parameters, Services services) {
26
        return new MemoryBasicTypesIndexProvider<Integer>();
26
        return new MemoryBasicTypesIndexProvider<Integer>(Integer.class);
27 27
    }
28 28

  
29 29
    @Override
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/indexes/memorybasictypes/MemoryBasicTypesIndexProvider.java
25 25

  
26 26
import java.util.List;
27 27
import java.util.TreeMap;
28
import java.util.logging.Level;
29
import java.util.logging.Logger;
28 30

  
29 31
import org.gvsig.fmap.dal.exception.DataException;
30 32
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
31 33
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
32 34
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dataTypes.CoercionException;
37
import org.gvsig.tools.dataTypes.DataType;
38
import org.gvsig.tools.dataTypes.DataTypeUtils;
39
import org.gvsig.tools.dataTypes.DataTypesManager;
33 40

  
34 41
public class MemoryBasicTypesIndexProvider<T> extends AbstractFeatureIndexProvider {
35 42

  
36 43
    private TreeMap<T,ListOfLong> index = null;
44
    private final Class<T> classt;
45
    private final int dataType;
37 46

  
38
    public MemoryBasicTypesIndexProvider() {
39

  
47
    public MemoryBasicTypesIndexProvider(Class<T> classt) {
48
        this.classt = classt;
49
        this.dataType = ToolsLocator.getDataTypesManager().getDataType(classt).getType(); // getCoercion()
40 50
    }
41 51

  
52
    @Override
42 53
    public void initialize() {
43 54
        try {
44 55
            this.index = new TreeMap<>();
......
47 58
        }
48 59
    }
49 60

  
61
    @Override
50 62
    public void delete(Object key_o, FeatureReferenceProviderServices fref) {
51 63
        T key_s = (T) key_o;
52 64
        long oid = (Long) fref.getOID();
......
60 72
        }
61 73
    }
62 74

  
75
    @Override
63 76
    public void insert(Object key_o, FeatureReferenceProviderServices fref) {
64 77
        if (key_o == null) {
65 78
            return;
......
74 87
        items.add(oid);
75 88
    }
76 89

  
90
    @Override
77 91
    public List match(Object key_o) throws FeatureIndexException {
78
        T key_s = (T) key_o;
92
//        T key_s = this.classt.cast(key_o);
93
        T key_s;
94
        try {
95
            key_s = (T) DataTypeUtils.coerce(this.dataType, key_o);
96
        } catch (CoercionException ex) {
97
            return null;
98
        }
79 99
        if( !this.index.containsKey(key_s) ) {
80 100
            return null;
81 101
        }
......
91 111
                "Can't perform this kind of search.");
92 112
    }
93 113

  
114
    @Override
94 115
    public List nearest(int count, Object value) throws FeatureIndexException {
95 116
        throw new UnsupportedOperationException(
96 117
                "Can't perform this kind of search.");
97 118
    }
98 119

  
120
    @Override
99 121
    public boolean isMatchSupported() {
100 122
        return true;
101 123
    }
102 124

  
125
    @Override
103 126
    public boolean isNearestSupported() {
104 127
        return false;
105 128
    }
106 129

  
130
    @Override
107 131
    public boolean isNearestToleranceSupported() {
108 132
        return false;
109 133
    }
110 134

  
135
    @Override
111 136
    public boolean isRangeSupported() {
112 137
        return false;
113 138
    }
114 139

  
140
    @Override
115 141
    public List nearest(int count, Object value, Object tolerance)
116 142
            throws FeatureIndexException {
117 143
        throw new UnsupportedOperationException();
118 144
    }
119 145

  
146
    @Override
120 147
    public List range(Object value1, Object value2)
121 148
            throws FeatureIndexException {
122 149
        throw new UnsupportedOperationException();
123 150
    }
124 151

  
152
    @Override
125 153
    public void clear() throws DataException {
126 154
        this.index.clear();
127 155
    }
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/indexes/memorybasictypes/MemoryLongIndexProviderFactory.java
23 23
    
24 24
    @Override
25 25
    public DataFactoryUnit create(DynObject parameters, Services services) {
26
        return new MemoryBasicTypesIndexProvider<Long>();
26
        return new MemoryBasicTypesIndexProvider<Long>(Long.class);
27 27
    }
28 28

  
29 29
    @Override
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/dal/feature/JoinTransform.java
30 30
import java.util.List;
31 31
import java.util.Map;
32 32
import java.util.Map.Entry;
33
import java.util.Objects;
34
import java.util.logging.Level;
33 35
import org.apache.commons.lang3.StringUtils;
34 36
import org.gvsig.fmap.dal.DataTypes;
35 37

  
......
46 48
import org.gvsig.fmap.dal.feature.FeatureType;
47 49
import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException;
48 50
import org.gvsig.tools.ToolsLocator;
51
import org.gvsig.tools.dataTypes.Coercion;
52
import org.gvsig.tools.dataTypes.CoercionException;
53
import org.gvsig.tools.dataTypes.DataType;
49 54
import org.gvsig.tools.dispose.DisposableIterator;
50 55
import org.gvsig.tools.dynobject.DynStruct;
51 56
import org.gvsig.tools.evaluator.Evaluator;
......
414 419
        private Object value;
415 420
        private String sql;
416 421
        private EvaluatorFieldsInfo info = null;
422
        private Coercion coercion;
417 423

  
418 424
        //		private int attributeIndex;
419 425
        public JoinTransformEvaluator(String attribute, boolean is_numeric) {
......
427 433

  
428 434
        public void updateValue(Object value) {
429 435
            this.value = value;
430
            String qt = this.isNumeric ? "" : "'";
431
            this.sql = this.attribute + " = " + qt + this.value + qt;
436
            this.coercion = null;
437
            if (this.value!=null) {
438
                DataType dataType = ToolsLocator.getDataTypesManager().getDataType(value.getClass());
439
                if (dataType!=null) {
440
                    this.coercion = dataType.getCoercion();
441
                }
442
                String qt = this.isNumeric ? "" : "'";
443
                this.sql = this.attribute + " = " + qt + this.value + qt;
444
            } else {
445
                this.sql = this.attribute + " = null";
446
            }
432 447
            this.info = new EvaluatorFieldsInfo();
433 448
            this.info.addMatchFieldValue(this.attribute, value);
434 449
        }
......
439 454
            if( curValue == null ) {
440 455
                return value == null;
441 456
            }
442
            return curValue.equals(value);
457
            if ( value == null) {
458
                return false;
459
            }
460
            Object coerceValue;
461
            if (this.coercion == null) {
462
                return StringUtils.equals(Objects.toString(curValue), Objects.toString(value));
463
            }
464
            try {
465
                coerceValue = this.coercion.coerce(curValue);
466
                return coerceValue.equals(value);
467
            } catch (CoercionException ex) {
468
                return StringUtils.equals(Objects.toString(curValue), Objects.toString(value));
469
            }
443 470
        }
444 471

  
445 472
        @Override

Also available in: Unified diff