-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathTupleReturn.java
More file actions
89 lines (77 loc) · 2.4 KB
/
Copy pathTupleReturn.java
File metadata and controls
89 lines (77 loc) · 2.4 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
/*
* Copyright (c) 2004-2013 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Tada AB
*/
package org.postgresql.pljava.example;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.postgresql.pljava.ResultSetProvider;
/**
* Illustrates various methods of returning composite values.
* @author Thomas Hallgren
*/
public class TupleReturn implements ResultSetProvider {
public static String makeString(ResultSet _testSetReturn)
throws SQLException {
int base = _testSetReturn.getInt(1);
int incbase = _testSetReturn.getInt(2);
Timestamp ctime = _testSetReturn.getTimestamp(3);
return "Base = \"" + base + "\", incbase = \"" + incbase
+ "\", ctime = \"" + ctime + "\"";
}
public static ResultSetProvider setReturn(int base, int increment)
throws SQLException {
return new TupleReturn(base, increment);
}
public static boolean tupleReturn(int base, int increment,
ResultSet receiver) throws SQLException {
receiver.updateInt(1, base);
receiver.updateInt(2, base + increment);
receiver.updateTimestamp(3, new Timestamp(System.currentTimeMillis()));
return true;
}
public static boolean tupleReturn(Integer base, Integer increment,
ResultSet receiver) throws SQLException {
if (base == null) {
receiver.updateNull(1);
receiver.updateNull(2);
} else {
receiver.updateInt(1, base.intValue());
if (increment == null)
receiver.updateNull(2);
else
receiver.updateInt(2, base.intValue() + increment.intValue());
}
receiver.updateTimestamp(3, new Timestamp(System.currentTimeMillis()));
return true;
}
private final int m_base;
private final int m_increment;
public TupleReturn(int base, int increment) {
m_base = base;
m_increment = increment;
}
@Override
public boolean assignRowValues(ResultSet receiver, int currentRow)
throws SQLException {
// Stop when we reach 12 rows.
//
if (currentRow >= 12)
return false;
receiver.updateInt(1, m_base);
receiver.updateInt(2, m_base + m_increment * currentRow);
receiver.updateTimestamp(3, new Timestamp(System.currentTimeMillis()));
return true;
}
@Override
public void close() {
}
}