aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:36:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:36:21 +0200
commiteef022894e7d6f1f371da432722a733b98fd8709 (patch)
tree23c42ae76accab7708b73efc98b210b87bc9b1ab
parent0b5578e85153c43374f022a0454bbb41288da52c (diff)
Initial implementation
-rw-r--r--makefile34
-rw-r--r--odb/tracer/database.cxx40
-rw-r--r--odb/tracer/database.hxx31
-rw-r--r--odb/tracer/makefile57
-rw-r--r--odb/tracer/transaction-impl.cxx53
-rw-r--r--odb/tracer/transaction-impl.hxx44
-rw-r--r--odb/tracer/transaction.cxx26
-rw-r--r--odb/tracer/transaction.hxx46
-rw-r--r--odb/tracer/transaction.ixx35
9 files changed, 366 insertions, 0 deletions
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..fef6eef
--- /dev/null
+++ b/makefile
@@ -0,0 +1,34 @@
+# file : makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))build/bootstrap.make
+
+default := $(out_base)/
+test := $(out_base)/.test
+install := $(out_base)/.install
+clean := $(out_base)/.clean
+
+# Build.
+#
+$(default): $(out_base)/odb/tracer/ #$(out_base)/tests/
+
+# Test.
+#
+$(test): $(out_base)/tests/.test
+
+# Install.
+#
+$(install): $(out_base)/odb/tracer/.install
+ $(call install-data,$(src_base)/LICENSE,$(install_doc_dir)/libodb-tracer/LICENSE)
+ $(call install-data,$(src_base)/README,$(install_doc_dir)/libodb-tracer/README)
+
+# Clean.
+#
+$(clean): $(out_base)/odb/tracer/.clean $(out_base)/tests/.clean
+
+$(call include,$(bld_root)/install.make)
+
+$(call import,$(src_base)/odb/tracer/makefile)
+#$(call import,$(src_base)/tests/makefile)
diff --git a/odb/tracer/database.cxx b/odb/tracer/database.cxx
new file mode 100644
index 0000000..5d59c16
--- /dev/null
+++ b/odb/tracer/database.cxx
@@ -0,0 +1,40 @@
+// file : odb/tracer/database.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/session.hxx>
+#include <odb/transaction.hxx>
+#include <odb/tracer/database.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ database::
+ ~database ()
+ {
+ }
+
+ transaction_impl* database::
+ begin_transaction ()
+ {
+ if (odb::transaction::has_current ())
+ throw already_in_transaction ();
+
+ if (session::has_current ())
+ return new transaction_impl (*this, session::current ());
+ else
+ return new transaction_impl (*this);
+ }
+
+ transaction_impl* database::
+ begin_transaction (session& s)
+ {
+ if (odb::transaction::has_current ())
+ throw already_in_transaction ();
+
+ return new transaction_impl (*this, s);
+ }
+ }
+}
diff --git a/odb/tracer/database.hxx b/odb/tracer/database.hxx
new file mode 100644
index 0000000..983f866
--- /dev/null
+++ b/odb/tracer/database.hxx
@@ -0,0 +1,31 @@
+// file : odb/tracer/database.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TRACER_DATABASE_HXX
+#define ODB_TRACER_DATABASE_HXX
+
+#include <odb/database.hxx>
+#include <odb/tracer/transaction-impl.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ class database: public odb::database
+ {
+ public:
+ virtual
+ ~database ();
+
+ virtual transaction_impl*
+ begin_transaction ();
+
+ virtual transaction_impl*
+ begin_transaction (session&);
+ };
+ }
+}
+
+#endif // ODB_TRACER_DATABASE_HXX
diff --git a/odb/tracer/makefile b/odb/tracer/makefile
new file mode 100644
index 0000000..aacde61
--- /dev/null
+++ b/odb/tracer/makefile
@@ -0,0 +1,57 @@
+# file : odb/tracer/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := database.cxx transaction.cxx transaction-impl.cxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+odb_tracer.l := $(out_base)/odb-tracer.l
+odb_tracer.l.cpp-options := $(out_base)/odb-tracer.l.cpp-options
+
+default := $(out_base)/
+install := $(out_base)/.install
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+# Build.
+#
+$(odb_tracer.l): $(cxx_obj) $(odb.l)
+$(odb_tracer.l.cpp-options): value := -I$(src_root)
+$(odb_tracer.l.cpp-options): $(odb.l.cpp-options)
+
+$(cxx_obj) $(cxx_od): $(odb_tracer.l.cpp-options)
+
+$(call include-dep,$(cxx_od))
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(odb_tracer.l)
+
+# Install.
+#
+$(install): $(odb_tracer.l)
+ $(call install-lib,$<,$(install_lib_dir)/$(ld_lib_prefix)odb-tracer$(ld_lib_suffix))
+ $(call install-dir,$(src_base),$(install_inc_dir)/odb/tracer,\
+'(' -name '*.hxx' -o -name '*.ixx' -o -name '*.txx' ')')
+
+# Clean.
+#
+$(clean): $(odb_tracer.l).o.clean \
+ $(odb_tracer.l.cpp-options).clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od))
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-l.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
diff --git a/odb/tracer/transaction-impl.cxx b/odb/tracer/transaction-impl.cxx
new file mode 100644
index 0000000..248ee61
--- /dev/null
+++ b/odb/tracer/transaction-impl.cxx
@@ -0,0 +1,53 @@
+// file : odb/tracer/transaction-impl.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <iostream>
+
+#include <odb/tracer/database.hxx>
+#include <odb/tracer/transaction-impl.hxx>
+
+using std::cout;
+using std::endl;
+
+namespace odb
+{
+ namespace tracer
+ {
+ transaction_impl::
+ transaction_impl (database_type& db)
+ : odb::transaction_impl (db), finilized_ (false)
+ {
+ cout << "begin transaction" << endl;
+ }
+
+ transaction_impl::
+ transaction_impl (database_type& db, session_type& s)
+ : odb::transaction_impl (db, s), finilized_ (false)
+ {
+ cout << "begin transaction" << endl;
+ }
+
+ transaction_impl::
+ ~transaction_impl ()
+ {
+ if (!finilized_)
+ cout << "end transaction without commit/rollback" << endl;
+ }
+
+ void transaction_impl::
+ commit ()
+ {
+ cout << "commit transaction" << endl;
+ finilized_ = true;
+ }
+
+ void transaction_impl::
+ rollback ()
+ {
+ cout << "rollback transaction" << endl;
+ finilized_ = true;
+ }
+ }
+}
diff --git a/odb/tracer/transaction-impl.hxx b/odb/tracer/transaction-impl.hxx
new file mode 100644
index 0000000..06fe849
--- /dev/null
+++ b/odb/tracer/transaction-impl.hxx
@@ -0,0 +1,44 @@
+// file : odb/tracer/transaction-impl.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TRACER_TRANSACTION_IMPL_HXX
+#define ODB_TRACER_TRANSACTION_IMPL_HXX
+
+#include <odb/transaction.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ class database;
+ class transaction;
+
+ class transaction_impl: public odb::transaction_impl
+ {
+ protected:
+ friend class database;
+ friend class transaction;
+
+ typedef tracer::database database_type;
+
+ transaction_impl (database_type&);
+ transaction_impl (database_type&, session_type&);
+
+ virtual
+ ~transaction_impl ();
+
+ virtual void
+ commit ();
+
+ virtual void
+ rollback ();
+
+ private:
+ bool finilized_;
+ };
+ }
+}
+
+#endif // ODB_TRACER_TRANSACTION_IMPL_HXX
diff --git a/odb/tracer/transaction.cxx b/odb/tracer/transaction.cxx
new file mode 100644
index 0000000..46309de
--- /dev/null
+++ b/odb/tracer/transaction.cxx
@@ -0,0 +1,26 @@
+// file : odb/tracer/transaction.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/tracer/transaction.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ transaction& transaction::
+ current ()
+ {
+ // While the impl type can be of the concrete type, the transaction
+ // object can be created as either odb:: or odb::tracer:: type. To
+ // work around that we are going to hard-cast one two the other
+ // relying on the fact that they have the same representation and
+ // no virtual functions. The former is checked in the tests.
+ //
+ odb::transaction& b (odb::transaction::current ());
+ dynamic_cast<transaction_impl&> (b.implementation ());
+ return reinterpret_cast<transaction&> (b);
+ }
+ }
+}
diff --git a/odb/tracer/transaction.hxx b/odb/tracer/transaction.hxx
new file mode 100644
index 0000000..2bcfa07
--- /dev/null
+++ b/odb/tracer/transaction.hxx
@@ -0,0 +1,46 @@
+// file : odb/tracer/transaction.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TRACER_TRANSACTION_HXX
+#define ODB_TRACER_TRANSACTION_HXX
+
+#include <odb/transaction.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ class database;
+ class transaction_impl;
+
+ class transaction: public odb::transaction
+ {
+ public:
+ typedef odb::database database_type;
+
+ explicit
+ transaction (transaction_impl*);
+
+ // Return the database this transaction is on.
+ //
+ database_type&
+ database ();
+
+ // Return current transaction or throw if there is no transaction
+ // in effect.
+ //
+ static transaction&
+ current ();
+
+ public:
+ transaction_impl&
+ implementation ();
+ };
+ }
+}
+
+#include <odb/tracer/transaction.ixx>
+
+#endif // ODB_TRACER_TRANSACTION_HXX
diff --git a/odb/tracer/transaction.ixx b/odb/tracer/transaction.ixx
new file mode 100644
index 0000000..35a2d78
--- /dev/null
+++ b/odb/tracer/transaction.ixx
@@ -0,0 +1,35 @@
+// file : odb/tracer/transaction.ixx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/tracer/database.hxx>
+#include <odb/tracer/transaction-impl.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ inline transaction::
+ transaction (transaction_impl* impl)
+ : odb::transaction (impl)
+ {
+ }
+
+ inline transaction::database_type& transaction::
+ database ()
+ {
+ return static_cast<database_type&> (odb::transaction::database ());
+ }
+
+ inline transaction_impl& transaction::
+ implementation ()
+ {
+ // We can use static_cast here since we have an instance of
+ // tracer::transaction.
+ //
+ return static_cast<transaction_impl&> (
+ odb::transaction::implementation ());
+ }
+ }
+}