Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
5bbeefaa
R
rocksdb
项目概览
kvdb
/
rocksdb
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5bbeefaa
编写于
4月 19, 2014
作者:
A
Ankit Gupta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding iterator JNI binding
上级
27d3bc18
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
134 addition
and
4 deletion
+134
-4
java/RocksDBSample.java
java/RocksDBSample.java
+6
-2
java/org/rocksdb/Iterator.java
java/org/rocksdb/Iterator.java
+42
-0
java/org/rocksdb/RocksDB.java
java/org/rocksdb/RocksDB.java
+5
-1
java/rocksjni/iterator.cc
java/rocksjni/iterator.cc
+41
-0
java/rocksjni/portal.h
java/rocksjni/portal.h
+33
-0
java/rocksjni/rocksjni.cc
java/rocksjni/rocksjni.cc
+7
-0
java/rocksjni/statistics.cc
java/rocksjni/statistics.cc
+0
-1
未找到文件。
java/RocksDBSample.java
浏览文件 @
5bbeefaa
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
// LICENSE file in the root directory of this source tree. An additional grant
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
// of patent rights can be found in the PATENTS file in the same directory.
import
java.util.*
;
import
java.util.Arrays
;
import
java.lang.*
;
import
org.rocksdb.*
;
import
org.rocksdb.*
;
import
org.rocksdb.util.SizeUnit
;
import
org.rocksdb.util.SizeUnit
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -142,6 +141,11 @@ public class RocksDBSample {
...
@@ -142,6 +141,11 @@ public class RocksDBSample {
System
.
out
.
println
(
"Failed in call to geHistogramData()"
);
System
.
out
.
println
(
"Failed in call to geHistogramData()"
);
assert
(
false
);
//Should never reach here.
assert
(
false
);
//Should never reach here.
}
}
Iterator
iterator
=
db
.
iterator
();
iterator
.
seekToFirst
();
assert
(
iterator
.
isValid
());
iterator
.
close
();
}
catch
(
RocksDBException
e
)
{
}
catch
(
RocksDBException
e
)
{
System
.
err
.
println
(
e
);
System
.
err
.
println
(
e
);
}
}
...
...
java/org/rocksdb/Iterator.java
0 → 100644
浏览文件 @
5bbeefaa
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package
org.rocksdb
;
public
class
Iterator
{
private
long
nativeHandle_
;
public
Iterator
(
long
nativeHandle
)
{
nativeHandle_
=
nativeHandle
;
}
public
boolean
isValid
()
{
assert
(
isInitialized
());
return
isValid0
(
nativeHandle_
);
}
public
void
seekToFirst
()
{
assert
(
isInitialized
());
seekToFirst0
(
nativeHandle_
);
}
public
synchronized
void
close
()
{
if
(
nativeHandle_
!=
0
)
{
close0
(
nativeHandle_
);
}
}
@Override
protected
void
finalize
()
{
close
();
}
private
boolean
isInitialized
()
{
return
(
nativeHandle_
!=
0
);
}
private
native
boolean
isValid0
(
long
handle
);
private
native
void
close0
(
long
handle
);
private
native
void
seekToFirst0
(
long
handle
);
}
\ No newline at end of file
java/org/rocksdb/RocksDB.java
浏览文件 @
5bbeefaa
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
package
org.rocksdb
;
package
org.rocksdb
;
import
java.util.*
;
import
java.io.Closeable
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -136,6 +135,10 @@ public class RocksDB {
...
@@ -136,6 +135,10 @@ public class RocksDB {
throws
RocksDBException
{
throws
RocksDBException
{
remove
(
nativeHandle_
,
writeOpt
.
nativeHandle_
,
key
,
key
.
length
);
remove
(
nativeHandle_
,
writeOpt
.
nativeHandle_
,
key
,
key
.
length
);
}
}
public
Iterator
iterator
()
{
return
new
Iterator
(
iterator0
(
nativeHandle_
));
}
@Override
protected
void
finalize
()
{
@Override
protected
void
finalize
()
{
close
();
close
();
...
@@ -170,6 +173,7 @@ public class RocksDB {
...
@@ -170,6 +173,7 @@ public class RocksDB {
protected
native
void
remove
(
protected
native
void
remove
(
long
handle
,
long
writeOptHandle
,
long
handle
,
long
writeOptHandle
,
byte
[]
key
,
int
keyLen
)
throws
RocksDBException
;
byte
[]
key
,
int
keyLen
)
throws
RocksDBException
;
protected
native
long
iterator0
(
long
optHandle
);
protected
native
void
close0
();
protected
native
void
close0
();
protected
long
nativeHandle_
;
protected
long
nativeHandle_
;
...
...
java/rocksjni/iterator.cc
0 → 100644
浏览文件 @
5bbeefaa
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// This file implements the "bridge" between Java and C++ and enables
// calling c++ rocksdb::Iterator methods from Java side.
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include "include/org_rocksdb_Iterator.h"
#include "rocksjni/portal.h"
#include "rocksdb/iterator.h"
jboolean
Java_org_rocksdb_Iterator_isValid0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
handle
)
{
auto
st
=
reinterpret_cast
<
rocksdb
::
Iterator
*>
(
handle
);
assert
(
st
!=
nullptr
);
return
st
->
Valid
();
}
void
Java_org_rocksdb_Iterator_seekToFirst0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
handle
)
{
auto
st
=
reinterpret_cast
<
rocksdb
::
Iterator
*>
(
handle
);
assert
(
st
!=
nullptr
);
st
->
SeekToFirst
();
}
void
Java_org_rocksdb_Iterator_close0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
handle
)
{
auto
st
=
reinterpret_cast
<
rocksdb
::
Iterator
*>
(
handle
);
assert
(
st
!=
nullptr
);
delete
st
;
rocksdb
::
IteratorJni
::
setHandle
(
env
,
jobj
,
nullptr
);
}
\ No newline at end of file
java/rocksjni/portal.h
浏览文件 @
5bbeefaa
...
@@ -213,5 +213,38 @@ class BackupableDBOptionsJni {
...
@@ -213,5 +213,38 @@ class BackupableDBOptionsJni {
reinterpret_cast
<
jlong
>
(
op
));
reinterpret_cast
<
jlong
>
(
op
));
}
}
};
};
class
IteratorJni
{
public:
// Get the java class id of org.rocksdb.Iteartor.
static
jclass
getJClass
(
JNIEnv
*
env
)
{
static
jclass
jclazz
=
env
->
FindClass
(
"org/rocksdb/Iterator"
);
assert
(
jclazz
!=
nullptr
);
return
jclazz
;
}
// Get the field id of the member variable of org.rocksdb.Iterator
// that stores the pointer to rocksdb::Iterator
static
jfieldID
getHandleFieldID
(
JNIEnv
*
env
)
{
static
jfieldID
fid
=
env
->
GetFieldID
(
getJClass
(
env
),
"nativeHandle_"
,
"J"
);
assert
(
fid
!=
nullptr
);
return
fid
;
}
// Get the pointer to rocksdb::Iterator
static
rocksdb
::
Iterator
*
getHandle
(
JNIEnv
*
env
,
jobject
jobj
)
{
return
reinterpret_cast
<
rocksdb
::
Iterator
*>
(
env
->
GetLongField
(
jobj
,
getHandleFieldID
(
env
)));
}
// Pass the rocksdb::Iterator pointer to the java side.
static
void
setHandle
(
JNIEnv
*
env
,
jobject
jobj
,
rocksdb
::
Iterator
*
op
)
{
env
->
SetLongField
(
jobj
,
getHandleFieldID
(
env
),
reinterpret_cast
<
jlong
>
(
op
));
}
};
}
// namespace rocksdb
}
// namespace rocksdb
#endif // JAVA_ROCKSJNI_PORTAL_H_
#endif // JAVA_ROCKSJNI_PORTAL_H_
java/rocksjni/rocksjni.cc
浏览文件 @
5bbeefaa
...
@@ -296,3 +296,10 @@ void Java_org_rocksdb_RocksDB_close0(
...
@@ -296,3 +296,10 @@ void Java_org_rocksdb_RocksDB_close0(
rocksdb
::
RocksDBJni
::
setHandle
(
env
,
java_db
,
nullptr
);
rocksdb
::
RocksDBJni
::
setHandle
(
env
,
java_db
,
nullptr
);
}
}
jlong
Java_org_rocksdb_RocksDB_iterator0
(
JNIEnv
*
env
,
jobject
jdb
,
jlong
db_handle
)
{
auto
db
=
reinterpret_cast
<
rocksdb
::
DB
*>
(
db_handle
);
rocksdb
::
Iterator
*
iterator
=
db
->
NewIterator
(
rocksdb
::
ReadOptions
());
return
reinterpret_cast
<
jlong
>
(
iterator
);
}
\ No newline at end of file
java/rocksjni/statistics.cc
浏览文件 @
5bbeefaa
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
#include "include/org_rocksdb_Statistics.h"
#include "include/org_rocksdb_Statistics.h"
#include "rocksjni/portal.h"
#include "rocksjni/portal.h"
#include "rocksdb/statistics.h"
#include "rocksdb/statistics.h"
#include <iostream>
/*
/*
* Class: org_rocksdb_Statistics
* Class: org_rocksdb_Statistics
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录