Support bulk writes.

This commit is contained in:
JoelKatz
2012-06-22 00:41:28 -07:00
parent d7fa4d17cd
commit 14a51421c9
2 changed files with 33 additions and 7 deletions

View File

@@ -119,4 +119,14 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash)
return obj;
}
HashedObjectBulkWriter::HashedObjectBulkWriter() : sl(theApp->getHashNodeDB()->getDBLock())
{
theApp->getHashNodeDB()->getDB()->executeSQL("BEGIN TRANSACTION;");
}
HashedObjectBulkWriter::~HashedObjectBulkWriter()
{
theApp->getHashNodeDB()->getDB()->executeSQL("END TRANSACTION;");
}
// vim:ts=4

View File

@@ -3,18 +3,17 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include "types.h"
#include "uint256.h"
#include "ScopedLock.h"
enum HashedObjectType
{
UNKNOWN=0,
LEDGER=1,
TRANSACTION=2,
ACCOUNT_NODE=3,
TRANSACTION_NODE=4
UNKNOWN = 0,
LEDGER = 1,
TRANSACTION = 2,
ACCOUNT_NODE = 3,
TRANSACTION_NODE = 4
};
class HashedObject
@@ -37,10 +36,27 @@ public:
const std::vector<unsigned char>& getData() { return mData; }
bool store() const;
static bool store(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data,
const uint256& hash);
static HashedObject::pointer retrieve(const uint256& hash);
};
class HashedObjectBulkWriter
{
protected:
ScopedLock sl;
public:
HashedObjectBulkWriter();
~HashedObjectBulkWriter();
bool store(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data, const uint256& hash)
{ return HashedObject::store(type, index, data, hash); }
HashedObject::pointer retrieve(const uint256& hash)
{ return HashedObject::retrieve(hash); }
};
#endif