| 67 | /// |
| 68 | /// @author Chen |
| 69 | public abstract class Database { |
| 70 | |
| 71 | /// Checks if this platform supports custom database paths. On platforms that |
| 72 | /// support this, you can pass a file path to `#openOrCreate(java.lang.String)`, `#exists(java.lang.String)`, |
| 73 | /// `#delete(java.lang.String)`, and `#getDatabasePath(java.lang.String)`. |
| 74 | /// |
| 75 | /// #### Returns |
| 76 | /// |
| 77 | /// True on platorms that support custom database paths. |
| 78 | public static boolean isCustomPathSupported() { |
| 79 | return Display.getInstance().isDatabaseCustomPathSupported(); |
| 80 | } |
| 81 | |
| 82 | private static void validateDatabaseNameArgument(String databaseName) { |
| 83 | // PMD Fix (CollapsibleIfStatements): Merge the custom path support and separator checks into one condition. |
| 84 | if (!isCustomPathSupported() && (databaseName.indexOf("/") != -1 || databaseName.indexOf("\\") != -1)) { |
| 85 | throw new IllegalArgumentException("This platform does not support custom database paths. The database name cannot contain file separators."); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /// Opens a database or create one if not exists. |
| 90 | /// |
| 91 | /// #### Parameters |
| 92 | /// |
| 93 | /// - `databaseName`: @param databaseName the name of the database. Platforms that support custom database |
| 94 | /// paths (i.e. `#isCustomPathSupported()` return true), will also accept a file path here. |
| 95 | /// |
| 96 | /// #### Returns |
| 97 | /// |
| 98 | /// Database Object or null if not supported on the platform |
| 99 | /// |
| 100 | /// #### Throws |
| 101 | /// |
| 102 | /// - `IOException`: if database cannot be created |
| 103 | public static Database openOrCreate(String databaseName) throws IOException { |
| 104 | validateDatabaseNameArgument(databaseName); |
| 105 | return Display.getInstance().openOrCreate(databaseName); |
| 106 | } |
| 107 | |
| 108 | /// Indicates weather a database exists |
| 109 | /// |
| 110 | /// **NOTE:** Not supported in the Javascript port. Will always return false. |
| 111 | /// |
| 112 | /// #### Parameters |
| 113 | /// |
| 114 | /// - `databaseName`: @param databaseName the name of the database. Platforms that support custom database |
| 115 | /// paths (i.e. `#isCustomPathSupported()` return true), will also accept a file path here. |
| 116 | /// |
| 117 | /// #### Returns |
| 118 | /// |
| 119 | /// true if database exists |
| 120 | public static boolean exists(String databaseName) { |
| 121 | validateDatabaseNameArgument(databaseName); |
| 122 | return Display.getInstance().exists(databaseName); |
| 123 | } |
| 124 | |
| 125 | /// Deletes database |
| 126 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected