void Type_initialize(void) { s_typeByOid = HashMap_create(59, TopMemoryContext); s_obtainerByOid = HashMap_create(59, TopMemoryContext); s_obtainerByJavaName = HashMap_create(59, TopMemoryContext); String_initialize(); Any_initialize(); Coerce_initialize(); Void_initialize(); Boolean_initialize(); Byte_initialize(); Short_initialize(); Integer_initialize(); Long_initialize(); Float_initialize(); Double_initialize(); BigDecimal_initialize(); Date_initialize(); Time_initialize(); Timestamp_initialize(); Oid_initialize(); AclId_initialize(); ErrorData_initialize(); LargeObject_initialize(); byte_array_initialize(); JavaWrapper_initialize(); ExecutionPlan_initialize(); Portal_initialize(); TriggerData_initialize(); Relation_initialize(); TupleDesc_initialize(); Tuple_initialize(); TupleTable_initialize(); Composite_initialize(); s_Map_class = JNI_newGlobalRef(PgObject_getJavaClass("java/util/Map")); s_Map_get = PgObject_getJavaMethod(s_Map_class, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); s_Iterator_class = JNI_newGlobalRef(PgObject_getJavaClass("java/util/Iterator")); s_Iterator_hasNext = PgObject_getJavaMethod(s_Iterator_class, "hasNext", "()Z"); s_Iterator_next = PgObject_getJavaMethod(s_Iterator_class, "next", "()Ljava/lang/Object;"); }
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; }
void Function_clearFunctionCache(void) { Entry entry; HashMap oldMap = s_funcMap; Iterator itor = Iterator_create(oldMap); s_funcMap = HashMap_create(59, TopMemoryContext); while((entry = Iterator_next(itor)) != 0) { Function func = (Function)Entry_getValue(entry); if(func != 0) { if(Function_inUse(func)) { /* This is the replace_jar function or similar. Just * move it to the new map. */ HashMap_put(s_funcMap, Entry_getKey(entry), func); } else { Entry_setValue(entry, 0); PgObject_free((PgObject)func); } } } PgObject_free((PgObject)itor); PgObject_free((PgObject)oldMap); }
void Function_initialize(void) { s_funcMap = HashMap_create(59, TopMemoryContext); s_Loader_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/sqlj/Loader")); s_Loader_getSchemaLoader = PgObject_getStaticJavaMethod(s_Loader_class, "getSchemaLoader", "(Ljava/lang/String;)Ljava/lang/ClassLoader;"); s_Loader_getTypeMap = PgObject_getStaticJavaMethod(s_Loader_class, "getTypeMap", "(Ljava/lang/String;)Ljava/util/Map;"); s_ClassLoader_class = JNI_newGlobalRef(PgObject_getJavaClass("java/lang/ClassLoader")); s_ClassLoader_loadClass = PgObject_getJavaMethod(s_ClassLoader_class, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); s_FunctionClass = PgObjectClass_create("Function", sizeof(struct Function_), _Function_finalize); }
char *test_create_hash() { spec_describe("Create"); HashMap *hash_map = HashMap_create(100); assert_ints_equal(hash_map_capacity(hash_map), 100, "capacity"); assert_ints_equal(hash_map_length(hash_map), 0, "length"); assert_ints_equal(array_capacity(hash_map_values(hash_map)), 100, "values capacity"); assert_ints_equal(array_length(hash_map_values(hash_map)), 0, "values length"); hash_map_free(hash_map); return NULL; }
char *test_get_value_from_empty() { spec_describe("Getting values from empty hash_map"); HashMap *hash_map = HashMap_create(10); String *key = String_create("key"); assert_equal(hash_map_get(hash_map, key), NULL, "return NULL"); string_free(key); hash_map_free(hash_map); return NULL; }
/* * Get the CLASSPATH. Result is always freshly palloc'd. */ static char* getClassPath(const char* prefix) { char* path; HashMap unique = HashMap_create(13, CurrentMemoryContext); StringInfoData buf; initStringInfo(&buf); appendPathParts(classpath, &buf, unique, prefix); appendPathParts(getenv("CLASSPATH"), &buf, unique, prefix); PgObject_free((PgObject)unique); path = buf.data; if(strlen(path) == 0) { pfree(path); path = 0; } return path; }
char *test_set_value() { spec_describe("Setting and getting value"); HashMap *hash_map = HashMap_create(10); String *key = String_create("key"); String *value = String_create("value"); hash_map_set(hash_map, key, value); assert_equal(hash_map_get(hash_map, key), value, "value same"); string_free(key); string_free(value); hash_map_free(hash_map); return NULL; }
/* * Get the CLASSPATH. Result is always freshly palloc'd. */ static char* getClassPath(const char* prefix) { char* path; HashMap unique = HashMap_create(13, CurrentMemoryContext); StringInfoData buf; initStringInfo(&buf); /* Put the pljava installed in the $libdir first in the path */ appendPathParts("$libdir/java/pljava.jar", &buf, unique, prefix); #if 0 /* * Currently pljava.classpath is user setable, which makes this a * security problem. If CLASSPATH needs to be setable beyond simply * locating the pljava.jar file then this requires modification. * * The Greenplum version of pljava currently uses the classpath guc * differently anyhow due to differences in storing the jar files * in the filesystem rather than in the database. */ appendPathParts(pljava_classpath, &buf, unique, prefix); /* * For this to be useful it needs to be propagated from the * master to all the segments, otherwise it wouldn't be the * same everyplace and that would be a problem. * * Using a jvm_classpath GUC makes more architectural sense, * for it to be secure it would need to be super-user only, * possibly conf file only. */ appendPathParts(getenv("CLASSPATH"), &buf, unique, prefix); #endif PgObject_free((PgObject)unique); path = buf.data; if(strlen(path) == 0) { pfree(path); path = 0; } return path; }
char *test_reset_value() { spec_describe("Setting and getting value"); HashMap *hash_map = HashMap_create(10); String *key = String_create("key"); String *value_1 = String_create("value"); String *value_2 = String_create("another value"); hash_map_set(hash_map, key, value_1); hash_map_set(hash_map, key, value_2); assert_equal(hash_map_get(hash_map, key), value_2, "value same"); int index = hash_map_index_for_key(hash_map, key); assert_ints_equal(list_length((List *)hash_map_list_at_index(hash_map, index)), 1, "no duplicates for key in list"); string_free(key); string_free(value_1); string_free(value_2); hash_map_free(hash_map); return NULL; }
void initializeProperties() { _sdf_globalPropertiesMap = HashMap_create(23, 0); }