Search code examples
javaxodus

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


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.


Solution

  • 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.