英文:
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 如何使用 subIterable
和 compareTo
?在 @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<String,Comparable>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论