aboutsummaryrefslogtreecommitdiff
path: root/mod/database-module
blob: 034324b713a51e8abca7c98ca4dcdf0ad2114b42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// file      : mod/database-module -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef MOD_DATABASE_MODULE
#define MOD_DATABASE_MODULE

#include <odb/forward.hxx> // database

#include <brep/types>
#include <brep/utility>

#include <mod/module>
#include <mod/options>

namespace brep
{
  // A module that utilises the database. Specifically, it will retry the
  // request in the face of recoverable database failures (deadlock, loss of
  // connection, etc) up to a certain number of times.
  //
  class database_module: public module
  {
  protected:
    database_module () = default;

    // Create a shallow copy (handling instance) if initialized and a deep
    // copy (context exemplar) otherwise.
    //
    explicit
    database_module (const database_module&);

    // Required to avoid getting warning from clang that
    // database_module::init() hides module::init() virtual functions. This
    // way all functions get to the same scope and become overloaded set.
    //
    using module::init;

    void
    init (const options::db&);

    virtual bool
    handle (request&, response&) = 0;

  protected:
    size_t retry_;
    shared_ptr<odb::core::database> db_;

  private:
    virtual bool
    handle (request&, response&, log&);
  };
}

#endif // MOD_DATABASE_MODULE