Skip to content

Commit 4042917

Browse files
Merge branch '190-config-package' into 'dev'
Create config package for FlatBuffers-generated config types #190 See merge request objectbox/objectbox-java!125
2 parents 9ff2508 + 93746a9 commit 4042917

15 files changed

+147
-28
lines changed

objectbox-java/spotbugs-exclude.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<Match>
66
<Class name="io.objectbox.DebugFlags" />
77
</Match>
8+
<Match>
9+
<Package name="io.objectbox.config" />
10+
</Match>
811
<Match>
912
<Package name="io.objectbox.model" />
1013
</Match>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,8 @@
4242
import io.objectbox.annotation.apihint.Beta;
4343
import io.objectbox.annotation.apihint.Experimental;
4444
import io.objectbox.annotation.apihint.Internal;
45+
import io.objectbox.config.DebugFlags;
46+
import io.objectbox.config.FlatStoreOptions;
4547
import io.objectbox.converter.PropertyConverter;
4648
import io.objectbox.exception.DbException;
4749
import io.objectbox.exception.DbExceptionListener;
@@ -136,7 +138,7 @@ public static String getVersionNative() {
136138
}
137139

138140
/**
139-
* Creates a native BoxStore instance with FlatBuffer {@link io.objectbox.model.FlatStoreOptions} {@code options}
141+
* Creates a native BoxStore instance with FlatBuffer {@link FlatStoreOptions} {@code options}
140142
* and a {@link ModelBuilder} {@code model}. Returns the handle of the native store instance.
141143
*/
142144
static native long nativeCreateWithFlatOptions(byte[] options, byte[] model);

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,15 +33,16 @@
3333

3434
import io.objectbox.annotation.apihint.Experimental;
3535
import io.objectbox.annotation.apihint.Internal;
36+
import io.objectbox.config.DebugFlags;
37+
import io.objectbox.config.FlatStoreOptions;
38+
import io.objectbox.config.ValidateOnOpenModeKv;
39+
import io.objectbox.config.ValidateOnOpenModePages;
3640
import io.objectbox.exception.DbException;
3741
import io.objectbox.exception.DbFullException;
3842
import io.objectbox.exception.DbMaxDataSizeExceededException;
3943
import io.objectbox.exception.DbMaxReadersExceededException;
4044
import io.objectbox.flatbuffers.FlatBufferBuilder;
4145
import io.objectbox.ideasonly.ModelUpdate;
42-
import io.objectbox.model.FlatStoreOptions;
43-
import io.objectbox.model.ValidateOnOpenMode;
44-
import io.objectbox.model.ValidateOnOpenModeKv;
4546
import org.greenrobot.essentials.io.IoUtils;
4647

