mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:04:57 +00:00
LibSQL: Remove Core::EventReceiver parent from SQL::Heap
This relationship was only used to provide a name and factory methods for the heap.
This commit is contained in:
parent
2c17742811
commit
4a04438e43
7 changed files with 29 additions and 21 deletions
|
@ -145,7 +145,7 @@ void insert_and_get_to_and_from_btree(int num_keys)
|
|||
{
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto btree = setup_btree(serializer);
|
||||
|
@ -162,7 +162,7 @@ void insert_and_get_to_and_from_btree(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto btree = setup_btree(serializer);
|
||||
|
@ -181,7 +181,7 @@ void insert_into_and_scan_btree(int num_keys)
|
|||
{
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto btree = setup_btree(serializer);
|
||||
|
@ -199,7 +199,7 @@ void insert_into_and_scan_btree(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto btree = setup_btree(serializer);
|
||||
|
|
|
@ -100,28 +100,28 @@ static void insert_and_verify(int count)
|
|||
TEST_CASE(create_heap)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
EXPECT_EQ(heap->version(), SQL::Heap::VERSION);
|
||||
}
|
||||
|
||||
TEST_CASE(create_from_dev_random)
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/dev/random");
|
||||
auto heap = MUST(SQL::Heap::create("/dev/random"));
|
||||
auto should_be_error = heap->open();
|
||||
EXPECT(should_be_error.is_error());
|
||||
}
|
||||
|
||||
TEST_CASE(create_from_unreadable_file)
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/etc/shadow");
|
||||
auto heap = MUST(SQL::Heap::create("/etc/shadow"));
|
||||
auto should_be_error = heap->open();
|
||||
EXPECT(should_be_error.is_error());
|
||||
}
|
||||
|
||||
TEST_CASE(create_in_non_existing_dir)
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/bogus/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/bogus/test.db"));
|
||||
auto should_be_error = heap->open();
|
||||
EXPECT(should_be_error.is_error());
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ void insert_and_get_to_and_from_hash_index(int num_keys)
|
|||
{
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto hash_index = setup_hash_index(serializer);
|
||||
|
@ -158,7 +158,7 @@ void insert_and_get_to_and_from_hash_index(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto hash_index = setup_hash_index(serializer);
|
||||
|
@ -238,7 +238,7 @@ void insert_into_and_scan_hash_index(int num_keys)
|
|||
{
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto hash_index = setup_hash_index(serializer);
|
||||
|
@ -256,7 +256,7 @@ void insert_into_and_scan_hash_index(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto heap = MUST(SQL::Heap::create("/tmp/test.db"));
|
||||
TRY_OR_FAIL(heap->open());
|
||||
SQL::Serializer serializer(heap);
|
||||
auto hash_index = setup_hash_index(serializer);
|
||||
|
|
|
@ -14,7 +14,7 @@ static constexpr auto db_path = "/tmp/test.db"sv;
|
|||
|
||||
static NonnullRefPtr<SQL::Heap> create_heap()
|
||||
{
|
||||
auto heap = MUST(SQL::Heap::try_create(db_path));
|
||||
auto heap = MUST(SQL::Heap::create(db_path));
|
||||
MUST(heap->open());
|
||||
return heap;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
namespace SQL {
|
||||
|
||||
Database::Database(DeprecatedString name)
|
||||
: m_heap(Heap::construct(move(name)))
|
||||
: m_heap(Heap::create(move(name)).release_value_but_fixme_should_propagate_errors())
|
||||
, m_serializer(m_heap)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -14,9 +14,14 @@
|
|||
|
||||
namespace SQL {
|
||||
|
||||
Heap::Heap(DeprecatedString file_name)
|
||||
ErrorOr<NonnullRefPtr<Heap>> Heap::create(DeprecatedString file_name)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Heap(move(file_name)));
|
||||
}
|
||||
|
||||
Heap::Heap(DeprecatedString file_name)
|
||||
: m_name(move(file_name))
|
||||
{
|
||||
set_name(move(file_name));
|
||||
}
|
||||
|
||||
Heap::~Heap()
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace SQL {
|
||||
|
@ -64,13 +64,14 @@ private:
|
|||
* A Heap can be thought of the backing storage of a single database. It's
|
||||
* assumed that a single SQL database is backed by a single Heap.
|
||||
*/
|
||||
class Heap : public Core::EventReceiver {
|
||||
C_OBJECT(Heap);
|
||||
|
||||
class Heap : public RefCounted<Heap> {
|
||||
public:
|
||||
static constexpr u32 VERSION = 4;
|
||||
|
||||
virtual ~Heap() override;
|
||||
static ErrorOr<NonnullRefPtr<Heap>> create(DeprecatedString);
|
||||
virtual ~Heap();
|
||||
|
||||
DeprecatedString const& name() const { return m_name; }
|
||||
|
||||
ErrorOr<void> open();
|
||||
ErrorOr<size_t> file_size_in_bytes() const;
|
||||
|
@ -135,6 +136,8 @@ private:
|
|||
ErrorOr<void> initialize_zero_block();
|
||||
ErrorOr<void> update_zero_block();
|
||||
|
||||
DeprecatedString m_name;
|
||||
|
||||
OwnPtr<Core::InputBufferedFile> m_file;
|
||||
Block::Index m_highest_block_written { 0 };
|
||||
Block::Index m_next_block { 1 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue