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 — Share db file: add API to check if database files are open. · TinyAndNeo/objectbox-java@28091b8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • BoxStore.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
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,41 @@ static boolean isFileOpenSync(String canonicalPath, boolean runFinalization) {
384384
}
385385
}
386386

387+
/**
388+
* Using an Android Context and an optional database name, as configured with {@link BoxStoreBuilder#name(String)},
389+
* checks if the associated database files are in use by a BoxStore instance.
390+
* <p>
391+
* Use this to check that database files are not open before copying or deleting them.
392+
*/
393+
public static boolean isDatabaseOpen(Object context, @Nullable String dbNameOrNull) throws IOException {
394+
File dbDir = BoxStoreBuilder.getAndroidDbDir(context, dbNameOrNull);
395+
return isFileOpen(dbDir.getCanonicalPath());
396+
}
397+
398+
/**
399+
* Using an optional base directory, as configured with {@link BoxStoreBuilder#baseDirectory(File)},
400+
* and an optional database name, as configured with {@link BoxStoreBuilder#name(String)},
401+
* checks if the associated database files are in use by a BoxStore instance.
402+
* <p>
403+
* Use this to check that database files are not open before copying or deleting them.
404+
*/
405+
public static boolean isDatabaseOpen(@Nullable File baseDirectoryOrNull,
406+
@Nullable String dbNameOrNull) throws IOException {
407+
408+
File dbDir = BoxStoreBuilder.getDbDir(baseDirectoryOrNull, dbNameOrNull);
409+
return isFileOpen(dbDir.getCanonicalPath());
410+
}
411+
412+
/**
413+
* Using a directory, as configured with {@link BoxStoreBuilder#directory(File)},
414+
* checks if the associated database files are in use by a BoxStore instance.
415+
* <p>
416+
* Use this to check that database files are not open before copying or deleting them.
417+
*/
418+
public static boolean isDatabaseOpen(File directory) throws IOException {
419+
return isFileOpen(directory.getCanonicalPath());
420+
}
421+
387422
/**
388423
* The size in bytes occupied by the data file on disk.
389424
*

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.