APIdia Launch Partner
Top Description Fields Constructors Methods
io.github.spannm.jackcess

public Class DatabaseBuilder

extends Object
Class Inheritance
Imports
io.github.spannm.jackcess.Database.FileFormat, io.github.spannm.jackcess.impl.CodecProvider, .DatabaseImpl, .PropertyMapImpl, io.github.spannm.jackcess.util.MemFileChannel, java.io.File, .IOException, java.nio.channels.FileChannel, java.nio.charset.Charset, java.nio.file.Path, java.text.SimpleDateFormat, java.util.Calendar, .Date, .GregorianCalendar, .HashMap, .Map, .TimeZone

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();

Field Summary

Modifier and TypeField and Description
private boolean
autoSync

whether or not to auto-sync writes to the filesystem

private FileChannel
channel

optional pre-opened FileChannel, will _not_ be closed by Database close

private Charset
charset

optional charset for mdbs with unspecified charsets

private CodecProvider
codecProvider

optional CodecProvider for handling encoded mdbs

private Map<String, PropertyMap.Property>
dbProps

database properties (if any)

private Database.FileFormat
fileFormat

FileFormat to use when creating a new mdb

private boolean
ignoreBrokenSystemCatalogIndex

flag indicating that the system catalog index is borked

private Path
mdbFile

the file name of the mdb to open/create

private boolean
readOnly

whether or not to open existing mdb read-only

private Map<String, PropertyMap.Property>
summaryProps

database summary properties (if any)

private TimeZone
timeZone

optional timezone override for interpreting dates

private Map<String, PropertyMap.Property>
userProps

database user-defined (if any)

Constructor Summary

AccessConstructor and Description
public
public
DatabaseBuilder(File mdbFile)
Deprecated use DatabaseBuilder(Path) instead

public
DatabaseBuilder(Path mdbFile)
Deprecated use DatabaseBuilder() with withPath instead

Method Summary

Modifier and TypeMethod and Description
public Database
create()

Creates a new Database using the configured information.

public static Database
create(Database.FileFormat
version of new database.
fileFormat
,
File
Location to write the new database to. If this file already exists, it will be overwritten.
mdbFile
)

Create a new Database for the given fileFormat

public static SimpleDateFormat
createDateFormat(String formatStr)

Returns a SimpleDateFormat for the given format string which is configured with a compatible Calendar instance (see toCompatibleCalendar).

public static ColumnBuilder
newColumn(String name)

Convenience method for constructing a ColumnBuilder.

public static ColumnBuilder
newColumn(String name, DataType type)

Convenience method for constructing a TableBuilder.

public static DatabaseBuilder
newDatabase()

Convenience method for constructing a DatabaseBuilder.

public static DatabaseBuilder
newDatabase(Path path)

Convenience method for constructing a DatabaseBuilder.

public static DatabaseBuilder
newDatabase(File file)

Convenience method for constructing a DatabaseBuilder.

public static IndexBuilder
newIndex(String name)

Convenience method for constructing an IndexBuilder.

public static IndexBuilder
newPrimaryKey(String... colNames)

Convenience method for constructing a primary key IndexBuilder.

public static RelationshipBuilder
newRelationship(String fromTable, String toTable)

Convenience method for constructing a RelationshipBuilder.

public static RelationshipBuilder
newRelationship(Table fromTable, Table toTable)

Convenience method for constructing a RelationshipBuilder.

public static TableBuilder
newTable(String name)

Convenience method for constructing a TableBuilder.

public static TableBuilder
newTable(String name, boolean escapeIdentifiers)

Convenience method for constructing a TableBuilder.

public Database
open()

Opens an existing new Database using the configured information.

public static Database
open(File
File containing the database
mdbFile
)

Open an existing Database.

public static Database
open(Path
File containing the database
mdbFile
)

Open an existing Database.

public DatabaseBuilder
putDatabaseProperty(String name, Object value)

Sets the database property with the given name to the given value.

public DatabaseBuilder
putDatabaseProperty(String name, DataType type, Object value)

