public interface Database extends Iterable<Table>, Closeable, Flushable
DatabaseBuilder.open(File)
) or creating
a new database file (DatabaseBuilder.create(Database.FileFormat,File)
) (for
more advanced opening/creating use DatabaseBuilder
). Once a
Database has been opened, you can interact with the data via the relevant
Table
. When a Database instance is no longer useful, it should
always be closed (close()
) to avoid corruption.
Database instances (and all the related objects) are not thread-safe. However, separate Database instances (and their respective objects) can be used by separate threads without a problem.
Database instances do not implement any "transactional" support, and therefore concurrent editing of the same database file by multiple Database instances (or with outside programs such as MS Access) will generally result in database file corruption.
Modifier and Type | Interface and Description |
---|---|
static class |
Database.FileFormat
Enum which indicates which version of Access created the database.
|
Modifier and Type | Field and Description |
---|---|
static String |
ALLOW_AUTONUM_INSERT_PROPERTY
system property which can be used to set the default allow auto number
insert policy.
|
static String |
BROKEN_NIO_PROPERTY
(boolean) system property which can be used to indicate that the current
vm has a poor nio implementation (specifically for
FileChannel.transferFrom ) |
static String |
CHARSET_PROPERTY_PREFIX
system property prefix which can be used to set the default Charset
used for text data (full property includes the JetFormat version).
|
static String |
COLUMN_ORDER_PROPERTY
system property which can be used to set the default sort order for
table columns.
|
static String |
DATE_TIME_TYPE_PROPERTY
system property which can be used to set the default date/Time type.
|
static boolean |
DEFAULT_AUTO_SYNC
default value for the auto-sync value (
true ). |
static Table.ColumnOrder |
DEFAULT_COLUMN_ORDER
the default sort order for table columns.
|
static String |
ENABLE_EXPRESSION_EVALUATION_PROPERTY
system property which can be used to disable expression evaluation
if necessary.
|
static String |
FK_ENFORCE_PROPERTY
system property which can be used to set the default enforcement of
foreign-key relationships.
|
static String |
RESOURCE_PATH_PROPERTY
system property which can be used to set the path from which classpath
resources are loaded (must end with a "/" if non-empty).
|
static String |
TIMEZONE_PROPERTY
system property which can be used to set the default TimeZone used for
date calculations.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the database file (and any linked databases).
|
void |
createLinkedTable(String name,
String linkedDbName,
String linkedTableName)
Create a new table in this database
|
void |
flush()
Flushes any current changes to the database file (and any linked
databases) to disk.
|
Charset |
getCharset()
Gets currently configured Charset (always non-
null ). |
Table.ColumnOrder |
getColumnOrder()
Gets currently configured
Table.ColumnOrder (always non-null ). |
ColumnValidatorFactory |
getColumnValidatorFactory()
Gets currently configured ColumnValidatorFactory (always non-
null ). |
String |
getDatabasePassword() |
PropertyMap |
getDatabaseProperties() |
DateTimeType |
getDateTimeType()
Gets the currently configured DateTimeType.
|
ErrorHandler |
getErrorHandler()
Gets the currently configured ErrorHandler (always non-
null ). |
EvalConfig |
getEvalConfig()
Returns the EvalConfig for configuring expression evaluation.
|
File |
getFile()
Returns the File underlying this Database
|
Database.FileFormat |
getFileFormat()
Returns the FileFormat of this database (which may involve inspecting the
database itself).
|
Map<String,Database> |
getLinkedDatabases()
Returns an unmodifiable view of the currently loaded linked databases,
mapped from the linked database file name to the linked database.
|
LinkResolver |
getLinkResolver()
Gets the currently configured LinkResolver (always non-
null ). |
Path |
getPath()
Returns the File underlying this Database
|
List<Query> |
getQueries()
Finds all the queries in the database.
|
List<Relationship> |
getRelationships()
Finds all the relationships in the database in non-system tables.
|
List<Relationship> |
getRelationships(Table table)
Finds all the relationships in the database for the given table.
|
List<Relationship> |
getRelationships(Table table1,
Table table2)
Finds all the relationships in the database between the given tables.
|
PropertyMap |
getSummaryProperties() |
List<Relationship> |
getSystemRelationships()
Finds all the relationships in the database, including system
tables.
|
Table |
getSystemTable(String tableName)
Returns a reference to any available table in this access
database, including system tables.
|
Set<String> |
getSystemTableNames() |
Table |
getTable(String name) |
TableMetaData |
getTableMetaData(String name) |
Set<String> |
getTableNames() |
TimeZone |
getTimeZone()
Gets currently configured TimeZone (always non-
null and aligned
with the ZoneId). |
PropertyMap |
getUserDefinedProperties() |
ZoneId |
getZoneId()
Gets currently configured ZoneId (always non-
null and aligned
with the TimeZone). |
boolean |
isAllowAutoNumberInsert()
Gets current allow auto number insert policy.
|
boolean |
isEnforceForeignKeys()
Gets current foreign-key enforcement policy.
|
boolean |
isEvaluateExpressions()
Gets the current expression evaluation policy.
|
boolean |
isLinkedTable(Table table)
Returns
true if this Database links to the given Table, false otherwise. |
Iterator<Table> |
iterator() |
TableIterableBuilder |
newIterable()
Convenience method for constructing a new TableIterableBuilder for this
cursor.
|
Iterable<TableMetaData> |
newTableMetaDataIterable() |
default Stream<TableMetaData> |
newTableMetaDataStream() |
void |
setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
Sets the new auto number insert policy for the database (unless
overridden at the Table level).
|
void |
setCharset(Charset newCharset)
Sets a new Charset.
|
void |
setColumnOrder(Table.ColumnOrder newColumnOrder)
Sets a new Table.ColumnOrder.
|
void |
setColumnValidatorFactory(ColumnValidatorFactory newFactory)
Sets a new ColumnValidatorFactory.
|
void |
setDateTimeType(DateTimeType dateTimeType)
Sets the DateTimeType.
|
void |
setEnforceForeignKeys(Boolean newEnforceForeignKeys)
Sets a new foreign-key enforcement policy.
|
void |
setErrorHandler(ErrorHandler newErrorHandler)
Sets a new ErrorHandler.
|
void |
setEvaluateExpressions(Boolean evaluateExpressions)
Sets the current expression evaluation policy.
|
void |
setLinkResolver(LinkResolver newLinkResolver)
Sets a new LinkResolver.
|
void |
setTimeZone(TimeZone newTimeZone)
Sets a new TimeZone.
|
void |
setZoneId(ZoneId newZoneId)
Sets a new ZoneId.
|
default Stream<Table> |
stream() |
forEach, spliterator
static final boolean DEFAULT_AUTO_SYNC
true
). this is slower,
but leaves more chance of a useable database in the face of failures.static final Table.ColumnOrder DEFAULT_COLUMN_ORDER
static final String TIMEZONE_PROPERTY
static final String CHARSET_PROPERTY_PREFIX
static final String RESOURCE_PATH_PROPERTY
static final String BROKEN_NIO_PROPERTY
FileChannel.transferFrom
)static final String COLUMN_ORDER_PROPERTY
Table.ColumnOrder
enum
values.static final String FK_ENFORCE_PROPERTY
true
.static final String ALLOW_AUTONUM_INSERT_PROPERTY
false
.static final String ENABLE_EXPRESSION_EVALUATION_PROPERTY
true
.static final String DATE_TIME_TYPE_PROPERTY
DateTimeType
enum values.File getFile()
Path getPath()
Set<String> getTableNames() throws IOException
IOException
Set<String> getSystemTableNames() throws IOException
getSystemTable(java.lang.String)
.
Extreme care should be taken if modifying these tables
directly!.IOException
Iterator<Table> iterator()
iterator
in interface Iterable<Table>
RuntimeIOException
- if an IOException is thrown by one of the
operations, the actual exception will be contained withinConcurrentModificationException
- if a table is added to the
database while an Iterator is in use.TableIterableBuilder newIterable()
Iterable<TableMetaData> newTableMetaDataIterable()
RuntimeIOException
- if an IOException is thrown by one of the
operations, the actual exception will be contained withinConcurrentModificationException
- if a table is added to the
database while an Iterator is in use.default Stream<TableMetaData> newTableMetaDataStream()
newTableMetaDataIterable()
Table getTable(String name) throws IOException
name
- User table name (case-insensitive)IOException
TableMetaData getTableMetaData(String name) throws IOException
name
- Table name (case-insensitive), may be any table type
(i.e. includes system or linked tables).IOException
List<Relationship> getRelationships(Table table1, Table table2) throws IOException
IOException
List<Relationship> getRelationships(Table table) throws IOException
IOException
List<Relationship> getRelationships() throws IOException
Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.
IOException
List<Relationship> getSystemRelationships() throws IOException
Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.
IOException
List<Query> getQueries() throws IOException
IOException
Table getSystemTable(String tableName) throws IOException
Warning, this method is not designed for common use, only for the occassional time when access to a system table is necessary. Messing with system tables can strip the paint off your house and give your whole family a permanent, orange afro. You have been warned.
tableName
- Table name, may be a system tablenull
if it doesn't existIOException
PropertyMap getDatabaseProperties() throws IOException
IOException
PropertyMap getSummaryProperties() throws IOException
IOException
PropertyMap getUserDefinedProperties() throws IOException
IOException
String getDatabasePassword() throws IOException
null
if none set.IOException
void createLinkedTable(String name, String linkedDbName, String linkedTableName) throws IOException
name
- Name of the table to create in this databaselinkedDbName
- path to the linked databaselinkedTableName
- name of the table in the linked databaseIOException
void flush() throws IOException
flush
in interface Flushable
IOException
void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
ErrorHandler getErrorHandler()
null
).
This will be used to handle all errors unless overridden at the Table or
Cursor level.void setErrorHandler(ErrorHandler newErrorHandler)
null
, resets to the
ErrorHandler.DEFAULT
.LinkResolver getLinkResolver()
null
).
This will be used to handle all linked database loading.void setLinkResolver(LinkResolver newLinkResolver)
null
, resets to the
LinkResolver.DEFAULT
.Map<String,Database> getLinkedDatabases()
boolean isLinkedTable(Table table) throws IOException
true
if this Database links to the given Table, false
otherwise.IOException
TimeZone getTimeZone()
null
and aligned
with the ZoneId).void setTimeZone(TimeZone newTimeZone)
null
, resets to the default value. Note
that setting the TimeZone will alter the ZoneId as well.ZoneId getZoneId()
null
and aligned
with the TimeZone).void setZoneId(ZoneId newZoneId)
null
, resets to the default value. Note
that setting the ZoneId will alter the TimeZone as well.Charset getCharset()
null
).void setCharset(Charset newCharset)
null
, resets to the default value.Table.ColumnOrder getColumnOrder()
Table.ColumnOrder
(always non-null
).void setColumnOrder(Table.ColumnOrder newColumnOrder)
null
, resets to the default value.boolean isEnforceForeignKeys()
void setEnforceForeignKeys(Boolean newEnforceForeignKeys)
null
, resets to
the default value.boolean isAllowAutoNumberInsert()
true
allows the caller to optionally set the value explicitly when
adding or updating rows (if a value is not provided, it will still be
handled internally by the Table). This value can be set database-wide
using setAllowAutoNumberInsert(java.lang.Boolean)
and/or on a per-table basis using
Table.setAllowAutoNumberInsert(java.lang.Boolean)
(and/or on a jvm-wide using the
ALLOW_AUTONUM_INSERT_PROPERTY
system property). Note that
enabling this feature should be done with care to reduce the
chances of screwing up the database.void setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
null
, resets to the default
value.boolean isEvaluateExpressions()
void setEvaluateExpressions(Boolean evaluateExpressions)
null
,
resets to the default value.ColumnValidatorFactory getColumnValidatorFactory()
null
).void setColumnValidatorFactory(ColumnValidatorFactory newFactory)
null
, resets to the
default value. The configured ColumnValidatorFactory will be used to
create ColumnValidator instances on any user tables loaded from
this point onward (this will not be used for system tables).Database.FileFormat getFileFormat() throws IOException
IllegalStateException
- if the file format cannot be determinedIOException
EvalConfig getEvalConfig()
DateTimeType getDateTimeType()
void setDateTimeType(DateTimeType dateTimeType)
null
, resets to the default value.Copyright © 2005–2024 OpenHMS. All rights reserved.