Skip to content

Commit 08fe7c9

Browse files
SyncClient: support adding and removing filter variables #280
1 parent c897c28 commit 08fe7c9

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ For more insights into what changed in the ObjectBox C++ core, [check the Object
2121
- Remove deprecated `ValidateOnOpenMode` constants, use `ValidateOnOpenModePages` instead.
2222
- Remove deprecated DAOcompat compatibility query methods. Use the regular query API instead.
2323

24+
### Sync
25+
26+
- Support configuring [Sync filter](https://sync.objectbox.io/sync-server/sync-filters) variables on a `SyncClient`.
27+
2428
## 4.3.1 - 2025-08-12
2529

2630
- Requires at least Kotlin compiler and standard library 1.7.

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,35 @@ public interface SyncClient extends Closeable {
127127
*/
128128
void setSyncTimeListener(@Nullable SyncTimeListener timeListener);
129129

130+
/**
131+
* Adds or replaces a Sync filter variable value for the given name.
132+
* <p>
133+
* Eventually, existing values for the same name are replaced.
134+
* <p>
135+
* Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the
136+
* filter. Filter variables must be added before login, so before calling {@link #start()}.
137+
*
138+
* @see #removeFilterVariable
139+
* @see #removeAllFilterVariables
140+
*/
141+
void putFilterVariable(String name, String value);
142+
143+
/**
144+
* Removes a previously added Sync filter variable value.
145+
*
146+
* @see #putFilterVariable
147+
* @see #removeAllFilterVariables
148+
*/
149+
void removeFilterVariable(String name);
150+
151+
/**
152+
* Removes all previously added Sync filter variable values.
153+
*
154+
* @see #putFilterVariable
155+
* @see #removeFilterVariable
156+
*/
157+
void removeAllFilterVariables();
158+
130159
/**
131160
* Updates the credentials used to authenticate with the server. This should not be required during regular use.
132161
* The original credentials were passed when building sync client.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ public void setSyncListener(@Nullable SyncListener listener) {
187187
setSyncChangeListener(listener);
188188
}
189189

190+
public void putFilterVariable(String name, String value) {
191+
nativePutFilterVariable(getHandle(), name, value);
192+
}
193+
194+
public void removeFilterVariable(String name) {
195+
nativeRemoveFilterVariable(getHandle(), name);
196+
}
197+
198+
public void removeAllFilterVariables() {
199+
nativeRemoveAllFilterVariables(getHandle());
200+
}
201+
190202
@Override
191203
public void setLoginCredentials(SyncCredentials credentials) {
192204
if (credentials == null) {
@@ -350,6 +362,15 @@ public ObjectsMessageBuilder startObjectsMessage(long flags, @Nullable String to
350362

351363
private native void nativeStop(long handle);
352364

365+
// extern "C" JNIEXPORT void JNICALL Java_io_objectbox_sync_SyncClientImpl_nativePutFilterVariable(JNIEnv* env, jobject, jlong handle, jstring name, jstring value)
366+
private native void nativePutFilterVariable(long handle, String name, String value);
367+
368+
// extern "C" JNIEXPORT void JNICALL Java_io_objectbox_sync_SyncClientImpl_nativeRemoveFilterVariable(JNIEnv* env, jobject, jlong handle, jstring name)
369+
private native void nativeRemoveFilterVariable(long handle, String name);
370+
371+
// extern "C" JNIEXPORT void JNICALL Java_io_objectbox_sync_SyncClientImpl_nativeRemoveAllFilterVariables(JNIEnv* env, jobject, jlong handle)
372+
private native void nativeRemoveAllFilterVariables(long handle);
373+
353374
private native void nativeSetLoginInfo(long handle, long credentialsType, @Nullable byte[] credentials);
354375

355376
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: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1+
/*
2+
* Copyright 2025 ObjectBox Ltd.
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+
117
package io.objectbox.sync;
218

3-
import io.objectbox.sync.listener.SyncTimeListener;
419
import org.junit.Test;
520

6-
721
import javax.annotation.Nullable;
822

923
import io.objectbox.sync.listener.SyncChangeListener;
1024
import io.objectbox.sync.listener.SyncCompletedListener;
1125
import io.objectbox.sync.listener.SyncConnectionListener;
1226
import io.objectbox.sync.listener.SyncListener;
1327
import io.objectbox.sync.listener.SyncLoginListener;
28+
import io.objectbox.sync.listener.SyncTimeListener;
1429

1530

1631
import static org.junit.Assert.assertEquals;
@@ -153,6 +168,18 @@ public void setSyncChangeListener(@Nullable SyncChangeListener listener) {
153168
public void setSyncTimeListener(@Nullable SyncTimeListener timeListener) {
154169
}
155170

171+
@Override
172+
public void putFilterVariable(String name, String value) {
173+
}
174+
175+
@Override
176+
public void removeFilterVariable(String name) {
177+
}
178+
179+
@Override
180+
public void removeAllFilterVariables() {
181+
}
182+
156183
@Override
157184
public void setLoginCredentials(SyncCredentials credentials) {
158185
}

0 commit comments

Comments
 (0)