nl.knaw.dans.common.dbflib
Class Database

java.lang.Object
  extended by nl.knaw.dans.common.dbflib.Database

public class Database
extends Object

Represents an xBase database. An xBase database is a directory containing table files (.DBF files) and supporting files like memo (.DBT) or index (.NDX) files. This class allows you to work with the database without having to open the lower level files directly. However, it is still possible to open individual tables directly through the Table class.

Author:
Jan van Mansum, Vesa Ã…kerman

Constructor Summary
Database(File databaseDirectory, Version version)
          Creates a new Database object.
Database(File databaseDirectory, Version version, String charsetName)
          Creates a new Database object.
 
Method Summary
 Table addTable(String name, List<Field> fields)
          Adds a new Table object to the set of Tables maintained by this Database object and returns it.
 String getCharsetName()
          Returns the name of the character set to use when reading from and writing to database files.
 Table getTable(String name)
          Returns the Table object with the specified name or null if it has not been added yet.
 Set<String> getTableNames()
          Returns an unmodifiable Set of table names.
 void removeTable(String name)
          Removes a Table object from the list of Table objects maintained by this Database object.
 void removeTable(Table table)
          Removes a Table object from the list of Table objects maintained by this Database object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database(File databaseDirectory,
                Version version)
Creates a new Database object. A file representing the database directory must be provided. If the directory does not exist, it is created. If the file represents a regular file and not a directory, throws an IllegalArgumentException.

All tables that exist in the database directory are added as Table objects and can be retrieved with getTable(String).

The parameter version does not trigger any validation on an existing database but is merely used to specify the version of newly added tables. It is therefore the responsibility of the caller to ensure that the correct version is specified.

Parameters:
databaseDirectory - a java.io.File object pointing to the directory containing the database
version - the version of xBase to use for new tables

Database

public Database(File databaseDirectory,
                Version version,
                String charsetName)
Creates a new Database object. A file representing the database directory must be provided. If the directory does not exist, it is created. If the file represents a regular file and not a directory, throws an IllegalArgumentException.

All tables that exist in the database directory are added as Table objects and can be retrieved with getTable(String).

The parameter version does not trigger any validation on an existing database but is merely used to specify the version of newly added tables. It is therefore the responsibility of the caller to ensure that the correct version is specified.

Parameters:
databaseDirectory - a java.io.File object pointing to the directory containing the database
version - the version of xBase to use for new tables
charsetName - the name of the character set to use, if null will be set to the platform's default charset.
Method Detail

getTableNames

public Set<String> getTableNames()
Returns an unmodifiable Set of table names.

Returns:
a Set of Table names.

getTable

public Table getTable(String name)
Returns the Table object with the specified name or null if it has not been added yet.

Parameters:
name - the name of the table, including extension
Returns:
a Table object

addTable

public Table addTable(String name,
                      List<Field> fields)
               throws InvalidFieldTypeException,
                      InvalidFieldLengthException
Adds a new Table object to the set of Tables maintained by this Database object and returns it. If a Table object with name already exists, it is returned.

Note that the actual table file (the .DBF file) may or may not exists. To create a new table on disk, see Table.open(IfNonExistent).

Parameters:
name - the name of the table
Returns:
a Table object
Throws:
InvalidFieldTypeException
InvalidFieldLengthException

removeTable

public void removeTable(String name)
Removes a Table object from the list of Table objects maintained by this Database object.

Note that the actual table file (the .DBF file) is not deleted by removing the table object. To delete a file on disk, see Table.delete().

Parameters:
name - the name of the table to remove

removeTable

public void removeTable(Table table)
Removes a Table object from the list of Table objects maintained by this Database object.

Note that the actual table file (the .DBF file) is not deleted by removing the table object. To delete a file on disk, see Table.delete().

Parameters:
table - the table to remove

getCharsetName

public String getCharsetName()
Returns the name of the character set to use when reading from and writing to database files. This value can be overridden by the one specified through Table's constructor.

Returns:
the charset name


Copyright © 2009-2012 DANS. All Rights Reserved.