Package com.healthmarketscience.jackcess
Class DatabaseBuilder
- java.lang.Object
-
- com.healthmarketscience.jackcess.DatabaseBuilder
-
public class DatabaseBuilder extends Object
Builder style class for opening/creating aDatabase.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
Constructors Constructor Description DatabaseBuilder()DatabaseBuilder(File mdbFile)DatabaseBuilder(Path mdbFile)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Databasecreate()Creates a new Database using the configured information.static Databasecreate(Database.FileFormat fileFormat, File mdbFile)Create a new Database for the given fileFormatstatic SimpleDateFormatcreateDateFormat(String formatStr)Returns a SimpleDateFormat for the given format string which is configured with a compatible Calendar instance (seetoCompatibleCalendar(java.util.Calendar)).static ColumnBuildernewColumn(String name)Convenience method for constructing a ColumnBuilder.static ColumnBuildernewColumn(String name, DataType type)Convenience method for constructing a TableBuilder.static DatabaseBuildernewDatabase()Convenience method for constructing a DatabaseBuilder.static DatabaseBuildernewDatabase(File file)Convenience method for constructing a DatabaseBuilder.static DatabaseBuildernewDatabase(Path path)Convenience method for constructing a DatabaseBuilder.static IndexBuildernewIndex(String name)Convenience method for constructing an IndexBuilder.static IndexBuildernewPrimaryKey(String... colNames)Convenience method for constructing a primary key IndexBuilder.static RelationshipBuildernewRelationship(Table fromTable, Table toTable)Convenience method for constructing a RelationshipBuilder.static RelationshipBuildernewRelationship(String fromTable, String toTable)Convenience method for constructing a RelationshipBuilder.static TableBuildernewTable(String name)Convenience method for constructing a TableBuilder.static TableBuildernewTable(String name, boolean escapeIdentifiers)Convenience method for constructing a TableBuilder.Databaseopen()Opens an existingnew Database using the configured information.static Databaseopen(File mdbFile)Open an existing Database.static Databaseopen(Path mdbFile)Open an existing Database.DatabaseBuilderputDatabaseProperty(String name, DataType type, Object value)Sets the database property with the given name and type to the given value.DatabaseBuilderputDatabaseProperty(String name, Object value)Sets the database property with the given name to the given value.DatabaseBuilderputSummaryProperty(String name, DataType type, Object value)Sets the summary database property with the given name and type to the given value.DatabaseBuilderputSummaryProperty(String name, Object value)Sets the summary database property with the given name to the given value.DatabaseBuilderputUserDefinedProperty(String name, DataType type, Object value)Sets the user-defined database property with the given name and type to the given value.DatabaseBuilderputUserDefinedProperty(String name, Object value)Sets the user-defined database property with the given name to the given value.DatabaseBuildersetAutoSync(boolean autoSync)Sets whether or not to enable auto-syncing on write.DatabaseBuildersetChannel(FileChannel channel)Sets a pre-opened FileChannel.DatabaseBuildersetCharset(Charset charset)Sets the Charset to use, ifnull, uses default.DatabaseBuildersetCodecProvider(CodecProvider codecProvider)Sets the CodecProvider for handling page encoding/decoding, may benullif no special encoding is necessaryDatabaseBuildersetFile(File mdbFile)DatabaseBuildersetFileFormat(Database.FileFormat fileFormat)Sets the version of new database (create()only).DatabaseBuildersetIgnoreBrokenSystemCatalogIndex(boolean ignore)Sets flag which, iftrue, will make the database ignore the index on the system catalog when looking up tables.DatabaseBuildersetPath(Path mdbFile)DatabaseBuildersetReadOnly(boolean readOnly)Sets flag which, ifftrue, will force opening file in read-only mode (open()only).DatabaseBuildersetTimeZone(TimeZone timeZone)Sets the TimeZone to use for interpreting dates, ifnull, uses defaultstatic CalendartoCompatibleCalendar(Calendar cal)Ensures that the givenCalendaris configured to be compatible with how Access handles dates.
-
-
-
Method Detail
-
setFile
public DatabaseBuilder setFile(File mdbFile)
File containing an existing database foropen()or target file for new database forcreate()(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 foropen()or target file for new database forcreate()(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, ifftrue, 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. iftrue, 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. iffalse, 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 usingDatabase.flush().- Usage:
- Intermediate: This method requires moderate API knowledge.
-
setCharset
public DatabaseBuilder setCharset(Charset charset)
Sets the Charset to use, ifnull, uses default.- Usage:
- Intermediate: This method requires moderate API knowledge.
-
setTimeZone
public DatabaseBuilder setTimeZone(TimeZone timeZone)
Sets the TimeZone to use for interpreting dates, ifnull, 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 benullif 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 fromDatabase.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 (seePropertyMap.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 (seePropertyMap.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 (seePropertyMap.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, iftrue, 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 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.
-
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.
-
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 (seetoCompatibleCalendar(java.util.Calendar)).
-
toCompatibleCalendar
public static Calendar toCompatibleCalendar(Calendar cal)
Ensures that the givenCalendaris 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.
-
-