Skip to content

Commit 8a3ce9b

Browse files
Merge branch '297-sync-clock-and-precedence-annotations' into dev
2 parents 72dc25d + 6761e31 commit 8a3ce9b

5 files changed

Lines changed: 115 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ For more insights into what changed in the database libraries, [check the Object
66

77
## Next release
88

9+
- Update Android and JVM libraries to database version `5.3.0-2026-03-23`
10+
- Admin: Status tab "Count and Sizes" and "System and Info" improved
11+
12+
### Sync
13+
14+
- Conflict resolution via the new annotations `@SyncClock` and `@SyncPrecedence` (allows last win with custom conflict
15+
resolution)
16+
- Fix bad Sync client state after multiple full sync messages were interrupted
17+
- Fix adding indexes to Sync types
18+
919
## 5.3.0 - 2026-03-10
1020

1121
- Gradle plugin: to apply the plugin, it is no longer necessary to add a manual mapping of the plugin ID in your
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright © 2026 ObjectBox Ltd. <https://objectbox.io>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.objectbox.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Marks a {@code long} (64-bit integer) field of a {@link Sync}-enabled {@link Entity} class as the sync clock, a
26+
* "hybrid logical clock" to resolve Sync conflicts.
27+
* <p>
28+
* These clock values allow "last write wins" conflict resolution.
29+
* <p>
30+
* There can be only one sync clock per sync entity type; which is also recommended for basic conflict resolution.
31+
* <p>
32+
* For new objects, initialize the property value to {@code 0} to reserve "a slot" in the object data. ObjectBox Sync
33+
* will update this property automatically on put operations.
34+
* <p>
35+
* As a hybrid clock, it combines a wall clock with a logical counter to compensate for some clock skew effects.
36+
*/
37+
@Retention(RetentionPolicy.CLASS)
38+
@Target(ElementType.FIELD)
39+
public @interface SyncClock {
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright © 2026 ObjectBox Ltd. <https://objectbox.io>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.objectbox.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Marks a {@code long} (64-bit integer) field of a {@link Sync}-enabled {@link Entity} class as the "sync precedence"
26+
* to customize Sync conflict resolution.
27+
* <p>
28+
* Developer-assigned precedence values are then used to resolve conflicts via "higher precedence wins". Defining and
29+
* assigning precedence values are completely in the hands of the developer (the ObjectBox user).
30+
* <p>
31+
* There can be only one sync precedence per sync entity type.
32+
* <p>
33+
* Typically, it is combined with a {@link SyncClock}, with the latter being the tie-breaker for equal precedence
34+
* values.
35+
*/
36+
@Retention(RetentionPolicy.CLASS)
37+
@Target(ElementType.FIELD)
38+
public @interface SyncPrecedence {
39+
}

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class BoxStore implements Closeable {
9292
* This is used (currently only in tests) to make sure a database library has a compatible JNI API by checking the
9393
* version number matches exactly and the date is the same or newer.
9494
*/
95-
private static final String VERSION = "5.2.0-2026-03-10";
95+
private static final String VERSION = "5.3.0-2026-03-23";
9696

9797
private static final String OBJECTBOX_PACKAGE_NAME = "objectbox";
9898
private static BoxStore defaultStore;

objectbox-java/src/main/java/io/objectbox/model/PropertyFlags.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 ObjectBox Ltd.
2+
* Copyright 2026 ObjectBox Ltd. <https://objectbox.io>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,5 +103,29 @@ private PropertyFlags() { }
103103
* However, the deletion process can be triggered by an API call.
104104
*/
105105
public static final int EXPIRATION_TIME = 65536;
106+
/**
107+
* Marks a Long (64-bit integer) property as a the sync clock, a "hybrid logical clock" to resolve Sync conflicts.
108+
* These clock values allow "last write wins" conflict resolution.
109+
* There can be only one sync clock per sync entity type; which is also recommended for basic conflict resolution.
110+
* For new objects, initialize a property value to 0 to reserve "a slot" in the object data.
111+
* ObjectBox Sync will update this property automatically on put operations.
112+
* As a hybrid clock, it combines a wall clock with a logical counter to compensate for some clock skew effects.
113+
*/
114+
public static final int SYNC_CLOCK = 131072;
115+
/**
116+
* Marks a Long (64-bit integer) property as a the "sync precedence" to customize Sync conflict resolution.
117+
* Developer-assigned precedence values are then used to resolve conflicts via "higher precedence wins".
118+
* Defining and assigning precedence values are completely in the hands of the developer (the ObjectBox user).
119+
* There can be only one sync precedence per sync entity type.
120+
* Typically, it is combined with a sync clock, with the latter being the tie-breaker for equal precedence values.
121+
* This can be used to model some business logic use cases, for example:
122+
* - Setting an object a special state, e.g. a final/closed state, which may not be overwritten by a lesser state
123+
* - Multiple workflow states that occur linearly (i.e. using an increasing precedence value)
124+
* - Role based, e.g. only admins set or increment the precedence..
125+
* - “Checkpoint timestamps:” e.g. when some changes are “checked” as in approved/applied,
126+
* the precedence is updated to the current timestamp.
127+
* “Non-checked” or previously checkpointed changes are disregarded.
128+
*/
129+
public static final int SYNC_PRECEDENCE = 262144;
106130
}
107131

0 commit comments

Comments
 (0)