Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

OmWritableDatabase Class Reference

This class provides writable access to a database. More...

#include <omdatabase.h>

Inheritance diagram for OmWritableDatabase:

Inheritance graph
[legend]
Collaboration diagram for OmWritableDatabase:

Collaboration graph
[legend]
List of all members.

Public Methods

 OmWritableDatabase (const OmSettings &params)
 Open a database for writing. More...

virtual ~OmWritableDatabase ()
 Destroy this handle on the database. More...

 OmWritableDatabase (const OmWritableDatabase &other)
 Copying is allowed. More...

void operator= (const OmWritableDatabase &other)
 Assignment is allowed. More...

void flush ()
 Flush to disk any modifications made to the database. More...

void begin_transaction ()
 Begin a transaction. More...

void commit_transaction ()
 End the transaction currently in progress, committing the modifications made to the database. More...

void cancel_transaction ()
 End the transaction currently in progress, cancelling the potential modifications made to the database. More...

om_docid add_document (const OmDocument &document)
 Add a new document to the database. More...

void delete_document (om_docid did)
 Delete a document in the database. More...

void replace_document (om_docid did, const OmDocument &document)
 Replace a given document in the database. More...

std::string get_description () const
 Introspection method. More...


Detailed Description

This class provides writable access to a database.

NOTE: this class is still under heavy development, and the interface is liable to change in the near future.


Constructor & Destructor Documentation

OmWritableDatabase::OmWritableDatabase const OmSettings   params
 

Open a database for writing.

Parameters:
params  an OmSettings object specifying the parameters to be used to open the database.
Exceptions:
OmInvalidArgumentError  will be thrown if an invalid argument is supplied, for example, an unknown database type.
OmOpeningError  may be thrown if the database cannot be opened.

virtual OmWritableDatabase::~OmWritableDatabase   [virtual]
 

Destroy this handle on the database.

If there are no copies of this object remaining, the database will be closed, and if there are any sessions or transactions in progress these will be ended.

OmWritableDatabase::OmWritableDatabase const OmWritableDatabase &    other
 

Copying is allowed.

The internals are reference counted, so copying is cheap.


Member Function Documentation

om_docid OmWritableDatabase::add_document const OmDocument   document
 

Add a new document to the database.

This method adds the specified document to the database, returning a newly allocated document ID.

Note that this does not mean the document will immediately appear in the database; see flush() for more details.

As with all database modification operations, the effect is atomic: the document will either be fully added, or the document fails to be added and an exception is thrown (possibly at a later time when the session is ended or flushed).

If a session is not in progress when this method is called, a session will be started.

Parameters:
document  The new document to be added.
Returns:
The document ID of the newly added document.
Exceptions:
OmDatabaseError  will be thrown if a problem occurs while writing to the database.
OmDatabaseCorruptError  will be thrown if the database is in a corrupt state.
OmDatabaseLockError  will be thrown if a lock couldn't be acquired or subsequently released on the database.

void OmWritableDatabase::begin_transaction  
 

Begin a transaction.

For the purposes of Xapian, a transaction is a group of modifications to the database which are grouped together such that either all or none of them will succeed. Even in the case of a power failure, this characteristic should be preserved (as long as the filesystem isn't corrupted, etc).

Transactions are only available with certain access methods, and as you might expect will generally have a fairly high performance cost.

A transaction may only be begun within a session, see begin_session().

Exceptions:
OmUnimplementedError  will be thrown if transactions are not available for this database type.
OmInvalidOperationError  will be thrown if this is called at an invalid time, such as when a transaction is already in progress.

void OmWritableDatabase::cancel_transaction  
 

End the transaction currently in progress, cancelling the potential modifications made to the database.

If an error occurs in this method, an exception will be thrown, but the transaction will be cancelled anyway.

Exceptions:
OmDatabaseError  will be thrown if a problem occurs while modifying the database.
OmDatabaseCorruptError  will be thrown if the database is in a corrupt state.
OmInvalidOperationError  will be thrown if a transaction is not currently in progress.
OmUnimplementedError  will be thrown if transactions are not available for this database type.

void OmWritableDatabase::commit_transaction  
 

End the transaction currently in progress, committing the modifications made to the database.

If this completes successfully, all the database modifications made during the transaction will have been committed to the database.

If an error occurs, an exception will be thrown, and none of the modifications made to the database during the transaction will have been applied to the database.

Whatever occurs, after this method the transaction will no longer be in progress.

Exceptions:
OmDatabaseError  will be thrown if a problem occurs while modifying the database.
OmDatabaseCorruptError  will be thrown if the database is in a corrupt state.
OmInvalidOperationError  will be thrown if a transaction is not currently in progress.
OmUnimplementedError  will be thrown if transactions are not available for this database type.

void OmWritableDatabase::delete_document om_docid    did
 

Delete a document in the database.

void OmWritableDatabase::flush  
 

Flush to disk any modifications made to the database.

For efficiency reasons, when performing multiple updates to a database it is best (indeed, almost essential) to make as many modifications as memory will permit in a single pass through the database. To ensure this, Xapian performs modifications in "sessions". Sessions are begun and ended implicitly, when the database is first modified, or closed.

Flush may be called at any time during a modification session to ensure that the modifications which have been made are written to disk: if the flush succeeds, all the preceding modifications will have been written to disk.

If any of the modifications fail, an exception will be thrown and the database will be left in a state in which each separate addition, replacement or deletion operation has either been fully performed or not performed at all: it is then up to the application to work out which operations need to be repeated.

If called within a transaction, this will flush database modifications made before the transaction was begun, but will not flush modifications made since begin_transaction() was called.

Beware of calling flush too frequently: this will have a severe performance cost.

Note that flush need not be called explicitly: it will be called automatically when the database is closed, or when a sufficient number of modifications have been made.

Exceptions:
OmDatabaseError  will be thrown if a problem occurs while modifying the database.
OmDatabaseCorruptError  will be thrown if the database is in a corrupt state.
OmDatabaseLockError  will be thrown if a lock couldn't be acquired on the database.

std::string OmWritableDatabase::get_description   const [virtual]
 

Introspection method.

Returns:
A string describing this object.

Reimplemented from OmDatabase.

void OmWritableDatabase::operator= const OmWritableDatabase &    other
 

Assignment is allowed.

The internals are reference counted, so assignment is cheap.

Note that only an OmWritableDatabase may be assigned to an OmWritableDatabase: an attempt to assign an OmDatabase will throw an exception.

void OmWritableDatabase::replace_document om_docid    did,
const OmDocument   document
 

Replace a given document in the database.


The documentation for this class was generated from the following file:
Documentation for Xapian (version 0.5.2).
Generated on 12 Oct 2002 by Doxygen 1.2.15.