Type Type_getCoerceIn(Type self, Type other) { Oid funcId; Type coerce; Oid fromOid = other->typeId; Oid toOid = self->typeId; if(self->inCoercions != 0) { coerce = HashMap_getByOid(self->inCoercions, fromOid); if(coerce != 0) return coerce; } if (!find_coercion_pathway(toOid, fromOid, COERCION_EXPLICIT, &funcId)) { elog(ERROR, "no conversion function from %s to %s", format_type_be(fromOid), format_type_be(toOid)); } if(funcId == InvalidOid) /* * Binary compatible type. No need for a special coercer */ return self; if(self->inCoercions == 0) self->inCoercions = HashMap_create(7, GetMemoryChunkContext(self)); coerce = Coerce_createIn(self, other, funcId); HashMap_putByOid(self->inCoercions, fromOid, coerce); return coerce; }
Function Function_getFunction(PG_FUNCTION_ARGS) { Oid funcOid = fcinfo->flinfo->fn_oid; Function func = (Function)HashMap_getByOid(s_funcMap, funcOid); if(func == 0) { func = Function_create(fcinfo); HashMap_putByOid(s_funcMap, funcOid, func); } return func; }
/* * Register this type. */ static void _registerType(Oid typeId, const char* javaTypeName, Type type, TypeObtainer obtainer) { CacheEntry ce = (CacheEntry)MemoryContextAlloc(TopMemoryContext, sizeof(CacheEntryData)); ce->typeId = typeId; ce->type = type; ce->obtainer = obtainer; if(javaTypeName != 0) HashMap_putByString(s_obtainerByJavaName, javaTypeName, ce); if(typeId != InvalidOid && HashMap_getByOid(s_obtainerByOid, typeId) == 0) HashMap_putByOid(s_obtainerByOid, typeId, ce); }
void Type_cacheByOid(Oid typeId, Type type) { HashMap_putByOid(s_typeByOid, typeId, type); }