File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
objectbox-java-api/src/main/java/io/objectbox/annotation Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .objectbox .annotation ;
2+
3+ /**
4+ * Used with {@link Unique} to specify the conflict resolution strategy.
5+ */
6+ public enum ConflictStrategy {
7+
8+ /**
9+ * Default. Throws UniqueViolationException if any property violates a {@link Unique} constraint.
10+ */
11+ FAIL ,
12+ /**
13+ * Ignore the offending object (the existing object is not changed). If there are multiple unique properties in an
14+ * entity, this strategy is evaluated first: if the property conflicts, no other properties will be checked for
15+ * conflicts.
16+ */
17+ IGNORE ,
18+ /**
19+ * The offending object replaces the existing object (deletes it). If there are multiple properties using this
20+ * strategy, a single put can potentially replace (delete) multiple existing objects.
21+ */
22+ REPLACE ,
23+ /**
24+ * The offending object overwrites the existing object while keeping its ID. All relations pointing to the existing
25+ * entity are preserved. This is useful for a "secondary" ID, such as a string "ID". Within an entity, this strategy
26+ * may be used once only (update target would be ambiguous otherwise).
27+ */
28+ UPDATE
29+
30+ }
Original file line number Diff line number Diff line change 2525 * Enforces that the value of a property is unique among all objects in a box before an object can be put.
2626 * <p>
2727 * Trying to put an object with offending values will result in a UniqueViolationException.
28+ * Specify a {@link ConflictStrategy} to change this default behavior.
2829 * <p>
2930 * Unique properties are based on an {@link Index @Index}, so the same restrictions apply.
3031 * It is supported to explicitly add the {@link Index @Index} annotation to configure the index.
3132 */
3233@ Retention (RetentionPolicy .CLASS )
3334@ Target (ElementType .FIELD )
3435public @interface Unique {
36+ ConflictStrategy onConflict () default ConflictStrategy .FAIL ;
3537}
You can’t perform that action at this time.
0 commit comments