4748
/**
@@ -413,13 +414,14 @@ public BoxStoreBuilder usePreviousCommit() {
413414
* See also {@link #validateOnOpenPageLimit(long)} to fine-tune this check and {@link #validateOnOpenKv(short)} for
414415
* additional checks.
415416
*
416-
* @param validateOnOpenMode One of {@link ValidateOnOpenMode}.
417+
* @param validateOnOpenModePages One of {@link ValidateOnOpenModePages}.
417418
*/
418-
public BoxStoreBuilder validateOnOpen(short validateOnOpenMode) {
419-
if (validateOnOpenMode < ValidateOnOpenMode.None || validateOnOpenMode > ValidateOnOpenMode.Full) {
420-
throw new IllegalArgumentException("Must be one of ValidateOnOpenMode");
419+
public BoxStoreBuilder validateOnOpen(short validateOnOpenModePages) {
420+
if (validateOnOpenModePages < ValidateOnOpenModePages.None
421+
|| validateOnOpenModePages > ValidateOnOpenModePages.Full) {
422+
throw new IllegalArgumentException("Must be one of ValidateOnOpenModePages");
421423
}
422-
this.validateOnOpenModePages = validateOnOpenMode;
424+
this.validateOnOpenModePages = validateOnOpenModePages;
423425
return this;
424426
}
425427

@@ -428,10 +430,12 @@ public BoxStoreBuilder validateOnOpen(short validateOnOpenMode) {
428430
* This is measured in "pages" with a page typically holding 4000.
429431
* Usually a low number (e.g. 1-20) is sufficient and does not impact startup performance significantly.
430432
* <p>
431-
* This can only be used with {@link ValidateOnOpenMode#Regular} and {@link ValidateOnOpenMode#WithLeaves}.
433+
* This can only be used with {@link ValidateOnOpenModePages#Regular} and
434+
* {@link ValidateOnOpenModePages#WithLeaves}.
432435
*/
433436
public BoxStoreBuilder validateOnOpenPageLimit(long limit) {
434-
if (validateOnOpenModePages != ValidateOnOpenMode.Regular && validateOnOpenModePages != ValidateOnOpenMode.WithLeaves) {
437+
if (validateOnOpenModePages != ValidateOnOpenModePages.Regular &&
438+
validateOnOpenModePages != ValidateOnOpenModePages.WithLeaves) {
435439
throw new IllegalStateException("Must call validateOnOpen(mode) with mode Regular or WithLeaves first");
436440
}
437441
if (limit < 1) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
/**
2222
* Debug flags typically enable additional "debug logging" that can be helpful to better understand what is going on
2323
* internally. These are intended for the development process only; typically one does not enable them for releases.
24+
*
25+
* @deprecated DebugFlags moved to config package: use {@link io.objectbox.config.DebugFlags} instead.
2426
*/
2527
@SuppressWarnings("unused")
28+
@Deprecated
2629
public final class DebugFlags {
2730
private DebugFlags() { }
2831
public static final int LOG_TRANSACTIONS_READ = 1;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2023 ObjectBox Ltd. All rights reserved.
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+
17+
// automatically generated by the FlatBuffers compiler, do not modify
18+
19+
package io.objectbox.config;
20+
21+
/**
22+
* Debug flags typically enable additional "debug logging" that can be helpful to better understand what is going on
23+
* internally. These are intended for the development process only; typically one does not enable them for releases.
24+
*/
25+
@SuppressWarnings("unused")
26+
public final class DebugFlags {
27+
private DebugFlags() { }
28+
public static final int LOG_TRANSACTIONS_READ = 1;
29+
public static final int LOG_TRANSACTIONS_WRITE = 2;
30+
public static final int LOG_QUERIES = 4;
31+
public static final int LOG_QUERY_PARAMETERS = 8;
32+
public static final int LOG_ASYNC_QUEUE = 16;
33+
public static final int LOG_CACHE_HITS = 32;
34+
public static final int LOG_CACHE_ALL = 64;
35+
public static final int LOG_TREE = 128;
36+
/**
37+
* For a limited number of error conditions, this will try to print stack traces.
38+
* Note: this is Linux-only, experimental, and has several limitations:
39+
* The usefulness of these stack traces depends on several factors and might not be helpful at all.
40+
*/
41+
public static final int LOG_EXCEPTION_STACK_TRACE = 256;
42+
/**
43+
* Run a quick self-test to verify basic threading; somewhat paranoia to check the platform and the library setup.
44+
*/
45+
public static final int RUN_THREADING_SELF_TEST = 512;
46+
}
47+

objectbox-java/src/main/java/io/objectbox/model/FlatStoreOptions.java renamed to objectbox-java/src/main/java/io/objectbox/config/FlatStoreOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// automatically generated by the FlatBuffers compiler, do not modify
1818

19-
package io.objectbox.model;
19+
package io.objectbox.config;
2020

2121
import io.objectbox.flatbuffers.BaseVector;
2222
import io.objectbox.flatbuffers.BooleanVector;

objectbox-java/src/main/java/io/objectbox/model/TreeOptionFlags.java renamed to objectbox-java/src/main/java/io/objectbox/config/TreeOptionFlags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// automatically generated by the FlatBuffers compiler, do not modify
1818

19-
package io.objectbox.model;
19+
package io.objectbox.config;
2020

2121
/**
2222
* Options flags for trees.

objectbox-java/src/main/java/io/objectbox/model/ValidateOnOpenModeKv.java renamed to objectbox-java/src/main/java/io/objectbox/config/ValidateOnOpenModeKv.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// automatically generated by the FlatBuffers compiler, do not modify
1818

19-
package io.objectbox.model;
19+
package io.objectbox.config;
2020

2121
/**
2222
* Defines if and how the database is checked for valid key/value (KV) entries when opening it.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 ObjectBox Ltd. All rights reserved.
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+
17+
// automatically generated by the FlatBuffers compiler, do not modify
18+
19+
package io.objectbox.config;
20+
21+
/**
22+
* Defines if and how the database is checked for structural consistency (pages) when opening it.
23+
*/
24+
@SuppressWarnings("unused")
25+
public final class ValidateOnOpenModePages {
26+
private ValidateOnOpenModePages() { }
27+
/**
28+
* Not a real type, just best practice (e.g. forward compatibility)
29+
*/
30+
public static final short Unknown = 0;
31+
/**
32+
* No additional checks are performed. This is fine if your file system is reliable (which it typically should be).
33+
*/
34+
public static final short None = 1;
35+
/**
36+
* Performs a limited number of checks on the most important database structures (e.g. "branch pages").
37+
*/
38+
public static final short Regular = 2;
39+
/**
40+
* Performs a limited number of checks on database structures including "data leaves".
41+
*/
42+
public static final short WithLeaves = 3;
43+
/**
44+
* Performs a unlimited number of checks on the most important database structures (e.g. "branch pages").
45+
*/
46+
public static final short AllBranches = 4;
47+
/**
48+
* Performs a unlimited number of checks on database structures including "data leaves".
49+
*/
50+
public static final short Full = 5;
51+
52+
public static final String[] names = { "Unknown", "None", "Regular", "WithLeaves", "AllBranches", "Full", };
53+
54+
public static String name(int e) { return names[e]; }
55+
}
56+

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
/**
2222
* Defines if and how the database is checked for structural consistency (pages) when opening it.
23+
*
24+
* @deprecated This class has moved to the config package, use {@link io.objectbox.config.ValidateOnOpenModePages} instead.
2325
*/
26+
@Deprecated
2427
@SuppressWarnings("unused")
2528
public final class ValidateOnOpenMode {
2629
private ValidateOnOpenMode() { }

tests/objectbox-java-test/src/test/java/io/objectbox/AbstractObjectBoxTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2018 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import io.objectbox.ModelBuilder.EntityBuilder;
2020
import io.objectbox.ModelBuilder.PropertyBuilder;
2121
import io.objectbox.annotation.IndexType;
22+
import io.objectbox.config.DebugFlags;
2223
import io.objectbox.model.PropertyFlags;
2324
import io.objectbox.model.PropertyType;
2425
import org.junit.After;

tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreValidationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323

24+
import io.objectbox.config.ValidateOnOpenModePages;
2425
import io.objectbox.exception.FileCorruptException;
2526
import io.objectbox.exception.PagesCorruptException;
26-
import io.objectbox.model.ValidateOnOpenMode;
2727
import org.greenrobot.essentials.io.IoUtils;
2828
import org.junit.Before;
2929
import org.junit.Test;
@@ -62,7 +62,7 @@ public void validateOnOpen() {
6262
// Then re-open database with validation and ensure db is operational
6363
builder = new BoxStoreBuilder(model).directory(boxStoreDir);
6464
builder.entity(new TestEntity_());
65-
builder.validateOnOpen(ValidateOnOpenMode.Full);
65+
builder.validateOnOpen(ValidateOnOpenModePages.Full);
6666
store = builder.build();
6767
assertNotNull(getTestEntityBox().get(id));
6868
getTestEntityBox().put(new TestEntity(0));
@@ -75,7 +75,7 @@ public void validateOnOpenCorruptFile() throws IOException {
7575
prepareBadDataFile(dir, "corrupt-pageno-in-branch-data.mdb");
7676

7777
builder = BoxStoreBuilder.createDebugWithoutModel().directory(dir);
78-
builder.validateOnOpen(ValidateOnOpenMode.Full);
78+
builder.validateOnOpen(ValidateOnOpenModePages.Full);
7979

8080
@SuppressWarnings("resource")
8181
FileCorruptException ex = assertThrows(PagesCorruptException.class, () -> builder.build());
@@ -90,7 +90,7 @@ public void usePreviousCommitWithCorruptFile() throws IOException {
9090
File dir = prepareTempDir("object-store-test-corrupted");
9191
prepareBadDataFile(dir, "corrupt-pageno-in-branch-data.mdb");
9292
builder = BoxStoreBuilder.createDebugWithoutModel().directory(dir);
93-
builder.validateOnOpen(ValidateOnOpenMode.Full).usePreviousCommit();
93+
builder.validateOnOpen(ValidateOnOpenModePages.Full).usePreviousCommit();
9494
store = builder.build();
9595
String diagnoseString = store.diagnose();
9696
assertTrue(diagnoseString.contains("entries=2"));
@@ -104,7 +104,7 @@ public void usePreviousCommitAfterFileCorruptException() throws IOException {
104104
File dir = prepareTempDir("object-store-test-corrupted");
105105
prepareBadDataFile(dir, "corrupt-pageno-in-branch-data.mdb");
106106
builder = BoxStoreBuilder.createDebugWithoutModel().directory(dir);
107-
builder.validateOnOpen(ValidateOnOpenMode.Full);
107+
builder.validateOnOpen(ValidateOnOpenModePages.Full);
108108
try {
109109
store = builder.build();
110110
fail("Should have thrown");

tests/objectbox-java-test/src/test/java/io/objectbox/query/AbstractQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2018-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@
2525
import io.objectbox.AbstractObjectBoxTest;
2626
import io.objectbox.Box;
2727
import io.objectbox.BoxStoreBuilder;
28-
import io.objectbox.DebugFlags;
2928
import io.objectbox.TestEntity;
29+
import io.objectbox.config.DebugFlags;
3030

3131
import javax.annotation.Nullable;
3232

tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@
1919
import io.objectbox.Box;
2020
import io.objectbox.BoxStore;
2121
import io.objectbox.BoxStoreBuilder;
22-
import io.objectbox.DebugFlags;
2322
import io.objectbox.TestEntity;
2423
import io.objectbox.TestEntity_;
2524
import io.objectbox.TestUtils;
2625
import io.objectbox.exception.DbExceptionListener;
2726
import io.objectbox.exception.NonUniqueResultException;
27+
import io.objectbox.config.DebugFlags;
2828
import io.objectbox.query.QueryBuilder.StringOrder;
2929
import io.objectbox.relation.MyObjectBox;
3030
import io.objectbox.relation.Order;

tests/objectbox-java-test/src/test/java/io/objectbox/relation/AbstractRelationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2023 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import io.objectbox.Box;
2828
import io.objectbox.BoxStore;
2929
import io.objectbox.BoxStoreBuilder;
30-
import io.objectbox.DebugFlags;
30+
import io.objectbox.config.DebugFlags;
3131

3232
public abstract class AbstractRelationTest extends AbstractObjectBoxTest {
3333

0 commit comments

Comments
 (0)