void Timestamp_initialize(void) { TypeClass cls; s_Timestamp_class = JNI_newGlobalRef(PgObject_getJavaClass("java/sql/Timestamp")); s_Timestamp_init = PgObject_getJavaMethod(s_Timestamp_class, "<init>", "(J)V"); s_Timestamp_getNanos = PgObject_getJavaMethod(s_Timestamp_class, "getNanos", "()I"); s_Timestamp_getTime = PgObject_getJavaMethod(s_Timestamp_class, "getTime", "()J"); s_Timestamp_setNanos = PgObject_getJavaMethod(s_Timestamp_class, "setNanos", "(I)V"); cls = TypeClass_alloc("type.Timestamp"); cls->JNISignature = "Ljava/sql/Timestamp;"; cls->javaTypeName = "java.sql.Timestamp"; cls->canReplaceType = _Timestamp_canReplaceType; cls->coerceDatum = _Timestamp_coerceDatum; cls->coerceObject = _Timestamp_coerceObject; Type_registerType(0, TypeClass_allocInstance(cls, TIMESTAMPOID)); s_TimestampClass = cls; cls = TypeClass_alloc("type.Timestamptz"); cls->JNISignature = "Ljava/sql/Timestamp;"; cls->javaTypeName = "java.sql.Timestamp"; cls->canReplaceType = _Timestamptz_canReplaceType; cls->coerceDatum = _Timestamptz_coerceDatum; cls->coerceObject = _Timestamptz_coerceObject; Type_registerType("java.sql.Timestamp", TypeClass_allocInstance(cls, TIMESTAMPTZOID)); s_TimestamptzClass = cls; }
void Double_initialize(void) { Type t_double; Type t_Double; TypeClass cls; s_Double_class = JNI_newGlobalRef(PgObject_getJavaClass("java/lang/Double")); s_DoubleArray_class = JNI_newGlobalRef(PgObject_getJavaClass("[Ljava/lang/Double;")); s_Double_init = PgObject_getJavaMethod(s_Double_class, "<init>", "(D)V"); s_Double_doubleValue = PgObject_getJavaMethod(s_Double_class, "doubleValue", "()D"); cls = TypeClass_alloc("type.Double"); cls->canReplaceType = _Double_canReplace; cls->JNISignature = "Ljava/lang/Double;"; cls->javaTypeName = "java.lang.Double"; cls->coerceDatum = _Double_coerceDatum; cls->coerceObject = _Double_coerceObject; t_Double = TypeClass_allocInstance(cls, FLOAT8OID); cls = TypeClass_alloc("type.double"); cls->JNISignature = "D"; cls->javaTypeName = "double"; cls->invoke = _double_invoke; cls->coerceDatum = _double_coerceDatum; cls->coerceObject = _Double_coerceObject; cls->createArrayType = _double_createArrayType; s_doubleClass = cls; t_double = TypeClass_allocInstance(cls, FLOAT8OID); t_double->objectType = t_Double; Type_registerType("double", t_double); Type_registerType("java.lang.Double", t_Double); }
void Boolean_initialize(void) { Type t_boolean; Type t_Boolean; TypeClass cls; s_Boolean_class = JNI_newGlobalRef(PgObject_getJavaClass("java/lang/Boolean")); s_Boolean_init = PgObject_getJavaMethod(s_Boolean_class, "<init>", "(Z)V"); s_Boolean_booleanValue = PgObject_getJavaMethod(s_Boolean_class, "booleanValue", "()Z"); cls = TypeClass_alloc("type.Boolean"); cls->canReplaceType = _Boolean_canReplace; cls->JNISignature = "Ljava/lang/Boolean;"; cls->javaTypeName = "java.lang.Boolean"; cls->coerceDatum = _Boolean_coerceDatum; cls->coerceObject = _Boolean_coerceObject; t_Boolean = TypeClass_allocInstance(cls, BOOLOID); cls = TypeClass_alloc("type.boolean"); cls->JNISignature = "Z"; cls->javaTypeName = "boolean"; cls->invoke = _boolean_invoke; cls->coerceDatum = _boolean_coerceDatum; cls->coerceObject = _Boolean_coerceObject; cls->createArrayType = _boolean_createArrayType; s_booleanClass = cls; t_boolean = TypeClass_allocInstance(cls, BOOLOID); t_boolean->objectType = t_Boolean; Type_registerType("boolean", t_boolean); Type_registerType("java.lang.Boolean", t_Boolean); }
void Integer_initialize(void) { Type t_int; Type t_Integer; TypeClass cls; s_Integer_class = JNI_newGlobalRef(PgObject_getJavaClass("java/lang/Integer")); s_Integer_init = PgObject_getJavaMethod(s_Integer_class, "<init>", "(I)V"); s_Integer_intValue = PgObject_getJavaMethod(s_Integer_class, "intValue", "()I"); cls = TypeClass_alloc("type.Integer"); cls->canReplaceType = _Integer_canReplace; cls->JNISignature = "Ljava/lang/Integer;"; cls->javaTypeName = "java.lang.Integer"; cls->coerceDatum = _Integer_coerceDatum; cls->coerceObject = _Integer_coerceObject; t_Integer = TypeClass_allocInstance(cls, INT4OID); cls = TypeClass_alloc("type.int"); cls->JNISignature = "I"; cls->javaTypeName = "int"; cls->invoke = _int_invoke; cls->coerceDatum = _int_coerceDatum; cls->coerceObject = _Integer_coerceObject; cls->createArrayType = _int_createArrayType; s_intClass = cls; t_int = TypeClass_allocInstance(cls, INT4OID); t_int->objectType = t_Integer; Type_registerType("int", t_int); Type_registerType("java.lang.Integer", t_Integer); }
void Tuple_initialize(void) { TypeClass cls; JNINativeMethod methods[] = { { "_getObject", "(JJILjava/lang/Class;)Ljava/lang/Object;", Java_org_postgresql_pljava_internal_Tuple__1getObject }, { "_free", "(J)V", Java_org_postgresql_pljava_internal_Tuple__1free }, { 0, 0, 0 }}; s_Tuple_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/Tuple")); PgObject_registerNatives2(s_Tuple_class, methods); s_Tuple_init = PgObject_getJavaMethod(s_Tuple_class, "<init>", "(J)V"); cls = JavaWrapperClass_alloc("type.Tuple"); cls->JNISignature = "Lorg/postgresql/pljava/internal/Tuple;"; cls->javaTypeName = "org.postgresql.pljava.internal.Tuple"; cls->coerceDatum = _Tuple_coerceDatum; Type_registerType("org.postgresql.pljava.internal.Tuple", TypeClass_allocInstance(cls, InvalidOid)); }
Type Array_fromOid2(Oid typeId, Type elementType, DatumCoercer coerceDatum, ObjectCoercer coerceObject) { Type self; TypeClass arrayClass; const char* elemClassName = PgObjectClass_getName(PgObject_getClass((PgObject)elementType)); const char* elemJNISignature = Type_getJNISignature(elementType); const char* elemJavaTypeName = Type_getJavaTypeName(elementType); MemoryContext currCtx = MemoryContextSwitchTo(TopMemoryContext); char* tmp = palloc(strlen(elemClassName) + 3); sprintf(tmp, "%s[]", elemClassName); arrayClass = TypeClass_alloc(tmp); tmp = palloc(strlen(elemJNISignature) + 2); sprintf(tmp, "[%s", elemJNISignature); arrayClass->JNISignature = tmp; tmp = palloc(strlen(elemJavaTypeName) + 3); sprintf(tmp, "%s[]", elemJavaTypeName); arrayClass->javaTypeName = tmp; arrayClass->coerceDatum = coerceDatum; arrayClass->coerceObject = coerceObject; arrayClass->canReplaceType = _Array_canReplaceType; self = TypeClass_allocInstance(arrayClass, typeId); MemoryContextSwitchTo(currCtx); self->elementType = elementType; Type_registerType(arrayClass->javaTypeName, self); if(Type_isPrimitive(elementType)) self->objectType = Array_fromOid(typeId, Type_getObjectType(elementType)); return self; }
static String String_create(TypeClass cls, Oid typeId) { HeapTuple typeTup = PgObject_getValidTuple(TYPEOID, typeId, "type"); Form_pg_type pgType = (Form_pg_type)GETSTRUCT(typeTup); String self = (String)TypeClass_allocInstance(cls, typeId); MemoryContext ctx = GetMemoryChunkContext(self); fmgr_info_cxt(pgType->typoutput, &self->textOutput, ctx); fmgr_info_cxt(pgType->typinput, &self->textInput, ctx); self->elementType = pgType->typelem; ReleaseSysCache(typeTup); return self; }
void byte_array_initialize(void) { TypeClass cls = TypeClass_alloc("type.byte[]"); cls->JNISignature = "[B"; cls->javaTypeName = "byte[]"; cls->coerceDatum = _byte_array_coerceDatum; cls->coerceObject = _byte_array_coerceObject; Type_registerType("byte[]", TypeClass_allocInstance(cls, BYTEAOID)); s_byteArray_class = JNI_newGlobalRef(PgObject_getJavaClass("[B")); s_BlobValue_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/jdbc/BlobValue")); s_BlobValue_length = PgObject_getJavaMethod(s_BlobValue_class, "length", "()J"); s_BlobValue_getContents = PgObject_getJavaMethod(s_BlobValue_class, "getContents", "(Ljava/nio/ByteBuffer;)V"); }
void TupleDesc_initialize(void) { TypeClass cls; JNINativeMethod methods[] = { { "_getColumnName", "(JI)Ljava/lang/String;", Java_org_postgresql_pljava_internal_TupleDesc__1getColumnName }, { "_getColumnIndex", "(JLjava/lang/String;)I", Java_org_postgresql_pljava_internal_TupleDesc__1getColumnIndex }, { "_formTuple", "(J[Ljava/lang/Object;)Lorg/postgresql/pljava/internal/Tuple;", Java_org_postgresql_pljava_internal_TupleDesc__1formTuple }, { "_getOid", "(JI)Lorg/postgresql/pljava/internal/Oid;", Java_org_postgresql_pljava_internal_TupleDesc__1getOid }, { "_free", "(J)V", Java_org_postgresql_pljava_internal_TupleDesc__1free }, { 0, 0, 0 }}; s_TupleDesc_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/TupleDesc")); PgObject_registerNatives2(s_TupleDesc_class, methods); s_TupleDesc_init = PgObject_getJavaMethod(s_TupleDesc_class, "<init>", "(JI)V"); cls = JavaWrapperClass_alloc("type.TupleDesc"); cls->JNISignature = "Lorg/postgresql/pljava/internal/TupleDesc;"; cls->javaTypeName = "org.postgresql.pljava.internal.TupleDesc"; cls->coerceDatum = _TupleDesc_coerceDatum; Type_registerType("org.postgresql.pljava.internal.TupleDesc", TypeClass_allocInstance(cls, InvalidOid)); }
void TriggerData_initialize(void) { TypeClass cls; JNINativeMethod methods[] = { { "_free", "(J)V", Java_org_postgresql_pljava_internal_TriggerData__1free }, { "_getRelation", "(J)Lorg/postgresql/pljava/internal/Relation;", Java_org_postgresql_pljava_internal_TriggerData__1getRelation }, { "_getTriggerTuple", "(J)Lorg/postgresql/pljava/internal/Tuple;", Java_org_postgresql_pljava_internal_TriggerData__1getTriggerTuple }, { "_getNewTuple", "(J)Lorg/postgresql/pljava/internal/Tuple;", Java_org_postgresql_pljava_internal_TriggerData__1getNewTuple }, { "_getArguments", "(J)[Ljava/lang/String;", Java_org_postgresql_pljava_internal_TriggerData__1getArguments }, { "_getName", "(J)Ljava/lang/String;", Java_org_postgresql_pljava_internal_TriggerData__1getName }, { "_isFiredAfter", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredAfter }, { "_isFiredBefore", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredBefore }, { "_isFiredForEachRow", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredForEachRow }, { "_isFiredForStatement", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredForStatement }, { "_isFiredByDelete", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredByDelete }, { "_isFiredByInsert", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredByInsert }, { "_isFiredByUpdate", "(J)Z", Java_org_postgresql_pljava_internal_TriggerData__1isFiredByUpdate }, { 0, 0, 0 } }; s_TriggerData_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/TriggerData")); PgObject_registerNatives2(s_TriggerData_class, methods); s_TriggerData_init = PgObject_getJavaMethod(s_TriggerData_class, "<init>", "(J)V"); s_TriggerData_getTriggerReturnTuple = PgObject_getJavaMethod(s_TriggerData_class, "getTriggerReturnTuple", "()J"); /* Use interface name for signatures. */ cls = TypeClass_alloc("type.TriggerData"); cls->JNISignature = "Lorg/postgresql/pljava/TriggerData;"; cls->javaTypeName = "org.postgresql.pljava.TriggerData"; Type_registerType("org.postgresql.pljava.TriggerData", TypeClass_allocInstance(cls, InvalidOid)); }
void LargeObject_initialize(void) { TypeClass cls; JNINativeMethod methods[] = { { "_create", "(I)Lorg/postgresql/pljava/internal/Oid;", Java_org_postgresql_pljava_internal_LargeObject__1create }, { "_drop", "(Lorg/postgresql/pljava/internal/Oid;)I", Java_org_postgresql_pljava_internal_LargeObject__1drop }, { "_open", "(Lorg/postgresql/pljava/internal/Oid;I)Lorg/postgresql/pljava/internal/LargeObject;", Java_org_postgresql_pljava_internal_LargeObject__1open }, { "_close", "(J)V", Java_org_postgresql_pljava_internal_LargeObject__1close }, { "_getId", "(J)Lorg/postgresql/pljava/internal/Oid;", Java_org_postgresql_pljava_internal_LargeObject__1getId }, { "_length", "(J)J", Java_org_postgresql_pljava_internal_LargeObject__1length }, { "_seek", "(JJI)J", Java_org_postgresql_pljava_internal_LargeObject__1seek }, { "_tell", "(J)J", Java_org_postgresql_pljava_internal_LargeObject__1tell }, { "_truncate", "(JJ)V", Java_org_postgresql_pljava_internal_LargeObject__1truncate }, { "_read", "(J[B)I", Java_org_postgresql_pljava_internal_LargeObject__1read }, { "_write", "(J[B)I", Java_org_postgresql_pljava_internal_LargeObject__1write }, { 0, 0, 0 } }; s_LargeObject_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/internal/LargeObject")); PgObject_registerNatives2(s_LargeObject_class, methods); s_LargeObject_init = PgObject_getJavaMethod(s_LargeObject_class, "<init>", "(J)V"); cls = TypeClass_alloc("type.LargeObject"); cls->JNISignature = "Lorg/postgresql/pljava/internal/LargeObject;"; cls->javaTypeName = "org.postgresql.pljava.internal.LargeObject"; Type_registerType("org.postgresql.pljava.internal.LargeObject", TypeClass_allocInstance(cls, InvalidOid)); }