columnfamilyhandle.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // This file implements the "bridge" between Java and C++ for
  7. // ROCKSDB_NAMESPACE::ColumnFamilyHandle.
  8. #include <jni.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "include/org_rocksdb_ColumnFamilyHandle.h"
  12. #include "rocksjni/portal.h"
  13. /*
  14. * Class: org_rocksdb_ColumnFamilyHandle
  15. * Method: getName
  16. * Signature: (J)[B
  17. */
  18. jbyteArray Java_org_rocksdb_ColumnFamilyHandle_getName(JNIEnv* env,
  19. jobject /*jobj*/,
  20. jlong jhandle) {
  21. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  22. std::string cf_name = cfh->GetName();
  23. return ROCKSDB_NAMESPACE::JniUtil::copyBytes(env, cf_name);
  24. }
  25. /*
  26. * Class: org_rocksdb_ColumnFamilyHandle
  27. * Method: getID
  28. * Signature: (J)I
  29. */
  30. jint Java_org_rocksdb_ColumnFamilyHandle_getID(JNIEnv* /*env*/,
  31. jobject /*jobj*/,
  32. jlong jhandle) {
  33. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  34. const int32_t id = cfh->GetID();
  35. return static_cast<jint>(id);
  36. }
  37. /*
  38. * Class: org_rocksdb_ColumnFamilyHandle
  39. * Method: getDescriptor
  40. * Signature: (J)Lorg/rocksdb/ColumnFamilyDescriptor;
  41. */
  42. jobject Java_org_rocksdb_ColumnFamilyHandle_getDescriptor(JNIEnv* env,
  43. jobject /*jobj*/,
  44. jlong jhandle) {
  45. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  46. ROCKSDB_NAMESPACE::ColumnFamilyDescriptor desc;
  47. ROCKSDB_NAMESPACE::Status s = cfh->GetDescriptor(&desc);
  48. if (s.ok()) {
  49. return ROCKSDB_NAMESPACE::ColumnFamilyDescriptorJni::construct(env, &desc);
  50. } else {
  51. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  52. return nullptr;
  53. }
  54. }
  55. /*
  56. * Class: org_rocksdb_ColumnFamilyHandle
  57. * Method: disposeInternal
  58. * Signature: (J)V
  59. */
  60. void Java_org_rocksdb_ColumnFamilyHandle_disposeInternal(JNIEnv* /*env*/,
  61. jobject /*jobj*/,
  62. jlong jhandle) {
  63. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  64. assert(cfh != nullptr);
  65. delete cfh;
  66. }