-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.java
More file actions
104 lines (87 loc) · 3.28 KB
/
Function.java
File metadata and controls
104 lines (87 loc) · 3.28 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
package javaxt.sql;
//******************************************************************************
//** Function Class
//******************************************************************************
/**
* The Function class is used to encapsulate SQL functions when inserting or
* updating records via the javaxt.sql.Recordset class. Example:
<pre>
rs.setValue("LAST_UPDATE", new javaxt.sql.Function("NOW()"));
rs.setValue("DATEDIFF_TEST", new javaxt.sql.Function("DATEDIFF(year, '2012/04/28', '2014/04/28')"));
</pre>
*
* Note that functions can be parameterized using standard JDBC syntax using
* question marks (? characters) like this:
<pre>
JSONObject json = new JSONObject();
rs.setValue("info", new javaxt.sql.Function("?::jsonb", json.toString()));
</pre>
*
* Parameterizing values is especially useful when dealing with strings and
* other values that may have invalid characters. It is also extremely useful
* when performing batch inserts.
*
******************************************************************************/
public class Function {
private String function;
private Object[] values;
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class using a function (e.g. "NOW()")
*/
public Function(String function){
this.function = function;
}
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class using a parameterized function.
*/
public Function(String function, Object... values){
this.function = function;
try{
if (values[0] instanceof Object[]){
values = (Object[]) values[0];
}
}
catch(Exception e){
}
this.values = values;
}
//**************************************************************************
//** getFunction
//**************************************************************************
/** Returns the function supplied in the constructor
*/
public String getFunction(){
return function;
}
//**************************************************************************
//** hasValues
//**************************************************************************
/** Returns true if values were supplied to the constructor
*/
public boolean hasValues(){
if (values!=null){
return (values.length>0);
}
return false;
}
//**************************************************************************
//** getValues
//**************************************************************************
/** Returns an array of values that were supplied in the constructor
*/
public Object[] getValues(){
return values;
}
//**************************************************************************
//** toString
//**************************************************************************
/** Returns the function supplied in the constructor
*/
public String toString(){
return function;
}
}