Sets the database property with the given name and type to the given value.

private static Map<String, PropertyMap.Property>
public DatabaseBuilder
putSummaryProperty(String name, Object value)

Sets the summary database property with the given name to the given value.

public DatabaseBuilder
putSummaryProperty(String name, DataType type, Object value)

Sets the summary database property with the given name and type to the given value.

public DatabaseBuilder
putUserDefinedProperty(String name, Object value)

Sets the user-defined database property with the given name to the given value.

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.

public static Calendar
toCompatibleCalendar(Calendar cal)

Ensures that the given Calendar is configured to be compatible with how Access handles dates.

private static Path
toPath(File file)

public DatabaseBuilder
withAutoSync(boolean newAutoSync)

Sets whether or not to enable auto-syncing on write.

public DatabaseBuilder
withChannel(FileChannel newChannel)

Sets a pre-opened FileChannel.

public DatabaseBuilder
withCharset(Charset newCharset)

Sets the Charset to use, if null, uses default.

public DatabaseBuilder
withCodecProvider(CodecProvider newCodecProvider)

Sets the CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary

public DatabaseBuilder
withFile(File newMdbFile)

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.

public DatabaseBuilder
withFileFormat(Database.FileFormat newFileFormat)

Sets the version of new database (create only).

public DatabaseBuilder
withIgnoreBrokenSystemCatalogIndex(boolean ignore)

Sets flag which, if true, will make the database ignore the index on the system catalog when looking up tables.

public DatabaseBuilder
withPath(Path newMdbFile)

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.

public DatabaseBuilder
withReadOnly(boolean newReadOnly)

Sets flag which, iff true, will force opening file in read-only mode (open only).

public DatabaseBuilder
withTimeZone(TimeZone newTimeZone)

Sets the TimeZone to use for interpreting dates, if null, uses default

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoSyncback to summary
private boolean autoSync

whether or not to auto-sync writes to the filesystem

channelback to summary
private FileChannel channel

optional pre-opened FileChannel, will _not_ be closed by Database close

charsetback to summary
private Charset charset

optional charset for mdbs with unspecified charsets

codecProviderback to summary
private CodecProvider codecProvider

optional CodecProvider for handling encoded mdbs

dbPropsback to summary
private Map<String, PropertyMap.Property> dbProps

database properties (if any)

fileFormatback to summary
private Database.FileFormat fileFormat

FileFormat to use when creating a new mdb

ignoreBrokenSystemCatalogIndexback to summary
private boolean ignoreBrokenSystemCatalogIndex

flag indicating that the system catalog index is borked

mdbFileback to summary
private Path mdbFile

the file name of the mdb to open/create

readOnlyback to summary
private boolean readOnly

whether or not to open existing mdb read-only

summaryPropsback to summary
private Map<String, PropertyMap.Property> summaryProps

database summary properties (if any)

timeZoneback to summary
private TimeZone timeZone

optional timezone override for interpreting dates

userPropsback to summary
private Map<String, PropertyMap.Property> userProps

database user-defined (if any)

Constructor Detail

DatabaseBuilderback to summary
public DatabaseBuilder()
DatabaseBuilderback to summary
public DatabaseBuilder(File mdbFile)

Deprecated

use DatabaseBuilder(Path) instead

Annotations
@Deprecated
DatabaseBuilderback to summary
public DatabaseBuilder(Path mdbFile)

Deprecated

use DatabaseBuilder() with withPath instead

Annotations
@Deprecated

Method Detail

createback to summary
public Database create() throws IOException

Creates a new Database using the configured information.

Annotations
@SuppressWarnings:java:S2095
createback to summary
public static Database create(Database.FileFormat fileFormat, File mdbFile) throws IOException

Create a new Database for the given fileFormat

Parameters
fileFormat:Database.FileFormat

version of new database.

mdbFile:File

Location to write the new database to. If this file already exists, it will be overwritten.

See Also
{@link DatabaseBuilder} for more flexible Database creation
createDateFormatback to summary
public static SimpleDateFormat createDateFormat(String formatStr)

