public class DatabaseBuilder
extends java.lang.Object
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();
| Modifier and Type | Field and Description |
|---|---|
private boolean |
_autoSync
whether or not to auto-sync writes to the filesystem
|
private java.nio.channels.FileChannel |
_channel
optional pre-opened FileChannel, will _not_ be closed by Database
close
|
private java.nio.charset.Charset |
_charset
optional charset for mdbs with unspecified charsets
|
private CodecProvider |
_codecProvider
optional CodecProvider for handling encoded mdbs
|
private java.util.Map<java.lang.String,PropertyMap.Property> |
_dbProps
database properties (if any)
|
private Database.FileFormat |
_fileFormat
FileFormat to use when creating a new mdb
|
private java.io.File |
_mdbFile
the file name of the mdb to open/create
|
private boolean |
_readOnly
whether or not to open existing mdb read-only
|
private java.util.Map<java.lang.String,PropertyMap.Property> |
_summaryProps
database summary properties (if any)
|
private java.util.TimeZone |
_timeZone
optional timezone override for interpreting dates
|
private java.util.Map<java.lang.String,PropertyMap.Property> |
_userProps
database user-defined (if any)
|
| Constructor and Description |
|---|
DatabaseBuilder() |
DatabaseBuilder(java.io.File mdbFile) |
| Modifier and Type | Method and Description |
|---|---|
Database |
create()
Creates a new Database using the configured information.
|
static Database |
create(Database.FileFormat fileFormat,
java.io.File mdbFile)
Create a new Database for the given fileFormat
|
static java.text.SimpleDateFormat |
createDateFormat(java.lang.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(java.io.File mdbFile)
Open an existing Database.
|
DatabaseBuilder |
putDatabaseProperty(java.lang.String name,
DataType type,
java.lang.Object value)
Sets the database property with the given name and type to the given
value.
|
DatabaseBuilder |
putDatabaseProperty(java.lang.String name,
java.lang.Object value)
Sets the database property with the given name to the given value.
|
private static java.util.Map<java.lang.String,PropertyMap.Property> |
putProperty(java.util.Map<java.lang.String,PropertyMap.Property> props,
java.lang.String name,
DataType type,
java.lang.Object value) |
DatabaseBuilder |
putSummaryProperty(java.lang.String name,
DataType type,
java.lang.Object value)
Sets the summary database property with the given name and type to
the given value.
|
DatabaseBuilder |
putSummaryProperty(java.lang.String name,
java.lang.Object value)
Sets the summary database property with the given name to the given
value.
|
DatabaseBuilder |
putUserDefinedProperty(java.lang.String name,
DataType type,
java.lang.Object value)
Sets the user-defined database property with the given name and type to
the given value.
|
DatabaseBuilder |
putUserDefinedProperty(java.lang.String name,
java.lang.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(java.nio.channels.FileChannel channel)
Sets a pre-opened FileChannel.
|
DatabaseBuilder |
setCharset(java.nio.charset.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(java.io.File mdbFile)
|
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(java.util.TimeZone timeZone)
Sets the TimeZone to use for interpreting dates, if
null, uses
default |
static java.util.Calendar |
toCompatibleCalendar(java.util.Calendar cal)
Ensures that the given
Calendar is configured to be compatible
with how Access handles dates. |
private java.io.File _mdbFile
private boolean _readOnly
private boolean _autoSync
private java.nio.charset.Charset _charset
private java.util.TimeZone _timeZone
private CodecProvider _codecProvider
private Database.FileFormat _fileFormat
private java.nio.channels.FileChannel _channel
private java.util.Map<java.lang.String,PropertyMap.Property> _dbProps
private java.util.Map<java.lang.String,PropertyMap.Property> _summaryProps
private java.util.Map<java.lang.String,PropertyMap.Property> _userProps
public DatabaseBuilder()
public DatabaseBuilder(java.io.File mdbFile)
public DatabaseBuilder setFile(java.io.File mdbFile)
public DatabaseBuilder setReadOnly(boolean readOnly)
true, will force opening file in
read-only mode (open() only).public DatabaseBuilder setAutoSync(boolean autoSync)
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().public DatabaseBuilder setCharset(java.nio.charset.Charset charset)
null, uses default.public DatabaseBuilder setTimeZone(java.util.TimeZone timeZone)
null, uses
defaultpublic DatabaseBuilder setCodecProvider(CodecProvider codecProvider)
null if no special encoding is necessarypublic DatabaseBuilder setFileFormat(Database.FileFormat fileFormat)
create() only).public DatabaseBuilder setChannel(java.nio.channels.FileChannel channel)
MemFileChannel). If provided, the File parameter will be
available from Database.getFile(), but otherwise ignored.public DatabaseBuilder putDatabaseProperty(java.lang.String name, java.lang.Object value)
PropertyMap.put(String,Object) for details on determining the
property type).public DatabaseBuilder putDatabaseProperty(java.lang.String name, DataType type, java.lang.Object value)
public DatabaseBuilder putSummaryProperty(java.lang.String name, java.lang.Object value)
PropertyMap.put(String,Object) for details on determining the
property type).public DatabaseBuilder putSummaryProperty(java.lang.String name, DataType type, java.lang.Object value)
public DatabaseBuilder putUserDefinedProperty(java.lang.String name, java.lang.Object value)
PropertyMap.put(String,Object) for details on determining the
property type).public DatabaseBuilder putUserDefinedProperty(java.lang.String name, DataType type, java.lang.Object value)
private static java.util.Map<java.lang.String,PropertyMap.Property> putProperty(java.util.Map<java.lang.String,PropertyMap.Property> props, java.lang.String name, DataType type, java.lang.Object value)
public Database open() throws java.io.IOException
java.io.IOExceptionpublic Database create() throws java.io.IOException
java.io.IOExceptionpublic static Database open(java.io.File mdbFile) throws java.io.IOException
mdbFile - File containing the databasejava.io.IOExceptionfor more flexible Database openingpublic static Database create(Database.FileFormat fileFormat, java.io.File mdbFile) throws java.io.IOException
fileFormat - version of new database.mdbFile - Location to write the new database to. If this file
already exists, it will be overwritten.java.io.IOExceptionfor more flexible Database creationpublic static java.text.SimpleDateFormat createDateFormat(java.lang.String formatStr)
toCompatibleCalendar(java.util.Calendar)).public static java.util.Calendar toCompatibleCalendar(java.util.Calendar cal)
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).