“subIterable” 方法是用于 Xodus 属性的方法吗?

huangapple go评论70阅读模式
英文:

What is the "subIterable" method for a Xodus property?

问题

以下是翻译的内容:

我有这个自定义属性类型:

public class EmbeddedEntityIterable implements Serializable, ByteIterable {
  
  @NotNull
  @Override
  public ByteIterable subIterable(int offset, int length) {
    return null;
  }

  @Override
  public int compareTo(@NotNull ByteIterable o) {
    return 0;
  }

}

Xodus 如何使用 subIterablecompareTo?在 @NotNull 方法上返回 NULL 值是否安全?这个 EmbeddedEntityIterable 基本上是底层的 Map<String, Comparable>,同时也是一个非常嵌套的 JSON 对象的表示。

英文:

I have this custom property type:

public class EmbeddedEntityIterable implements Serializable, ByteIterable {
  
  @NotNull
  @Override
  public ByteIterable subIterable(int offset, int length) {
    return null;
  }

  @Override
  public int compareTo(@NotNull ByteIterable o) {
    return 0;
  }

}

How does Xodus use subIterable and compareTo? Is it safe just to return a NULL value on a @NotNull method? This EmbeddedEntityIterable is basically a Map&lt;String,Comparable&gt; under the hood, that is also a representation of a very nested JSON object.

答案1

得分: 1

不安全返回null,必须实现非平凡的compareTo。否则将无法将ByteIterable用作键(与任何类型的存储一起)和值(与可能具有键重复的存储一起)。如果使用EntityStores API并且将ByteIterable用作属性值,则必须实现这些方法,因为ByteIterable将在幕后用作属性值索引中的键。

对于自定义的ByteIterable实现,最好继承自ByteIterableBase抽象类,该类具有方法的基本实现。

此外,如果定义自定义属性类型,则必须定义顺序,以支持排序、查找值或在值范围内搜索等开箱即用功能。如果不需要这些功能,那么将此类数据保存在blob或blob字符串中可能更有意义。

英文:

It is not safe to return null, and you have to implement non-trivial compareTo. Otherwise you won't be able to use your ByteIterable as a key (with Stores of any type) and value (with Stores that can have key duplicates). If you use EntityStores API and your ByteIterable as a property value, then you definitely have to implement the methods, since the ByteIterable would be used under the hood as a key in a property value index.

For custom implementations of ByteIterable, it's prefereble to inherit from ByteIterableBase abstract class which has basic implementations of the methods.

In addtiton, if you define custom property type then you must define order to support out-of-the-box features like sorting, searching for a value or searching in a range of values. If you don't need these features then probably it makes sense to save such data in blobs or blob strings instead of properties.

huangapple
  • 本文由 发表于 2020年10月5日 17:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64206121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定