com.healthmarketscience.jackcess
Class Database

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

public class Database
extends Object
implements Iterable<Table>, Closeable, Flushable

An Access database.

There is now experimental, optional support for large indexes (disabled by default). This optional support can be enabled via a few different means:

Author:
Tim McCune

Field Summary
static boolean DEFAULT_AUTO_SYNC
          default value for the auto-sync value (true).
static String USE_BIG_INDEX_PROPERTY
          system property which can be used to make big index support the default.
 
Method Summary
 void close()
          Close the database file
 void copyTable(String name, ResultSet source)
          Copy an existing JDBC ResultSet into a new table in this database
 void copyTable(String name, ResultSet source, ImportFilter filter)
          Copy an existing JDBC ResultSet into a new table in this database
static Database create(File mdbFile)
          Create a new Database
static Database create(File mdbFile, boolean autoSync)
          Create a new Database
 void createTable(String name, List<Column> columns)
          Create a new table in this database
 boolean defaultUseBigIndex()
          Returns true if "big index support" has been enabled explicity on the this Database or via a system property, false otherwise.
 boolean doUseBigIndex()
          Whether or not big index support is enabled for tables.
 void flush()
          Flushes any current changes to the database file to disk.
 Table getAccessControlEntries()
           
 JetFormat getFormat()
           
 PageChannel getPageChannel()
           
 List<Relationship> getRelationships(Table table1, Table table2)
          Finds all the relationships in the database between the given tables.
 Table getSystemCatalog()
           
 Table getTable(String name)
           
 Table getTable(String name, boolean useBigIndex)
           
 Set<String> getTableNames()
           
 void importFile(String name, File f, String delim)
          Copy a delimited text file into a new table in this database
 void importFile(String name, File f, String delim, ImportFilter filter)
          Copy a delimited text file into a new table in this database
 void importReader(String name, BufferedReader in, String delim)
          Copy a delimited text file into a new table in this database
 void importReader(String name, BufferedReader in, String delim, ImportFilter filter)
          Copy a delimited text file into a new table in this database
static boolean isReservedWord(String s)
           
 Iterator<Table> iterator()
           
static Database open(File mdbFile)
          Open an existing Database.
static Database open(File mdbFile, boolean readOnly)
          Open an existing Database.
static Database open(File mdbFile, boolean readOnly, boolean autoSync)
          Open an existing Database.
 void setUseBigIndex(boolean useBigIndex)
          Set whether or not big index support is enabled for tables.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_AUTO_SYNC

public static final boolean DEFAULT_AUTO_SYNC
default value for the auto-sync value (true). this is slower, but leaves more chance of a useable database in the face of failures.

See Also:
Constant Field Values

USE_BIG_INDEX_PROPERTY

public static final String USE_BIG_INDEX_PROPERTY
system property which can be used to make big index support the default.

See Also:
Constant Field Values
Method Detail

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

open

public static Database open(File mdbFile,
                            boolean readOnly)
                     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. Auto-syncing is enabled for the returned Database.

Parameters:
mdbFile - File containing the database
readOnly - iff true, force opening file in read-only mode
Throws:
IOException

open

public static Database open(File mdbFile,
                            boolean readOnly,
                            boolean autoSync)
                     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
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.
Throws:
IOException

create

public static Database create(File mdbFile)
                       throws IOException
Create a new Database

Parameters:
mdbFile - Location to write the new database to. If this file already exists, it will be overwritten.
Throws:
IOException

create

public static Database create(File mdbFile,
                              boolean autoSync)
                       throws IOException
Create a new Database

Parameters:
mdbFile - Location to write the new database to. If this file already exists, it will be overwritten.
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.
Throws:
IOException

getPageChannel

public PageChannel getPageChannel()

getFormat

public JetFormat getFormat()

getSystemCatalog

public Table getSystemCatalog()
Returns:
The system catalog table

getAccessControlEntries

public Table getAccessControlEntries()
Returns:
The system Access Control Entries table

doUseBigIndex

public boolean doUseBigIndex()
Whether or not big index support is enabled for tables.


setUseBigIndex

public void setUseBigIndex(boolean useBigIndex)
Set whether or not big index support is enabled for tables.


getTableNames

public Set<String> getTableNames()
Returns:
The names of all of the user tables (String)

iterator

public Iterator<Table> iterator()
Specified by:
iterator in interface Iterable<Table>
Returns:
an unmodifiable Iterator of the user Tables in this Database.
Throws:
IllegalStateException - if an IOException is thrown by one of the operations, the actual exception will be contained within
ConcurrentModificationException - if a table is added to the database while an Iterator is in use.

getTable

public Table getTable(String name)
               throws IOException
Parameters:
name - Table name
Returns:
The table, or null if it doesn't exist
Throws:
IOException

getTable

public Table getTable(String name,
                      boolean useBigIndex)
               throws IOException
Parameters:
name - Table name
useBigIndex - whether or not "big index support" should be enabled for the table (this value will override any other settings)
Returns:
The table, or null if it doesn't exist
Throws:
IOException

createTable

public void createTable(String name,
                        List<Column> 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

getRelationships

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

Throws:
IOException

copyTable

public void copyTable(String name,
                      ResultSet source)
               throws SQLException,
                      IOException
Copy an existing JDBC ResultSet into a new table in this database

Parameters:
name - Name of the new table to create
source - ResultSet to copy from
Throws:
SQLException
IOException

copyTable

public void copyTable(String name,
                      ResultSet source,
                      ImportFilter filter)
               throws SQLException,
                      IOException
Copy an existing JDBC ResultSet into a new table in this database

Parameters:
name - Name of the new table to create
source - ResultSet to copy from
filter - valid import filter
Throws:
SQLException
IOException

importFile

public void importFile(String name,
                       File f,
                       String delim)
                throws IOException
Copy a delimited text file into a new table in this database

Parameters:
name - Name of the new table to create
f - Source file to import
delim - Regular expression representing the delimiter string.
Throws:
IOException

importFile

public void importFile(String name,
                       File f,
                       String delim,
                       ImportFilter filter)
                throws IOException
Copy a delimited text file into a new table in this database

Parameters:
name - Name of the new table to create
f - Source file to import
delim - Regular expression representing the delimiter string.
filter - valid import filter
Throws:
IOException

importReader

public void importReader(String name,
                         BufferedReader in,
                         String delim)
                  throws IOException
Copy a delimited text file into a new table in this database

Parameters:
name - Name of the new table to create
in - Source reader to import
delim - Regular expression representing the delimiter string.
Throws:
IOException

importReader

public void importReader(String name,
                         BufferedReader in,
                         String delim,
                         ImportFilter filter)
                  throws IOException
Copy a delimited text file into a new table in this database

Parameters:
name - Name of the new table to create
in - Source reader to import
delim - Regular expression representing the delimiter string.
filter - valid import filter
Throws:
IOException

flush

public void flush()
           throws IOException
Flushes any current changes to the database file to disk.

Specified by:
flush in interface Flushable
Throws:
IOException

close

public void close()
           throws IOException
Close the database file

Specified by:
close in interface Closeable
Throws:
IOException

isReservedWord

public static boolean isReservedWord(String s)
Returns:
true if the given string is a reserved word, false otherwise

toString

public String toString()
Overrides:
toString in class Object

defaultUseBigIndex

public boolean defaultUseBigIndex()
Returns true if "big index support" has been enabled explicity on the this Database or via a system property, false otherwise.



Copyright ? 2005-2008 Health Market Science. All Rights Reserved.