com.healthmarketscience.jackcess.impl
Class DatabaseImpl

java.lang.Object
  extended by com.healthmarketscience.jackcess.impl.DatabaseImpl
All Implemented Interfaces:
Database, Closeable, Flushable, Iterable<Table>

public class DatabaseImpl
extends Object
implements Database

Author:
Tim McCune
Usage:
General: This class is general use.

Nested Class Summary
static class DatabaseImpl.FileFormatDetails
          Internal details for each FileForrmat
 
Nested classes/interfaces inherited from interface com.healthmarketscience.jackcess.Database
Database.FileFormat
 
Field Summary
static String DEFAULT_RESOURCE_PATH
          the default value for the resource path used to load classpath resources.
static int HIDDEN_OBJECT_FLAG
          this object is hidden
static String RO_CHANNEL_MODE
          read-only channel access mode
static String RW_CHANNEL_MODE
          read/write channel access mode
 
Fields inherited from interface com.healthmarketscience.jackcess.Database
BROKEN_NIO_PROPERTY, CHARSET_PROPERTY_PREFIX, COLUMN_ORDER_PROPERTY, DEFAULT_AUTO_SYNC, DEFAULT_COLUMN_ORDER, FK_ENFORCE_PROPERTY, RESOURCE_PATH_PROPERTY, TIMEZONE_PROPERTY
 
Method Summary
 void close()
          Close the database file (and any linked databases).
static DatabaseImpl create(Database.FileFormat fileFormat, File mdbFile, FileChannel channel, boolean autoSync, Charset charset, TimeZone timeZone)
          Create a new Database for the given fileFormat
 void createLinkedTable(String name, String linkedDbName, String linkedTableName)
          Create a new table in this database
 void createTable(String name, List<ColumnBuilder> columns)
          Create a new table in this database
 void createTable(String name, List<ColumnBuilder> columns, List<IndexBuilder> indexes)
          Create a new table in this database
 void flush()
          Flushes any current changes to the database file (and any linked databases) to disk.
 TableImpl getAccessControlEntries()
           
 Charset getCharset()
          Gets currently configured Charset (always non-null).
 Table.ColumnOrder getColumnOrder()
          Gets currently configured Table.ColumnOrder (always non-null).
 String getDatabasePassword()
           
 PropertyMap getDatabaseProperties()
           
static Charset getDefaultCharset(JetFormat format)
          Returns the default Charset for the given JetFormat.
 short getDefaultCodePage()
           
static Table.ColumnOrder getDefaultColumnOrder()
          Returns the default Table.ColumnOrder.
static boolean getDefaultEnforceForeignKeys()
          Returns the default enforce foreign-keys policy.
 ColumnImpl.SortOrder getDefaultSortOrder()
           
static TimeZone getDefaultTimeZone()
          Returns the default TimeZone.
 ErrorHandler getErrorHandler()
          Gets the currently configured ErrorHandler (always non-null).
 File getFile()
          Returns the File underlying this Database
 Database.FileFormat getFileFormat()
          Returns the FileFormat of this database (which may involve inspecting the database itself).
static DatabaseImpl.FileFormatDetails getFileFormatDetails(Database.FileFormat fileFormat)
           
 JetFormat getFormat()
           
 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).
 PageChannel getPageChannel()
           
 PropertyMaps getPropertiesForObject(int objectId)
           
 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(TableImpl table1, TableImpl table2)
           
 List<Relationship> getRelationships(Table table1, Table table2)
          Finds all the relationships in the database between the given tables.
 PropertyMap getSummaryProperties()
           
 TableImpl getSystemCatalog()
           
 TableImpl getSystemComplexColumns()
           
 List<Relationship> getSystemRelationships()
          Finds all the relationships in the database, including system tables.
 TableImpl getSystemTable(String tableName)
          Returns a reference to any available table in this access database, including system tables.
 Set<String> getSystemTableNames()
           
 TableImpl getTable(int tableDefPageNumber)
           
 TableImpl getTable(String name)
           
 Set<String> getTableNames()
           
 TimeZone getTimeZone()
          Gets currently configured TimeZone (always non-null).
 PropertyMap getUserDefinedProperties()
           
 boolean isEnforceForeignKeys()
          Gets currently foreign-key enforcement policy.
 Iterator<Table> iterator()
           
static DatabaseImpl open(File mdbFile, boolean readOnly, FileChannel channel, boolean autoSync, Charset charset, TimeZone timeZone, CodecProvider provider)
          Open an existing Database.
 PropertyMaps readProperties(byte[] propsBytes, int objectId, RowIdImpl rowId)
           
 void setCharset(Charset newCharset)
          Sets a new Charset.
 void setColumnOrder(Table.ColumnOrder newColumnOrder)
          Sets a new Table.ColumnOrder.
 void setEnforceForeignKeys(Boolean newEnforceForeignKeys)
          Sets a new foreign-key enforcement policy.
 void setErrorHandler(ErrorHandler newErrorHandler)
          Sets a new ErrorHandler.
 void setLinkResolver(LinkResolver newLinkResolver)
          Sets a new LinkResolver.
 void setTimeZone(TimeZone newTimeZone)
          Sets a new TimeZone.
