aboutsummaryrefslogtreecommitdiff
path: root/mod/database-module
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-21 16:05:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-21 16:05:13 +0200
commit2a0f39b29c1bea6a4497c0f1826052ffa453af9e (patch)
tree283f6bf1569c1b9f00b6e25fe986ccfff8a8629f /mod/database-module
parentc6b4d6c6489731eedba606d3c85c4319c4478b50 (diff)
Move module implementation from brep/ to mod/
Diffstat (limited to 'mod/database-module')
-rw-r--r--mod/database-module55
1 files changed, 55 insertions, 0 deletions
diff --git a/mod/database-module b/mod/database-module
new file mode 100644
index 0000000..0933794
--- /dev/null
+++ b/mod/database-module
@@ -0,0 +1,55 @@
+// file : mod/database-module -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 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