Class DatabaseBuilder


  • public class DatabaseBuilder
    extends Object
    Builder style class for opening/creating a Database.

    Simple example usage:

       Database db = DatabaseBuilder.open(new File("test.mdb"));

    Advanced example usage:

       Database db = new DatabaseBuilder(new File("test.mdb"))
         .setReadOnly(true)
         .open();
    Author:
    James Ahlborn
    Usage:
    General: This class is general use.
    • Constructor Detail

      • DatabaseBuilder

        public DatabaseBuilder()
      • DatabaseBuilder

        public DatabaseBuilder​(File mdbFile)
      • DatabaseBuilder

        public DatabaseBuilder​(Path mdbFile)
    • Method Detail

      • setFile

        public DatabaseBuilder setFile​(File mdbFile)
        File containing an existing database for open() or target file for new database for create() (in which case, tf this file already exists, it will be overwritten.)
        Usage:
        General: This method is general use.
      • setPath

        public DatabaseBuilder setPath​(Path mdbFile)
        File containing an existing database for open() or target file for new database for create() (in which case, tf this file already exists, it will be overwritten.)
        Usage:
        General: This method is general use.
      • setReadOnly

        public DatabaseBuilder setReadOnly​(boolean readOnly)
        Sets flag which, iff true, will force opening file in read-only mode (open() only).
        Usage:
        General: This method is general use.
      • setAutoSync

        public DatabaseBuilder setAutoSync​(boolean autoSync)
        Sets whether or not to enable auto-syncing on write. if true, write operations will be immediately flushed to disk upon completion. 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 Database.flush().
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • setCharset

        public DatabaseBuilder setCharset​(Charset charset)
        Sets the Charset to use, if null, uses default.
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • setTimeZone

        public DatabaseBuilder setTimeZone​(TimeZone timeZone)
        Sets the TimeZone to use for interpreting dates, if null, uses default
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • setCodecProvider

        public DatabaseBuilder setCodecProvider​(CodecProvider codecProvider)
        Sets the CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary
        Usage:
        Intermediate: This method requires moderate API knowledge.
      • setChannel

        public DatabaseBuilder setChannel​(FileChannel channel)
        Sets a pre-opened FileChannel. if provided explicitly, it will not be closed by the Database instance. This allows ultimate control of where the mdb file exists (which may not be on disk, e.g. MemFileChannel). If provided, the File parameter will be available from Database.getFile(), but otherwise ignored.
        Usage:
        Advanced: This method is for advanced/internal use.
      • putDatabaseProperty

        public DatabaseBuilder putDatabaseProperty​(String name,
                                                   Object value)
        Sets the database property with the given name to the given value. Attempts to determine the type of the property (see PropertyMap.put(String,Object) for details on determining the property type).
      • putDatabaseProperty

        public DatabaseBuilder putDatabaseProperty​(String name,
                                                   DataType type,
                                                   Object value)
        Sets the database property with the given name and type to the given value.
      • putSummaryProperty

        public DatabaseBuilder putSummaryProperty​(String name,
                                                  Object value)
        Sets the summary database property with the given name to the given value. Attempts to determine the type of the property (see PropertyMap.put(String,Object) for details on determining the property type).
      • putSummaryProperty

        public DatabaseBuilder putSummaryProperty​(String name,
                                                  DataType type,
                                                  Object value)
        Sets the summary database property with the given name and type to the given value.
      • putUserDefinedProperty

        public DatabaseBuilder putUserDefinedProperty​(String name,
                                                      Object value)
        Sets the user-defined database property with the given name to the given value. Attempts to determine the type of the property (see PropertyMap.put(String,Object) for details on determining the property type).
      • putUserDefinedProperty

        public DatabaseBuilder putUserDefinedProperty​(String name,
                                                      DataType type,
                                                      Object value)
        Sets the user-defined database property with the given name and type to the given value.
      • setIgnoreBrokenSystemCatalogIndex

        public DatabaseBuilder setIgnoreBrokenSystemCatalogIndex​(boolean ignore)
        Sets flag which, if true, will make the database ignore the index on the system catalog when looking up tables. This will make table retrieval slower, but can be used to workaround broken indexes.
      • open

        public static Database open​(File mdbFile)
                             throws IOException
        Open an existing Database. If the existing file is not writeable, the file will be opened read-only. Auto-syncing is enabled for the returned Database.
        Parameters:
        mdbFile - File containing the database
        Throws:
        IOException
        See Also:
        for more flexible Database opening
        Usage:
        General: This method is general use.
      • open

        public static Database open​(Path mdbFile)
                             throws IOException
        Open an existing Database. If the existing file is not writeable, the file will be opened read-only. Auto-syncing is enabled for the returned Database.
        Parameters:
        mdbFile - File containing the database
        Throws:
        IOException
        See Also:
        for more flexible Database opening
        Usage:
        General: This method is general use.
      • toCompatibleCalendar

        public static Calendar toCompatibleCalendar​(Calendar cal)
        Ensures that the given Calendar is configured to be compatible with how Access handles dates. Specifically, alters the gregorian change (the java default gregorian change switches to julian dates for dates pre 1582-10-15, whereas Access uses proleptic gregorian dates).
      • newDatabase

        public static DatabaseBuilder newDatabase()
        Convenience method for constructing a DatabaseBuilder.
      • newDatabase

        public static DatabaseBuilder newDatabase​(Path path)
        Convenience method for constructing a DatabaseBuilder.
      • newDatabase

        public static DatabaseBuilder newDatabase​(File file)
        Convenience method for constructing a DatabaseBuilder.
      • newTable

        public static TableBuilder newTable​(String name)
        Convenience method for constructing a TableBuilder.
      • newTable

        public static TableBuilder newTable​(String name,
                                            boolean escapeIdentifiers)
        Convenience method for constructing a TableBuilder.
      • newColumn

        public static ColumnBuilder newColumn​(String name)
        Convenience method for constructing a ColumnBuilder.
      • newColumn

        public static ColumnBuilder newColumn​(String name,
                                              DataType type)
        Convenience method for constructing a TableBuilder.
      • newIndex

        public static IndexBuilder newIndex​(String name)
        Convenience method for constructing an IndexBuilder.
      • newPrimaryKey

        public static IndexBuilder newPrimaryKey​(String... colNames)
        Convenience method for constructing a primary key IndexBuilder.
      • newRelationship

        public static RelationshipBuilder newRelationship​(String fromTable,
                                                          String toTable)
        Convenience method for constructing a RelationshipBuilder.
      • newRelationship

        public static RelationshipBuilder newRelationship​(Table fromTable,
                                                          Table toTable)
        Convenience method for constructing a RelationshipBuilder.