com.healthmarketscience.jackcess.util
Class CustomLinkResolver

java.lang.Object
  extended by com.healthmarketscience.jackcess.util.CustomLinkResolver
All Implemented Interfaces:
LinkResolver

public abstract class CustomLinkResolver
extends Object
implements LinkResolver

Utility base implementaton of LinkResolver which facilitates loading linked tables from files which are not access databases. The LinkResolver API ultimately presents linked table information to the primary database using the jackcess 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:

Author:
James Ahlborn

Field Summary
static Database.FileFormat DEFAULT_FORMAT
          the default file format used for temp dbs
static boolean DEFAULT_IN_MEMORY
          temp dbs default to the filesystem, not in memory
static File DEFAULT_TEMP_DIR
          temp dbs end up in the system temp dir by default
 
Fields inherited from interface com.healthmarketscience.jackcess.util.LinkResolver
DEFAULT
 
Constructor Summary
protected CustomLinkResolver()
          Creates a CustomLinkResolver using the default behavior for creating temp dbs, see DEFAULT_FORMAT, DEFAULT_IN_MEMORY and DEFAULT_TEMP_DIR.
protected CustomLinkResolver(Database.FileFormat defaultFormat, boolean defaultInMemory, File defaultTempDir)
          Creates a CustomLinkResolver with the given default behavior for creating temp dbs.
 
Method Summary
protected  Database createTempDb(Object customFile, Database.FileFormat format, boolean inMemory, File tempDir)
          Creates a temporary database for holding the table data from linkeeFileName.
protected  Database.FileFormat getDefaultFormat()
           
protected  File getDefaultTempDirectory()
           
protected  boolean isDefaultInMemory()
           
protected abstract  Object loadCustomFile(Database linkerDb, String linkeeFileName)
          Called by resolveLinkedDatabase(com.healthmarketscience.jackcess.Database, java.lang.String) to determine whether the linkeeFileName should be treated as a custom file (thus utiliziing a temp db) or a normal access db (loaded via the default behavior).
protected abstract  boolean loadCustomTable(Database tempDb, Object customFile, String tableName)
          Called by an instance of a temp db when a missing table is first requested.
 Database resolveLinkedDatabase(Database linkerDb, String linkeeFileName)
          Custom implementation is:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FORMAT

public static final Database.FileFormat DEFAULT_FORMAT
the default file format used for temp dbs


DEFAULT_IN_MEMORY

public static final boolean DEFAULT_IN_MEMORY
temp dbs default to the filesystem, not in memory

See Also:
Constant Field Values

DEFAULT_TEMP_DIR

public static final File DEFAULT_TEMP_DIR
temp dbs end up in the system temp dir by default

Constructor Detail

CustomLinkResolver

protected CustomLinkResolver()
Creates a CustomLinkResolver using the default behavior for creating temp dbs, see DEFAULT_FORMAT, DEFAULT_IN_MEMORY and DEFAULT_TEMP_DIR.


CustomLinkResolver

protected CustomLinkResolver(Database.FileFormat defaultFormat,
                             boolean defaultInMemory,
                             File defaultTempDir)
Creates a CustomLinkResolver with the given default behavior for creating temp dbs.

Parameters:
defaultFormat - the default format for the temp db
defaultInMemory - 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)
defaultTempDir - the default temp dir for a file based temp db (null for the system defaqult temp directory)
Method Detail

getDefaultFormat

protected Database.FileFormat getDefaultFormat()

isDefaultInMemory

protected boolean isDefaultInMemory()

getDefaultTempDirectory

protected File getDefaultTempDirectory()

resolveLinkedDatabase

public Database resolveLinkedDatabase(Database linkerDb,
                                      String linkeeFileName)
                               throws IOException
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 custmom file, load using the default behavior
   return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName);
 

Specified by:
resolveLinkedDatabase in interface LinkResolver
Throws:
IOException
See Also:
loadCustomFile(com.healthmarketscience.jackcess.Database, java.lang.String), createTempDb(java.lang.Object, com.healthmarketscience.jackcess.Database.FileFormat, boolean, java.io.File), LinkResolver.DEFAULT

createTempDb

protected Database createTempDb(Object customFile,
                                Database.FileFormat format,
                                boolean inMemory,
                                File tempDir)
                         throws IOException
Creates a temporary database for holding the table data from linkeeFileName.

Parameters:
customFile - custom file state returned from loadCustomFile(com.healthmarketscience.jackcess.Database, java.lang.String)
format - the access format for the temp db
inMemory - 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)
tempDir - the temp dir for a file based temp db (null for the system default temp directory)
Returns:
the temp db for holding the linked table info
Throws:
IOException

loadCustomFile

protected abstract Object loadCustomFile(Database linkerDb,
                                         String linkeeFileName)
                                  throws IOException
Called by resolveLinkedDatabase(com.healthmarketscience.jackcess.Database, java.lang.String) to determine whether the linkeeFileName should be treated as a custom file (thus utiliziing a temp db) or a normal access db (loaded via the default behavior). Loads any state necessary for subsequently loading data from linkeeFileName.

The returned custom file state object will be maintained with the temp db and passed to loadCustomTable(com.healthmarketscience.jackcess.Database, java.lang.Object, java.lang.String) whenever a new table needs to be loaded. Also, if this object is Closeable, it will be closed with the temp db.

Parameters:
linkerDb - the primary database in which the link is defined
linkeeFileName - the name of the linked file
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.
Throws:
IOException

loadCustomTable

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.

Parameters:
tempDb - the temp db instance which should be populated with the relevant table info for the given tableName
customFile - custom file state returned from loadCustomFile(com.healthmarketscience.jackcess.Database, java.lang.String)
tableName - the name of the table which is requested from the linked file
Returns:
true if the table was available in the linked file, false otherwise
Throws:
IOException


Copyright © 2005-2017 Health Market Science. All Rights Reserved.