Skip to content

Commit a5795cb

Browse files
Add and use native feature detection API.
1 parent b326fdb commit a5795cb

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.objectbox;
1818

19+
import io.objectbox.internal.Feature;
1920
import org.greenrobot.essentials.collections.LongHashMap;
2021

2122
import java.io.Closeable;
@@ -186,34 +187,28 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
186187

187188
static native long nativeSysProcStatusKb(String key);
188189

189-
/** @return sync availability (0: none; 1: client; 2: server) */
190-
static native int nativeGetSupportedSync();
190+
private static native boolean nativeHasFeature(int feature);
191191

192-
public static boolean isObjectBrowserAvailable() {
193-
NativeLibraryLoader.ensureLoaded();
194-
return nativeIsObjectBrowserAvailable();
195-
}
196-
197-
private static int getSupportedSync() {
198-
NativeLibraryLoader.ensureLoaded();
192+
public static boolean hasFeature(Feature feature) {
199193
try {
200-
int supportedSync = nativeGetSupportedSync();
201-
if (supportedSync < 0 || supportedSync > 2) {
202-
throw new IllegalStateException("Unexpected sync support: " + supportedSync);
203-
}
204-
return supportedSync;
194+
NativeLibraryLoader.ensureLoaded();
195+
return nativeHasFeature(feature.id);
205196
} catch (UnsatisfiedLinkError e) {
206197
System.err.println("Old JNI lib? " + e); // No stack
207-
return 0;
198+
return false;
208199
}
209200
}
210201

202+
public static boolean isObjectBrowserAvailable() {
203+
return hasFeature(Feature.ADMIN);
204+
}
205+
211206
public static boolean isSyncAvailable() {
212-
return getSupportedSync() != 0;
207+
return hasFeature(Feature.SYNC);
213208
}
214209

215210
public static boolean isSyncServerAvailable() {
216-
return getSupportedSync() == 2;
211+
return hasFeature(Feature.SYNC_SERVER);
217212
}
218213

219214
native long nativePanicModeRemoveAllObjects(long store, int entityId);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.objectbox.internal;
2+
3+
/**
4+
* Use with {@link io.objectbox.BoxStore#hasFeature(Feature)}.
5+
*/
6+
public enum Feature {
7+
8+
/** Internal feature, not relevant if using ObjectBox through JNI. */
9+
RESULT_ARRAY(1),
10+
11+
/** TimeSeries support (date/date-nano companion ID and other time-series functionality). */
12+
TIME_SERIES(2),
13+
14+
/** Sync client availability. Visit https://objectbox.io/sync for more details. */
15+
SYNC(3),
16+
17+
/** Check whether debug log can be enabled during runtime. */
18+
DEBUG_LOG(4),
19+
20+
/** HTTP server with a database browser. */
21+
ADMIN(5),
22+
23+
/** Trees & GraphQL support */
24+
TREES(6),
25+
26+
/** Embedded Sync server availability. */
27+
SYNC_SERVER(7);
28+
29+
public int id;
30+
31+
Feature(int id) {
32+
this.id = id;
33+
}
34+
}

0 commit comments

Comments
 (0)