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 package org.rocksdb;
7 
8 import java.nio.ByteBuffer;
9 
10 /**
11  * A simple abstraction to allow a Java class to wrap a custom comparator
12  * implemented in C++.
13  *
14  * The native comparator must directly extend rocksdb::Comparator.
15  */
16 public abstract class NativeComparatorWrapper
17     extends AbstractComparator {
18 
19   @Override
20   final ComparatorType getComparatorType() {
21     return ComparatorType.JAVA_NATIVE_COMPARATOR_WRAPPER;
22   }
23 
24   @Override
25   public final String name() {
26     throw new IllegalStateException("This should not be called. " +
27         "Implementation is in Native code");
28   }
29 
30   @Override
31   public final int compare(final ByteBuffer s1, final ByteBuffer s2) {
32     throw new IllegalStateException("This should not be called. " +
33         "Implementation is in Native code");
34   }
35 
36   @Override
37   public final void findShortestSeparator(final ByteBuffer start, final ByteBuffer limit) {
38     throw new IllegalStateException("This should not be called. " +
39         "Implementation is in Native code");
40   }
41 
42   @Override
43   public final void findShortSuccessor(final ByteBuffer key) {
44     throw new IllegalStateException("This should not be called. " +
45         "Implementation is in Native code");
46   }
47 
48   /**
49    * We override {@link RocksCallbackObject#disposeInternal()}
50    * as disposing of a native rocksdb::Comparator extension requires
51    * a slightly different approach as it is not really a RocksCallbackObject
52    */
53   @Override
54   protected void disposeInternal() {
55     disposeInternal(nativeHandle_);
56   }
57 
58   private native void disposeInternal(final long handle);
59 }
60