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).
8 import java
.nio
.ByteBuffer
;
10 public abstract class AbstractWriteBatch
extends RocksObject
11 implements WriteBatchInterface
{
13 protected AbstractWriteBatch(final long nativeHandle
) {
19 return count0(nativeHandle_
);
23 public void put(byte[] key
, byte[] value
) throws RocksDBException
{
24 put(nativeHandle_
, key
, key
.length
, value
, value
.length
);
28 public void put(ColumnFamilyHandle columnFamilyHandle
, byte[] key
,
29 byte[] value
) throws RocksDBException
{
30 put(nativeHandle_
, key
, key
.length
, value
, value
.length
,
31 columnFamilyHandle
.nativeHandle_
);
35 public void merge(byte[] key
, byte[] value
) throws RocksDBException
{
36 merge(nativeHandle_
, key
, key
.length
, value
, value
.length
);
40 public void merge(ColumnFamilyHandle columnFamilyHandle
, byte[] key
,
41 byte[] value
) throws RocksDBException
{
42 merge(nativeHandle_
, key
, key
.length
, value
, value
.length
,
43 columnFamilyHandle
.nativeHandle_
);
48 public void remove(byte[] key
) throws RocksDBException
{
49 delete(nativeHandle_
, key
, key
.length
);
54 public void remove(ColumnFamilyHandle columnFamilyHandle
, byte[] key
)
55 throws RocksDBException
{
56 delete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
);
59 public void put(ByteBuffer key
, ByteBuffer value
) throws RocksDBException
{
60 assert key
.isDirect() && value
.isDirect();
61 putDirect(nativeHandle_
, key
, key
.position(), key
.remaining(), value
, value
.position(),
62 value
.remaining(), 0);
63 key
.position(key
.limit());
64 value
.position(value
.limit());
68 public void put(ColumnFamilyHandle columnFamilyHandle
, ByteBuffer key
, ByteBuffer value
)
69 throws RocksDBException
{
70 assert key
.isDirect() && value
.isDirect();
71 putDirect(nativeHandle_
, key
, key
.position(), key
.remaining(), value
, value
.position(),
72 value
.remaining(), columnFamilyHandle
.nativeHandle_
);
73 key
.position(key
.limit());
74 value
.position(value
.limit());
78 public void delete(byte[] key
) throws RocksDBException
{
79 delete(nativeHandle_
, key
, key
.length
);
83 public void delete(ColumnFamilyHandle columnFamilyHandle
, byte[] key
)
84 throws RocksDBException
{
85 delete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
);
90 public void singleDelete(byte[] key
) throws RocksDBException
{
91 singleDelete(nativeHandle_
, key
, key
.length
);
95 public void singleDelete(ColumnFamilyHandle columnFamilyHandle
, byte[] key
)
96 throws RocksDBException
{
97 singleDelete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
);
101 public void deleteRange(byte[] beginKey
, byte[] endKey
)
102 throws RocksDBException
{
103 deleteRange(nativeHandle_
, beginKey
, beginKey
.length
, endKey
, endKey
.length
);
107 public void deleteRange(ColumnFamilyHandle columnFamilyHandle
,
108 byte[] beginKey
, byte[] endKey
) throws RocksDBException
{
109 deleteRange(nativeHandle_
, beginKey
, beginKey
.length
, endKey
, endKey
.length
,
110 columnFamilyHandle
.nativeHandle_
);
113 public void remove(ByteBuffer key
) throws RocksDBException
{
114 removeDirect(nativeHandle_
, key
, key
.position(), key
.remaining(), 0);
115 key
.position(key
.limit());
119 public void remove(ColumnFamilyHandle columnFamilyHandle
, ByteBuffer key
)
120 throws RocksDBException
{
122 nativeHandle_
, key
, key
.position(), key
.remaining(), columnFamilyHandle
.nativeHandle_
);
123 key
.position(key
.limit());
127 public void putLogData(byte[] blob
) throws RocksDBException
{
128 putLogData(nativeHandle_
, blob
, blob
.length
);
132 public void clear() {
133 clear0(nativeHandle_
);
137 public void setSavePoint() {
138 setSavePoint0(nativeHandle_
);
142 public void rollbackToSavePoint() throws RocksDBException
{
143 rollbackToSavePoint0(nativeHandle_
);
147 public void popSavePoint() throws RocksDBException
{
148 popSavePoint(nativeHandle_
);
152 public void setMaxBytes(final long maxBytes
) {
153 setMaxBytes(nativeHandle_
, maxBytes
);
157 public WriteBatch
getWriteBatch() {
158 return getWriteBatch(nativeHandle_
);
161 abstract int count0(final long handle
);
163 abstract void put(final long handle
, final byte[] key
, final int keyLen
,
164 final byte[] value
, final int valueLen
) throws RocksDBException
;
166 abstract void put(final long handle
, final byte[] key
, final int keyLen
,
167 final byte[] value
, final int valueLen
, final long cfHandle
)
168 throws RocksDBException
;
170 abstract void putDirect(final long handle
, final ByteBuffer key
, final int keyOffset
,
171 final int keyLength
, final ByteBuffer value
, final int valueOffset
, final int valueLength
,
172 final long cfHandle
) throws RocksDBException
;
174 abstract void merge(final long handle
, final byte[] key
, final int keyLen
,
175 final byte[] value
, final int valueLen
) throws RocksDBException
;
177 abstract void merge(final long handle
, final byte[] key
, final int keyLen
,
178 final byte[] value
, final int valueLen
, final long cfHandle
)
179 throws RocksDBException
;
181 abstract void delete(final long handle
, final byte[] key
,
182 final int keyLen
) throws RocksDBException
;
184 abstract void delete(final long handle
, final byte[] key
,
185 final int keyLen
, final long cfHandle
) throws RocksDBException
;
187 abstract void singleDelete(final long handle
, final byte[] key
,
188 final int keyLen
) throws RocksDBException
;
190 abstract void singleDelete(final long handle
, final byte[] key
,
191 final int keyLen
, final long cfHandle
) throws RocksDBException
;
193 abstract void removeDirect(final long handle
, final ByteBuffer key
, final int keyOffset
,
194 final int keyLength
, final long cfHandle
) throws RocksDBException
;
196 abstract void deleteRange(final long handle
, final byte[] beginKey
, final int beginKeyLen
,
197 final byte[] endKey
, final int endKeyLen
) throws RocksDBException
;
199 abstract void deleteRange(final long handle
, final byte[] beginKey
, final int beginKeyLen
,
200 final byte[] endKey
, final int endKeyLen
, final long cfHandle
) throws RocksDBException
;
202 abstract void putLogData(final long handle
, final byte[] blob
,
203 final int blobLen
) throws RocksDBException
;
205 abstract void clear0(final long handle
);
207 abstract void setSavePoint0(final long handle
);
209 abstract void rollbackToSavePoint0(final long handle
);
211 abstract void popSavePoint(final long handle
) throws RocksDBException
;
213 abstract void setMaxBytes(final long handle
, long maxBytes
);
215 abstract WriteBatch
getWriteBatch(final long handle
);