kyotocabinet::FileDB Class Reference

Basic implementation for file database. More...

#include <kcdb.h>

List of all members.

Classes

class  Cursor
 Interface of cursor to indicate a record. More...
class  Error
 Error data. More...
class  FileProcessor
 Interface to process the database file. More...

Public Types

enum  OpenMode {
  OREADER = 1 << 0, OWRITER = 1 << 1, OCREATE = 1 << 2, OTRUNCATE = 1 << 3,
  OAUTOTRAN = 1 << 4, OAUTOSYNC = 1 << 5, ONOLOCK = 1 << 6, OTRYLOCK = 1 << 7,
  ONOREPAIR = 1 << 8
}
 

Open modes.

More...

Public Member Functions

virtual ~FileDB ()
 Destructor.
virtual Error error () const =0
 Get the last happened error.
virtual void set_error (Error::Code code, const char *message)=0
 Set the error information.
virtual bool open (const std::string &path, uint32_t mode=OWRITER|OCREATE)=0
 Open a database file.
virtual bool close ()=0
 Close the database file.
virtual bool synchronize (bool hard=false, FileProcessor *proc=NULL)=0
 Synchronize updated contents with the file and the device.
virtual bool copy (const std::string &dest)
 Create a copy of the database file.
virtual bool begin_transaction (bool hard=false)=0
 Begin transaction.
virtual bool begin_transaction_try (bool hard=false)=0
 Try to begin transaction.
virtual bool end_transaction (bool commit=true)=0
 End transaction.
virtual int64_t size ()=0
 Get the size of the database file.
virtual std::string path ()=0
 Get the path of the database file.
virtual bool status (std::map< std::string, std::string > *strmap)=0
 Get the miscellaneous status information.
