forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTupleTable.c
More file actions
75 lines (60 loc) · 2 KB
/
Copy pathTupleTable.c
File metadata and controls
75 lines (60 loc) · 2 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
/*
* 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 "pljava/type/Type_priv.h"
#include "pljava/type/TupleTable.h"
#include "pljava/type/Tuple.h"
#include "pljava/type/TupleDesc.h"
static jclass s_TupleTable_class;
static jmethodID s_TupleTable_init;
jobject TupleTable_createFromSlot(TupleTableSlot* tts)
{
HeapTuple tuple;
jobject tupdesc;
jobjectArray tuples;
MemoryContext curr;
if(tts == 0)
return 0;
curr = MemoryContextSwitchTo(JavaMemoryContext);
#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER == 0)
tupdesc = TupleDesc_internalCreate(tts->ttc_tupleDescriptor);
tuple = heap_copytuple(tts->val);
#else
tupdesc = TupleDesc_internalCreate(tts->tts_tupleDescriptor);
tuple = ExecCopySlotTuple(tts);
#endif
tuples = Tuple_createArray(&tuple, 1, false);
MemoryContextSwitchTo(curr);
return JNI_newObject(s_TupleTable_class, s_TupleTable_init, tupdesc, tuples);
}
jobject TupleTable_create(SPITupleTable* tts, jobject knownTD)
{
jobjectArray tuples;
MemoryContext curr;
if(tts == 0)
return 0;
curr = MemoryContextSwitchTo(JavaMemoryContext);
if(knownTD == 0)
knownTD = TupleDesc_internalCreate(tts->tupdesc);
tuples = Tuple_createArray(tts->vals, (jint)(tts->alloced - tts->free), true);
MemoryContextSwitchTo(curr);
return JNI_newObject(s_TupleTable_class, s_TupleTable_init, knownTD, tuples);
}
/* Make this datatype available to the postgres system.
*/
extern void TupleTable_initialize(void);
void TupleTable_initialize(void)
{
s_TupleTable_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/TupleTable"));
s_TupleTable_init = PgObject_getJavaMethod(
s_TupleTable_class, "<init>",
"(Lorg/postgresql/pljava/internal/TupleDesc;[Lorg/postgresql/pljava/internal/Tuple;)V");
}