Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the functionality to report tool version #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions inc/vcf/error-odb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <odb/no-op-cache-traits.hxx>
#include <odb/polymorphic-info.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/polymorphic-object-result.hxx>
#include <odb/view-image.hxx>
#include <odb/view-result.hxx>
Expand Down Expand Up @@ -987,6 +988,48 @@ namespace odb
static void
callback (database&, const object_type&, callback_event);
};

// ToolVersion
//
template <>
struct class_traits< ::ebi::vcf::ToolVersion >
{
static const class_kind kind = class_object;
};

template <>
class access::object_traits< ::ebi::vcf::ToolVersion >
{
public:
typedef ::ebi::vcf::ToolVersion object_type;
typedef ::ebi::vcf::ToolVersion* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;

static const bool polymorphic = false;

typedef long unsigned int id_type;

static const bool auto_id = true;

static const bool abstract = false;

static id_type
id (const object_type&);

typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;

typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;

static void
callback (database&, object_type&, callback_event);

static void
callback (database&, const object_type&, callback_event);
};
}

#include <odb/details/buffer.hxx>
Expand Down Expand Up @@ -4810,6 +4853,180 @@ namespace odb
{
};

// ToolVersion
//
template <typename A>
struct query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >
{
// tool_version
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
tool_version_type_;

static const tool_version_type_ tool_version;

// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
long unsigned int,
sqlite::id_integer >::query_type,
sqlite::id_integer >
id_type_;

static const id_type_ id;
};

template <typename A>
const typename query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >::tool_version_type_
query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >::
tool_version (A::table_name, "\"tool_version\"", 0);

template <typename A>
const typename query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >::id_type_
query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);

template <typename A>
struct pointer_query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >:
query_columns< ::ebi::vcf::ToolVersion, id_sqlite, A >
{
};

template <>
class access::object_traits_impl< ::ebi::vcf::ToolVersion, id_sqlite >:
public access::object_traits< ::ebi::vcf::ToolVersion >
{
public:
struct id_image_type
{
long long id_value;
bool id_null;

std::size_t version;
};

struct image_type
{
// tool_version
//
details::buffer tool_version_value;
std::size_t tool_version_size;
bool tool_version_null;

// id_
//
long long id_value;
bool id_null;

std::size_t version;
};

struct extra_statement_cache_type;

using object_traits<object_type>::id;

static id_type
id (const id_image_type&);

static id_type
id (const image_type&);

static bool
grow (image_type&,
bool*);

static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);

static void
bind (sqlite::bind*, id_image_type&);

static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);

static void
init (object_type&,
const image_type&,
database*);

static void
init (id_image_type&, const id_type&);

typedef sqlite::object_statements<object_type> statements_type;

typedef sqlite::query_base query_base_type;

static const std::size_t column_count = 2UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 1UL;
static const std::size_t managed_optimistic_column_count = 0UL;

static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;

static const bool versioned = false;

static const char persist_statement[];
static const char find_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];

static const char table_name[];

static void
persist (database&, object_type&);

static bool
find (database&, const id_type&, object_type&);

static bool
reload (database&, object_type&);

static void
update (database&, const object_type&);

static void
erase (database&, const id_type&);

static void
erase (database&, const object_type&);

static result<object_type>
query (database&, const query_base_type&);

static unsigned long long
erase_query (database&, const query_base_type&);

public:
static bool
find_ (statements_type&,
const id_type*);

static void
load_ (statements_type&,
object_type&,
bool reload);
};

template <>
class access::object_traits_impl< ::ebi::vcf::ToolVersion, id_common >:
public access::object_traits_impl< ::ebi::vcf::ToolVersion, id_sqlite >
{
};

// Error
//
// ErrorCount
Expand Down Expand Up @@ -4858,6 +5075,8 @@ namespace odb
//
// DuplicationError
//
// ToolVersion
//
}

#include "vcf/error-odb.ipp"
Expand Down
51 changes: 51 additions & 0 deletions inc/vcf/error-odb.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,35 @@ namespace odb
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}

// ToolVersion
//

inline
access::object_traits< ::ebi::vcf::ToolVersion >::id_type
access::object_traits< ::ebi::vcf::ToolVersion >::
id (const object_type& o)
{
return o.id_;
}

inline
void access::object_traits< ::ebi::vcf::ToolVersion >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}

inline
void access::object_traits< ::ebi::vcf::ToolVersion >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}

#include <odb/details/unique-ptr.hxx>
Expand Down Expand Up @@ -1277,5 +1306,27 @@ namespace odb
b[1UL].version++;
b[2UL].version++;
}

// ToolVersion
//

inline
void access::object_traits_impl< ::ebi::vcf::ToolVersion, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}

inline
void access::object_traits_impl< ::ebi::vcf::ToolVersion, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}

19 changes: 19 additions & 0 deletions inc/vcf/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace ebi
struct NormalizationError;
struct DuplicationError;

struct ToolVersion;

/**
*
* This function allows throwing Error with some polymorphism, without using raw pointers.
Expand Down Expand Up @@ -365,6 +367,23 @@ namespace ebi
virtual ~DuplicationError() override { }
virtual void apply_visitor(ErrorVisitor &visitor) override { visitor.visit(*this); }
};

/**
* class for writing the tool version to db.
*/
#pragma db object
struct ToolVersion
{
ToolVersion(const std::string &tool_version) : tool_version{tool_version} {}
const std::string tool_version;
std::string get_tool_version() const { return tool_version; }

private:
friend class odb::access;

#pragma db id auto
unsigned long id_;
};
}
}

Expand Down
8 changes: 5 additions & 3 deletions inc/vcf/odb_report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,27 @@ namespace ebi
{
public:

OdbReportRW(const std::string &db_name);
OdbReportRW(const std::string &db_name, const std::string tool_version);
virtual ~OdbReportRW();
void flush(); // before reading, make sure you destroy or flush the writer OdbReportRW

// ReportWriter implementation
virtual void write_error(Error &error) override;
virtual void write_warning(Error &error) override;
virtual void write_message(const std::string &report_result) override;
virtual void write_message(const std::string &message) override;
virtual void write_version(ToolVersion tool_version) override;

// ReportReader implementation
virtual size_t count_warnings() override;
virtual void for_each_warning(std::function<void(std::shared_ptr<Error>)> user_function) override;
virtual size_t count_errors() override;
virtual void for_each_error(std::function<void(std::shared_ptr<Error>)> user_function) override;

virtual std::string get_report_message() override;
virtual std::string get_filename() override;

private:
std::string db_name;
ToolVersion tool_version;
std::unique_ptr<odb::core::database> db;
odb::core::transaction transaction;
size_t current_transaction_size;
Expand Down
Loading