GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Store: add dbSize and dbSizeOnDisk, deprecate sizeOnDisk #203 · Hancony/objectbox-java@fc1b827

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • BoxStore.java
  • tests/objectbox-java-test/src/test/java/io/objectbox
    • BoxStoreTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/BoxStore.java
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
194194

195195
static native boolean nativeIsObjectBrowserAvailable();
196196

197-
native long nativeSizeOnDisk(long store);
197+
native long nativeDbSize(long store);
198+
199+
native long nativeDbSizeOnDisk(long store);
198200

199201
native long nativeValidate(long store, long pageLimit, boolean checkLeafLevel);
200202

@@ -484,9 +486,31 @@ public static long sysProcStatusKb(String key) {
484486
* The size in bytes occupied by the data file on disk.
485487
*
486488
* @return 0 if the size could not be determined (does not throw unless this store was already closed)
489+
* @deprecated Use {@link #dbSize()} or {@link #dbSizeOnDisk()} instead which properly handle in-memory databases.
487490
*/
491+
@Deprecated
488492
public long sizeOnDisk() {
489-
return nativeSizeOnDisk(getNativeStore());
493+
return dbSize();
494+
}
495+
496+
/**
497+
* Get the size of this store. For a disk-based store type, this corresponds to the size on disk, and for the
498+
* in-memory store type, this is roughly the used memory bytes occupied by the data.
499+
*
500+
* @return The size in bytes of the database, or 0 if the file does not exist or some error occurred.
501+
*/
502+
public long dbSize() {
503+
return nativeDbSize(getNativeStore());
504+
}
505+
506+
/**
507+
* The size in bytes occupied by the database on disk (if any).
508+
*
509+
* @return The size in bytes of the database on disk, or 0 if the underlying database is in-memory only
510+
* or the size could not be determined.
511+
*/
512+
public long dbSizeOnDisk() {
513+
return nativeDbSizeOnDisk(getNativeStore());
490514
}
491515

492516
/**
Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTest.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTest.java
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public void testClose() {
114114

115115
// Methods using the native store should throw.
116116
assertThrowsStoreIsClosed(store::sizeOnDisk);
117+
assertThrowsStoreIsClosed(store::dbSize);
118+
assertThrowsStoreIsClosed(store::dbSizeOnDisk);
117119
assertThrowsStoreIsClosed(store::beginTx);
118120
assertThrowsStoreIsClosed(store::beginReadTx);
119121
assertThrowsStoreIsClosed(store::isReadOnly);
@@ -306,9 +308,18 @@ private Callable<String> createTestCallable(final int[] countHolder) {
306308

307309
@Test
308310
public void testSizeOnDisk() {
309-
long size = store.sizeOnDisk();
310311
// Note: initial database does have a non-zero (file) size.
311-
assertTrue(size > 0);
312+
long legacySizeOnDisk = store.sizeOnDisk();
313+
assertTrue(legacySizeOnDisk > 0);
314+
315+
assertTrue(store.dbSize() > 0);
316+
317+
long sizeOnDisk = store.dbSizeOnDisk();
318+
if (IN_MEMORY) {
319+
assertEquals(0, sizeOnDisk);
320+
} else {
321+
assertTrue(sizeOnDisk > 0);
322+
}
312323
}
313324

314325
@Test

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.