kyotocabinet::PlantDB< BASEDB, DBTYPE > Class Template Reference

Plant database. More...

#include <kcplantdb.h>

List of all members.

Classes

class  Cursor
 Cursor to indicate a record. More...
struct  InnerNode
 Inner node of B+ tree.
struct  InnerSlot
 Slot cache of inner nodes.
struct  LeafNode
 Leaf node of B+ tree.
struct  LeafSlot
 Slot cache of leaf nodes.
struct  Link
 Link to a node.
struct  LinkComparator
 Comparator for links.
struct  Record
 Record data.
struct  RecordComparator
 Comparator for records.

Public Types

enum  Option { TSMALL = BASEDB::TSMALL, TLINEAR = BASEDB::TLINEAR, TCOMPRESS = BASEDB::TCOMPRESS }
 

Tuning options.

More...
enum  Flag { FOPEN = BASEDB::FOPEN, FFATAL = BASEDB::FFATAL }
 

Status flags.

More...

Public Member Functions

 PlantDB ()
 Default constructor.
virtual ~PlantDB ()
 Destructor.
bool accept (const char *kbuf, size_t ksiz, Visitor *visitor, bool writable=true)
 Accept a visitor to a record.
bool iterate (Visitor *visitor, bool writable=true, ProgressChecker *checker=NULL)
 Iterate to accept a visitor for each record.
Error error () const
 Get the last happened error.
void set_error (const char *file, int32_t line, const char *func, Error::Code code, const char *message)
 Set the error information.
bool open (const std::string &path, uint32_t mode=OWRITER|OCREATE)
 Open a database file.
bool close ()
 Close the database file.
bool synchronize (bool hard=false, FileProcessor *proc=NULL, ProgressChecker *checker=NULL)
 Synchronize updated contents with the file and the device.
bool begin_transaction (bool hard=false)
 Begin transaction.
bool begin_transaction_try (bool hard=false)
 Try to begin transaction.
bool end_transaction (bool commit=true)
 End transaction.
bool clear ()
 Remove all records.
int64_t count ()
 Get the number of records.
int64_t size ()
 Get the size of the database file.
std::string path ()
 Get the path of the database file.
bool status (std::map< std::string, std::string > *strmap)
 Get the miscellaneous status information.
Cursorcursor ()
 Create a cursor object.
bool tune_logger (Logger *logger, uint32_t kinds=Logger::WARN|Logger::ERROR)
 Set the internal logger.
bool tune_meta_trigger (MetaTrigger *trigger)
 Set the internal meta operation trigger.
bool tune_alignment (int8_t apow)
 Set the power of the alignment of record size.
bool tune_fbp (int8_t fpow)
 Set the power of the capacity of the free block pool.
bool tune_options (int8_t opts)
 Set the optional features.
bool tune_buckets (int64_t bnum)
 Set the number of buckets of the hash table.
bool tune_page (int32_t psiz)
 Set the size of each page.
bool tune_map (int64_t msiz)
 Set the size of the internal memory-mapped region.
bool tune_defrag (int64_t dfunit)
 Set the unit step number of auto defragmentation.
bool tune_page_cache (int64_t pccap)
 Set the capacity size of the page cache.
bool tune_compressor (Compressor *comp)
 Set the data compressor.
bool tune_comparator (Comparator *rcomp)
 Set the record comparator.
char * opaque ()
 Get the opaque data.
bool synchronize_opaque ()
 Synchronize the opaque data.
bool defrag (int64_t step=0)
 Perform defragmentation of the file.
uint8_t flags ()
 Get the status flags.
Comparatorrcomp ()
 Get the record comparator.

Protected Member Functions

void report (const char *file, int32_t line, const char *func, Logger::Kind kind, const char *format,...)
 Report a message for debugging.
void report_valist (const char *file, int32_t line, const char *func, Logger::Kind kind, const char *format, va_list ap)
 Report a message for debugging with variable number of arguments.
void report_binary (const char *file, int32_t line, const char *func, Logger::Kind kind, const char *name, const char *buf, size_t size)
 Report the content of a binary buffer for debugging.
void trigger_meta (MetaTrigger::Kind kind, const char *message)
 Trigger a meta database operation.

Detailed Description

template<class BASEDB, uint8_t DBTYPE>
class kyotocabinet::PlantDB< BASEDB, DBTYPE >

Plant database.

Parameters:
BASEDB a class compatible with the file hash database class.
DBTYPE the database type number of the class.
Note:
This class template is a template for concrete classes to operate tree databases. Template instance classes can be inherited but overwriting methods is forbidden. The class TreeDB is the instance of the file tree database. The class ForestDB is the instance of the directory tree database. Before every database operation, it is necessary to call the BasicDB::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 BasicDB::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. It is forbidden to share a database object with child processes.

Member Enumeration Documentation

template<class BASEDB , uint8_t DBTYPE>
enum kyotocabinet::PlantDB::Option

Tuning options.

Enumerator:
TSMALL 

use 32-bit addressing

TLINEAR 

use linear collision chaining

TCOMPRESS 

compress each record

