File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
objectbox-java/src/main/java/io/objectbox/sync Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1919import java .util .Arrays ;
2020import java .util .Collections ;
2121import java .util .List ;
22+ import java .util .Map ;
23+ import java .util .TreeMap ;
2224
2325import javax .annotation .Nullable ;
2426
@@ -57,6 +59,8 @@ public final class SyncBuilder {
5759 boolean uncommittedAcks ;
5860
5961 RequestUpdatesMode requestUpdatesMode = RequestUpdatesMode .AUTO ;
62+ // To be helpful when debugging, use a TreeMap so variables are eventually passed ordered by name to the native API
63+ final Map <String , String > filterVariables = new TreeMap <>();
6064
6165 public enum RequestUpdatesMode {
6266 /**
@@ -137,6 +141,22 @@ String serverUrl() {
137141 return url ;
138142 }
139143
144+ /**
145+ * Adds or replaces a <a href="https://sync.objectbox.io/sync-server/sync-filters">Sync filter</a> variable value
146+ * for the given name.
147+ * <p>
148+ * Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the
149+ * filter.
150+ *
151+ * @see SyncClient#putFilterVariable
152+ */
153+ public SyncBuilder filterVariable (String name , String value ) {
154+ checkNotNull (name , "Filter variable name is null." );
155+ checkNotNull (value , "Filter variable value is null." );
156+ filterVariables .put (name , value );
157+ return this ;
158+ }
159+
140160 /**
141161 * Configures a custom set of directory or file paths to search for trusted certificates in.
142162 * The first path that exists will be used.
Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ public interface SyncClient extends Closeable {
128128 void setSyncTimeListener (@ Nullable SyncTimeListener timeListener );
129129
130130 /**
131- * Adds or replaces a Sync filter variable value for the given name.
131+ * Adds or replaces a <a href="https://sync.objectbox.io/sync-server/sync-filters">Sync filter</a> variable value
132+ * for the given name.
132133 * <p>
133134 * Eventually, existing values for the same name are replaced.
134135 * <p>
Original file line number Diff line number Diff line change 1616
1717package io .objectbox .sync ;
1818
19+ import java .util .Map ;
1920import java .util .concurrent .CountDownLatch ;
2021import java .util .concurrent .TimeUnit ;
2122
@@ -71,6 +72,10 @@ public final class SyncClientImpl implements SyncClient {
7172 }
7273 this .handle = handle ;
7374
75+ for (Map .Entry <String , String > entry : builder .filterVariables .entrySet ()) {
76+ putFilterVariable (entry .getKey (), entry .getValue ());
77+ }
78+
7479 // Only change setting if not default (automatic sync updates and push subscription enabled).
7580 if (builder .requestUpdatesMode != RequestUpdatesMode .AUTO ) {
7681 boolean autoRequestUpdates = builder .requestUpdatesMode != RequestUpdatesMode .MANUAL ;
You can’t perform that action at this time.
0 commit comments