Returns a SimpleDateFormat for the given format string which is configured with a compatible Calendar instance (see toCompatibleCalendar).

newColumnback to summary
public static ColumnBuilder newColumn(String name)

Convenience method for constructing a ColumnBuilder.

newColumnback to summary
public static ColumnBuilder newColumn(String name, DataType type)

Convenience method for constructing a TableBuilder.

newDatabaseback to summary
public static DatabaseBuilder newDatabase()

Convenience method for constructing a DatabaseBuilder.

newDatabaseback to summary
public static DatabaseBuilder newDatabase(Path path)

Convenience method for constructing a DatabaseBuilder.

newDatabaseback to summary
public static DatabaseBuilder newDatabase(File file)

Convenience method for constructing a DatabaseBuilder.

newIndexback to summary
public static IndexBuilder newIndex(String name)

Convenience method for constructing an IndexBuilder.

newPrimaryKeyback to summary
public static IndexBuilder newPrimaryKey(String... colNames)

Convenience method for constructing a primary key IndexBuilder.

newRelationshipback to summary
public static RelationshipBuilder newRelationship(String fromTable, String toTable)

Convenience method for constructing a RelationshipBuilder.

newRelationshipback to summary
public static RelationshipBuilder newRelationship(Table fromTable, Table toTable)

Convenience method for constructing a RelationshipBuilder.

newTableback to summary
public static TableBuilder newTable(String name)

Convenience method for constructing a TableBuilder.

newTableback to summary
public static TableBuilder newTable(String name, boolean escapeIdentifiers)

Convenience method for constructing a TableBuilder.

openback to summary
public Database open() throws IOException

Opens an existing new Database using the configured information.

openback to summary
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

File containing the database

See Also
{@link DatabaseBuilder} for more flexible Database opening
openback to summary
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:Path

File containing the database

See Also
{@link DatabaseBuilder} for more flexible Database opening
putDatabasePropertyback to summary
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).

putDatabasePropertyback to summary
public DatabaseBuilder putDatabaseProperty(String name, DataType type, Object value)

Sets the database property with the given name and type to the given value.

putPropertyback to summary
private static Map<String, PropertyMap.Property> putProperty(Map<String, PropertyMap.Property> props, String name, DataType type, Object value)
putSummaryPropertyback to summary
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).

putSummaryPropertyback to summary
public DatabaseBuilder putSummaryProperty(String name, DataType type, Object value)

Sets the summary database property with the given name and type to the given value.

putUserDefinedPropertyback to summary
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).

putUserDefinedPropertyback to summary
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.

toCompatibleCalendarback to summary
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).

toPathback to summary
private static Path toPath(File file)
withAutoSyncback to summary
public DatabaseBuilder withAutoSync(boolean newAutoSync)

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.

withChannelback to summary
public DatabaseBuilder withChannel(FileChannel newChannel)

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.

withCharsetback to summary
public DatabaseBuilder withCharset(Charset newCharset)

Sets the Charset to use, if null, uses default.

withCodecProviderback to summary
public DatabaseBuilder withCodecProvider(CodecProvider newCodecProvider)

Sets the CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary

withFileback to summary
public DatabaseBuilder withFile(File newMdbFile)

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

withFileFormatback to summary
public DatabaseBuilder withFileFormat(Database.FileFormat newFileFormat)

Sets the version of new database (create only).

withIgnoreBrokenSystemCatalogIndexback to summary
public DatabaseBuilder withIgnoreBrokenSystemCatalogIndex(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.

withPathback to summary
public DatabaseBuilder withPath(Path newMdbFile)

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

withReadOnlyback to summary
public DatabaseBuilder withReadOnly(boolean newReadOnly)

Sets flag which, iff true, will force opening file in read-only mode (open only).

withTimeZoneback to summary
public DatabaseBuilder withTimeZone(TimeZone newTimeZone)

Sets the TimeZone to use for interpreting dates, if null, uses default