virtual bool set (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
 Set the value of a record.
virtual bool set (const std::string &key, const std::string &value)
 Set the value of a record.
virtual bool add (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
 Add a record.
virtual bool add (const std::string &key, const std::string &value)
 Set the value of a record.
virtual bool append (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
 Append the value of a record.
virtual bool append (const std::string &key, const std::string &value)
 Set the value of a record.
virtual int64_t increment (const char *kbuf, size_t ksiz, int64_t num)
 Add a number to the numeric value of a record.
virtual int64_t increment (const std::string &key, int64_t num)
 Add a number to the numeric value of a record.
virtual double increment (const char *kbuf, size_t ksiz, double num)
 Add a number to the numeric value of a record.
virtual double increment (const std::string &key, double num)
 Add a number to the numeric value of a record.
virtual bool cas (const char *kbuf, size_t ksiz, const char *ovbuf, size_t ovsiz, const char *nvbuf, size_t nvsiz)
 Perform compare-and-swap.
virtual bool cas (const std::string &key, const std::string &ovalue, const std::string &nvalue)
 Perform compare-and-swap.
virtual bool remove (const char *kbuf, size_t ksiz)
 Remove a record.
virtual bool remove (const std::string &key)
 Remove a record.
virtual char * get (const char *kbuf, size_t ksiz, size_t *sp)
 Retrieve the value of a record.
virtual std::string * get (const std::string &key)
 Retrieve the value of a record.
virtual int32_t get (const char *kbuf, size_t ksiz, char *vbuf, size_t max)
 Retrieve the value of a record.
virtual bool dump_snapshot (std::ostream *dest)
 Dump records into a data stream.
virtual bool dump_snapshot (const std::string &dest)
 Dump records into a file.
virtual bool load_snapshot (std::istream *src)
 Load records from a data stream.
virtual bool load_snapshot (const std::string &src)
 Load records from a file.
virtual Cursorcursor ()=0
 Create a cursor object.

Detailed Description

Basic implementation for file database.

Note:
Before every database operation, it is necessary to call the FileDB::open method in order to open a database file and connect the database object to it. To avoid data missing or corruption, it is important to close every database file by the FileDB::close method when the database is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.

Member Enumeration Documentation

Open modes.

Enumerator:
OREADER 

open as a reader

OWRITER 

open as a writer

OCREATE 

writer creating

OTRUNCATE 

writer truncating

OAUTOTRAN 

auto transaction

OAUTOSYNC 

auto synchronization

ONOLOCK 

open without locking

OTRYLOCK 

lock without blocking

ONOREPAIR 

open without auto repair


Constructor & Destructor Documentation

virtual kyotocabinet::FileDB::~FileDB (  )  [virtual]

Destructor.

Note:
If the database is not closed, it is closed implicitly.

Member Function Documentation

virtual Error kyotocabinet::FileDB::error (  )  const [pure virtual]

Get the last happened error.

Returns:
the last happened error.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual void kyotocabinet::FileDB::set_error ( Error::Code  code,
const char *  message 
) [pure virtual]

Set the error information.

Parameters:
code an error code.
message a supplement message.
virtual bool kyotocabinet::FileDB::open ( const std::string &  path,
uint32_t  mode = OWRITER|OCREATE 
) [pure virtual]

Open a database file.

Parameters:
path the path of a database file.
mode the connection mode. FileDB::OWRITER as a writer, FileDB::OREADER as a reader. The following may be added to the writer mode by bitwise-or: FileDB::OCREATE, which means it creates a new database if the file does not exist, FileDB::OTRUNCATE, which means it creates a new database regardless if the file exists, FileDB::OAUTOTRAN, which means each updating operation is performed in implicit transaction, FileDB::OAUTOSYNC, which means each updating operation is followed by implicit synchronization with the file system. The following may be added to both of the reader mode and the writer mode by bitwise-or: FileDB::ONOLOCK, which means it opens the database file without file locking, FileDB::OTRYLOCK, which means locking is performed without blocking, File::ONOREPAIR, which means the database file is not repaired implicitly even if file destruction is detected.
Returns:
true on success, or false on failure.
Note:
Every opened database must be closed by the FileDB::close method when it is no longer in use.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::close (  )  [pure virtual]

Close the database file.

Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::synchronize ( bool  hard = false,
FileProcessor proc = NULL 
) [pure virtual]

Synchronize updated contents with the file and the device.

Parameters:
hard true for physical synchronization with the device, or false for logical synchronization with the file system.
proc a postprocessor object. If it is NULL, no postprocessing is performed.
Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::copy ( const std::string &  dest  )  [virtual]

Create a copy of the database file.

Parameters:
dest the path of the destination file.
Returns:
true on success, or false on failure.
virtual bool kyotocabinet::FileDB::begin_transaction ( bool  hard = false  )  [pure virtual]

Begin transaction.

Parameters:
hard true for physical synchronization with the device, or false for logical synchronization with the file system.
Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::begin_transaction_try ( bool  hard = false  )  [pure virtual]

Try to begin transaction.

Parameters:
hard true for physical synchronization with the device, or false for logical synchronization with the file system.
Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::end_transaction ( bool  commit = true  )  [pure virtual]

End transaction.

Parameters:
commit true to commit the transaction, or false to abort the transaction.
Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual int64_t kyotocabinet::FileDB::size (  )  [pure virtual]

Get the size of the database file.

Returns:
the size of the database file in bytes, or -1 on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual std::string kyotocabinet::FileDB::path (  )  [pure virtual]

Get the path of the database file.

Returns:
the path of the database file in bytes, or an empty string on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::status ( std::map< std::string, std::string > *  strmap  )  [pure virtual]

Get the miscellaneous status information.

Parameters:
strmap a string map to contain the result.
Returns:
true on success, or false on failure.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.

virtual bool kyotocabinet::FileDB::set ( const char *  kbuf,
size_t  ksiz,
const char *  vbuf,
size_t  vsiz 
) [virtual]

Set the value of a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
vbuf the pointer to the value region.
vsiz the size of the value region.
Returns:
true on success, or false on failure.
Note:
If no record corresponds to the key, a new record is created. If the corresponding record exists, the value is overwritten.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::set ( const std::string &  key,
const std::string &  value 
) [virtual]

Set the value of a record.

Note:
Equal to the original DB::set method except that the parameters are std::string.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::add ( const char *  kbuf,
size_t  ksiz,
const char *  vbuf,
size_t  vsiz 
) [virtual]

Add a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
vbuf the pointer to the value region.
vsiz the size of the value region.
Returns:
true on success, or false on failure.
Note:
If no record corresponds to the key, a new record is created. If the corresponding record exists, the record is not modified and false is returned.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::add ( const std::string &  key,
const std::string &  value 
) [virtual]

Set the value of a record.

Note:
Equal to the original DB::add method except that the parameters are std::string.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::append ( const char *  kbuf,
size_t  ksiz,
const char *  vbuf,
size_t  vsiz 
) [virtual]

Append the value of a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
vbuf the pointer to the value region.
vsiz the size of the value region.
Returns:
true on success, or false on failure.
Note:
If no record corresponds to the key, a new record is created. If the corresponding record exists, the given value is appended at the end of the existing value.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::append ( const std::string &  key,
const std::string &  value 
) [virtual]

Set the value of a record.

Note:
Equal to the original DB::append method except that the parameters are std::string.

Implements kyotocabinet::DB.

virtual int64_t kyotocabinet::FileDB::increment ( const char *  kbuf,
size_t  ksiz,
int64_t  num 
) [virtual]

Add a number to the numeric value of a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
num the additional number.
Returns:
the result value, or INT64_MIN on failure.

Implements kyotocabinet::DB.

virtual int64_t kyotocabinet::FileDB::increment ( const std::string &  key,
int64_t  num 
) [virtual]

Add a number to the numeric value of a record.

Note:
Equal to the original DB::increment method except that the parameter is std::string.

Implements kyotocabinet::DB.

virtual double kyotocabinet::FileDB::increment ( const char *  kbuf,
size_t  ksiz,
double  num 
) [virtual]

Add a number to the numeric value of a record.

Note:
Equal to the original DB::increment method except that the parameter and the return value are double.

Implements kyotocabinet::DB.

virtual double kyotocabinet::FileDB::increment ( const std::string &  key,
double  num 
) [virtual]

Add a number to the numeric value of a record.

Note:
Equal to the original DB::increment method except that the parameter is std::string and the return value is double.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::cas ( const char *  kbuf,
size_t  ksiz,
const char *  ovbuf,
size_t  ovsiz,
const char *  nvbuf,
size_t  nvsiz 
) [virtual]

Perform compare-and-swap.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
ovbuf the pointer to the old value region. NULL means that no record corresponds.
ovsiz the size of the old value region.
nvbuf the pointer to the new value region. NULL means that the record is removed.
nvsiz the size of new old value region.
Returns:
true on success, or false on failure.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::cas ( const std::string &  key,
const std::string &  ovalue,
const std::string &  nvalue 
) [virtual]

Perform compare-and-swap.

Note:
Equal to the original DB::cas method except that the parameters are std::string.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::remove ( const char *  kbuf,
size_t  ksiz 
) [virtual]

Remove a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
Returns:
true on success, or false on failure.
Note:
If no record corresponds to the key, false is returned.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::remove ( const std::string &  key  )  [virtual]

Remove a record.

Note:
Equal to the original DB::remove method except that the parameter is std::string.

Implements kyotocabinet::DB.

virtual char* kyotocabinet::FileDB::get ( const char *  kbuf,
size_t  ksiz,
size_t *  sp 
) [virtual]

Retrieve the value of a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
sp the pointer to the variable into which the size of the region of the return value is assigned.
Returns:
the pointer to the value region of the corresponding record, or NULL on failure.
Note:
If no record corresponds to the key, NULL is returned. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a C-style string. Because the region of the return value is allocated with the the new[] operator, it should be released with the delete[] operator when it is no longer in use.

Implements kyotocabinet::DB.

virtual std::string* kyotocabinet::FileDB::get ( const std::string &  key  )  [virtual]

Retrieve the value of a record.

Note:
Equal to the original DB::get method except that the parameter and the return value are std::string. The return value should be deleted explicitly by the caller.

Implements kyotocabinet::DB.

virtual int32_t kyotocabinet::FileDB::get ( const char *  kbuf,
size_t  ksiz,
char *  vbuf,
size_t  max 
) [virtual]

Retrieve the value of a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
vbuf the pointer to the buffer into which the value of the corresponding record is written.
max the size of the buffer.
Returns:
the size of the value, or -1 on failure.

Implements kyotocabinet::DB.

virtual bool kyotocabinet::FileDB::dump_snapshot ( std::ostream *  dest  )  [virtual]

Dump records into a data stream.

Parameters:
dest the destination stream.
Returns:
true on success, or false on failure.
virtual bool kyotocabinet::FileDB::dump_snapshot ( const std::string &  dest  )  [virtual]

Dump records into a file.

Parameters:
dest the path of the destination file.
Returns:
true on success, or false on failure.
virtual bool kyotocabinet::FileDB::load_snapshot ( std::istream *  src  )  [virtual]

Load records from a data stream.

Parameters:
src the source stream.
Returns:
true on success, or false on failure.
virtual bool kyotocabinet::FileDB::load_snapshot ( const std::string &  src  )  [virtual]

Load records from a file.

Parameters:
src the path of the source file.
Returns:
true on success, or false on failure.
virtual Cursor* kyotocabinet::FileDB::cursor (  )  [pure virtual]

Create a cursor object.

Returns:
the return value is the created cursor object.
Note:
Because the object of the return value is allocated by the constructor, it should be released with the delete operator when it is no longer in use.

Implements kyotocabinet::DB.

Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.


Generated on Tue Apr 27 21:44:18 2010 for Kyoto Cabinet by  doxygen 1.6.1