Class CustomLinkResolver

  • All Implemented Interfaces:
    LinkResolver

    public abstract class CustomLinkResolver
    extends Object
    implements LinkResolver
    Utility base implementation 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:

    • Supports custom behavior for non-mdb files, see loadCustomFile(com.healthmarketscience.jackcess.Database, java.lang.String). Mdb files fall back to the default resolver, which refuses to open them unless link resolution has been enabled, see resolveLinkedDatabase(com.healthmarketscience.jackcess.Database, java.lang.String)
    • Temp db can be an actual file or entirely in memory
    • Linked tables are loaded on-demand, see loadCustomTable(com.healthmarketscience.jackcess.Database, java.lang.Object, java.lang.String)
    • Temp db files will be automatically deleted on close
    Author:
    James Ahlborn
    Usage:
    Intermediate: This class requires moderate API knowledge.
    • 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 Path DEFAULT_TEMP_DIR
        temp dbs end up in the system temp dir by default
    • Method Detail

      • 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 custom file, load using the default behavior
           return DatabaseImpl.getDefaultLinkResolver()
             .resolveLinkedDatabase(linkerDb, linkeeFileName);
        The fallback is the resolver a Database uses when none has been configured, so it refuses to open the linked database. Override this method and delegate to LinkResolver.UNRESTRICTED only when the linked database file names can be trusted.
        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.nio.file.Path, boolean), LinkResolver.DEFAULT, LinkResolver.UNRESTRICTED