forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubXactListener.c
More file actions
113 lines (105 loc) · 3.19 KB
/
Copy pathSubXactListener.c
File metadata and controls
113 lines (105 loc) · 3.19 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
/*
* 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 "pljava/Backend.h"
#include "pljava/Exception.h"
#include "pljava/SPI.h"
#include "org_postgresql_pljava_internal_SubXactListener.h"
#include <access/xact.h>
static jclass s_SubXactListener_class;
static jmethodID s_SubXactListener_onStart;
static jmethodID s_SubXactListener_onCommit;
static jmethodID s_SubXactListener_onAbort;
static void subXactCB(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void* arg)
{
Ptr2Long p2l;
p2l.longVal = 0L; /* ensure that the rest is zeroed out */
p2l.ptrVal = arg;
switch(event)
{
case SUBXACT_EVENT_START_SUB:
{
Ptr2Long infant2l;
infant->xid = mySubid;
infant2l.longVal = 0L; /* ensure that the rest is zeroed out */
infant2l.ptrVal = infant;
JNI_callStaticVoidMethod(s_SubXactListener_class, s_SubXactListener_onStart, p2l.longVal, infant2l.longVal, parentSubid);
}
break;
case SUBXACT_EVENT_COMMIT_SUB:
JNI_callStaticVoidMethod(s_SubXactListener_class, s_SubXactListener_onCommit, p2l.longVal, mySubid, parentSubid);
break;
case SUBXACT_EVENT_ABORT_SUB:
JNI_callStaticVoidMethod(s_SubXactListener_class, s_SubXactListener_onAbort, p2l.longVal, mySubid, parentSubid);
}
}
extern void SubXactListener_initialize(void);
void SubXactListener_initialize(void)
{
JNINativeMethod methods[] = {
{
"_register",
"(J)V",
Java_org_postgresql_pljava_internal_SubXactListener__1register
},
{
"_unregister",
"(J)V",
Java_org_postgresql_pljava_internal_SubXactListener__1unregister
},
{ 0, 0, 0 }};
PgObject_registerNatives("org/postgresql/pljava/internal/SubXactListener", methods);
s_SubXactListener_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/SubXactListener"));
s_SubXactListener_onAbort = PgObject_getStaticJavaMethod(s_SubXactListener_class, "onAbort", "(JII)V");
s_SubXactListener_onCommit = PgObject_getStaticJavaMethod(s_SubXactListener_class, "onCommit", "(JII)V");
s_SubXactListener_onStart = PgObject_getStaticJavaMethod(s_SubXactListener_class, "onStart", "(JJI)V");
}
/*
* Class: org_postgresql_pljava_internal_SubXactListener
* Method: _register
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_org_postgresql_pljava_internal_SubXactListener__1register(JNIEnv* env, jclass cls, jlong listenerId)
{
BEGIN_NATIVE
PG_TRY();
{
Ptr2Long p2l;
p2l.longVal = listenerId;
RegisterSubXactCallback(subXactCB, p2l.ptrVal);
}
PG_CATCH();
{
Exception_throw_ERROR("RegisterSubXactCallback");
}
PG_END_TRY();
END_NATIVE
}
/*
* Class: org_postgresql_pljava_internal_SubXactListener
* Method: _unregister
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_org_postgresql_pljava_internal_SubXactListener__1unregister(JNIEnv* env, jclass cls, jlong listenerId)
{
BEGIN_NATIVE
PG_TRY();
{
Ptr2Long p2l;
p2l.longVal = listenerId;
UnregisterSubXactCallback(subXactCB, p2l.ptrVal);
}
PG_CATCH();
{
Exception_throw_ERROR("UnregisterSubXactCallback");
}
PG_END_TRY();
END_NATIVE
}