2005-03-30 07:38:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* $RCSfile: db.hxx,v $
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2006-06-19 23:39:17 +00:00
|
|
|
* $Revision: 1.6 $
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2006-06-19 23:39:17 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2006-06-20 00:39:17 $
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
2005-09-09 11:19:26 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2005-03-30 07:38:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef BERKELEYDBPROXY_DB_HXX_
|
|
|
|
#define BERKELEYDBPROXY_DB_HXX_
|
|
|
|
|
2005-04-11 08:32:00 +00:00
|
|
|
#ifdef SYSTEM_DB
|
|
|
|
#include <db.h>
|
|
|
|
#else
|
2005-03-30 07:38:07 +00:00
|
|
|
#include <berkeleydb/db.h>
|
2005-04-11 08:32:00 +00:00
|
|
|
#endif
|
2005-03-30 07:38:07 +00:00
|
|
|
|
|
|
|
#include <rtl/string.hxx>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
typedef void *(*db_malloc_fcn_type)(size_t);
|
|
|
|
typedef void *(*db_realloc_fcn_type)(void *, size_t);
|
|
|
|
typedef void (*db_free_fcn_type)(void *);
|
2006-06-19 23:39:17 +00:00
|
|
|
}
|
2005-03-30 07:38:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace berkeleydbproxy {
|
|
|
|
|
|
|
|
class DbEnv;
|
|
|
|
class Dbc;
|
|
|
|
class Dbt;
|
|
|
|
|
|
|
|
namespace db_internal
|
|
|
|
{
|
|
|
|
class Noncopyable
|
|
|
|
{
|
|
|
|
// not implemented
|
|
|
|
Noncopyable(const Noncopyable&);
|
|
|
|
void operator=(const Noncopyable&);
|
|
|
|
protected:
|
|
|
|
Noncopyable() {}
|
|
|
|
~Noncopyable() {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class DbException
|
|
|
|
{
|
|
|
|
rtl::OString what_;
|
|
|
|
public:
|
2006-06-19 23:39:17 +00:00
|
|
|
explicit DbException(rtl::OString const & whatparam)
|
|
|
|
: what_(whatparam)
|
2005-03-30 07:38:07 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
const char *what() const
|
|
|
|
{ return what_.getStr(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DbEnv : db_internal::Noncopyable
|
|
|
|
{
|
|
|
|
friend class Db;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DB_ENV* m_pDBENV;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit DbEnv(u_int32_t flags);
|
|
|
|
~DbEnv();
|
|
|
|
|
|
|
|
int open(const char *db_home, u_int32_t flags, int mode);
|
|
|
|
void close(u_int32_t flags);
|
|
|
|
|
|
|
|
int set_alloc(
|
|
|
|
db_malloc_fcn_type app_malloc,
|
|
|
|
db_realloc_fcn_type app_realloc,
|
|
|
|
db_free_fcn_type app_free);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Db : db_internal::Noncopyable
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
DB* m_pDBP;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Db(DbEnv* dbbenv,u_int32_t flags);
|
|
|
|
~Db();
|
|
|
|
|
|
|
|
int close(u_int32_t flags);
|
|
|
|
|
|
|
|
int open(DB_TXN *txnid,
|
|
|
|
const char *file,
|
|
|
|
const char *database,
|
|
|
|
DBTYPE type,
|
|
|
|
u_int32_t flags,
|
|
|
|
int mode);
|
|
|
|
|
|
|
|
|
|
|
|
int get(DB_TXN* txnid, Dbt *key, Dbt *data, u_int32_t flags);
|
|
|
|
int put(DB_TXN* txnid, Dbt *key, Dbt *data, u_int32_t flags);
|
|
|
|
|
|
|
|
int cursor(DB_TXN *txnid, Dbc **cursorp, u_int32_t flags);
|
|
|
|
|
|
|
|
int set_alloc(
|
|
|
|
db_malloc_fcn_type app_malloc,
|
|
|
|
db_realloc_fcn_type app_realloc,
|
|
|
|
db_free_fcn_type app_free);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Dbc : db_internal::Noncopyable
|
|
|
|
{
|
|
|
|
friend class Db;
|
|
|
|
friend class Dbt;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DBC* m_pDBC;
|
|
|
|
|
|
|
|
explicit Dbc(DBC* pDBC);
|
|
|
|
~Dbc();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int close();
|
|
|
|
|
|
|
|
int get(Dbt *key, Dbt *data, u_int32_t flags);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Dbt: private DBT
|
|
|
|
{
|
|
|
|
friend class Db;
|
|
|
|
friend class Dbc;
|
|
|
|
|
|
|
|
public:
|
2005-04-11 07:42:09 +00:00
|
|
|
Dbt(void *data_arg, u_int32_t size_arg);
|
2005-03-30 07:38:07 +00:00
|
|
|
|
|
|
|
Dbt();
|
|
|
|
Dbt(const Dbt & other);
|
|
|
|
Dbt & operator=(const Dbt & other);
|
|
|
|
|
|
|
|
~Dbt();
|
|
|
|
|
|
|
|
void *get_data() const;
|
|
|
|
void set_data(void *value);
|
|
|
|
|
|
|
|
u_int32_t get_size() const;
|
|
|
|
void set_size(u_int32_t value);
|
|
|
|
|
|
|
|
void set_flags(u_int32_t);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|