Skip to content

V3.0.0

Compare
Choose a tag to compare
@greenrobot-team greenrobot-team released this 19 Oct 12:45
· 251 commits to main since this release

Note: this version contains a bug that prevents usage with Android Java only projects. Use 3.0.1 instead.

  • A new Query API is available that works similar to the ObjectBox for Dart/Flutter Query API and makes it easier to create nested conditions. #201
    // equal AND (less OR oneOf)
    val query = box.query(
          User_.firstName equal "Joe"
                  and (User_.age less 12
                  or (User_.stamp oneOf longArrayOf(1012))))
          .order(User_.age)
          .build()
  • For the existing Query API, String property conditions now require to explicitly specify case. See the documentation of StringOrder for which one to choose (typically StringOrder.CASE_INSENSITIVE).
    // Replace String conditions like
    query().equal(User_.firstName, "Joe")
    // With the one accepting a StringOrder
    query().equal(User_.firstName, "Joe", StringOrder.CASE_INSENSITIVE)
  • The Gradle plugin will now warn when an @Entity class is missing a no-arg (easy to add) or all properties (best for performance) constructor. #900
    Example for an all properties constructor:
    @Entity
    public class Order {
    
        @Id
        private long id;
        private ToOne<Customer> customer;
        private ToMany<Order> relatedOrders;
    
        // All properties constructor for ObjectBox:
        // - make sure type matches exactly,
        // - for ToOne add its virtual ID property instead,
        // - for ToMany add no parameter.
        public Order(long id, long customerId) {
            this.id = id;
            this.customer.setTargetId(customerId);
        }
    
        // TODO getters and setters for properties
    }
  • Subscriptions now publish results in serial instead of in parallel (using a single thread vs. multiple threads per publisher). Publishing in parallel could previously lead to outdated results getting delivered after the latest results. As a side-effect transformers now run in serial instead of in parallel as well (on the same single thread per publisher). #793
  • Support annotating a single property with @Unique(onConflict = ConflictStrategy.REPLACE) to replace an existing Object if a conflict occurs when doing a put. #509
    @Entity
    data class Example(
            @Id
            var id: Long = 0,
            @Unique(onConflict = ConflictStrategy.REPLACE)
            var uniqueKey: String? = null
    )
  • Support @Unsigned to indicate that values of an integer property (e.g. Integer and Long in Java) should be treated as unsigned when doing queries or creating indexes.
  • Store time in nanoseconds using the new @Type annotation:
    @Type(DatabaseType.DateNano)
    var timeInNanos: Long;
  • Package FlatBuffers version into library to avoid conflicts with apps or other libraries using FlatBuffers. #894
  • Kotlin: add Flow extension functions for BoxStore and Query. #990
  • Data browser: display query results if a property has a NaN value. #984
  • Android 12: support using Data Browser if targeting Android 12 (SDK 31). #1007

New supported property types

  • String arrays (Java String[] and Kotlin Array<String>) and lists (Java List<String> and Kotlin MutableList<String>). Using the new containsElement("item") condition, it is also possible to query for entities where "item" is equal to one of the elements.
    @Entity
    data class Example(
            @Id
            var id: Long = 0,
            var stringArray: Array<String>? = null,
            var stringMap: MutableMap<String, String>? = null
    )
    
    // matches [“first”, “second”, “third”]
    box.query(Example_.stringArray.containsElement(“second”)).build()
  • String maps (Java Map<String, String> or Kotlin MutableMap<String, String>). Stored internally as a byte array using FlexBuffers.
  • Flexible maps:
    • map keys must all have the same type,
    • map keys or values must not be null,
    • map values must be one of the supported database type, or a list of them (e.g. String, Boolean, Integer, Double, byte array...).

Sync

  • The generated JSON model file no longer contains Java-specific flags that would lead to errors if used with Sync server.
  • Additional checks when calling client or server methods.

All release notes & docs