com.healthmarketscience.jackcess
Class DatabaseBuilder

java.lang.Object
  extended by com.healthmarketscience.jackcess.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 Summary
DatabaseBuilder()
           
DatabaseBuilder(File mdbFile)
           
 
Method Summary
 Database create()
          Creates a new Database using the configured information.
static Database create(Database.FileFormat fileFormat, File mdbFile)
          Create a new Database for the given fileFormat
static SimpleDateFormat createDateFormat(String formatStr)
          Returns a SimpleDateFormat for the given format string which is configured with a compatible Calendar instance (see toCompatibleCalendar(java.util.Calendar)).
 Database open()
          Opens an existingnew Database using the configured information.
static Database open(File mdbFile)
          Open an existing Database.
 DatabaseBuilder putDatabaseProperty(String name, DataType type, Object value)
          Sets the database property with the given name and type to the given value.
 DatabaseBuilder putDatabaseProperty(String name, Object value)
          Sets the database property with the given name to the given value.
 DatabaseBuilder putSummaryProperty(String name, DataType type, Object value)
          Sets the summary database property with the given name and type to the given value.
 DatabaseBuilder putSummaryProperty(String name, Object value)
          Sets the summary database property with the given name to the given value.
 DatabaseBuilder putUserDefinedProperty(String name, DataType type, Object value)
          Sets the user-defined database property with the given name and type to the given value.
 DatabaseBuilder putUserDefinedProperty(String name, Object value)
          Sets the user-defined database property with the given name to the given value.
 DatabaseBuilder setAutoSync(boolean autoSync)
          Sets whether or not to enable auto-syncing on write.
 DatabaseBuilder setChannel(FileChannel channel)
          Sets a pre-opened FileChannel.
 DatabaseBuilder setCharset(Charset charset)
          Sets the Charset to use, if null, uses default.
 DatabaseBuilder setCodecProvider(CodecProvider codecProvider)
          Sets the CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary
 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.)
 DatabaseBuilder setFileFormat(Database.FileFormat fileFormat)
          Sets the version of new database (create() only).
 DatabaseBuilder setReadOnly(boolean readOnly)
          Sets flag which, iff true, will force opening file in read-only mode (open() only).
 DatabaseBuilder setTimeZone(TimeZone timeZone)
          Sets the TimeZone to use for interpreting dates, if null, uses default
static Calendar toCompatibleCalendar(Calendar cal)
          Ensures that the given Calendar is configured to be compatible with how Access handles dates.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseBuilder

public DatabaseBuilder()

DatabaseBuilder

public DatabaseBuilder(File 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.

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.

setFileFormat

public DatabaseBuilder setFileFormat(Database.FileFormat fileFormat)
Sets the version of new database (create() only).

Usage:
General: This method is general use.

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.


open

public Database open()
              throws IOException
Opens an existingnew Database using the configured information.

Throws:
IOException

create

public Database create()
                throws IOException
Creates a new Database using the configured information.

Throws:
IOException

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.

create

public static Database create(Database.FileFormat fileFormat,
                              File mdbFile)
                       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.
Throws:
IOException
See Also:
for more flexible Database creation
Usage:
General: This method is general use.

createDateFormat

public static SimpleDateFormat createDateFormat(String formatStr)
Returns a SimpleDateFormat for the given format string which is configured with a compatible Calendar instance (see toCompatibleCalendar(java.util.Calendar)).


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).



Copyright © 2005–2017 Health Market Science. All rights reserved.