static String toLookupName(String name)
           
 String toString()
           
static void validateIdentifierName(String name, int maxLength, String identifierType)
          Validates an identifier name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_RESOURCE_PATH

public static final String DEFAULT_RESOURCE_PATH
the default value for the resource path used to load classpath resources.

See Also:
Constant Field Values

HIDDEN_OBJECT_FLAG

public static final int HIDDEN_OBJECT_FLAG
this object is hidden

See Also:
Constant Field Values

RO_CHANNEL_MODE

public static final String RO_CHANNEL_MODE
read-only channel access mode

See Also:
Constant Field Values

RW_CHANNEL_MODE

public static final String RW_CHANNEL_MODE
read/write channel access mode

See Also:
Constant Field Values
Method Detail

open

public static DatabaseImpl open(File mdbFile,
                                boolean readOnly,
                                FileChannel channel,
                                boolean autoSync,
                                Charset charset,
                                TimeZone timeZone,
                                CodecProvider provider)
                         throws IOException
Open an existing Database. If the existing file is not writeable or the readOnly flag is true, the file will be opened read-only.

Parameters:
mdbFile - File containing the database
readOnly - iff true, force opening file in read-only mode
channel - pre-opened FileChannel. if provided explicitly, it will not be closed by this Database instance
autoSync - whether or not to enable auto-syncing on write. if true, writes will be immediately flushed to disk. 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 flush().
charset - Charset to use, if null, uses default
timeZone - TimeZone to use, if null, uses default
provider - CodecProvider for handling page encoding/decoding, may be null if no special encoding is necessary
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

create

public static DatabaseImpl create(Database.FileFormat fileFormat,
                                  File mdbFile,
                                  FileChannel channel,
                                  boolean autoSync,
                                  Charset charset,
                                  TimeZone timeZone)
                           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.
channel - pre-opened FileChannel. if provided explicitly, it will not be closed by this Database instance
autoSync - whether or not to enable auto-syncing on write. if true, writes will be immediately flushed to disk. 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 flush().
charset - Charset to use, if null, uses default
timeZone - TimeZone to use, if null, uses default
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

getFile

public File getFile()
Description copied from interface: Database
Returns the File underlying this Database

Specified by:
getFile in interface Database

getPageChannel

public PageChannel getPageChannel()
Usage:
Advanced: This method is for advanced/internal use.

getFormat

public JetFormat getFormat()
Usage:
Advanced: This method is for advanced/internal use.

getSystemCatalog

public TableImpl getSystemCatalog()
Returns:
The system catalog table
Usage:
Advanced: This method is for advanced/internal use.

getAccessControlEntries

public TableImpl getAccessControlEntries()
                                  throws IOException
Returns:
The system Access Control Entries table (loaded on demand)
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

getSystemComplexColumns

public TableImpl getSystemComplexColumns()
                                  throws IOException
Returns:
the complex column system table (loaded on demand)
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

getErrorHandler

public ErrorHandler getErrorHandler()
Description copied from interface: Database
Gets the currently configured ErrorHandler (always non-null). This will be used to handle all errors unless overridden at the Table or Cursor level.

Specified by:
getErrorHandler in interface Database

setErrorHandler

public void setErrorHandler(ErrorHandler newErrorHandler)
Description copied from interface: Database
Sets a new ErrorHandler. If null, resets to the ErrorHandler.DEFAULT.

Specified by:
setErrorHandler in interface Database

getLinkResolver

public LinkResolver getLinkResolver()
Description copied from interface: Database
Gets the currently configured LinkResolver (always non-null). This will be used to handle all linked database loading.

Specified by:
getLinkResolver in interface Database

setLinkResolver

public void setLinkResolver(LinkResolver newLinkResolver)
Description copied from interface: Database
Sets a new LinkResolver. If null, resets to the LinkResolver.DEFAULT.

Specified by:
setLinkResolver in interface Database

getLinkedDatabases

public Map<String,Database> getLinkedDatabases()
Description copied from interface: Database
Returns an unmodifiable view of the currently loaded linked databases, mapped from the linked database file name to the linked database. This information may be useful for implementing a LinkResolver.

Specified by:
getLinkedDatabases in interface Database

getTimeZone

public TimeZone getTimeZone()
Description copied from interface: Database
Gets currently configured TimeZone (always non-null).

Specified by:
getTimeZone in interface Database

setTimeZone

