刚写了两个数据库增删改查的接口, 为什么要用 ByteIterator?有什么好处?什么场景下用?

 @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?有什么好处?什么场景下用?
=

阅读 1.4k
1 个回答

这压根也不是 JDK 提供的类。

P.S. 你要是用了某些框架就按人家的范式来,抛开框架还谈个毛线。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题