Skip to content

Commit a30a331

Browse files
committed
update FlatStoreOptions and use reversed skipReadSchema semantics
1 parent 793085d commit a30a331

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public static boolean isObjectBrowserAvailable() {
268268
queryAttempts = Math.max(builder.queryAttempts, 1);
269269
}
270270

271-
private byte[] buildFlatStoreOptions(BoxStoreBuilder builder, String canonicalPath) {
271+
private static byte[] buildFlatStoreOptions(BoxStoreBuilder builder, String canonicalPath) {
272272
FlatBufferBuilder fbb = new FlatBufferBuilder();
273273
// FlatBuffer default values are set in generated code, e.g. may be different from here, so always store value.
274274
fbb.forceDefaults(true);
@@ -291,9 +291,9 @@ private byte[] buildFlatStoreOptions(BoxStoreBuilder builder, String canonicalPa
291291
FlatStoreOptions.addValidateOnOpenPageLimit(fbb, validateOnOpenPageLimit);
292292
}
293293
}
294-
FlatStoreOptions.addReadSchema(fbb, !builder.doNotReadSchema);
295-
FlatStoreOptions.addUsePreviousCommit(fbb, builder.usePreviousCommit);
296-
FlatStoreOptions.addReadOnly(fbb, builder.readOnly);
294+
if(builder.skipReadSchema) FlatStoreOptions.addSkipReadSchema(fbb, builder.skipReadSchema);
295+
if(builder.usePreviousCommit) FlatStoreOptions.addUsePreviousCommit(fbb, builder.usePreviousCommit);
296+
if(builder.readOnly) FlatStoreOptions.addReadOnly(fbb, builder.readOnly);
297297
int debugFlags = builder.debugFlags;
298298
if (debugFlags != 0) {
299299
FlatStoreOptions.addDebugFlags(fbb, debugFlags);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class BoxStoreBuilder {
9595
int queryAttempts;
9696

9797
/** For DebugCursor. */
98-
boolean doNotReadSchema;
98+
boolean skipReadSchema;
9999

100100
boolean readOnly;
101101
boolean usePreviousCommit;
@@ -112,7 +112,7 @@ public class BoxStoreBuilder {
112112
@Internal
113113
public static BoxStoreBuilder createDebugWithoutModel() {
114114
BoxStoreBuilder builder = new BoxStoreBuilder();
115-
builder.doNotReadSchema = true;
115+
builder.skipReadSchema = true;
116116
return builder;
117117
}
118118

objectbox-java/src/main/java/io/objectbox/model/FlatStoreOptions.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/**
2727
* Options to open a store with. Set only the values you want; defaults are used otherwise.
2828
* Reminder: enable "force defaults" in the FlatBuffers builder, e.g. to pass in booleans with value "false".
29+
* NOTE: some setting are for "advanced" purposes that you can typically ignore for regular usage.
30+
* When using advanced setting, you should know exactly what you are doing.
2931
*/
3032
@SuppressWarnings("unused")
3133
public final class FlatStoreOptions extends Table {
@@ -35,16 +37,31 @@ public final class FlatStoreOptions extends Table {
3537
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
3638
public FlatStoreOptions __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
3739

40+
/**
41+
* Location of the database on disk; this will be a directory containing files.
42+
*/
3843
public String directoryPath() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
3944
public ByteBuffer directoryPathAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
4045
public ByteBuffer directoryPathInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
46+
/**
47+
* Provide a data model, e.g. to initialize or update the schema.
48+
*/
4149
public int modelBytes(int j) { int o = __offset(6); return o != 0 ? bb.get(__vector(o) + j * 1) & 0xFF : 0; }
4250
public int modelBytesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
4351
public ByteVector modelBytesVector() { return modelBytesVector(new ByteVector()); }
4452
public ByteVector modelBytesVector(ByteVector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), bb) : null; }
4553
public ByteBuffer modelBytesAsByteBuffer() { return __vector_as_bytebuffer(6, 1); }
4654
public ByteBuffer modelBytesInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); }
55+
/**
56+
* This maximum size setting is meant to prevent your database from growing to unexpected sizes,
57+
* e.g. caused by programming error.
58+
* If your app runs into errors like "db full", you may consider to raise the limit.
59+
*/
4760
public long maxDbSizeInKByte() { int o = __offset(8); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
61+
/**
62+
* File permissions given in Unix style octal bit flags (e.g. 0644). Ignored on Windows.
63+
* Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
64+
*/
4865
public long fileMode() { int o = __offset(10); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; }
4966
/**
5067
* The maximum number of readers.
@@ -72,16 +89,25 @@ public final class FlatStoreOptions extends Table {
7289
* This is only to be used with ValidateOnOpenMode "Regular" and "WithLeaves".
7390
*/
7491
public long validateOnOpenPageLimit() { int o = __offset(16); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
92+
/**
93+
* Don't touch unless you know exactly what you are doing:
94+
* Advanced setting typically meant for language bindings (not end users). See PutPaddingMode description.
95+
*/
7596
public int putPaddingMode() { int o = __offset(18); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
76-
public boolean readSchema() { int o = __offset(20); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
7797
/**
78-
* Recommended to be used together with read-only mode to ensure no data is lost.
98+
* Advanced setting meant only for special scenarios: opens the database in a limited, schema-less mode.
99+
* If you don't know what this means exactly: ignore this flag.
100+
*/
101+
public boolean skipReadSchema() { int o = __offset(20); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
102+
/**
103+
* Advanced setting recommended to be used together with read-only mode to ensure no data is lost.
79104
* Ignores the latest data snapshot (committed transaction state) and uses the previous snapshot instead.
80105
* When used with care (e.g. backup the DB files first), this option may also recover data removed by the latest
81106
* transaction.
82107
*/
83108
public boolean usePreviousCommit() { int o = __offset(22); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
84109
/**
110+
* NOT IMPLEMENTED YET. Placeholder for a future version only.
85111
* If consistency checks fail during opening the DB (see also the pagesToValidateOnOpen setting), ObjectBox
86112
* automatically switches to the previous commit (see also usePreviousCommit). This way, this constitutes
87113
* an auto-recover mode from severe failures. HOWEVER, keep in mind that any consistency failure
@@ -93,6 +119,9 @@ public final class FlatStoreOptions extends Table {
93119
* Open store in read-only mode: no schema update, no write transactions.
94120
*/
95121
public boolean readOnly() { int o = __offset(26); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
122+
/**
123+
* For debugging purposes you may want enable specific logging.
124+
*/
96125
public long debugFlags() { int o = __offset(28); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; }
97126

98127
public static int createFlatStoreOptions(FlatBufferBuilder builder,
@@ -104,7 +133,7 @@ public static int createFlatStoreOptions(FlatBufferBuilder builder,
104133
int validateOnOpen,
105134
long validateOnOpenPageLimit,
106135
int putPaddingMode,
107-
boolean readSchema,
136+
boolean skipReadSchema,
108137
boolean usePreviousCommit,
109138
boolean usePreviousCommitOnValidationFailure,
110139
boolean readOnly,
@@ -122,7 +151,7 @@ public static int createFlatStoreOptions(FlatBufferBuilder builder,
122151
FlatStoreOptions.addReadOnly(builder, readOnly);
123152
FlatStoreOptions.addUsePreviousCommitOnValidationFailure(builder, usePreviousCommitOnValidationFailure);
124153
FlatStoreOptions.addUsePreviousCommit(builder, usePreviousCommit);
125-
FlatStoreOptions.addReadSchema(builder, readSchema);
154+
FlatStoreOptions.addSkipReadSchema(builder, skipReadSchema);
126155
return FlatStoreOptions.endFlatStoreOptions(builder);
127156
}
128157

@@ -138,7 +167,7 @@ public static int createFlatStoreOptions(FlatBufferBuilder builder,
138167
public static void addValidateOnOpen(FlatBufferBuilder builder, int validateOnOpen) { builder.addShort(5, (short)validateOnOpen, (short)0); }
139168
public static void addValidateOnOpenPageLimit(FlatBufferBuilder builder, long validateOnOpenPageLimit) { builder.addLong(6, validateOnOpenPageLimit, 0L); }
140169
public static void addPutPaddingMode(FlatBufferBuilder builder, int putPaddingMode) { builder.addShort(7, (short)putPaddingMode, (short)0); }
141-
public static void addReadSchema(FlatBufferBuilder builder, boolean readSchema) { builder.addBoolean(8, readSchema, false); }
170+
public static void addSkipReadSchema(FlatBufferBuilder builder, boolean skipReadSchema) { builder.addBoolean(8, skipReadSchema, false); }
142171
public static void addUsePreviousCommit(FlatBufferBuilder builder, boolean usePreviousCommit) { builder.addBoolean(9, usePreviousCommit, false); }
143172
public static void addUsePreviousCommitOnValidationFailure(FlatBufferBuilder builder, boolean usePreviousCommitOnValidationFailure) { builder.addBoolean(10, usePreviousCommitOnValidationFailure, false); }
144173
public static void addReadOnly(FlatBufferBuilder builder, boolean readOnly) { builder.addBoolean(11, readOnly, false); }

0 commit comments

Comments
 (0)