public void setTimeZone(TimeZone newTimeZone)
Description copied from interface: Database
Sets a new TimeZone. If null, resets to the default value.

Specified by:
setTimeZone in interface Database

getCharset

public Charset getCharset()
Description copied from interface: Database
Gets currently configured Charset (always non-null).

Specified by:
getCharset in interface Database

setCharset

public void setCharset(Charset newCharset)
Description copied from interface: Database
Sets a new Charset. If null, resets to the default value.

Specified by:
setCharset in interface Database

getColumnOrder

public Table.ColumnOrder getColumnOrder()
Description copied from interface: Database
Gets currently configured Table.ColumnOrder (always non-null).

Specified by:
getColumnOrder in interface Database

setColumnOrder

public void setColumnOrder(Table.ColumnOrder newColumnOrder)
Description copied from interface: Database
Sets a new Table.ColumnOrder. If null, resets to the default value.

Specified by:
setColumnOrder in interface Database

isEnforceForeignKeys

public boolean isEnforceForeignKeys()
Description copied from interface: Database
Gets currently foreign-key enforcement policy.

Specified by:
isEnforceForeignKeys in interface Database

setEnforceForeignKeys

public void setEnforceForeignKeys(Boolean newEnforceForeignKeys)
Description copied from interface: Database
Sets a new foreign-key enforcement policy. If null, resets to the default value.

Specified by:
setEnforceForeignKeys in interface Database

getFileFormat

public Database.FileFormat getFileFormat()
                                  throws IOException
Description copied from interface: Database
Returns the FileFormat of this database (which may involve inspecting the database itself).

Specified by:
getFileFormat in interface Database
Throws:
IOException

getDefaultSortOrder

public ColumnImpl.SortOrder getDefaultSortOrder()
                                         throws IOException
Returns:
the currently configured database default language sort order for textual columns
Throws:
IOException
Usage:
Intermediate: This method requires moderate API knowledge.

getDefaultCodePage

public short getDefaultCodePage()
                         throws IOException
Returns:
the currently configured database default code page for textual data (may not be relevant to all database versions)
Throws:
IOException
Usage:
Intermediate: This method requires moderate API knowledge.

readProperties

public PropertyMaps readProperties(byte[] propsBytes,
                                   int objectId,
                                   RowIdImpl rowId)
                            throws IOException
Returns:
a PropertyMaps instance decoded from the given bytes (always returns non-null result).
Throws:
IOException
Usage:
Intermediate: This method requires moderate API knowledge.

getTableNames

public Set<String> getTableNames()
                          throws IOException
Specified by:
getTableNames in interface Database
Returns:
The names of all of the user tables
Throws:
IOException

getSystemTableNames

public Set<String> getSystemTableNames()
                                throws IOException
Specified by:
getSystemTableNames in interface Database
Returns:
The names of all of the system tables (String). Note, in order to read these tables, you must use Database.getSystemTable(java.lang.String). Extreme care should be taken if modifying these tables directly!.
Throws:
IOException

iterator

public Iterator<Table> iterator()
Specified by:
iterator in interface Database
Specified by:
iterator in interface Iterable<Table>
Returns:
an unmodifiable Iterator of the user Tables in this Database.

getTable

public TableImpl getTable(String name)
                   throws IOException
Specified by:
getTable in interface Database
Parameters:
name - Table name (case-insensitive)
Returns:
The table, or null if it doesn't exist
Throws:
IOException

getTable

public TableImpl getTable(int tableDefPageNumber)
                   throws IOException
Parameters:
tableDefPageNumber - the page number of a table definition
Returns:
The table, or null if it doesn't exist
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

createTable

public void createTable(String name,
                        List<ColumnBuilder> columns)
                 throws IOException
Create a new table in this database

Parameters:
name - Name of the table to create
columns - List of Columns in the table
Throws:
IOException
Usage:
General: This method is general use.

createTable

public void createTable(String name,
                        List<ColumnBuilder> columns,
                        List<IndexBuilder> indexes)
                 throws IOException
Create a new table in this database

Parameters:
name - Name of the table to create
columns - List of Columns in the table
indexes - List of IndexBuilders describing indexes for the table
Throws:
IOException
Usage:
General: This method is general use.

createLinkedTable

public void createLinkedTable(String name,
                              String linkedDbName,
                              String linkedTableName)
                       throws IOException
Description copied from interface: Database
Create a new table in this database

Specified by:
createLinkedTable in interface Database
Parameters:
name - Name of the table to create in this database
linkedDbName - path to the linked database
linkedTableName - name of the table in the linked database
Throws:
IOException

getRelationships

public List<Relationship> getRelationships(Table table1,
                                           Table table2)
                                    throws IOException
Description copied from interface: Database
Finds all the relationships in the database between the given tables.

Specified by:
getRelationships in interface Database
Throws:
IOException

