forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPgSavepoint.c
More file actions
174 lines (167 loc) · 3.7 KB
/
Copy pathPgSavepoint.c
File metadata and controls
174 lines (167 loc) · 3.7 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
/*
* 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
*
* @author Thomas Hallgren
*/
#include <postgres.h>
#include <executor/spi.h>
#include <executor/tuptable.h>
#include "org_postgresql_pljava_internal_PgSavepoint.h"
#include "pljava/Exception.h"
#include "pljava/type/String.h"
#include "pljava/SPI.h"
extern void PgSavepoint_initialize(void);
void PgSavepoint_initialize(void)
{
JNINativeMethod methods[] =
{
{
"_set",
"(Ljava/lang/String;)J",
Java_org_postgresql_pljava_internal_PgSavepoint__1set
},
{
"_release",
"(J)V",
Java_org_postgresql_pljava_internal_PgSavepoint__1release
},
{
"_rollback",
"(J)V",
Java_org_postgresql_pljava_internal_PgSavepoint__1rollback
},
{
"_getName",
"(J)Ljava/lang/String;",
Java_org_postgresql_pljava_internal_PgSavepoint__1getName
},
{
"_getId",
"(J)I",
Java_org_postgresql_pljava_internal_PgSavepoint__1getId
},
{ 0, 0, 0 }
};
PgObject_registerNatives("org/postgresql/pljava/internal/PgSavepoint", methods);
}
/****************************************
* JNI methods
****************************************/
/*
* Class: org_postgresql_pljava_internal_PgSavepoint
* Method: _set
* Signature: (Ljava/lang/String;)J;
*/
JNIEXPORT jlong JNICALL
Java_org_postgresql_pljava_internal_PgSavepoint__1set(JNIEnv* env, jclass cls, jstring jname)
{
jlong result = 0;
BEGIN_NATIVE
PG_TRY();
{
Ptr2Long p2l;
char* name = String_createNTS(jname);
MemoryContext currCtx = MemoryContextSwitchTo(JavaMemoryContext);
p2l.longVal = 0L; /* ensure that the rest is zeroed out */
p2l.ptrVal = SPI_setSavepoint(name);
result = p2l.longVal;
MemoryContextSwitchTo(currCtx);
pfree(name);
}
PG_CATCH();
{
Exception_throw_ERROR("SPI_setSavepoint");
}
PG_END_TRY();
END_NATIVE
return result;
}
/*
* Class: org_postgresql_pljava_internal_PgSavepoint
* Method: _getName
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_org_postgresql_pljava_internal_PgSavepoint__1getName(JNIEnv* env, jclass clazz, jlong _this)
{
jstring result = 0;
if(_this != 0)
{
BEGIN_NATIVE
Ptr2Long p2l;
p2l.longVal = _this;
result = String_createJavaStringFromNTS(((Savepoint*)p2l.ptrVal)->name);
END_NATIVE
}
return result;
}
/*
* Class: org_postgresql_pljava_internal_PgSavepoint
* Method: _getId
* Signature: (J)I
*/
JNIEXPORT jint JNICALL
Java_org_postgresql_pljava_internal_PgSavepoint__1getId(JNIEnv* env, jclass clazz, jlong _this)
{
jint result = (jint)InvalidSubTransactionId;
if(_this != 0)
{
Ptr2Long p2l;
p2l.longVal = _this;
result = (jint)((Savepoint*)p2l.ptrVal)->xid;
}
return result;
}
/*
* Class: org_postgresql_pljava_internal_PgSavepoint
* Method: _release
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_org_postgresql_pljava_internal_PgSavepoint__1release(JNIEnv* env, jclass clazz, jlong _this)
{
if(_this != 0)
{
BEGIN_NATIVE
Ptr2Long p2l;
p2l.longVal = _this;
PG_TRY();
{
SPI_releaseSavepoint((Savepoint*)p2l.ptrVal);
}
PG_CATCH();
{
Exception_throw_ERROR("SPI_releaseSavepoint");
}
PG_END_TRY();
END_NATIVE
}
}
/*
* Class: org_postgresql_pljava_internal_PgSavepoint
* Method: _rollback
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_org_postgresql_pljava_internal_PgSavepoint__1rollback(JNIEnv* env, jclass clazz, jlong _this)
{
if(_this != 0)
{
BEGIN_NATIVE
Ptr2Long p2l;
p2l.longVal = _this;
PG_TRY();
{
SPI_rollbackSavepoint((Savepoint*)p2l.ptrVal);
}
PG_CATCH();
{
Exception_throw_ERROR("SPI_rollbackSavepoint");
}
PG_END_TRY();
END_NATIVE
}
}