forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.h
More file actions
289 lines (244 loc) · 8.69 KB
/
Copy pathType.h
File metadata and controls
289 lines (244 loc) · 8.69 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
* Copyright (c) 2004-2018 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
* Chapman Flack
*/
#ifndef __pljava_type_Type_h
#define __pljava_type_Type_h
#include "pljava/PgObject.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <catalog/pg_type.h>
/*********************************************************************
* The Type class is responsible for data type conversions between the
* Postgres Datum and the Java jvalue. A Type can also perform optimized
* JNI calls that are type dependent (returning primitives) such as
* CallIntMethod(...) or CallBooleanMethod(...). Consequently, the Type
* of the return value of a function is responsible for its invocation.
*
* Types that are not mapped will default to a java.lang.String mapping
* and use the Form_pg_type text conversion routines.
*
* @author Thomas Hallgren
*
*********************************************************************/
struct Type_;
typedef struct Type_* Type;
struct TypeClass_;
typedef struct TypeClass_* TypeClass;
/*
* Returns the TypeClass
*/
extern TypeClass Type_getClass(Type self);
/*
* Returns true if the Type is primitive (i.e. not a real object in
* the Java domain).
*/
extern bool Type_isPrimitive(Type self);
/*
* Returns true if this type uses the same postgres type the other type.
* This is used when explicit java signatures are declared functions to
* verify that the declared Java type is compatible with the SQL type.
*
* At present, the type argument must be either equal to self, or if
* self is a Boolean, Character, or any Number, the primitive that
* corresponds to that number (i.e. java.lang.Short == short).
*/
extern bool Type_canReplaceType(Type self, Type type);
/*
* Translate a given Datum into a jvalue according to the type represented
* by this instance.
*/
extern jvalue Type_coerceDatum(Type self, Datum datum);
/*
* Translate a given Datum into a jvalue, where the type represented
* by this instance is derived from the PG type of the datum, and rqcls, if
* not NULL, is the Java class wanted by the caller (JDBC 4.1 feature).
* Reduces to Type_coerceDatum if rqcls is NULL, or there is no TypeClass that
* can replace this Type and produce the requested class.
*/
extern jvalue Type_coerceDatumAs(Type self, Datum datum, jclass rqcls);
/*
* Translate a given Object into a Datum accorging to the type represented
* by this instance. The caller must be certain that 'object' is an instance
* of a Java type expected by the coercer for this TypeClass.
*/
extern Datum Type_coerceObject(Type self, jobject object);
/*
* Translate a given Object into a Datum accorging to the type represented
* by this instance. The object may be an instance of TypeBridge.Holder holding
* an object of an alternate Java class than what the coercer for this TypeClass
* expects. Otherwise, it must be an object of the expected class, just as for
* Type_coerceObject.
*/
extern Datum Type_coerceObjectBridged(Type self, jobject object);
/*
* Return a Type based on a Postgres Oid. Creates a new type if
* necessary.
*/
extern Type Type_fromOid(Oid typeId, jobject typeMap);
/*
* Return a Type from the Oid cache based on a Postgres Oid. This method
* returns NULL if no such Type is cached.
*/
extern Type Type_fromOidCache(Oid typeId);
/*
* Return a coerce type that can front this type when doing parameter coercion
*/
extern Type Type_getCoerceIn(Type self, Type other);
/*
* Return a coerce type that this type can hand over to when doing result value
* coercion
*/
extern Type Type_getCoerceOut(Type self, Type other);
/*
* Returns true if the type represents the dynamic (any) type.
*/
extern bool Type_isDynamic(Type self);
/*
* Returns the type alignment (i.e. pg_type->typalign).
*/
extern char Type_getAlign(Type self);
/*
* Returns the type length (i.e. pg_type->typlen).
*/
extern int16 Type_getLength(Type self);
/*
* Returns the type length (i.e. pg_type->typlen).
*/
extern jclass Type_getJavaClass(Type self);
/*
* Returns true if the type is passed by value (i.e. pg_type->typbyval).
*/
extern bool Type_isByValue(Type self);
/*
* Returns true if the invocation will create an out parameter (ResultSet typically)
* to collect the return value. If so, the real return value will be a bool.
*/
extern bool Type_isOutParameter(Type self);
/*
* Returns the real type for a dynamic type. A non dynamic type will
* return itself.
*/
extern Type Type_getRealType(Type self, Oid realTypeID, jobject typeMap);
/*
* Return a Type based on a PostgreSQL Oid. If the found
* type is a primitive, return it's object corresponcance
*/
extern Type Type_objectTypeFromOid(Oid typeId, jobject typeMap);
/*
* Return a Type based on a default SQL type and a java type name.
*/
extern Type Type_fromJavaType(Oid dfltType, const char* javaTypeName);
/*
* Returns the Java type name for the Type.
*/
extern const char* Type_getJavaTypeName(Type self);
/*
* Returns the JNI signature for the Type.
*/
extern const char* Type_getJNISignature(Type self);
/*
* Returns the JNI signature used when returning instances
* of this type.
*/
extern const char* Type_getJNIReturnSignature(Type self, bool forMultiCall, bool useAltRepr);
/*
* Returns the array Type. The type is created if it doesn't exist
*/
extern Type Type_getArrayType(Type self, Oid arrayTypeId);
/*
* Returns the element Type if this type is an array.
*/
extern Type Type_getElementType(Type self);
/*
* Returns the object Type if the type is primitive and NULL if not.
*/
extern Type Type_getObjectType(Type self);
/*
* Returns the Oid associated with this type.
*/
extern Oid Type_getOid(Type self);
/*
* Returns the TupleDesc associated with this type.
*/
extern TupleDesc Type_getTupleDesc(Type self, PG_FUNCTION_ARGS);
/*
* Calls a java method using one of the Call<type>MethodA routines where
* <type> corresponds to the type represented by this instance and
* coerces the returned value into a Datum.
*
* The method will set the value pointed to by the wasNull parameter
* to true if the Java method returned null. The method expects that
* the wasNull parameter is set to false by the caller prior to the
* call.
*/
extern Datum Type_invoke(Type self, jclass clazz, jmethodID method, jvalue* args, PG_FUNCTION_ARGS);
/*
* Calls a Set Returning Function (SRF).
*/
extern Datum Type_invokeSRF(Type self, jclass clazz, jmethodID method, jvalue* args, PG_FUNCTION_ARGS);
/*
* Obtains the Java object that acts as the SRF producer. This instance will be
* called once for each row that should be produced.
*/
extern jobject Type_getSRFProducer(Type self, jclass clazz, jmethodID method, jvalue* args);
/*
* Obtains the optional Java object that will act as the value collector for
* the SRF producer. The collector typically manifest itself as an OUT
* parameter of type java.sql.ResultSet in calls to the SRF producer.
*/
extern jobject Type_getSRFCollector(Type self, PG_FUNCTION_ARGS);
/*
* Called to determine if the producer will produce another row.
*/
extern bool Type_hasNextSRF(Type self, jobject producer, jobject collector, jlong counter);
/*
* Converts the next row into a Datum of the expected type.
*/
extern Datum Type_nextSRF(Type self, jobject producer, jobject collector);
/*
* Called at the end of an SRF iteration.
*/
extern void Type_closeSRF(Type self, jobject producer);
/*
* Function used when obtaining a type based on an Oid
* structure. In most cases, this function should return a
* singleton. The only current exception from this is the
* String since it makes use of functions stored in the
* Form_pg_type structure.
*
* In adding JDBC 4.1 support, this is decreed: a TypeObtainer
* may return its singleton, if that's what it does, regardless
* of whether the Oid stored there matches the one passed to the
* obtainer. In other words, it may ignore the typeId argument.
* It's often appropriate for the caller to check the returned
* type with Type_canReplaceType to determine if it is usable
* for the intended purpose.
*/
typedef Type (*TypeObtainer)(Oid typeId);
/*
* Function that can coerce a Datum into a jvalue
*/
typedef jvalue (*DatumCoercer)(Type, Datum);
/*
* Function that can coerce a jobject into a Datum
*/
typedef Datum (*ObjectCoercer)(Type, jobject);
/*
* Register this type as the default mapping for a postgres type.
*/
extern void Type_registerType(const char* javaTypeName, Type type);
extern void Type_registerType2(Oid typeId, const char* javaTypeName, TypeObtainer obtainer);
#ifdef __cplusplus
}
#endif
#endif