getRelationships

public List<Relationship> getRelationships(TableImpl table1,
                                           TableImpl table2)
                                    throws IOException
Throws:
IOException

getRelationships

public List<Relationship> getRelationships(Table table)
                                    throws IOException
Description copied from interface: Database
Finds all the relationships in the database for the given table.

Specified by:
getRelationships in interface Database
Throws:
IOException

getRelationships

public List<Relationship> getRelationships()
                                    throws IOException
Description copied from interface: Database
Finds all the relationships in the database in non-system tables.

Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.

Specified by:
getRelationships in interface Database
Throws:
IOException

getSystemRelationships

public List<Relationship> getSystemRelationships()
                                          throws IOException
Description copied from interface: Database
Finds all the relationships in the database, including system tables.

Warning, this may load all the Tables (metadata, not data) in the database which could cause memory issues.

Specified by:
getSystemRelationships in interface Database
Throws:
IOException

getQueries

public List<Query> getQueries()
                       throws IOException
Description copied from interface: Database
Finds all the queries in the database.

Specified by:
getQueries in interface Database
Throws:
IOException

getSystemTable

public TableImpl getSystemTable(String tableName)
                         throws IOException
Description copied from interface: Database
Returns a reference to any available table in this access database, including system tables.

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.

Specified by:
getSystemTable in interface Database
Parameters:
tableName - Table name, may be a system table
Returns:
The table, or null if it doesn't exist
Throws:
IOException

getDatabaseProperties

public PropertyMap getDatabaseProperties()
                                  throws IOException
Specified by:
getDatabaseProperties in interface Database
Returns:
the core properties for the database
Throws:
IOException

getSummaryProperties

public PropertyMap getSummaryProperties()
                                 throws IOException
Specified by:
getSummaryProperties in interface Database
Returns:
the summary properties for the database
Throws:
IOException

getUserDefinedProperties

public PropertyMap getUserDefinedProperties()
                                     throws IOException
Specified by:
getUserDefinedProperties in interface Database
Returns:
the user-defined properties for the database
Throws:
IOException

getPropertiesForObject

public PropertyMaps getPropertiesForObject(int objectId)
                                    throws IOException
Returns:
the PropertyMaps for the object with the given id
Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.

getDatabasePassword

public String getDatabasePassword()
                           throws IOException
Specified by:
getDatabasePassword in interface Database
Returns:
the current database password, or null if none set.
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: Database
Flushes any current changes to the database file (and any linked databases) to disk.

Specified by:
flush in interface Database
Specified by:
flush in interface Flushable
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: Database
Close the database file (and any linked databases). A Database must be closed after use or changes could be lost and the Database file corrupted. A Database instance should be treated like any other external resource which would be closed in a finally block (e.g. an OutputStream or jdbc Connection).

Specified by:
close in interface Database
Specified by:
close in interface Closeable
Throws:
IOException

validateIdentifierName

public static void validateIdentifierName(String name,
                                          int maxLength,
                                          String identifierType)
Validates an identifier name.

Usage:
Advanced: This method is for advanced/internal use.

toString

public String toString()
Overrides:
toString in class Object

toLookupName

public static String toLookupName(String name)
Returns:
a string usable in the _tableLookup map.

getDefaultTimeZone

public static TimeZone getDefaultTimeZone()
Returns the default TimeZone. This is normally the platform default TimeZone as returned by TimeZone.getDefault(), but can be overridden using the system property "com.healthmarketscience.jackcess.timeZone".

Usage:
Advanced: This method is for advanced/internal use.

getDefaultCharset

public static Charset getDefaultCharset(JetFormat format)
Returns the default Charset for the given JetFormat. This may or may not be platform specific, depending on the format, but can be overridden using a system property composed of the prefix "com.healthmarketscience.jackcess.charset." followed by the JetFormat version to which the charset should apply, e.g. "com.healthmarketscience.jackcess.charset.VERSION_3".

Usage:
Advanced: This method is for advanced/internal use.

getDefaultColumnOrder

public static Table.ColumnOrder getDefaultColumnOrder()
Returns the default Table.ColumnOrder. This defaults to Database.DEFAULT_COLUMN_ORDER, but can be overridden using the system property "com.healthmarketscience.jackcess.columnOrder".

Usage:
Advanced: This method is for advanced/internal use.

getDefaultEnforceForeignKeys

public static boolean getDefaultEnforceForeignKeys()
Returns the default enforce foreign-keys policy. This defaults to true, but can be overridden using the system property "com.healthmarketscience.jackcess.enforceForeignKeys".

Usage:
Advanced: This method is for advanced/internal use.

getFileFormatDetails

public static DatabaseImpl.FileFormatDetails getFileFormatDetails(Database.FileFormat fileFormat)


Copyright © 2005-2013 Health Market Science. All Rights Reserved.