Module: SimpleOracleJDBC::TypeMap

Included in:
Binding, OraArray, OraRecord
Defined in:
lib/simple_oracle_jdbc/type_map.rb

Instance Method Summary collapse

Instance Method Details

#java_date_as_date(v) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/simple_oracle_jdbc/type_map.rb', line 4

def java_date_as_date(v)
  if v
    Date.new(v.get_year+1900, v.get_month+1, v.get_date)
  else
    nil
  end
end

#java_date_as_time(v) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/simple_oracle_jdbc/type_map.rb', line 12

def java_date_as_time(v)
  if v
    Time.at(v.get_time.to_f / 1000)
  else
    nil
  end
end

#java_integer_as_integer(v) ⇒ Object



28
29
30
31
# File 'lib/simple_oracle_jdbc/type_map.rb', line 28

def java_integer_as_integer(v)
  # JRuby automatically converts INT to INT

  v
end

#java_number_as_float(v) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/simple_oracle_jdbc/type_map.rb', line 20

def java_number_as_float(v)
  if v
    v.double_value
  else
    nil
  end
end

#java_string_as_string(v) ⇒ Object



33
34
35
36
# File 'lib/simple_oracle_jdbc/type_map.rb', line 33

def java_string_as_string(v)
  # JRubyt automatically converts to a Ruby string

  v
end

#oracle_raw_as_string(v) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/simple_oracle_jdbc/type_map.rb', line 38

def oracle_raw_as_string(v)
  if v
    v.string_value
  else
    nil
  end
end

#ruby_any_date_as_jdbc_date(v) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/simple_oracle_jdbc/type_map.rb', line 62

def ruby_any_date_as_jdbc_date(v)
  if v
    if v.is_a? Date
      ruby_date_as_jdbc_date(v)
    elsif v.is_a? Time
      ruby_time_as_jdbc_timestamp(v)
    else
      raise "#{v.class}: unimplemented Ruby date type for arrays. Use Date or Time"
    end
  else
    nil
  end
end

#ruby_date_as_jdbc_date(v) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/simple_oracle_jdbc/type_map.rb', line 46

def ruby_date_as_jdbc_date(v)
  if v
    jdbc_date = Java::JavaSql::Date.new(v.strftime("%s").to_f * 1000)
  else
    nil
  end
end

#ruby_number_as_jdbc_number(v) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/simple_oracle_jdbc/type_map.rb', line 76

def ruby_number_as_jdbc_number(v)
  if v
    # Avoid warning that appeared in JRuby 1.7.3. There are many signatures of

    # Java::OracleSql::NUMBER and it has to pick one. This causes a warning. This

    # technique works around the warning and forces it to the the signiture with a

    # double input - see https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby

    # under the Constructors section.

    construct = Java::OracleSql::NUMBER.java_class.constructor(Java::double)
    construct.new_instance(v)
  else
    nil
  end
end

#ruby_raw_string_as_jdbc_raw(v) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/simple_oracle_jdbc/type_map.rb', line 90

def ruby_raw_string_as_jdbc_raw(v)
  if v
    Java::OracleSql::RAW.new(v)
  else
    v
  end
end

#ruby_time_as_jdbc_timestamp(v) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/simple_oracle_jdbc/type_map.rb', line 54

def ruby_time_as_jdbc_timestamp(v)
  if v
    TIMESTAMP.new(Java::JavaSql::Timestamp.new(v.to_f * 1000))
  else
    nil
  end
end