template<class BASEDB , uint8_t DBTYPE>
enum kyotocabinet::PlantDB::Flag

Status flags.

Enumerator:
FOPEN 

whether opened

FFATAL 

whether with fatal error


Constructor & Destructor Documentation

template<class BASEDB , uint8_t DBTYPE>
kyotocabinet::PlantDB< BASEDB, DBTYPE >::PlantDB (  )  [explicit]

Default constructor.

template<class BASEDB , uint8_t DBTYPE>
virtual kyotocabinet::PlantDB< BASEDB, DBTYPE >::~PlantDB (  )  [virtual]

Destructor.

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

Member Function Documentation

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::accept ( const char *  kbuf,
size_t  ksiz,
Visitor visitor,
bool  writable = true 
) [virtual]

Accept a visitor to a record.

Parameters:
kbuf the pointer to the key region.
ksiz the size of the key region.
visitor a visitor object.
writable true for writable operation, or false for read-only operation.
Returns:
true on success, or false on failure.
Note:
The operation for each record is performed atomically and other threads accessing the same record are blocked. To avoid deadlock, any database operation must not be performed in this function.

Implements kyotocabinet::DB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::iterate ( Visitor visitor,
bool  writable = true,
ProgressChecker checker = NULL 
) [virtual]

Iterate to accept a visitor for each record.

Parameters:
visitor a visitor object.
writable true for writable operation, or false for read-only operation.
checker a progress checker object. If it is NULL, no checking is performed.
Returns:
true on success, or false on failure.
Note:
The whole iteration is performed atomically and other threads are blocked. To avoid deadlock, any database operation must not be performed in this function.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
Error kyotocabinet::PlantDB< BASEDB, DBTYPE >::error (  )  const [virtual]

Get the last happened error.

Returns:
the last happened error.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
void kyotocabinet::PlantDB< BASEDB, DBTYPE >::set_error ( const char *  file,
int32_t  line,
const char *  func,
Error::Code  code,
const char *  message 
)

Set the error information.

Parameters:
file the file name of the program source code.
line the line number of the program source code.
func the function name of the program source code.
code an error code.
message a supplement message.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::open ( const std::string &  path,
uint32_t  mode = OWRITER | OCREATE 
) [virtual]

Open a database file.

Parameters:
path the path of a database file.
mode the connection mode. BasicDB::OWRITER as a writer, BasicDB::OREADER as a reader. The following may be added to the writer mode by bitwise-or: BasicDB::OCREATE, which means it creates a new database if the file does not exist, BasicDB::OTRUNCATE, which means it creates a new database regardless if the file exists, BasicDB::OAUTOTRAN, which means each updating operation is performed in implicit transaction, BasicDB::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: BasicDB::ONOLOCK, which means it opens the database file without file locking, BasicDB::OTRYLOCK, which means locking is performed without blocking, BasicDB::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 BasicDB::close method when it is no longer in use. It is not allowed for two or more database objects in the same process to keep their connections to the same database file at the same time.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::close (  )  [virtual]

Close the database file.

