Revision 2083 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataType.java

View differences:

DefaultDataType.java
66 66
    }
67 67
  }
68 68

  
69
  private static final NumberPrecisionAndScale BYTE_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(BYTE_MAX_PRECISION, 0);
70
  private static final NumberPrecisionAndScale INT_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(INT_MAX_PRECISION, 0);
71
  private static final NumberPrecisionAndScale LONG_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(LONG_MAX_PRECISION, 0);
69
  public static final int NO_SUPPORT_SCALE = -1;
70
  public static final int NO_SUPPORT_PRECISION = -1;
71
  
72 72
  private static final NumberPrecisionAndScale EMPTY_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(0, 0);
73 73

  
74 74
  private Coercion coercion;
......
80 80
  private int max_precision;
81 81
  private int default_precision;
82 82
  private int default_scale;
83
  private boolean fixedPrecision;
83 84

  
84 85
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion) {
85 86
    this(type, subtype, name, defaultClass, coercion, "datatype-any");
86 87
  }
87 88

  
88 89
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName) {
89
    this(type, subtype, name, defaultClass, coercion, "datatype-any", 0, 0, 0);
90
    this(type, subtype, name, defaultClass, coercion, "datatype-any", false, NO_SUPPORT_PRECISION, NO_SUPPORT_PRECISION, NO_SUPPORT_SCALE);
90 91
  }
91 92

  
92
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int max_precision, int default_precision, int default_scale) {
93
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision) {
94
    this(type, subtype, name, defaultClass, coercion, "datatype-any", isFixedPrecision, max_precision, default_precision, NO_SUPPORT_SCALE);
95
  }
93 96

  
97
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision, int default_scale) {
98

  
94 99
    if (name == null) {
95 100
      LOG.trace("Can't register null type name for type {}.", new Object[]{Integer.toHexString(type).toUpperCase()});
96 101
      throw new IllegalArgumentException();
......
104 109
    this.max_precision = max_precision;
105 110
    this.default_precision = default_precision;
106 111
    this.default_scale = default_scale;
112
    this.fixedPrecision = isFixedPrecision;
107 113
  }
108 114

  
109 115
  @Override
......
265 271

  
266 272
  @Override
267 273
  public boolean supportPrecision() {
268
    if( this.max_precision<=0 ) {
269
      return false;
270
    }
271
    return true;
274
    return this.max_precision!=NO_SUPPORT_PRECISION;
272 275
  }
273 276

  
274 277
  @Override
275 278
  public boolean supportScale() {
276
    if( this.max_precision<=0 ) {
277
      return false;
278
    }
279
    switch (this.type) {
280
      case DataTypes.FLOAT:
281
      case DataTypes.DOUBLE:
282
      case DataTypes.DECIMAL:
283
        return true;
284
      default:
285
        return false;
286
    }
279
    return this.default_scale!=NO_SUPPORT_SCALE;
287 280
  }
288 281

  
289 282
  @Override
290 283
  public NumberPrecisionAndScale fixPrecisionAndScale(int precision, int scale) {
291
    if( this.max_precision > 0 ) {
292
      // Si el tipo tiene asignada una precision maxima asumimos que debemos
293
      // controlar la precision y la escala.
294
      DefaultNumberPrecisionAndScale r = new DefaultNumberPrecisionAndScale(
295
              precision, 
296
              scale
297
      );
284
    if( this.max_precision==NO_SUPPORT_PRECISION ) {
285
       return EMPTY_PRECISION_AND_SCALE;
286
    }
287
    DefaultNumberPrecisionAndScale r = new DefaultNumberPrecisionAndScale(
288
            precision, 
289
            scale
290
    );
291
    if( this.fixedPrecision ) {
292
      r.precision = max_precision;
293
    }
294
    if( this.default_scale==NO_SUPPORT_SCALE ) {
295
      // Soporta precision y no escala (byte, int, long... enteros)
296
      r.scale = 0;
297
      if( r.precision > max_precision ) {
298
        r.precision = max_precision;
299
      }
300
    } else {
301
      // Soporta precision y escala.
298 302
      if (r.precision < 1) {
299 303
        // Sin precision
300 304
        if (r.scale < 1) {
......
363 367
          }
364 368
        }
365 369
      }
366
      return r;
367 370
    }
368
    // Para los tipos enteros basicos, ya tienen una precision y escala fijas.
369
    switch(this.type) {
370
      case DataTypes.BYTE:
371
        return BYTE_PRECISION_AND_SCALE;
372
        
373
      case DataTypes.INT:
374
        return INT_PRECISION_AND_SCALE;
375
        
376
      case DataTypes.LONG:
377
        return LONG_PRECISION_AND_SCALE;
378
        
379
      default:
380
        return EMPTY_PRECISION_AND_SCALE;
381
    }
371
    return r;
382 372
  }
373

  
374
  @Override
375
  public int getMaxPrecision() {
376
    return this.max_precision;
377
  }
378

  
379
  @Override
380
  public int getDefaultPrecision() {
381
    return this.default_precision;
382
  }
383

  
384
  @Override
385
  public int getDefaultScale() {
386
    return this.default_scale;
387
  }
388

  
389
  public boolean isFixedPrecision() {
390
    return this.fixedPrecision;
391
  }
383 392
}

Also available in: Unified diff