Separate archive_location into its own TU.
This commit is contained in:
@@ -19,6 +19,8 @@ impeller_component("archivist") {
|
||||
"archive_class_registration.h",
|
||||
"archive_database.cc",
|
||||
"archive_database.h",
|
||||
"archive_location.cc",
|
||||
"archive_location.h",
|
||||
"archive_statement.cc",
|
||||
"archive_statement.h",
|
||||
"archive_transaction.cc",
|
||||
|
||||
@@ -5,9 +5,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace impeller {
|
||||
|
||||
struct ArchiveDef {
|
||||
using Member = uint64_t;
|
||||
using Members = std::vector<Member>;
|
||||
|
||||
const ArchiveDef* isa = nullptr;
|
||||
const std::string table_name;
|
||||
const bool auto_key = true;
|
||||
const Members members;
|
||||
};
|
||||
|
||||
class ArchiveLocation;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/archivist/archive_class_registration.h"
|
||||
#include "impeller/archivist/archive_database.h"
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
#include "impeller/archivist/archive_statement.h"
|
||||
#include "impeller/archivist/archive_vector.h"
|
||||
|
||||
@@ -22,14 +23,14 @@ Archive::~Archive() {
|
||||
<< "There must be no pending transactions";
|
||||
}
|
||||
|
||||
bool Archive::IsReady() const {
|
||||
return database_->IsReady();
|
||||
bool Archive::IsValid() const {
|
||||
return database_->IsValid();
|
||||
}
|
||||
|
||||
bool Archive::ArchiveInstance(const ArchiveDef& definition,
|
||||
const Archivable& archivable,
|
||||
int64_t& lastInsertIDOut) {
|
||||
if (!IsReady()) {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ bool Archive::ArchiveInstance(const ArchiveDef& definition,
|
||||
|
||||
auto statement = registration->GetInsertStatement();
|
||||
|
||||
if (!statement.IsReady() || !statement.Reset()) {
|
||||
if (!statement.IsValid() || !statement.Reset()) {
|
||||
/*
|
||||
* Must be able to reset the statement for a new write
|
||||
*/
|
||||
@@ -73,7 +74,7 @@ bool Archive::ArchiveInstance(const ArchiveDef& definition,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (statement.Run() != ArchiveStatement::Result::kDone) {
|
||||
if (statement.Execute() != ArchiveStatement::Result::kDone) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ bool Archive::UnarchiveInstance(const ArchiveDef& definition,
|
||||
size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
|
||||
Archive::UnarchiveStep stepper,
|
||||
Archivable::ArchiveName name) {
|
||||
if (!IsReady()) {
|
||||
if (!IsValid()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
|
||||
|
||||
auto statement = registration->GetQueryStatement(isQueryingSingle);
|
||||
|
||||
if (!statement.IsReady() || !statement.Reset()) {
|
||||
if (!statement.IsValid() || !statement.Reset()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -150,7 +151,7 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
|
||||
|
||||
size_t itemsRead = 0;
|
||||
|
||||
while (statement.Run() == ArchiveStatement::Result::kRow) {
|
||||
while (statement.Execute() == ArchiveStatement::Result::kRow) {
|
||||
itemsRead++;
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,24 +11,11 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/archivist/archivable.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ArchiveLocation;
|
||||
class ArchiveClassRegistration;
|
||||
class ArchiveDatabase;
|
||||
class ArchiveStatement;
|
||||
|
||||
struct ArchiveDef {
|
||||
using Member = uint64_t;
|
||||
using Members = std::vector<Member>;
|
||||
|
||||
const ArchiveDef* isa = nullptr;
|
||||
const std::string table_name;
|
||||
const bool auto_key = true;
|
||||
const Members members;
|
||||
};
|
||||
|
||||
static const Archivable::ArchiveName ArchiveNameAuto = 0;
|
||||
|
||||
@@ -38,7 +25,7 @@ class Archive {
|
||||
|
||||
~Archive();
|
||||
|
||||
bool IsReady() const;
|
||||
bool IsValid() const;
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
@@ -83,182 +70,4 @@ class Archive {
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Archive);
|
||||
};
|
||||
|
||||
class ArchiveLocation {
|
||||
public:
|
||||
template <class T, class = std::enable_if<std::is_integral<T>::value>>
|
||||
bool Write(ArchiveDef::Member member, T item) {
|
||||
return WriteIntegral(member, static_cast<int64_t>(item));
|
||||
}
|
||||
|
||||
bool Write(ArchiveDef::Member member, double item);
|
||||
|
||||
bool Write(ArchiveDef::Member member, const std::string& item);
|
||||
|
||||
bool Write(ArchiveDef::Member member, const Allocation& allocation);
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool WriteArchivable(ArchiveDef::Member member, const T& other) {
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
return Write(member, otherDef, other);
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_enum<T>::value>>
|
||||
bool WriteEnum(ArchiveDef::Member member, const T& item) {
|
||||
return WriteIntegral(member, static_cast<int64_t>(item));
|
||||
}
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool Write(ArchiveDef::Member member, const std::vector<T>& items) {
|
||||
/*
|
||||
* All items in the vector are individually encoded and their keys noted
|
||||
*/
|
||||
std::vector<int64_t> members;
|
||||
members.reserve(items.size());
|
||||
|
||||
const ArchiveDef& itemDefinition = T::ArchiveDefinition;
|
||||
for (const auto& item : items) {
|
||||
int64_t added = 0;
|
||||
bool result = context_.ArchiveInstance(itemDefinition, item, added);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
members.emplace_back(added);
|
||||
}
|
||||
|
||||
/*
|
||||
* The keys are flattened into the vectors table. Write to that table
|
||||
*/
|
||||
auto vectorInsert = WriteVectorKeys(std::move(members));
|
||||
|
||||
if (!vectorInsert.first) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return WriteIntegral(member, vectorInsert.second);
|
||||
}
|
||||
|
||||
template <class Super,
|
||||
class Current,
|
||||
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
|
||||
std::is_base_of<Archivable, Current>::value>>
|
||||
bool WriteSuper(const Current& thiz) {
|
||||
std::string oldClass = current_class_;
|
||||
current_class_ = Super::ArchiveDefinition.className;
|
||||
auto success = thiz.Super::serialize(*this);
|
||||
current_class_ = oldClass;
|
||||
return success;
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_integral<T>::value>>
|
||||
bool Read(ArchiveDef::Member member, T& item) {
|
||||
int64_t decoded = 0;
|
||||
auto result = ReadIntegral(member, decoded);
|
||||
item = static_cast<T>(decoded);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Read(ArchiveDef::Member member, double& item);
|
||||
|
||||
bool Read(ArchiveDef::Member member, std::string& item);
|
||||
|
||||
bool Read(ArchiveDef::Member member, Allocation& allocation);
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool ReadArchivable(ArchiveDef::Member member, T& other) {
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
return decode(member, otherDef, other);
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_enum<T>::value>>
|
||||
bool ReadEnum(ArchiveDef::Member member, T& item) {
|
||||
int64_t desugared = 0;
|
||||
if (ReadIntegral(member, desugared)) {
|
||||
item = static_cast<T>(desugared);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool Read(ArchiveDef::Member member, std::vector<T>& items) {
|
||||
/*
|
||||
* From the member, find the foreign key of the vector
|
||||
*/
|
||||
int64_t vectorForeignKey = 0;
|
||||
if (!ReadIntegral(member, vectorForeignKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get vector keys
|
||||
*/
|
||||
std::vector<int64_t> keys;
|
||||
if (!ReadVectorKeys(vectorForeignKey, keys)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
for (const auto& key : keys) {
|
||||
items.emplace_back();
|
||||
|
||||
if (!context_.UnarchiveInstance(otherDef, key, items.back())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Super,
|
||||
class Current,
|
||||
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
|
||||
std::is_base_of<Archivable, Current>::value>>
|
||||
bool ReadSuper(Current& thiz) {
|
||||
std::string oldClass = current_class_;
|
||||
current_class_ = Super::ArchiveDefinition.className;
|
||||
auto success = thiz.Super::deserialize(*this);
|
||||
current_class_ = oldClass;
|
||||
return success;
|
||||
}
|
||||
|
||||
Archivable::ArchiveName Name() const;
|
||||
|
||||
private:
|
||||
Archive& context_;
|
||||
ArchiveStatement& statement_;
|
||||
const ArchiveClassRegistration& registration_;
|
||||
Archivable::ArchiveName name_;
|
||||
std::string current_class_;
|
||||
|
||||
friend class Archive;
|
||||
|
||||
ArchiveLocation(Archive& context,
|
||||
ArchiveStatement& statement,
|
||||
const ArchiveClassRegistration& registration,
|
||||
Archivable::ArchiveName name);
|
||||
|
||||
bool WriteIntegral(ArchiveDef::Member member, int64_t item);
|
||||
|
||||
bool ReadIntegral(ArchiveDef::Member member, int64_t& item);
|
||||
|
||||
std::pair<bool, int64_t> WriteVectorKeys(std::vector<int64_t>&& members);
|
||||
|
||||
bool ReadVectorKeys(Archivable::ArchiveName name,
|
||||
std::vector<int64_t>& members);
|
||||
|
||||
bool Write(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
const Archivable& other);
|
||||
|
||||
bool Read(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
Archivable& other);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ArchiveLocation);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -45,7 +45,7 @@ size_t ArchiveClassRegistration::GetMemberCount() const {
|
||||
return member_count_;
|
||||
}
|
||||
|
||||
bool ArchiveClassRegistration::IsReady() const {
|
||||
bool ArchiveClassRegistration::IsValid() const {
|
||||
return is_ready_;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ bool ArchiveClassRegistration::CreateTable(bool autoIncrement) {
|
||||
|
||||
auto statement = database_.CreateStatement(stream.str());
|
||||
|
||||
if (!statement.IsReady()) {
|
||||
if (!statement.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ bool ArchiveClassRegistration::CreateTable(bool autoIncrement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return statement.Run() == ArchiveStatement::Result::kDone;
|
||||
return statement.Execute() == ArchiveStatement::Result::kDone;
|
||||
}
|
||||
|
||||
ArchiveStatement ArchiveClassRegistration::GetQueryStatement(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/archivist/archive.h"
|
||||
#include "impeller/archivist/archive_statement.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -19,7 +20,7 @@ class ArchiveClassRegistration {
|
||||
|
||||
size_t GetMemberCount() const;
|
||||
|
||||
bool IsReady() const;
|
||||
bool IsValid() const;
|
||||
|
||||
ArchiveStatement GetInsertStatement() const;
|
||||
|
||||
|
||||
@@ -35,21 +35,21 @@ ArchiveDatabase::ArchiveDatabase(const std::string& filename) {
|
||||
begin_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
|
||||
new ArchiveStatement(database_, "BEGIN TRANSACTION;"));
|
||||
|
||||
if (!begin_transaction_stmt_->IsReady()) {
|
||||
if (!begin_transaction_stmt_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
end_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
|
||||
new ArchiveStatement(database_, "END TRANSACTION;"));
|
||||
|
||||
if (!end_transaction_stmt_->IsReady()) {
|
||||
if (!end_transaction_stmt_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
rollback_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
|
||||
new ArchiveStatement(database_, "ROLLBACK TRANSACTION;"));
|
||||
|
||||
if (!rollback_transaction_stmt_->IsReady()) {
|
||||
if (!rollback_transaction_stmt_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ ArchiveDatabase::~ArchiveDatabase() {
|
||||
::sqlite3_close(DB_HANDLE);
|
||||
}
|
||||
|
||||
bool ArchiveDatabase::IsReady() const {
|
||||
bool ArchiveDatabase::IsValid() const {
|
||||
return ready_;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ static inline const ArchiveClassRegistration* RegistrationIfReady(
|
||||
if (registration == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return registration->IsReady() ? registration : nullptr;
|
||||
return registration->IsValid() ? registration : nullptr;
|
||||
}
|
||||
|
||||
const ArchiveClassRegistration* ArchiveDatabase::GetRegistrationForDefinition(
|
||||
@@ -95,7 +95,7 @@ const ArchiveClassRegistration* ArchiveDatabase::GetRegistrationForDefinition(
|
||||
registrations_.emplace(definition.table_name, std::move(registration));
|
||||
|
||||
/*
|
||||
* If the new class registation is ready, return it to the caller.
|
||||
* If the new class registration is ready, return it to the caller.
|
||||
*/
|
||||
return res.second ? RegistrationIfReady((*(res.first)).second.get())
|
||||
: nullptr;
|
||||
|
||||
@@ -16,13 +16,16 @@ class ArchiveStatement;
|
||||
class ArchiveClassRegistration;
|
||||
struct ArchiveDef;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief A handle to the underlying database connection for an archive.
|
||||
///
|
||||
class ArchiveDatabase {
|
||||
public:
|
||||
ArchiveDatabase(const std::string& filename);
|
||||
|
||||
~ArchiveDatabase();
|
||||
|
||||
bool IsReady() const;
|
||||
bool IsValid() const;
|
||||
|
||||
int64_t GetLastInsertRowID();
|
||||
|
||||
|
||||
11
engine/src/flutter/impeller/archivist/archive_location.cc
Normal file
11
engine/src/flutter/impeller/archivist/archive_location.cc
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
|
||||
} // namespace impeller
|
||||
198
engine/src/flutter/impeller/archivist/archive_location.h
Normal file
198
engine/src/flutter/impeller/archivist/archive_location.h
Normal file
@@ -0,0 +1,198 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/archivist/archivable.h"
|
||||
#include "impeller/archivist/archive.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class Archive;
|
||||
class ArchiveClassRegistration;
|
||||
class ArchiveStatement;
|
||||
|
||||
class ArchiveLocation {
|
||||
public:
|
||||
template <class T, class = std::enable_if<std::is_integral<T>::value>>
|
||||
bool Write(ArchiveDef::Member member, T item) {
|
||||
return WriteIntegral(member, static_cast<int64_t>(item));
|
||||
}
|
||||
|
||||
bool Write(ArchiveDef::Member member, double item);
|
||||
|
||||
bool Write(ArchiveDef::Member member, const std::string& item);
|
||||
|
||||
bool Write(ArchiveDef::Member member, const Allocation& allocation);
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool WriteArchivable(ArchiveDef::Member member, const T& other) {
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
return Write(member, otherDef, other);
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_enum<T>::value>>
|
||||
bool WriteEnum(ArchiveDef::Member member, const T& item) {
|
||||
return WriteIntegral(member, static_cast<int64_t>(item));
|
||||
}
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool Write(ArchiveDef::Member member, const std::vector<T>& items) {
|
||||
/*
|
||||
* All items in the vector are individually encoded and their keys noted
|
||||
*/
|
||||
std::vector<int64_t> members;
|
||||
members.reserve(items.size());
|
||||
|
||||
const ArchiveDef& itemDefinition = T::ArchiveDefinition;
|
||||
for (const auto& item : items) {
|
||||
int64_t added = 0;
|
||||
bool result = context_.ArchiveInstance(itemDefinition, item, added);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
members.emplace_back(added);
|
||||
}
|
||||
|
||||
/*
|
||||
* The keys are flattened into the vectors table. Write to that table
|
||||
*/
|
||||
auto vectorInsert = WriteVectorKeys(std::move(members));
|
||||
|
||||
if (!vectorInsert.first) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return WriteIntegral(member, vectorInsert.second);
|
||||
}
|
||||
|
||||
template <class Super,
|
||||
class Current,
|
||||
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
|
||||
std::is_base_of<Archivable, Current>::value>>
|
||||
bool WriteSuper(const Current& thiz) {
|
||||
std::string oldClass = current_class_;
|
||||
current_class_ = Super::ArchiveDefinition.className;
|
||||
auto success = thiz.Super::serialize(*this);
|
||||
current_class_ = oldClass;
|
||||
return success;
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_integral<T>::value>>
|
||||
bool Read(ArchiveDef::Member member, T& item) {
|
||||
int64_t decoded = 0;
|
||||
auto result = ReadIntegral(member, decoded);
|
||||
item = static_cast<T>(decoded);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Read(ArchiveDef::Member member, double& item);
|
||||
|
||||
bool Read(ArchiveDef::Member member, std::string& item);
|
||||
|
||||
bool Read(ArchiveDef::Member member, Allocation& allocation);
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool ReadArchivable(ArchiveDef::Member member, T& other) {
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
return decode(member, otherDef, other);
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if<std::is_enum<T>::value>>
|
||||
bool ReadEnum(ArchiveDef::Member member, T& item) {
|
||||
int64_t desugared = 0;
|
||||
if (ReadIntegral(member, desugared)) {
|
||||
item = static_cast<T>(desugared);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T,
|
||||
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
|
||||
bool Read(ArchiveDef::Member member, std::vector<T>& items) {
|
||||
/*
|
||||
* From the member, find the foreign key of the vector
|
||||
*/
|
||||
int64_t vectorForeignKey = 0;
|
||||
if (!ReadIntegral(member, vectorForeignKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get vector keys
|
||||
*/
|
||||
std::vector<int64_t> keys;
|
||||
if (!ReadVectorKeys(vectorForeignKey, keys)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const ArchiveDef& otherDef = T::ArchiveDefinition;
|
||||
for (const auto& key : keys) {
|
||||
items.emplace_back();
|
||||
|
||||
if (!context_.UnarchiveInstance(otherDef, key, items.back())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Super,
|
||||
class Current,
|
||||
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
|
||||
std::is_base_of<Archivable, Current>::value>>
|
||||
bool ReadSuper(Current& thiz) {
|
||||
std::string oldClass = current_class_;
|
||||
current_class_ = Super::ArchiveDefinition.className;
|
||||
auto success = thiz.Super::deserialize(*this);
|
||||
current_class_ = oldClass;
|
||||
return success;
|
||||
}
|
||||
|
||||
Archivable::ArchiveName Name() const;
|
||||
|
||||
private:
|
||||
Archive& context_;
|
||||
ArchiveStatement& statement_;
|
||||
const ArchiveClassRegistration& registration_;
|
||||
Archivable::ArchiveName name_;
|
||||
std::string current_class_;
|
||||
|
||||
friend class Archive;
|
||||
|
||||
ArchiveLocation(Archive& context,
|
||||
ArchiveStatement& statement,
|
||||
const ArchiveClassRegistration& registration,
|
||||
Archivable::ArchiveName name);
|
||||
|
||||
bool WriteIntegral(ArchiveDef::Member member, int64_t item);
|
||||
|
||||
bool ReadIntegral(ArchiveDef::Member member, int64_t& item);
|
||||
|
||||
std::pair<bool, int64_t> WriteVectorKeys(std::vector<int64_t>&& members);
|
||||
|
||||
bool ReadVectorKeys(Archivable::ArchiveName name,
|
||||
std::vector<int64_t>& members);
|
||||
|
||||
bool Write(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
const Archivable& other);
|
||||
|
||||
bool Read(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
Archivable& other);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ArchiveLocation);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -37,7 +37,7 @@ ArchiveStatement::~ArchiveStatement() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ArchiveStatement::IsReady() const {
|
||||
bool ArchiveStatement::IsValid() const {
|
||||
return ready_;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ static constexpr int ToParam(size_t index) {
|
||||
|
||||
static constexpr int ToColumn(size_t index) {
|
||||
/*
|
||||
* sqlite columns begin from 1
|
||||
* sqlite columns begin from 0
|
||||
*/
|
||||
return static_cast<int>(index);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ bool ArchiveStatement::ReadValue(size_t index, Allocation& item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ArchiveStatement::Result ArchiveStatement::Run() {
|
||||
ArchiveStatement::Result ArchiveStatement::Execute() {
|
||||
switch (::sqlite3_step(STATEMENT_HANDLE)) {
|
||||
case SQLITE_DONE:
|
||||
return Result::kDone;
|
||||
|
||||
@@ -11,14 +11,48 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Represents a read/write query to an archive database. Statements
|
||||
/// are expensive to create and must be cached for as long as
|
||||
/// possible.
|
||||
///
|
||||
class ArchiveStatement {
|
||||
public:
|
||||
~ArchiveStatement();
|
||||
|
||||
ArchiveStatement(ArchiveStatement&& message);
|
||||
|
||||
bool IsReady() const;
|
||||
bool IsValid() const;
|
||||
|
||||
enum class Result {
|
||||
//--------------------------------------------------------------------------
|
||||
/// The statement is done executing.
|
||||
///
|
||||
kDone,
|
||||
//--------------------------------------------------------------------------
|
||||
/// The statement found a row of information ready for reading.
|
||||
///
|
||||
kRow,
|
||||
//--------------------------------------------------------------------------
|
||||
/// Statement execution was a failure.
|
||||
///
|
||||
kFailure,
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Execute the given statement with the provided data.
|
||||
///
|
||||
/// @return Is the execution was succeessful.
|
||||
///
|
||||
[[nodiscard]] Result Execute();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief All writes after the last successfull `Run` call are reset.
|
||||
/// Since statements are expensive to create, reset them for new
|
||||
/// writes instead of creating new statements.
|
||||
///
|
||||
/// @return If the statement writes were reset.
|
||||
///
|
||||
bool Reset();
|
||||
|
||||
bool WriteValue(size_t index, const std::string& item);
|
||||
@@ -45,21 +79,13 @@ class ArchiveStatement {
|
||||
|
||||
size_t GetColumnCount();
|
||||
|
||||
enum class Result {
|
||||
kDone,
|
||||
kRow,
|
||||
kFailure,
|
||||
};
|
||||
|
||||
[[nodiscard]] Result Run();
|
||||
|
||||
private:
|
||||
void* statement_handle_ = nullptr;
|
||||
bool ready_ = false;
|
||||
|
||||
friend class ArchiveDatabase;
|
||||
|
||||
ArchiveStatement(void* db, const std::string& statememt);
|
||||
ArchiveStatement(void* db, const std::string& statement);
|
||||
|
||||
bool BindIntegral(size_t index, int64_t item);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ ArchiveTransaction::ArchiveTransaction(int64_t& transactionCount,
|
||||
rollback_stmt_(rollbackStatement),
|
||||
transaction_count_(transactionCount) {
|
||||
if (transaction_count_ == 0) {
|
||||
cleanup_ = beginStatement.Run() == ArchiveStatement::Result::kDone;
|
||||
cleanup_ = beginStatement.Execute() == ArchiveStatement::Result::kDone;
|
||||
}
|
||||
transaction_count_++;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ ArchiveTransaction::~ArchiveTransaction() {
|
||||
|
||||
FML_CHECK(transaction_count_ != 0);
|
||||
if (transaction_count_ == 1 && cleanup_) {
|
||||
auto res = successful_ ? end_stmt_.Run() : rollback_stmt_.Run();
|
||||
auto res = successful_ ? end_stmt_.Execute() : rollback_stmt_.Execute();
|
||||
FML_CHECK(res == ArchiveStatement::Result::kDone)
|
||||
<< "Must be able to commit the nested transaction";
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ArchiveVector::ArchiveVector(std::vector<int64_t>&& keys)
|
||||
|
||||
@@ -27,6 +27,8 @@ void ArchivistFixture::SetUp() {
|
||||
}
|
||||
|
||||
void ArchivistFixture::TearDown() {
|
||||
// TODO: Tear this down. For now, I am inspecting the files for readability of
|
||||
// schema.
|
||||
// DeleteArchiveFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "impeller/archivist/archive.h"
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
#include "impeller/archivist/archivist_fixture.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -55,24 +56,24 @@ using ArchiveTest = ArchivistFixture;
|
||||
|
||||
TEST_F(ArchiveTest, SimpleInitialization) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(ArchiveTest, AddStorageClass) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(ArchiveTest, AddData) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
Sample sample;
|
||||
ASSERT_TRUE(archive.Write(sample));
|
||||
}
|
||||
|
||||
TEST_F(ArchiveTest, AddDataMultiple) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
Sample sample(i + 1);
|
||||
@@ -82,7 +83,7 @@ TEST_F(ArchiveTest, AddDataMultiple) {
|
||||
|
||||
TEST_F(ArchiveTest, ReadData) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
|
||||
size_t count = 50;
|
||||
|
||||
@@ -105,7 +106,7 @@ TEST_F(ArchiveTest, ReadData) {
|
||||
|
||||
TEST_F(ArchiveTest, ReadDataWithNames) {
|
||||
Archive archive(GetArchiveFileName().c_str());
|
||||
ASSERT_TRUE(archive.IsReady());
|
||||
ASSERT_TRUE(archive.IsValid());
|
||||
|
||||
size_t count = 8;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user