@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
byte[] value = db.get(key.getBytes());
Map<String, ByteIterator> deserialized = deserialize(value);
result.putAll(deserialized);
} catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
return Status.ERROR;
}
return Status.OK;
}
@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
System.out.println("Scan called! NOP for now");
return Status.OK;
}
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
try {
byte[] serialized = serialize(values);
db.put(key.getBytes(), serialized);
} catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
return Status.ERROR;
}
return Status.OK;
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
byte[] value = db.get(key.getBytes());
Map<String, ByteIterator> deserialized = deserialize(value);
result.putAll(deserialized);
} catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
return Status.ERROR;
}
return Status.OK;
}
@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
System.out.println("Scan called! NOP for now");
return Status.OK;
}
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
try {
byte[] serialized = serialize(values);
db.put(key.getBytes(), serialized);
} catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
return Status.ERROR;
}
return Status.OK;
刚写了两个数据库增删改查的接口, 为什么要用 ByteIterator?有什么好处?什么场景下用?
=
这压根也不是 JDK 提供的类。
P.S. 你要是用了某些框架就按人家的范式来,抛开框架还谈个毛线。