Skip to content

Commit af79ef5

Browse files
Sync client: support applying filter variable updates
1 parent 6374111 commit af79ef5

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Notable changes to the ObjectBox Java library.
55
For more insights into what changed in the database libraries, [check the ObjectBox C changelog](https://github.com/objectbox/objectbox-c/blob/main/CHANGELOG.md).
66

77
## Next release
8+
9+
### Sync
10+
11+
- SyncClient: support updating filter variables. After login, stage updates using put and remove, then schedule to send
12+
them to the server with `applyFilterVariables()`.
813

914
## 5.2.0 - 2026-02-16
1015

objectbox-java/src/main/java/io/objectbox/sync/SyncClient.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,25 @@ public interface SyncClient extends Closeable {
145145
* Eventually, existing values for the same name are replaced.
146146
* <p>
147147
* Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the
148-
* filter. Filter variables must be added before login, so before calling {@link #start()}.
148+
* filter.
149+
* <p>
150+
* Filter variables can be set in two states:
151+
* <ol>
152+
* <li>Before login (e.g. before calling {@link #start()} or setting credentials): no
153+
* {@link #applyFilterVariables()} call required.</li>
154+
* <li>After login: updates are staged as "pending" until {@link #applyFilterVariables()} is called.</li>
155+
* </ol>
149156
*
150157
* @see #removeFilterVariable
151158
* @see #removeAllFilterVariables
159+
* @see #applyFilterVariables()
152160
*/
153161
void putFilterVariable(String name, String value);
154162

155163
/**
156164
* Removes a previously added Sync filter variable value.
165+
* <p>
166+
* If used after login, see {@link #putFilterVariable} for notes about {@link #applyFilterVariables}.
157167
*
158168
* @see #putFilterVariable
159169
* @see #removeAllFilterVariables
@@ -162,12 +172,27 @@ public interface SyncClient extends Closeable {
162172

163173
/**
164174
* Removes all previously added Sync filter variable values.
175+
* <p>
176+
* If used after login, see {@link #putFilterVariable} for notes about {@link #applyFilterVariables}.
165177
*
166178
* @see #putFilterVariable
167179
* @see #removeFilterVariable
168180
*/
169181
void removeAllFilterVariables();
170182

183+
/**
184+
* Applies all pending Sync filter variable updates (from {@link #putFilterVariable} and
185+
* {@link #removeFilterVariable} calls).
186+
* <p>
187+
* If the client is connected, sends the updated variables to the server. If the client is not connected,
188+
* the updated variables will be included in the next login message.
189+
*
190+
* @see #putFilterVariable
191+
* @see #removeFilterVariable
192+
* @see #removeAllFilterVariables
193+
*/
194+
void applyFilterVariables();
195+
171196
/**
172197
* Sets credentials to authenticate the client with the server.
173198
* <p>

objectbox-java/src/main/java/io/objectbox/sync/SyncClientImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ public void removeAllFilterVariables() {
233233
nativeRemoveAllFilterVariables(getHandle());
234234
}
235235

236+
public void applyFilterVariables() {
237+
nativeApplyFilterVariables(getHandle());
238+
}
239+
236240
@Override
237241
public void setLoginCredentials(List<SyncCredentials> credentials) {
238242
if (credentials.size() == 1) {
@@ -467,6 +471,9 @@ public ObjectsMessageBuilder startObjectsMessage(long flags, @Nullable String to
467471
// extern "C" JNIEXPORT void JNICALL Java_io_objectbox_sync_SyncClientImpl_nativeRemoveAllFilterVariables(JNIEnv* env, jobject, jlong handle)
468472
private native void nativeRemoveAllFilterVariables(long handle);
469473

474+
// extern "C" JNIEXPORT void JNICALL Java_io_objectbox_sync_SyncClientImpl_nativeApplyFilterVariables(JNIEnv* env, jobject, jlong handle)
475+
private native void nativeApplyFilterVariables(long handle);
476+
470477
private native void nativeSetLoginInfo(long handle, long credentialsType, @Nullable byte[] credentials);
471478

472479
private native void nativeSetLoginInfoUserPassword(long handle, long credentialsType, String username, String password);

tests/objectbox-java-test/src/test/java/io/objectbox/sync/ConnectivityMonitorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public void removeFilterVariable(String name) {
187187
public void removeAllFilterVariables() {
188188
}
189189

190+
@Override
191+
public void applyFilterVariables() {
192+
}
193+
190194
@Override
191195
public void setLoginCredentials(SyncCredentials credentials) {
192196
}

0 commit comments

Comments
 (0)