Returns:
true on success, or false on failure.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::synchronize ( bool  hard = false,
FileProcessor proc = NULL,
ProgressChecker checker = NULL 
) [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.
checker a progress checker object. If it is NULL, no checking is performed.
Returns:
true on success, or false on failure.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::begin_transaction ( bool  hard = false  )  [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.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::begin_transaction_try ( bool  hard = false  )  [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.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::end_transaction ( bool  commit = true  )  [virtual]

End transaction.

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

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::clear (  )  [virtual]

Remove all records.

Returns:
true on success, or false on failure.

Implements kyotocabinet::DB.

template<class BASEDB , uint8_t DBTYPE>
int64_t kyotocabinet::PlantDB< BASEDB, DBTYPE >::count (  )  [virtual]

Get the number of records.

Returns:
the number of records, or -1 on failure.

Implements kyotocabinet::DB.

template<class BASEDB , uint8_t DBTYPE>
int64_t kyotocabinet::PlantDB< BASEDB, DBTYPE >::size (  )  [virtual]

Get the size of the database file.

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

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
std::string kyotocabinet::PlantDB< BASEDB, DBTYPE >::path (  )  [virtual]

Get the path of the database file.

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

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::status ( std::map< std::string, std::string > *  strmap  )  [virtual]

Get the miscellaneous status information.

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

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
Cursor* kyotocabinet::PlantDB< BASEDB, DBTYPE >::cursor (  )  [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::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_logger ( Logger logger,
uint32_t  kinds = Logger::WARN | Logger::ERROR 
) [virtual]

Set the internal logger.

Parameters:
logger the logger object.
kinds kinds of logged messages by bitwise-or: Logger::DEBUG for debugging, Logger::INFO for normal information, Logger::WARN for warning, and Logger::ERROR for fatal error.
Returns:
true on success, or false on failure.

Implements kyotocabinet::BasicDB.

template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_meta_trigger ( MetaTrigger *  trigger  ) 

Set the internal meta operation trigger.

Parameters:
trigger the trigger object.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_alignment ( int8_t  apow  ) 

Set the power of the alignment of record size.

Parameters:
apow the power of the alignment of record size.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_fbp ( int8_t  fpow  ) 

Set the power of the capacity of the free block pool.

Parameters:
fpow the power of the capacity of the free block pool.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_options ( int8_t  opts  ) 

Set the optional features.

Parameters:
opts the optional features by bitwise-or: BasicDB::TSMALL to use 32-bit addressing, BasicDB::TLINEAR to use linear collision chaining, BasicDB::TCOMPRESS to compress each record.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_buckets ( int64_t  bnum  ) 

Set the number of buckets of the hash table.

Parameters:
bnum the number of buckets of the hash table.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_page ( int32_t  psiz  ) 

Set the size of each page.

Parameters:
psiz the size of each page.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_map ( int64_t  msiz  ) 

Set the size of the internal memory-mapped region.

Parameters:
msiz the size of the internal memory-mapped region.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_defrag ( int64_t  dfunit  ) 

Set the unit step number of auto defragmentation.

Parameters:
dfunit the unit step number of auto defragmentation.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_page_cache ( int64_t  pccap  ) 

Set the capacity size of the page cache.

Parameters:
pccap the capacity size of the page cache.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_compressor ( Compressor comp  ) 

Set the data compressor.

Parameters:
comp the data compressor object.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::tune_comparator ( Comparator rcomp  ) 

Set the record comparator.

Parameters:
rcomp the record comparator object.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
char* kyotocabinet::PlantDB< BASEDB, DBTYPE >::opaque (  ) 

Get the opaque data.

Returns:
the pointer to the opaque data region, whose size is 16 bytes.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::synchronize_opaque (  ) 

Synchronize the opaque data.

Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
bool kyotocabinet::PlantDB< BASEDB, DBTYPE >::defrag ( int64_t  step = 0  ) 

Perform defragmentation of the file.

Parameters:
step the number of steps. If it is not more than 0, the whole region is defraged.
Returns:
true on success, or false on failure.
template<class BASEDB , uint8_t DBTYPE>
uint8_t kyotocabinet::PlantDB< BASEDB, DBTYPE >::flags (  ) 

Get the status flags.

Returns:
the status flags, or 0 on failure.
template<class BASEDB , uint8_t DBTYPE>
Comparator* kyotocabinet::PlantDB< BASEDB, DBTYPE >::rcomp (  ) 

Get the record comparator.

Returns:
the record comparator object.
template<class BASEDB , uint8_t DBTYPE>
void kyotocabinet::PlantDB< BASEDB, DBTYPE >::report ( const char *  file,
int32_t  line,
const char *  func,
Logger::Kind  kind,
const char *  format,
  ... 
) [protected]

Report a message for debugging.

Parameters:
file the file name of the program source code.
line the line number of the program source code.
func the function name of the program source code.
kind the kind of the event. Logger::DEBUG for debugging, Logger::INFO for normal information, Logger::WARN for warning, and Logger::ERROR for fatal error.
format the printf-like format string.
... used according to the format string.
template<class BASEDB , uint8_t DBTYPE>
void kyotocabinet::PlantDB< BASEDB, DBTYPE >::report_valist ( const char *  file,
int32_t  line,
const char *  func,
Logger::Kind  kind,
const char *  format,
va_list  ap 
) [protected]

Report a message for debugging with variable number of arguments.

Parameters:
file the file name of the program source code.
line the line number of the program source code.
func the function name of the program source code.
kind the kind of the event. Logger::DEBUG for debugging, Logger::INFO for normal information, Logger::WARN for warning, and Logger::ERROR for fatal error.
format the printf-like format string.
ap used according to the format string.
template<class BASEDB , uint8_t DBTYPE>
void kyotocabinet::PlantDB< BASEDB, DBTYPE >::report_binary ( const char *  file,
int32_t  line,
const char *  func,
Logger::Kind  kind,
const char *  name,
const char *  buf,
size_t  size 
) [protected]

Report the content of a binary buffer for debugging.

Parameters:
file the file name of the epicenter.
line the line number of the epicenter.
func the function name of the program source code.
kind the kind of the event. Logger::DEBUG for debugging, Logger::INFO for normal information, Logger::WARN for warning, and Logger::ERROR for fatal error.
name the name of the information.
buf the binary buffer.
size the size of the binary buffer
template<class BASEDB , uint8_t DBTYPE>
void kyotocabinet::PlantDB< BASEDB, DBTYPE >::trigger_meta ( MetaTrigger::Kind  kind,
const char *  message 
) [protected]

Trigger a meta database operation.

Parameters:
kind the kind of the event. MetaTrigger::OPEN for opening, MetaTrigger::CLOSE for closing, MetaTrigger::CLEAR for clearing, MetaTrigger::ITERATE for iteration, MetaTrigger::SYNCHRONIZE for synchronization, MetaTrigger::BEGINTRAN for beginning transaction, MetaTrigger::COMMITTRAN for committing transaction, MetaTrigger::ABORTTRAN for aborting transaction, and MetaTrigger::MISC for miscellaneous operations.
message the supplement message.
Generated on Sun Dec 19 12:53:11 2010 for Kyoto Cabinet by  doxygen 1.6.3