Skip to content

Commit fa4fdea

Browse files
Use nativeCreateWithFlatOptions with existing options.
1 parent 4469bd5 commit fa4fdea

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.objectbox;
1818

19+
import com.google.flatbuffers.FlatBufferBuilder;
20+
1921
import org.greenrobot.essentials.collections.LongHashMap;
2022

2123
import java.io.Closeable;
@@ -47,6 +49,7 @@
4749
import io.objectbox.exception.DbSchemaException;
4850
import io.objectbox.internal.NativeLibraryLoader;
4951
import io.objectbox.internal.ObjectBoxThreadPool;
52+
import io.objectbox.model.FlatStoreOptions;
5053
import io.objectbox.reactive.DataObserver;
5154
import io.objectbox.reactive.DataPublisher;
5255
import io.objectbox.reactive.SubscriptionBuilder;
@@ -237,7 +240,7 @@ public static boolean isObjectBrowserAvailable() {
237240
canonicalPath = getCanonicalPath(directory);
238241
verifyNotAlreadyOpen(canonicalPath);
239242

240-
handle = nativeCreate(canonicalPath, builder.maxSizeInKByte, builder.maxReaders, builder.model);
243+
handle = nativeCreateWithFlatOptions(buildFlatStoreOptions(builder, canonicalPath), builder.model);
241244
int debugFlags = builder.debugFlags;
242245
if (debugFlags != 0) {
243246
nativeSetDebugFlags(handle, debugFlags);
@@ -281,6 +284,27 @@ public static boolean isObjectBrowserAvailable() {
281284
queryAttempts = Math.max(builder.queryAttempts, 1);
282285
}
283286

287+
private byte[] buildFlatStoreOptions(BoxStoreBuilder builder, String canonicalPath) {
288+
FlatBufferBuilder fbb = new FlatBufferBuilder();
289+
290+
// Add non-integer values first...
291+
int directoryPathOffset = fbb.createString(canonicalPath);
292+
293+
FlatStoreOptions.startFlatStoreOptions(fbb);
294+
295+
// ...then build options.
296+
FlatStoreOptions.addDirectoryPath(fbb, directoryPathOffset);
297+
// FlatStoreOptions.addModelBytes(fbb, modelBytesOffset); // TODO Use this instead of model param on JNI method?
298+
FlatStoreOptions.addMaxDbSizeInKByte(fbb, builder.maxSizeInKByte);
299+
FlatStoreOptions.addMaxReaders(fbb, builder.maxReaders);
300+
// FlatStoreOptions.addDebugFlags(fbb, builder.debugFlags); // TODO Use this instead of nativeSetDebugFlags?
301+
// TODO Add new values.
302+
303+
int offset = FlatStoreOptions.endFlatStoreOptions(fbb);
304+
fbb.finish(offset);
305+
return fbb.sizedByteArray();
306+
}
307+
284308
static String getCanonicalPath(File directory) {
285309
if (directory.exists()) {
286310
if (!directory.isDirectory()) {

0 commit comments

Comments
 (0)