7#include "documentdatadb.h"
8#include "enginedebug.h"
12DocumentDataDB::DocumentDataDB(MDB_dbi dbi, MDB_txn* txn)
16 Q_ASSERT(txn !=
nullptr);
20DocumentDataDB::~DocumentDataDB()
24MDB_dbi DocumentDataDB::create(MDB_txn* txn)
27 int rc = mdb_dbi_open(txn,
"documentdatadb", MDB_CREATE | MDB_INTEGERKEY, &dbi);
29 qCWarning(ENGINE) <<
"DocumentDataDB::create" << mdb_strerror(rc);
36MDB_dbi DocumentDataDB::open(MDB_txn* txn)
39 int rc = mdb_dbi_open(txn,
"documentdatadb", MDB_INTEGERKEY, &dbi);
41 qCWarning(ENGINE) <<
"DocumentDataDB::open" << mdb_strerror(rc);
48void DocumentDataDB::put(quint64 docId,
const QByteArray& url)
54 key.mv_size =
sizeof(quint64);
55 key.mv_data =
static_cast<void*
>(&docId);
58 val.mv_size = url.
size();
59 val.mv_data =
static_cast<void*
>(
const_cast<char*
>(url.
constData()));
61 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
63 qCWarning(ENGINE) <<
"DocumentDataDB::put" << mdb_strerror(rc);
72 key.mv_size =
sizeof(quint64);
73 key.mv_data =
static_cast<void*
>(&docId);
75 MDB_val val{0,
nullptr};
76 int rc = mdb_get(m_txn, m_dbi, &key, &val);
78 if (rc != MDB_NOTFOUND) {
79 qCDebug(ENGINE) <<
"DocumentDataDB::get" << docId << mdb_strerror(rc);
84 return QByteArray(
static_cast<char*
>(val.mv_data), val.mv_size);
87void DocumentDataDB::del(quint64 docId)
92 key.mv_size =
sizeof(quint64);
93 key.mv_data =
static_cast<void*
>(&docId);
95 int rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
96 if (rc != 0 && rc != MDB_NOTFOUND) {
97 qCDebug(ENGINE) <<
"DocumentDataDB::del" << docId << mdb_strerror(rc);
101bool DocumentDataDB::contains(quint64 docId)
106 key.mv_size =
sizeof(quint64);
107 key.mv_data =
static_cast<void*
>(&docId);
109 MDB_val val{0,
nullptr};
110 int rc = mdb_get(m_txn, m_dbi, &key, &val);
112 if (rc != MDB_NOTFOUND) {
113 qCDebug(ENGINE) <<
"DocumentDataDB::contains" << docId << mdb_strerror(rc);
124 mdb_cursor_open(m_txn, m_dbi, &cursor);
126 MDB_val key = {0,
nullptr};
131 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
133 qCDebug(ENGINE) <<
"DocumentDataDB::toTestMap" << mdb_strerror(rc);
137 const quint64
id = *(
static_cast<quint64*
>(key.mv_data));
138 const QByteArray ba(
static_cast<char*
>(val.mv_data), val.mv_size);
142 mdb_cursor_close(cursor);
Implements storage for docIds without any associated data Instantiated for:
const char * constData() const const
bool isEmpty() const const
qsizetype size() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)