-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValue.java
More file actions
109 lines (97 loc) · 3.55 KB
/
Value.java
File metadata and controls
109 lines (97 loc) · 3.55 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package javaxt.sql;
//******************************************************************************
//** Value Class
//******************************************************************************
/**
* Used to represent a value for a given field in the database. The value can
* be converted into a number of Java primatives (strings, integers, doubles,
* booleans, etc).
*
******************************************************************************/
public class Value extends javaxt.utils.Value {
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of Value. */
public Value(Object value){
super(value);
}
//**************************************************************************
//** toTimeStamp
//**************************************************************************
/** Returns the value as a java.sql.Timestamp. Returns a null if there was a
* problem converting the value to a Timestamp or if the value is null.
*/
public java.sql.Timestamp toTimeStamp(){
Object obj = super.toObject();
if (obj!=null){
if (obj instanceof java.sql.Timestamp){
return (java.sql.Timestamp) obj;
}
else{
javaxt.utils.Date date = toDate();
if (date!=null){
return new java.sql.Timestamp(date.getDate().getTime());
}
}
}
return null;
}
//**************************************************************************
//** toArray
//**************************************************************************
/** If the value is a java.sql.Array, returns the output from the
* java.sql.Array.getArray() method. Returns a null if there was a problem
* converting the value to a java.sql.Array or if the value is null.
*/
public Object toArray(){
Object obj = super.toObject();
if (obj!=null){
try{
return ((java.sql.Array) obj).getArray();
}
catch(Exception e){
}
}
return null;
}
//**************************************************************************
//** toString
//**************************************************************************
/** Returns the value as a String. Returns a null if there was a problem
* converting the value to a String or if the value is null.
*/
public String toString(){
Object obj = super.toObject();
if (obj!=null){
if (obj instanceof java.sql.Clob){
String str = null;
java.sql.Clob clob = (java.sql.Clob) obj;
try{
long len = clob.length();
if (len < Integer.MIN_VALUE || len > Integer.MAX_VALUE){
//CLOB size too big for String!
}
else{
str = clob.getSubString(1, (int) clob.length());
}
}
catch(Exception e){
}
finally{
if (clob!=null){
try{
clob.free();
}
catch(Exception e){}
}
}
return str;
}
else{
return obj.toString();
}
}
return null;
}
}