forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPI.java
More file actions
179 lines (170 loc) · 4.17 KB
/
Copy pathSPI.java
File metadata and controls
179 lines (170 loc) · 4.17 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright (c) 2004, 2005, 2006 TADA AB - Taby Sweden
* Distributed under the terms shown in the file COPYRIGHT
* found in the root folder of this project or at
* http://eng.tada.se/osprojects/COPYRIGHT.html
*/
package org.postgresql.pljava.internal;
/**
* The <code>SPI</code> class provides access to some global
* variables used by SPI.
*
* @author Thomas Hallgren
*/
public class SPI
{
public static final int ERROR_CONNECT = -1;
public static final int ERROR_COPY = -2;
public static final int ERROR_OPUNKNOWN = -3;
public static final int ERROR_UNCONNECTED = -4;
public static final int ERROR_CURSOR = -5;
public static final int ERROR_ARGUMENT = -6;
public static final int ERROR_PARAM = -7;
public static final int ERROR_TRANSACTION = -8;
public static final int ERROR_NOATTRIBUTE = -9;
public static final int ERROR_NOOUTFUNC = -10;
public static final int ERROR_TYPUNKNOWN = -11;
public static final int OK_CONNECT = 1;
public static final int OK_FINISH = 2;
public static final int OK_FETCH = 3;
public static final int OK_UTILITY = 4;
public static final int OK_SELECT = 5;
public static final int OK_SELINTO = 6;
public static final int OK_INSERT = 7;
public static final int OK_DELETE = 8;
public static final int OK_UPDATE = 9;
public static final int OK_CURSOR = 10;
/**
* Execute a command using the internal <code>SPI_exec</code> function.
* @param command The command to execute.
* @param rowCount The maximum number of tuples to create. A value
* of <code>rowCount</code> of zero is interpreted as no limit, i.e.,
* run to completion.
* @return One of the declared status codes.
*/
public static int exec(String command, int rowCount)
{
synchronized(Backend.THREADLOCK)
{
return _exec(System.identityHashCode(Thread.currentThread()), command, rowCount);
}
}
public static void freeTupTable()
{
synchronized(Backend.THREADLOCK)
{
_freeTupTable();
}
}
/**
* Returns the value of the global variable <code>SPI_processed</code>.
*/
public static int getProcessed()
{
synchronized(Backend.THREADLOCK)
{
return _getProcessed();
}
}
/**
* Returns the value of the global variable <code>SPI_result</code>.
*/
public static int getResult()
{
synchronized(Backend.THREADLOCK)
{
return _getResult();
}
}
/**
* Returns the value of the global variable <code>SPI_tuptable</code>.
*/
public static TupleTable getTupTable(TupleDesc known)
{
synchronized(Backend.THREADLOCK)
{
return _getTupTable(known);
}
}
/**
* Returns a textual representatio of a result code
*/
public static String getResultText(int resultCode)
{
String s;
switch(resultCode)
{
case ERROR_CONNECT:
s = "ERROR_CONNECT";
break;
case ERROR_COPY:
s = "ERROR_COPY";
break;
case ERROR_OPUNKNOWN:
s = "ERROR_OPUNKNOWN";
break;
case ERROR_UNCONNECTED:
s = "ERROR_UNCONNECTED";
break;
case ERROR_CURSOR:
s = "ERROR_CURSOR";
break;
case ERROR_ARGUMENT:
s = "ERROR_ARGUMENT";
break;
case ERROR_PARAM:
s = "ERROR_PARAM";
break;
case ERROR_TRANSACTION:
s = "ERROR_TRANSACTION";
break;
case ERROR_NOATTRIBUTE:
s = "ERROR_NOATTRIBUTE";
break;
case ERROR_NOOUTFUNC:
s = "ERROR_NOOUTFUNC";
break;
case ERROR_TYPUNKNOWN:
s = "ERROR_TYPUNKNOWN";
break;
case OK_CONNECT:
s = "OK_CONNECT";
break;
case OK_FINISH:
s = "OK_FINISH";
break;
case OK_FETCH:
s = "OK_FETCH";
break;
case OK_UTILITY:
s = "OK_UTILITY";
break;
case OK_SELECT:
s = "OK_SELECT";
break;
case OK_SELINTO:
s = "OK_SELINTO";
break;
case OK_INSERT:
s = "OK_INSERT";
break;
case OK_DELETE:
s = "OK_DELETE";
break;
case OK_UPDATE:
s = "OK_UPDATE";
break;
case OK_CURSOR:
s = "OK_CURSOR";
break;
default:
s = "Unkown result code: " + resultCode;
}
return s;
}
private native static int _exec(long threadId, String command, int rowCount);
private native static int _getProcessed();
private native static int _getResult();
private native static void _freeTupTable();
private native static TupleTable _getTupTable(TupleDesc known);
}