Package helma.objectmodel.dom

# Class XmlDatabase

java.lang.Object
helma.objectmodel.dom.XmlDatabase

All Implemented Interfaces:
  `IDatabase`

public final class XmlDatabase extends Object implements IDatabase
A simple XML-database

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Application`
`app`
`protected File`
`dbHomeDir`
`protected String`
`encoding`
`protected XmlIDGenerator`
`idgen`
`protected NodeManager`
`nmgr`

## Constructor Summary

Constructors
Constructor
Description
`XmlDatabase()`

## Method Summary

Modifier and Type
Method
Description
`void`
`abortTransaction(ITransaction txn)`
Abort the given transaction
`ITransaction`
`beginTransaction()`
Start a new transaction.
`void`
`commitTransaction(ITransaction txn)`
committ the given transaction, makint its changes persistent
`void`
`deleteNode(ITransaction txn, String kstr)`
Marks an element from the database as deleted
`String`
`getEncoding()`
get the file encoding used by this database
`XmlIDGenerator`
`getIDGenerator(ITransaction txn)`
Get the id-generator for this database.
`INode`
`getNode(ITransaction txn, String kstr)`
Retrieves a Node from the database.
`void`
`init(File dbHome, Application app)`
Initializes the database from an application.
`void`
`insertNode(ITransaction txn, String kstr, INode node)`
Save a node with the given key.
`String`
`nextID()`
Get the id for the next new object to be stored.
`void`
`saveIDGenerator(ITransaction txn)`
Write the id-generator to file.
`void`
`setEncoding(String encoding)`
set the file encoding to use
`void`
`shutdown()`
Shut down the database
`void`
`updateNode(ITransaction txn, String kstr, INode node)`
Update a node with the given key.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### dbHomeDir

protected File dbHomeDir

### app

protected Application app

### nmgr

protected NodeManager nmgr

### idgen

protected XmlIDGenerator idgen

### encoding

protected String encoding

## Constructor Details

### XmlDatabase

public XmlDatabase()

## Method Details

### init

public void init(File dbHome, Application app) throws DatabaseException
Initializes the database from an application.

Specified by:
  `init` in interface `IDatabase`
Parameters:
  `app` -
Throws:
  `DatabaseException`

### shutdown

public void shutdown()
Shut down the database

Specified by:
  `shutdown` in interface `IDatabase`

### beginTransaction

public ITransaction beginTransaction() throws DatabaseException
Start a new transaction.

Specified by:
  `beginTransaction` in interface `IDatabase`
Returns:
  the new tranaction object
Throws:
  `DatabaseException`

### commitTransaction

public void commitTransaction(ITransaction txn) throws DatabaseException
committ the given transaction, makint its changes persistent

Specified by:
  `commitTransaction` in interface `IDatabase`
Parameters:
  `txn` -
Throws:
  `DatabaseException`

### abortTransaction

public void abortTransaction(ITransaction txn) throws DatabaseException
Abort the given transaction

Specified by:
  `abortTransaction` in interface `IDatabase`
Parameters:
  `txn` -
Throws:
  `DatabaseException`

### nextID

public String nextID() throws ObjectNotFoundException
Get the id for the next new object to be stored.

Specified by:
  `nextID` in interface `IDatabase`
Returns:
  the id for the next new object to be stored
Throws:
  `ObjectNotFoundException`

### getIDGenerator

public XmlIDGenerator getIDGenerator(ITransaction txn) throws ObjectNotFoundException
Get the id-generator for this database.

Parameters:
  `txn` -
Returns:
  the id-generator for this database
Throws:
  `ObjectNotFoundException`

### saveIDGenerator

public void saveIDGenerator(ITransaction txn) throws IOException
Write the id-generator to file.

Parameters:
  `txn` -
Throws:
  `IOException`

### getNode

public INode getNode(ITransaction txn, String kstr) throws IOException, ObjectNotFoundException
Retrieves a Node from the database.

Specified by:
  `getNode` in interface `IDatabase`
Parameters:
  `txn` - the current transaction
  `kstr` - the key
Returns:
  the object associated with the given key
Throws:
  `IOException` - if an I/O error occurred loading the object.
  `ObjectNotFoundException` - if no object is stored by this key.

### insertNode

public void insertNode(ITransaction txn, String kstr, INode node) throws IOException
Save a node with the given key. Writes the node to a temporary file which is copied to its final name when the transaction is committed.

Specified by:
  `insertNode` in interface `IDatabase`
Parameters:
  `txn` -
  `kstr` -
  `node` -
Throws:
  `IOException`

### updateNode

public void updateNode(ITransaction txn, String kstr, INode node) throws IOException
Update a node with the given key. Writes the node to a temporary file which is copied to its final name when the transaction is committed.

Specified by:
  `updateNode` in interface `IDatabase`
Parameters:
  `txn` -
  `kstr` -
  `node` -
Throws:
  `IOException`

### deleteNode

public void deleteNode(ITransaction txn, String kstr) throws IOException
Marks an element from the database as deleted

Specified by:
  `deleteNode` in interface `IDatabase`
Parameters:
  `txn` -
  `kstr` -
Throws:
  `IOException`

### setEncoding

public void setEncoding(String encoding)
set the file encoding to use

Parameters:
  `encoding` - the database's file encoding

### getEncoding

public String getEncoding()
get the file encoding used by this database

Returns:
  the file encoding used by this database