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

 @Override
  public Status read(String table, String key, Set fields, Map result) {
    try {
      byte[] value = db.get(key.getBytes());
      Map 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 fields, Vector> result) {
    System.out.println("Scan called! NOP for now");
    return Status.OK;
  }

  @Override
  public Status update(String table, String key, Map 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 fields, Map result) {
    try {
      byte[] value = db.get(key.getBytes());
      Map 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 fields, Vector> result) {
    System.out.println("Scan called! NOP for now");
    return Status.OK;
  }

  @Override
  public Status update(String table, String key, Map 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. 你要是用了某些框架就按人家的范式来,抛开框架还谈个毛线。