diff --git a/src/HashedObject.cpp b/src/HashedObject.cpp index ceb7a1b2a..52f520f8a 100644 --- a/src/HashedObject.cpp +++ b/src/HashedObject.cpp @@ -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 diff --git a/src/HashedObject.h b/src/HashedObject.h index 7234082c4..6a0fa2869 100644 --- a/src/HashedObject.h +++ b/src/HashedObject.h @@ -3,18 +3,17 @@ #include -#include - #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& getData() { return mData; } bool store() const; + static bool store(HashedObjectType type, uint32 index, const std::vector& 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& data, const uint256& hash) + { return HashedObject::store(type, index, data, hash); } + HashedObject::pointer retrieve(const uint256& hash) + { return HashedObject::retrieve(hash); } +}; + #endif