Commit 991fdda4 authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

recurse to store message tree

parent 9513366e
......@@ -27,6 +27,8 @@
#include <profanedb/format/marshaller.h>
#include <profanedb/vault/storage.h>
#include <boost/log/trivial.hpp>
namespace profanedb {
// Db should be the main interface when embedding ProfaneDB
......@@ -43,15 +45,19 @@ public:
const Message & Get(const protobuf::Key & key) const
{
BOOST_LOG_TRIVIAL(debug) << "Retrieving " << key.message_type();
return this->marshaller->Unmarshal(this->storage->Retrieve(key));
}
bool Put(const Message & message)
{
BOOST_LOG_TRIVIAL(debug) << "Marshalling message for storage";
const protobuf::MessageTreeNode & messageTree = this->marshaller->Marshal(message);
// TODO Iterate over MessageTreeNode and store all
this->storage->Store(messageTree.message());
BOOST_LOG_TRIVIAL(debug) << "Storing " << messageTree.message().key().message_type();
this->StoreMessageTree(messageTree);
// TODO Check exceptions
return true;
......@@ -59,9 +65,22 @@ public:
bool Delete(const protobuf::Key & key)
{
BOOST_LOG_TRIVIAL(debug) << "Deleting " << key.message_type();
// TODO
}
protected:
// Store a message tree recursively
void StoreMessageTree(const protobuf::MessageTreeNode & messageTree)
{
// Traverse all children messages...
for (const auto & child: messageTree.children())
this->StoreMessageTree(child);
// ... and store from the last nested ones to the root
this->storage->Store(messageTree.message());
}
private:
std::shared_ptr<vault::Storage> storage;
std::shared_ptr< format::Marshaller<Message> > marshaller;
......
......@@ -65,7 +65,11 @@ profanedb::format::protobuf::Loader::Loader(
{
// profanedb.protobuf.options.key is defined in here
// It is used to mark the primary key on Messages
schemaPool.FindFileByName("profanedb/protobuf/options.proto");
const FileDescriptor * optionsFile = schemaPool.FindFileByName("profanedb/protobuf/options.proto");
FileDescriptorProto optionsProto;
optionsFile->CopyTo(&optionsProto);
this->normalizedDescriptorDb.AddAndOwn(&optionsProto);
BOOST_LOG_TRIVIAL(debug) << "Loading profanedb/protobuf/options.proto and copying to normalized descriptor db";
// Just in case schema is defined in more than one place
for (const auto & path: schemaSourceTree->paths) {
......@@ -114,7 +118,7 @@ DescriptorProto profanedb::format::protobuf::Loader::ParseAndNormalizeDescriptor
const Descriptor * descriptor)
{
BOOST_LOG_TRIVIAL(debug) << "Parsing descriptor " << descriptor->full_name();
BOOST_LOG_TRIVIAL(trace) << descriptor->DebugString();
BOOST_LOG_TRIVIAL(trace) << std::endl << descriptor->DebugString();
DescriptorProto normDescProto;
descriptor->CopyTo(&normDescProto);
......
......@@ -23,5 +23,9 @@ if(BUILD_PROFANEDB_SERVER)
add_library(profanedb_grpc STATIC ${GRPC_CC} ${GRPC_H})
target_link_libraries(profanedb_grpc profanedb_protobuf ${GRPC_LIBRARIES})
if(BUILD_SHARED_LIBS)
set_target_properties(profanedb_grpc PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
endif()
......@@ -124,6 +124,7 @@ Status Server::DbServiceImpl::Put(ServerContext * context, const PutReq * reques
this->protobufMarshaller->CreateMessage(ProtobufMarshaller::SCHEMA, type.substr(type.rfind('/')+1, std::string::npos));
request->serializable().UnpackTo(unpackedMessage);
BOOST_LOG_TRIVIAL(trace) << "Unpacked message" << std::endl << unpackedMessage->DebugString();
this->profane->Put(*unpackedMessage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment