Skip to content

Commit ab85404

Browse files
committed
Merge branch 'dev' into sync
# Conflicts: # objectbox-java/src/main/java/io/objectbox/BoxStore.java # tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTest.java
2 parents 24349b7 + 84a2274 commit ab85404

20 files changed

+591
-42
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<img width="466" src="https://raw.githubusercontent.com/objectbox/objectbox-java/master/logo.png">
22

3-
# Do you ♥️ using ObjectBox?
43
[![Follow ObjectBox on Twitter](https://img.shields.io/twitter/follow/ObjectBox_io.svg?style=flat-square&logo=twitter&color=fff)](https://twitter.com/ObjectBox_io)
54

6-
We want to [hear about your app](https://docs.google.com/forms/d/e/1FAIpQLScIYiOIThcq-AnDVoCvnZOMgxO4S-fBtDSFPQfWldJnhi2c7Q/viewform)!
7-
It will - literally - take just a minute, but help us a lot. Thank you!​ 🙏​
8-
95
# ObjectBox Java (Kotlin, Android)
106
ObjectBox is a superfast object-oriented database with strong relation support.
117
ObjectBox is embedded into your Android, Linux, macOS, or Windows app.
128

13-
**Latest version: [2.5.1 (2020/02/10)](https://docs.objectbox.io/#objectbox-changelog)**
9+
**Latest version: [2.7.0 (2020/07/30)](https://docs.objectbox.io/#objectbox-changelog)**
1410

1511
Demo code using ObjectBox:
1612

@@ -29,15 +25,15 @@ Besides JVM based languages like Java and Kotlin, ObjectBox also offers:
2925
* [ObjectBox Swift](https://github.com/objectbox/objectbox-swift): build fast mobile apps for iOS (and macOS)
3026
* [ObjectBox Dart/Flutter](https://github.com/objectbox/objectbox-dart): cross-plattform for mobile and desktop apps (beta)
3127
* [ObjectBox Go](https://github.com/objectbox/objectbox-go): great for data-driven tools and small server applications
32-
* [ObjectBox C API](https://github.com/objectbox/objectbox-c): native speed with zero copy access to FlatBuffer objects
28+
* [ObjectBox C and C++](https://github.com/objectbox/objectbox-c): native speed with zero copy access to FlatBuffer objects
3329

3430
Gradle setup
3531
------------
3632
Add this to your root build.gradle (project level):
3733

3834
```groovy
3935
buildscript {
40-
ext.objectboxVersion = '2.5.1'
36+
ext.objectboxVersion = '2.7.0'
4137
dependencies {
4238
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
4339
}
@@ -72,7 +68,7 @@ Box<Playlist> box = boxStore.boxFor(Playlist.class);
7268

7369
The `Box` object gives you access to all major functions, like `put`, `get`, `remove`, and `query`.
7470

75-
For details please check the [docs](http://objectbox.io/documentation/).
71+
For details please check the [docs](https://docs.objectbox.io).
7672

7773
Links
7874
-----
@@ -88,6 +84,8 @@ We love to get your feedback
8884
Let us know how we are doing: [2 minute questionnaire](https://docs.google.com/forms/d/e/1FAIpQLSe_fq-FlBThK_96bkHv1oEDizoHwEu_b6M4FJkMv9V5q_Or9g/viewform?usp=sf_link).
8985
Thanks!
9086

87+
Also, we want to [hear about your app](https://docs.google.com/forms/d/e/1FAIpQLScIYiOIThcq-AnDVoCvnZOMgxO4S-fBtDSFPQfWldJnhi2c7Q/viewform)!
88+
It will - literally - take just a minute, but help us a lot. Thank you!​ 🙏​
9189

9290
License
9391
-------

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
33
// Typically, only edit those two:
4-
def objectboxVersionNumber = '2.6.0' // without "-SNAPSHOT", e.g. '2.5.0' or '2.4.0-RC'
4+
def objectboxVersionNumber = '2.7.1' // without "-SNAPSHOT", e.g. '2.5.0' or '2.4.0-RC'
55
def objectboxVersionRelease = false // set to true for releasing to ignore versionPostFix to avoid e.g. "-dev" versions
66

77
// version post fix: '-<value>' or '' if not defined; e.g. used by CI to pass in branch name

objectbox-java/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ dependencies {
99
implementation 'org.greenrobot:essentials:3.0.0-RC1'
1010
implementation 'com.google.flatbuffers:flatbuffers-java:1.12.0'
1111
api 'com.google.code.findbugs:jsr305:3.0.2'
12+
13+
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.0.4'
1214
}
1315

1416
spotbugs {
1517
ignoreFailures = true
18+
excludeFilter = file("spotbugs-exclude.xml")
1619
}
1720

1821
javadoc {

objectbox-java/spotbugs-exclude.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<Match>
4+
<!-- Exclude FlatBuffers generated code. -->
5+
<Class name="~io\.objectbox\.model\.Model.*" />
6+
</Match>
7+
</FindBugsFilter>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ public List<T> getAll() {
317317
}
318318
}
319319

320+
/**
321+
* Check if an object with the given ID exists in the database.
322+
* This is more efficient than a {@link #get(long)} and comparing against null.
323+
* @since 2.7
324+
* @return true if a object with the given ID was found, false otherwise
325+
*/
326+
public boolean contains(long id) {
327+
Cursor<T> reader = getReader();
328+
try {
329+
return reader.seek(id);
330+
} finally {
331+
releaseReader(reader);
332+
}
333+
}
334+
320335
/**
321336
* Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID
322337
* will be assigned to the entity (and returned). If the entity was already put in the box before, it will be

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

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2020 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.
@@ -16,6 +16,7 @@
1616

1717
package io.objectbox;
1818

19+
import io.objectbox.annotation.apihint.Beta;
1920
import org.greenrobot.essentials.collections.LongHashMap;
2021

2122
import java.io.Closeable;
@@ -66,9 +67,9 @@ public class BoxStore implements Closeable {
6667
@Nullable private static Object relinker;
6768

6869
/** Change so ReLinker will update native library when using workaround loading. */
69-
public static final String JNI_VERSION = "2.6.0-RC";
70+
public static final String JNI_VERSION = "2.7.0";
7071

71-
private static final String VERSION = "2.6.0-2020-04-30";
72+
private static final String VERSION = "2.7.0-2020-07-30";
7273
private static BoxStore defaultStore;
7374

7475
/** Currently used DB dirs with values from {@link #getCanonicalPath(File)}. */
@@ -138,7 +139,13 @@ public static String getVersionNative() {
138139
*/
139140
public static native void testUnalignedMemoryAccess();
140141

141-
static native long nativeCreate(String directory, long maxDbSizeInKByte, int maxReaders, byte[] model);
142+
/**
143+
* Creates a native BoxStore instance with FlatBuffer {@link io.objectbox.model.FlatStoreOptions} {@code options}
144+
* and a {@link ModelBuilder} {@code model}. Returns the handle of the native store instance.
145+
*/
146+
static native long nativeCreateWithFlatOptions(byte[] options, byte[] model);
147+
148+
static native boolean nativeIsReadOnly(long store);
142149

143150
static native void nativeDelete(long store);
144151

@@ -170,6 +177,10 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
170177

171178
static native boolean nativeIsObjectBrowserAvailable();
172179

180+
native long nativeSizeOnDisk(long store);
181+
182+
native long nativeValidate(long store, long pageLimit, boolean checkLeafLevel);
183+
173184
static native int nativeGetSupportedSync();
174185

175186
public static boolean isObjectBrowserAvailable() {
@@ -242,10 +253,9 @@ public static boolean isSyncServerAvailable() {
242253
canonicalPath = getCanonicalPath(directory);
243254
verifyNotAlreadyOpen(canonicalPath);
244255

245-
handle = nativeCreate(canonicalPath, builder.maxSizeInKByte, builder.maxReaders, builder.model);
256+
handle = nativeCreateWithFlatOptions(builder.buildFlatStoreOptions(canonicalPath), builder.model);
246257
int debugFlags = builder.debugFlags;
247258
if (debugFlags != 0) {
248-
nativeSetDebugFlags(handle, debugFlags);
249259
debugTxRead = (debugFlags & DebugFlags.LOG_TRANSACTIONS_READ) != 0;
250260
debugTxWrite = (debugFlags & DebugFlags.LOG_TRANSACTIONS_WRITE) != 0;
251261
} else {
@@ -360,6 +370,16 @@ static boolean isFileOpenSync(String canonicalPath, boolean runFinalization) {
360370
}
361371
}
362372

373+
/**
374+
* The size in bytes occupied by the data file on disk.
375+
*
376+
* @return 0 if the size could not be determined (does not throw unless this store was already closed)
377+
*/
378+
public long sizeOnDisk() {
379+
checkOpen();
380+
return nativeSizeOnDisk(handle);
381+
}
382+
363383
/**
364384
* Explicitly call {@link #close()} instead to avoid expensive finalization.
365385
*/
@@ -464,6 +484,14 @@ public boolean isClosed() {
464484
return closed;
465485
}
466486

487+
/**
488+
* Whether the store was created using read-only mode.
489+
* If true the schema is not updated and write transactions are not possible.
490+
*/
491+
public boolean isReadOnly() {
492+
return nativeIsReadOnly(handle);
493+
}
494+
467495
/**
468496
* Closes the BoxStore and frees associated resources.
469497
* This method is useful for unit tests;
@@ -926,6 +954,24 @@ public String diagnose() {
926954
return nativeDiagnose(handle);
927955
}
928956

957+
/**
958+
* Validate database pages, a lower level storage unit (integrity check).
959+
* Do not call this inside a transaction (currently unsupported).
960+
* @param pageLimit the maximum of pages to validate (e.g. to limit time spent on validation).
961+
* Pass zero set no limit and thus validate all pages.
962+
* @param checkLeafLevel Flag to validate leaf pages. These do not point to other pages but contain data.
963+
* @return Number of pages validated, which may be twice the given pageLimit as internally there are "two DBs".
964+
* @throws DbException if validation failed to run (does not tell anything about DB file consistency).
965+
* @throws io.objectbox.exception.FileCorruptException if the DB file is actually inconsistent (corrupt).
966+
*/
967+
@Beta
968+
public long validate(long pageLimit, boolean checkLeafLevel) {
969+
if (pageLimit < 0) {
970+
throw new IllegalArgumentException("pageLimit must be zero or positive");
971+
}
972+
return nativeValidate(handle, pageLimit, checkLeafLevel);
973+
}
974+
929975
public int cleanStaleReadTransactions() {
930976
return nativeCleanStaleReadTransactions(handle);
931977
}

0 commit comments

Comments
 (0)