columnfamilyhandle.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. jclass /*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*/, jclass /*jcls*/,
  31. jlong jhandle) {
  32. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  33. const int32_t id = cfh->GetID();
  34. return static_cast<jint>(id);
  35. }
  36. /*
  37. * Class: org_rocksdb_ColumnFamilyHandle
  38. * Method: getDescriptor
  39. * Signature: (J)Lorg/rocksdb/ColumnFamilyDescriptor;
  40. */
  41. jobject Java_org_rocksdb_ColumnFamilyHandle_getDescriptor(JNIEnv* env,
  42. jclass /*jcls*/,
  43. jlong jhandle) {
  44. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  45. ROCKSDB_NAMESPACE::ColumnFamilyDescriptor desc;
  46. ROCKSDB_NAMESPACE::Status s = cfh->GetDescriptor(&desc);
  47. if (s.ok()) {
  48. return ROCKSDB_NAMESPACE::ColumnFamilyDescriptorJni::construct(env, &desc);
  49. } else {
  50. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  51. return nullptr;
  52. }
  53. }
  54. /*
  55. * Class: org_rocksdb_ColumnFamilyHandle
  56. * Method: disposeInternal
  57. * Signature: (J)V
  58. */
  59. void Java_org_rocksdb_ColumnFamilyHandle_disposeInternalJni(JNIEnv* /*env*/,
  60. jclass /*jobj*/,
  61. jlong jhandle) {
  62. auto* cfh = reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jhandle);
  63. assert(cfh != nullptr);
  64. delete cfh;
  65. }