1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef BERKELEYDBPROXY_DB_HXX_
31 #define BERKELEYDBPROXY_DB_HXX_
36 #include <berkeleydb/db.h>
39 #include "com/sun/star/ucb/XSimpleFileAccess.hpp"
42 #include <rtl/string.hxx>
45 typedef void *(*db_malloc_fcn_type
)(size_t);
46 typedef void *(*db_realloc_fcn_type
)(void *, size_t);
47 typedef void (*db_free_fcn_type
)(void *);
51 namespace berkeleydbproxy
{
61 Noncopyable(const Noncopyable
&);
62 void operator=(const Noncopyable
&);
73 explicit DbException(rtl::OString
const & whatparam
)
77 const char *what() const
78 { return what_
.getStr(); }
83 bool operator()( const rtl::OString
& rKey1
, const rtl::OString
& rKey2
) const
84 { return rKey1
.compareTo( rKey2
) == 0; }
89 size_t operator()( const rtl::OString
& rName
) const
90 { return rName
.hashCode(); }
103 void copyToBuffer( const char* pSrcData
, int nSize
);
111 { delete [] m_pBuffer
; }
115 const char* getData() const
116 { return m_pBuffer
; }
119 typedef std::hash_map
< rtl::OString
,std::pair
<int,int>,ha
,eq
> StringToValPosMap
;
120 typedef std::hash_map
< rtl::OString
,rtl::OString
,ha
,eq
> StringToDataMap
;
124 rtl::OUString m_aFileName
;
125 StringToDataMap
* m_pStringToDataMap
;
126 StringToValPosMap
* m_pStringToValPosMap
;
127 com::sun::star::uno::Reference
< com::sun::star::ucb::XSimpleFileAccess
>
130 com::sun::star::uno::Sequence
< sal_Int8
>
132 const char* m_pItData
;
136 bool implReadLenAndData( const char* pData
, int& riPos
, DBData
& rValue
);
139 DBHelp( const rtl::OUString
& rFileName
,
140 com::sun::star::uno::Reference
< com::sun::star::ucb::XSimpleFileAccess
> xSFA
)
141 : m_aFileName( rFileName
)
142 , m_pStringToDataMap( NULL
)
143 , m_pStringToValPosMap( NULL
)
150 { releaseHashMap(); }
152 void createHashMap( bool bOptimizeForPerformance
= false );
153 void releaseHashMap( void );
156 bool testAgainstDb( const rtl::OString
& fileName
, bool bOldDbAccess
);
159 bool getValueForKey( const rtl::OString
& rKey
, DBData
& rValue
);
161 bool startIteration( void );
162 bool getNextKeyAndValue( DBData
& rKey
, DBData
& rValue
);
163 void stopIteration( void );
166 class Db
: db_internal::Noncopyable
176 void setDBHelp( DBHelp
* pDBHelp
)
177 { m_pDBHelp
= pDBHelp
; }
178 DBHelp
* getDBHelp( void )
179 { return m_pDBHelp
; }
181 int close(u_int32_t flags
);
183 int open(DB_TXN
*txnid
,
185 const char *database
,
191 int get(DB_TXN
* txnid
, Dbt
*key
, Dbt
*data
, u_int32_t flags
);
193 int cursor(DB_TXN
*txnid
, Dbc
**cursorp
, u_int32_t flags
);
196 class Dbc
: db_internal::Noncopyable
204 explicit Dbc(DBC
* pDBC
);
210 int get(Dbt
*key
, Dbt
*data
, u_int32_t flags
);
213 class Dbt
: private DBT
219 Dbt(void *data_arg
, u_int32_t size_arg
);
222 //Dbt(const Dbt & other);
223 //Dbt & operator=(const Dbt & other);
227 void *get_data() const;
228 void set_data(void *value
);
230 u_int32_t
get_size() const;
231 void set_size(u_int32_t value
);
233 void set_flags(u_int32_t
);