|
16 | 16 |
|
17 | 17 | package io.objectbox;
|
18 | 18 |
|
| 19 | +import com.google.flatbuffers.FlatBufferBuilder; |
| 20 | + |
19 | 21 | import org.greenrobot.essentials.collections.LongHashMap;
|
20 | 22 |
|
21 | 23 | import java.io.Closeable;
|
|
47 | 49 | import io.objectbox.exception.DbSchemaException;
|
48 | 50 | import io.objectbox.internal.NativeLibraryLoader;
|
49 | 51 | import io.objectbox.internal.ObjectBoxThreadPool;
|
| 52 | +import io.objectbox.model.FlatStoreOptions; |
50 | 53 | import io.objectbox.reactive.DataObserver;
|
51 | 54 | import io.objectbox.reactive.DataPublisher;
|
52 | 55 | import io.objectbox.reactive.SubscriptionBuilder;
|
@@ -237,7 +240,7 @@ public static boolean isObjectBrowserAvailable() {
|
237 | 240 | canonicalPath = getCanonicalPath(directory);
|
238 | 241 | verifyNotAlreadyOpen(canonicalPath);
|
239 | 242 |
|
240 |
| - handle = nativeCreate(canonicalPath, builder.maxSizeInKByte, builder.maxReaders, builder.model); |
| 243 | + handle = nativeCreateWithFlatOptions(buildFlatStoreOptions(builder, canonicalPath), builder.model); |
241 | 244 | int debugFlags = builder.debugFlags;
|
242 | 245 | if (debugFlags != 0) {
|
243 | 246 | nativeSetDebugFlags(handle, debugFlags);
|
@@ -281,6 +284,27 @@ public static boolean isObjectBrowserAvailable() {
|
281 | 284 | queryAttempts = Math.max(builder.queryAttempts, 1);
|
282 | 285 | }
|
283 | 286 |
|
| 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 | + |
284 | 308 | static String getCanonicalPath(File directory) {
|
285 | 309 | if (directory.exists()) {
|
286 | 310 | if (!directory.isDirectory()) {
|
|
0 commit comments