JNIEXPORT void JNICALL Java_com_snappydb_internal_DBImpl__1_1destroy( JNIEnv * env, jobject thiz, jstring dbpath) { LOGI("Destroying database %s", databasePath); const char* path = env->GetStringUTFChars(dbpath, 0); if (isDBopen) { delete db; isDBopen = false; free(databasePath); databasePath = NULL; } leveldb::Options options; leveldb::Status status = DestroyDB(path, options); env->ReleaseStringUTFChars(dbpath, path); if (status.ok()) { free(databasePath); databasePath = NULL; isDBopen = false; } else { isDBopen = false; std::string err("Failed to destroy database: " + status.ToString()); throwException (env, err.c_str()); } }
/** @throw runtime_error */ void LevCrawlDb::create_new(const char* path, bool deleteIfExists) { if (deleteIfExists) { (void)DestroyDB(path, Options()); } Options options; options.error_if_exists = true; options.create_if_missing = true; Status status = DB::Open(options, path, &mDatabase); if (!status.ok()) { throw std::runtime_error(status.ToString()); } }