Basic implementation for file database. More...
#include <kcdb.h>
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 Cursor * | cursor ()=0 |
Create a cursor object. |
Basic implementation for file database.
virtual kyotocabinet::FileDB::~FileDB | ( | ) | [virtual] |
Destructor.
virtual Error kyotocabinet::FileDB::error | ( | ) | const [pure virtual] |
Get 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.
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.
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. |
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.
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.
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. |
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.
dest | the path of the destination file. |
virtual bool kyotocabinet::FileDB::begin_transaction | ( | bool | hard = false |
) | [pure virtual] |
Begin transaction.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. |
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.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. |
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.
commit | true to commit the transaction, or false to abort the transaction. |
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.
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.
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.
strmap | a string map to contain the result. |
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.
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. |
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::set | ( | const std::string & | key, | |
const std::string & | value | |||
) | [virtual] |
Set the value of a record.
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::add | ( | const char * | kbuf, | |
size_t | ksiz, | |||
const char * | vbuf, | |||
size_t | vsiz | |||
) | [virtual] |
Add a record.
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. |
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::add | ( | const std::string & | key, | |
const std::string & | value | |||
) | [virtual] |
Set the value of a record.
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.
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. |
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::append | ( | const std::string & | key, | |
const std::string & | value | |||
) | [virtual] |
Set the value of a record.
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.
kbuf | the pointer to the key region. | |
ksiz | the size of the key region. | |
num | the additional number. |
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.
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.
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.
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.
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. |
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.
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::remove | ( | const char * | kbuf, | |
size_t | ksiz | |||
) | [virtual] |
Remove a record.
kbuf | the pointer to the key region. | |
ksiz | the size of the key region. |
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::remove | ( | const std::string & | key | ) | [virtual] |
Remove a record.
Implements kyotocabinet::DB.
virtual char* kyotocabinet::FileDB::get | ( | const char * | kbuf, | |
size_t | ksiz, | |||
size_t * | sp | |||
) | [virtual] |
Retrieve the value of a record.
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. |
Implements kyotocabinet::DB.
virtual std::string* kyotocabinet::FileDB::get | ( | const std::string & | key | ) | [virtual] |
Retrieve the value of a record.
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.
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. |
Implements kyotocabinet::DB.
virtual bool kyotocabinet::FileDB::dump_snapshot | ( | std::ostream * | dest | ) | [virtual] |
Dump records into a data stream.
dest | the destination stream. |
virtual bool kyotocabinet::FileDB::dump_snapshot | ( | const std::string & | dest | ) | [virtual] |
Dump records into a file.
dest | the path of the destination file. |
virtual bool kyotocabinet::FileDB::load_snapshot | ( | std::istream * | src | ) | [virtual] |
Load records from a data stream.
src | the source stream. |
virtual bool kyotocabinet::FileDB::load_snapshot | ( | const std::string & | src | ) | [virtual] |
Load records from a file.
src | the path of the source file. |
virtual Cursor* kyotocabinet::FileDB::cursor | ( | ) | [pure virtual] |
Create a cursor object.
Implements kyotocabinet::DB.
Implemented in kyotocabinet::CacheDB, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::ProtoDB< STRMAP >, and kyotocabinet::TreeDB.