jclass Type_getJavaClass(Type self) { TypeClass typeClass = self->typeClass; if(typeClass->javaClass == 0) { jclass cls; const char* cp = typeClass->JNISignature; if(cp == 0 || *cp == 0) ereport(ERROR, ( errmsg("Type '%s' has no corresponding java class", PgObjectClass_getName((PgObjectClass)typeClass)))); if(*cp == 'L') { /* L<object name>; should be just <object name>. Strange * since the L and ; are retained if its an array. */ int len = strlen(cp) - 2; char* bp = palloc(len + 1); memcpy(bp, cp + 1, len); bp[len] = 0; cls = PgObject_getJavaClass(bp); pfree(bp); } else cls = PgObject_getJavaClass(cp); typeClass->javaClass = JNI_newGlobalRef(cls); JNI_deleteLocalRef(cls); } return typeClass->javaClass; }
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; }