Class DatabaseImpl

    • Field Detail

      • DEFAULT_RESOURCE_PATH

        public static final String DEFAULT_RESOURCE_PATH
        the default value for the resource path used to load classpath resources.
        See Also:
        Constant Field Values
      • HIDDEN_OBJECT_FLAG

        public static final int HIDDEN_OBJECT_FLAG
        this object is hidden
        See Also:
        Constant Field Values
    • Method Detail

      • open

        public static DatabaseImpl open​(Path mdbFile,
                                        boolean readOnly,
                                        FileChannel channel,
                                        boolean autoSync,
                                        Charset charset,
                                        TimeZone timeZone,
                                        CodecProvider provider,
                                        boolean ignoreSystemCatalogIndex)
                                 throws IOException
        Open an existing Database. If the existing file is not writeable or the readOnly flag is true, the file will be opened read-only.
        Parameters:
        mdbFile - File containing the database
        readOnly - iff true, force opening file in read-only mode
        channel - pre-opened FileChannel. if provided explicitly, it will not be closed by this Database instance
        autoSync - whether or not to enable auto-syncing on write. if true, writes will be immediately flushed to disk. This leaves the database in a (fairly) consistent state on each write, but can be very inefficient for many updates. if false, flushing to disk happens at the jvm's leisure, which can be much faster, but may leave the database in an inconsistent state if failures are encountered during writing. Writes may be flushed at any time using flush().
        charset - Charset to use, if null, uses default
        timeZone - TimeZone to use, if null, uses default
        provider - CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • create

        public static DatabaseImpl create​(Database.FileFormat fileFormat,
                                          Path mdbFile,
                                          FileChannel channel,
                                          boolean autoSync,
                                          Charset charset,
                                          TimeZone timeZone)
                                   throws IOException
        Create a new Database for the given fileFormat
        Parameters:
        fileFormat - version of new database.
        mdbFile - Location to write the new database to. If this file already exists, it will be overwritten.
        channel - pre-opened FileChannel. if provided explicitly, it will not be closed by this Database instance
        autoSync - whether or not to enable auto-syncing on write. if true, writes will be immediately flushed to disk. This leaves the database in a (fairly) consistent state on each write, but can be very inefficient for many updates. if false, flushing to disk happens at the jvm's leisure, which can be much faster, but may leave the database in an inconsistent state if failures are encountered during writing. Writes may be flushed at any time using flush().
        charset - Charset to use, if null, uses default
        timeZone - TimeZone to use, if null, uses default
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • getFile

        public File getFile()
        Description copied from interface: Database
        Returns the File underlying this Database
        Specified by:
        getFile in interface Database
      • getPath

        public Path getPath()
        Description copied from interface: Database
        Returns the File underlying this Database
        Specified by:
        getPath in interface Database
      • getName

        public String getName()
      • isReadOnly

        public boolean isReadOnly()
      • getPageChannel

        public PageChannel getPageChannel()
        Usage:
        Advanced: This method is for advanced/internal use.
      • getFormat

        public JetFormat getFormat()
        Usage:
        Advanced: This method is for advanced/internal use.
      • getSystemCatalog

        public TableImpl getSystemCatalog()
        Returns:
        The system catalog table
        Usage:
        Advanced: This method is for advanced/internal use.
      • getAccessControlEntries

        public TableImpl getAccessControlEntries()
                                          throws IOException
        Returns:
        The system Access Control Entries table (loaded on demand)
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • getSystemComplexColumns

        public TableImpl getSystemComplexColumns()
                                          throws IOException
        Returns:
        the complex column system table (loaded on demand)
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • getErrorHandler

        public ErrorHandler getErrorHandler()
        Description copied from interface: Database
        Gets the currently configured ErrorHandler (always non-null). This will be used to handle all errors unless overridden at the Table or Cursor level.
        Specified by:
        getErrorHandler in interface Database
      • getLinkResolver

        public LinkResolver getLinkResolver()
        Description copied from interface: Database
        Gets the currently configured LinkResolver (always non-null). This will be used to handle all linked database loading.
        Specified by:
        getLinkResolver in interface Database
      • getLinkedDatabases

        public Map<String,​Database> getLinkedDatabases()
        Description copied from interface: Database
        Returns an unmodifiable view of the currently loaded linked databases, mapped from the linked database file name to the linked database. This information may be useful for implementing a LinkResolver.
        Specified by:
        getLinkedDatabases in interface Database
      • getTimeZone

        public TimeZone getTimeZone()
        Description copied from interface: Database
        Gets currently configured TimeZone (always non-null and aligned with the ZoneId).
        Specified by:
        getTimeZone in interface Database
      • setTimeZone

        public void setTimeZone​(TimeZone newTimeZone)
        Description copied from interface: Database
        Sets a new TimeZone. If null, resets to the default value. Note that setting the TimeZone will alter the ZoneId as well.
        Specified by:
        setTimeZone in interface Database
      • getZoneId

        public ZoneId getZoneId()
        Description copied from interface: Database
        Gets currently configured ZoneId (always non-null and aligned with the TimeZone).
        Specified by:
        getZoneId in interface Database
      • setZoneId

        public void setZoneId​(ZoneId newZoneId)
        Description copied from interface: Database
        Sets a new ZoneId. If null, resets to the default value. Note that setting the ZoneId will alter the TimeZone as well.
        Specified by:
        setZoneId in interface Database
      • setDateTimeType

        public void setDateTimeType​(DateTimeType dateTimeType)
        Description copied from interface: Database
        Sets the DateTimeType. If null, resets to the default value.
        Specified by:
        setDateTimeType in interface Database
      • getDateTimeFactory

        public com.healthmarketscience.jackcess.impl.ColumnImpl.DateTimeFactory getDateTimeFactory()
      • getCharset

        public Charset getCharset()
        Description copied from interface: Database
        Gets currently configured Charset (always non-null).
        Specified by:
        getCharset in interface Database
      • setCharset

        public void setCharset​(Charset newCharset)
        Description copied from interface: Database
        Sets a new Charset. If null, resets to the default value.
        Specified by:
        setCharset in interface Database
      • setColumnOrder

        public void setColumnOrder​(Table.ColumnOrder newColumnOrder)
        Description copied from interface: Database
        Sets a new Table.ColumnOrder. If null, resets to the default value.
        Specified by:
        setColumnOrder in interface Database
      • isEnforceForeignKeys

        public boolean isEnforceForeignKeys()
        Description copied from interface: Database
        Gets current foreign-key enforcement policy.
        Specified by:
        isEnforceForeignKeys in interface Database
      • setEnforceForeignKeys

        public void setEnforceForeignKeys​(Boolean newEnforceForeignKeys)
        Description copied from interface: Database
        Sets a new foreign-key enforcement policy. If null, resets to the default value.
        Specified by:
        setEnforceForeignKeys in interface Database
      • isAllowAutoNumberInsert

        public boolean isAllowAutoNumberInsert()
        Description copied from interface: Database
        Gets current allow auto number insert policy. By default, jackcess does not allow auto numbers to be inserted or updated directly (they are always handled internally by the Table). Setting this policy to true allows the caller to optionally set the value explicitly when adding or updating rows (if a value is not provided, it will still be handled internally by the Table). This value can be set database-wide using Database.setAllowAutoNumberInsert(java.lang.Boolean) and/or on a per-table basis using Table.setAllowAutoNumberInsert(java.lang.Boolean) (and/or on a jvm-wide using the Database.ALLOW_AUTONUM_INSERT_PROPERTY system property). Note that enabling this feature should be done with care to reduce the chances of screwing up the database.
        Specified by:
        isAllowAutoNumberInsert in interface Database
      • setAllowAutoNumberInsert

        public void setAllowAutoNumberInsert​(Boolean allowAutoNumInsert)
        Description copied from interface: Database
        Sets the new auto number insert policy for the database (unless overridden at the Table level). If null, resets to the default value.
        Specified by:
        setAllowAutoNumberInsert in interface Database
      • isEvaluateExpressions

        public boolean isEvaluateExpressions()
        Description copied from interface: Database
        Gets the current expression evaluation policy. Expression evaluation is enabled by default but can be disabled if necessary.
        Specified by:
        isEvaluateExpressions in interface Database
      • setEvaluateExpressions

        public void setEvaluateExpressions​(Boolean evaluateExpressions)
        Description copied from interface: Database
        Sets the current expression evaluation policy. Expression evaluation is enabled by default but can be disabled if necessary. If null, resets to the default value.
        Specified by:
        setEvaluateExpressions in interface Database
      • setWriteBrokenIndex

        public void setWriteBrokenIndex​(Boolean writeBrokenIndex)
        Description copied from interface: Database
        Sets the current write broken index policy. If null, resets to the default value.
        Specified by:
        setWriteBrokenIndex in interface Database
      • setColumnValidatorFactory

        public void setColumnValidatorFactory​(ColumnValidatorFactory newFactory)
        Description copied from interface: Database
        Sets a new ColumnValidatorFactory. If null, resets to the default value. The configured ColumnValidatorFactory will be used to create ColumnValidator instances on any user tables loaded from this point onward (this will not be used for system tables).
        Specified by:
        setColumnValidatorFactory in interface Database
      • getEvalConfig

        public EvalConfig getEvalConfig()
        Description copied from interface: Database
        Returns the EvalConfig for configuring expression evaluation.
        Specified by:
        getEvalConfig in interface Database
      • getDefaultSortOrder

        public ColumnImpl.SortOrder getDefaultSortOrder()
                                                 throws IOException
        Returns:
        the currently configured database default language sort order for textual columns
        Throws:
        IOException
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • getDefaultCodePage

        public short getDefaultCodePage()
                                 throws IOException
        Returns:
        the currently configured database default code page for textual data (may not be relevant to all database versions)
        Throws:
        IOException
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • readProperties

        public PropertyMaps readProperties​(byte[] propsBytes,
                                           int objectId,
                                           RowIdImpl rowId)
                                    throws IOException
        Returns:
        a PropertyMaps instance decoded from the given bytes (always returns non-null result).
        Throws:
        IOException
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • newIterable

        public TableIterableBuilder newIterable()
        Description copied from interface: Database
        Convenience method for constructing a new TableIterableBuilder for this cursor. A TableIterableBuilder provides a variety of options for more flexible iteration of Tables.
        Specified by:
        newIterable in interface Database
      • newTableMetaDataIterable

        public Iterable<TableMetaData> newTableMetaDataIterable()
        Specified by:
        newTableMetaDataIterable in interface Database
        Returns:
        an Iterable which returns an unmodifiable Iterator of the the TableMetaData for all tables in this Database.
      • getTable

        public TableImpl getTable​(String name)
                           throws IOException
        Specified by:
        getTable in interface Database
        Parameters:
        name - User table name (case-insensitive)
        Returns:
        The Table, or null if it doesn't exist (or is a system table)
        Throws:
        IOException
      • getTableMetaData

        public TableMetaData getTableMetaData​(String name)
                                       throws IOException
        Specified by:
        getTableMetaData in interface Database
        Parameters:
        name - Table name (case-insensitive), may be any table type (i.e. includes system or linked tables).
        Returns:
        The meta data for the table, or null if it doesn't exist
        Throws:
        IOException
      • getTable

        public TableImpl getTable​(int tableDefPageNumber)
                           throws IOException
        Parameters:
        tableDefPageNumber - the page number of a table definition
        Returns:
        The table, or null if it doesn't exist
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • createLinkedTable

        public void createLinkedTable​(String name,
                                      String linkedDbName,
                                      String linkedTableName)
                               throws IOException
        Description copied from interface: Database
        Create a new table in this database
        Specified by:
        createLinkedTable in interface Database
        Parameters:
        name - Name of the table to create in this database
        linkedDbName - path to the linked database
        linkedTableName - name of the table in the linked database
        Throws:
        IOException
      • getRelationships

        public List<Relationship> getRelationships()
                                            throws IOException
        Description copied from interface: Database
        Finds all the relationships in the database in non-system tables.

        Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.

        Specified by:
        getRelationships in interface Database
        Throws:
        IOException
      • getSystemRelationships

        public List<Relationship> getSystemRelationships()
                                                  throws IOException
        Description copied from interface: Database
        Finds all the relationships in the database, including system tables.

        Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.

        Specified by:
        getSystemRelationships in interface Database
        Throws:
        IOException
      • getSystemTable

        public TableImpl getSystemTable​(String tableName)
                                 throws IOException
        Description copied from interface: Database
        Returns a reference to any available table in this access database, including system tables.

        Warning, this method is not designed for common use, only for the occassional time when access to a system table is necessary. Messing with system tables can strip the paint off your house and give your whole family a permanent, orange afro. You have been warned.

        Specified by:
        getSystemTable in interface Database
        Parameters:
        tableName - Table name, may be a system table
        Returns:
        The table, or null if it doesn't exist
        Throws:
        IOException
      • getPropertiesForObject

        public PropertyMaps getPropertiesForObject​(int objectId,
                                                   com.healthmarketscience.jackcess.impl.PropertyMaps.Owner owner)
                                            throws IOException
        Returns:
        the PropertyMaps for the object with the given id
        Throws:
        IOException
        Usage:
        Advanced: This method is for advanced/internal use.
      • flush

        public void flush()
                   throws IOException
        Description copied from interface: Database
        Flushes any current changes to the database file (and any linked databases) to disk.
        Specified by:
        flush in interface Database
        Specified by:
        flush in interface Flushable
        Throws:
        IOException
      • close

        public void close()
                   throws IOException
        Description copied from interface: Database
        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).
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface Database
        Throws:
        IOException
      • validateIdentifierName

        public static void validateIdentifierName​(String name,
                                                  int maxLength,
                                                  String identifierType)
        Validates an identifier name. Names of fields, controls, and objects in Microsoft Access:
        • Can include any combination of letters, numbers, spaces, and special characters except a period (.), an exclamation point (!), an accent grave (`), and brackets ([ ]).
        • Can't begin with leading spaces.
        • Can't include control characters (ASCII values 0 through 31).
        Usage:
        Advanced: This method is for advanced/internal use.
      • toLookupName

        public static String toLookupName​(String name)
        Returns:
        a string usable in the _tableLookup map.
      • getDefaultCharset

        public static Charset getDefaultCharset​(JetFormat format)
        Returns the default Charset for the given JetFormat. This may or may not be platform specific, depending on the format, but can be overridden using a system property composed of the prefix "com.healthmarketscience.jackcess.charset." followed by the JetFormat version to which the charset should apply, e.g. "com.healthmarketscience.jackcess.charset.VERSION_3".
        Usage:
        Advanced: This method is for advanced/internal use.
      • getDefaultEnforceForeignKeys

        public static boolean getDefaultEnforceForeignKeys()
        Returns the default enforce foreign-keys policy. This defaults to true, but can be overridden using the system property "com.healthmarketscience.jackcess.enforceForeignKeys".
        Usage:
        Advanced: This method is for advanced/internal use.
      • getDefaultAllowAutoNumberInsert

        public static boolean getDefaultAllowAutoNumberInsert()
        Returns the default allow auto number insert policy. This defaults to false, but can be overridden using the system property "com.healthmarketscience.jackcess.allowAutoNumberInsert".
        Usage:
        Advanced: This method is for advanced/internal use.
      • getDefaultEvaluateExpressions

        public static boolean getDefaultEvaluateExpressions()
        Returns the default enable expression evaluation policy. This defaults to true, but can be overridden using the system property "com.healthmarketscience.jackcess.enableExpressionEvaluation".
        Usage:
        Advanced: This method is for advanced/internal use.
      • getDefaultWriteBrokenIndex

        public static boolean getDefaultWriteBrokenIndex()
        Returns the default allow broken index policy. This defaults to false, but can be overridden using the system property "com.healthmarketscience.jackcess.writeBrokenIndex".
        Usage:
        Advanced: This method is for advanced/internal use.
      • getPasswordMask

        public static byte[] getPasswordMask​(ByteBuffer buffer,
                                             JetFormat format)
        Returns the password mask retrieved from the given header page and format, or null if this format does not use a password mask.
        Usage:
        Advanced: This method is for advanced/internal use.