Skip to content

Commit 74e88d9

Browse files
java-api: add SyncClock and SyncPrecedence annotations
1 parent e24210b commit 74e88d9

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

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+
}

0 commit comments

Comments
 (0)