Database and Table classes. In order to consume linked tables in non-mdb files, they need to
somehow be coerced into the appropriate form. The approach taken by this utility is to make it easy to copy the
external tables into a temporary mdb file for consumption by the primary database.
The primary features of this utility:
loadCustomFileLinkResolver#UNRESTRICTEDloadCustomTable| Modifier and Type | Class and Description |
|---|---|
| private static class | CustomLinkResolver.
Subclass of DatabaseImpl which allows us to load tables "on demand" as well as delete the temporary db on close. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Random | |
| public static final Database. | DEFAULT_FORMAT
the default file format used for temp dbs |
| public static final boolean | DEFAULT_IN_MEMORY
temp dbs default to the filesystem, not in memory |
| public static final Path | DEFAULT_TEMP_DIR
temp dbs end up in the system temp dir by default |
| private final Database. | |
| private final boolean | |
| private final Path | |
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| protected | CustomLinkResolver()
Creates a CustomLinkResolver using the default behavior for creating temp dbs, see |
| protected | CustomLinkResolver(Database.
the default format for the temp db defaultFormat,whether or not the temp db should be entirely in memory by default (while this will be
faster, it should only be used if table data is expected to fit entirely in memory) defaultInMemory, Path the default temp dir for a file based temp db ( defaultTempDir)null for the system defaqult temp
directory)Creates a CustomLinkResolver with the given default behavior for creating temp dbs. |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| protected Database | Returns: the temp db for holding the linked table infocustom file state returned from customFile, Database.loadCustomFilethe access format for the temp db format,whether or not the temp db should be entirely in memory (while this will be faster, it should
only be used if table data is expected to fit entirely in memory) inMemory, Path the temp dir for a file based temp db ( tempDir, boolean readOnly)null for the system default temp directory)Creates a temporary database for holding the table data from linkeeFileName. |
| private static void | |
| protected Database. | |
| protected Path | |
| protected boolean | |
| protected abstract Object | Returns: non-null if linkeeFileName should be treated as a custom file (using a temp db) or null
if it should be treated as a normal access db.the primary database in which the link is defined linkerDb, String the name of the linked file linkeeFileName)Called by |
| protected abstract boolean | Returns: true if the table was available in the linked file, false otherwisethe temp db instance which should be populated with the relevant table info for the given tableName tempDb, Object custom file state returned from customFile, String loadCustomFilethe name of the table which is requested from the linked file tableName)Called by an instance of a temp db when a missing table is first requested. |
| public Database | resolveLinkedDatabase(Database linkerDb, String linkeeFileName)
Implements io. Custom implementation is:
// attempt to load the linkeeFileName as a custom file
Object customFile = loadCustomFile(linkerDb, linkeeFileName);
if (customFile != null) {
// this is a custom file, create and return relevant temp db
return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(),
getDefaultTempDirectory());
}
// not a custom file, load using the default behavior
return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName);
|
| DB_ID | back to summary |
|---|---|
| private static final Random DB_ID | |
| DEFAULT_FORMAT | back to summary |
|---|---|
| public static final Database. the default file format used for temp dbs | |
| DEFAULT_IN_MEMORY | back to summary |
|---|---|
| public static final boolean DEFAULT_IN_MEMORY temp dbs default to the filesystem, not in memory | |
| DEFAULT_TEMP_DIR | back to summary |
|---|---|
| public static final Path DEFAULT_TEMP_DIR temp dbs end up in the system temp dir by default | |
| defaultFormat | back to summary |
|---|---|
| private final Database. | |
| defaultInMemory | back to summary |
|---|---|
| private final boolean defaultInMemory | |
| defaultTempDir | back to summary |
|---|---|
| private final Path defaultTempDir | |
| FILE_DB_PREFIX | back to summary |
|---|---|
| private static final String FILE_DB_PREFIX | |
| MEM_DB_PREFIX | back to summary |
|---|---|
| private static final String MEM_DB_PREFIX | |
| CustomLinkResolver | back to summary |
|---|---|
| protected CustomLinkResolver() Creates a CustomLinkResolver using the default behavior for creating temp dbs, see | |
| CustomLinkResolver | back to summary |
|---|---|
| protected CustomLinkResolver(Database. Creates a CustomLinkResolver with the given default behavior for creating temp dbs.
| |
| closeCustomFile | back to summary |
|---|---|
| private static void closeCustomFile(Object customFile) | |
| createTempDb | back to summary |
|---|---|
| protected Database createTempDb(Object customFile, Database. Creates a temporary database for holding the table data from linkeeFileName.
| |
| deleteDbFile | back to summary |
|---|---|
| private static void deleteDbFile(Path dbFile) | |
| getDefaultFormat | back to summary |
|---|---|
| protected Database. | |
| getDefaultTempDirectory | back to summary |
|---|---|
| protected Path getDefaultTempDirectory() | |
| isDefaultInMemory | back to summary |
|---|---|
| protected boolean isDefaultInMemory() | |
| loadCustomFile | back to summary |
|---|---|
| protected abstract Object loadCustomFile(Database linkerDb, String linkeeFileName) Called by
The returned custom file state object will be maintained with the temp db and passed to | |
| loadCustomTable | back to summary |
|---|---|
| protected abstract boolean loadCustomTable(Database tempDb, Object customFile, String tableName) throws IOException Called by an instance of a temp db when a missing table is first requested.
| |
| resolveLinkedDatabase | back to summary |
|---|---|
| public Database resolveLinkedDatabase(Database linkerDb, String linkeeFileName) throws IOException Implements io. Custom implementation is:
// attempt to load the linkeeFileName as a custom file
Object customFile = loadCustomFile(linkerDb, linkeeFileName);
if (customFile != null) {
// this is a custom file, create and return relevant temp db
return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(),
getDefaultTempDirectory());
}
// not a custom file, load using the default behavior
return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName);
The fallback behavior denies automatic linked database resolution. The loadCustomFile implementation is
application-provided and is responsible for validating its own input. Override this method and explicitly
delegate to LinkResolver#UNRESTRICTED only when linked database paths come from a trusted source.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private final CustomLinkResolver |
| Access | Constructor and Description |
|---|---|
| protected | TempDatabaseImpl(CustomLinkResolver resolver, Object customFile, Path file, FileChannel channel, Database.
|
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides io. Implements io. Close the database file (and any linked databases). |
| protected TableImpl | getTable(String name, boolean includeSystemTables)
Overrides io. Returns the table, or null if it doesn't exist. |
| pack-priv static FileChannel |
| customFile | back to summary |
|---|---|
| private final Object customFile | |
| resolver | back to summary |
|---|---|
| private final CustomLinkResolver resolver | |
| TempDatabaseImpl | back to summary |
|---|---|
| protected TempDatabaseImpl(CustomLinkResolver resolver, Object customFile, Path file, FileChannel channel, Database. | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides io. Implements io. Doc from io. Close the database file (and any linked databases). A Database must be closed after use or changes could be lost and the Database file corrupted. A Database instance should be treated like any other external resource which would be closed in a finally block (e.g. an OutputStream or jdbc Connection).
| |
| getTable | back to summary |
|---|---|
| protected TableImpl getTable(String name, boolean includeSystemTables) throws IOException Overrides io. Doc from io. Returns the table, or null if it doesn't exist.
| |
| initDbChannel | back to summary |
|---|---|
| pack-priv static FileChannel initDbChannel(FileChannel channel, Database. | |