summaryrefslogtreecommitdiff
path: root/src/dbc/scala/dbc/value/Factory.scala
blob: cc7406a9454e2837ee6ccd65cdd1974e7546739c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala.dbc
package value;


import java.math.BigInteger;
import java.math.BigDecimal;

@deprecated(DbcIsDeprecated) object Factory {

  def create (result: java.sql.ResultSet, index: Int, expectedDataType: DataType): Value = {
    expectedDataType.nativeTypeId match {
      case DataType.OBJECT =>
        new value.Unknown {
          val dataType = expectedDataType.asInstanceOf[datatype.Unknown];
          val nativeValue: AnyRef = result.getObject(index);
        }
      case DataType.STRING => {
        expectedDataType match {
          case t:datatype.Character =>
              new value.Character {
              val dataType = t;
              val nativeValue: String = result.getString(index);
            }
          case t:datatype.CharacterVarying =>
            new value.CharacterVarying {
              val dataType = t;
              val nativeValue: String = result.getString(index);
            }
          case t:datatype.CharacterLargeObject =>
            new value.CharacterLargeObject {
              val dataType = t;
              val nativeValue: String = result.getString(index);
            }
        }
      }
      case DataType.BOOLEAN =>
        new value.Boolean {
          val dataType = expectedDataType.asInstanceOf[datatype.Boolean];
          val nativeValue: scala.Boolean = result.getBoolean(index);
        }
      case DataType.FLOAT  =>
        new value.ApproximateNumeric[Float] {
          val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Float]];
          val nativeValue: Float = result.getFloat(index);
        }
      case DataType.DOUBLE =>
        new value.ApproximateNumeric[Double] {
          val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Double]];
           val nativeValue: Double = result.getDouble(index);
        }
      case DataType.BYTE =>
        new value.ExactNumeric[Byte] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Byte]];
          val nativeValue: Byte = result.getByte(index);
        }
      case DataType.SHORT =>
        new value.ExactNumeric[Short] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Short]];
          val nativeValue: Short = result.getShort(index);
        }
      case DataType.INT =>
        new value.ExactNumeric[Int] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Int]];
          val nativeValue: Int = result.getInt(index);
        }
      case DataType.LONG =>
        new value.ExactNumeric[Long] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Long]];
          val nativeValue:Long = result.getLong(index);
        }
      case DataType.BIG_INTEGER =>
        new value.ExactNumeric[BigInteger] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigInteger]];
          val nativeValue: BigInteger = result.getBigDecimal(index).unscaledValue();
        }
      case DataType.BIG_DECIMAL =>
        new value.ExactNumeric[BigDecimal] {
          val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigDecimal]];
          val nativeValue: BigDecimal = result.getBigDecimal(index);
        }

    }
  }

}