aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/tracer/connection.cxx37
-rw-r--r--odb/tracer/connection.hxx44
-rw-r--r--odb/tracer/database.cxx25
-rw-r--r--odb/tracer/database.hxx17
-rw-r--r--odb/tracer/forward.hxx35
-rw-r--r--odb/tracer/makefile7
-rw-r--r--odb/tracer/transaction-impl.cxx7
-rw-r--r--odb/tracer/transaction-impl.hxx10
8 files changed, 160 insertions, 22 deletions
diff --git a/odb/tracer/connection.cxx b/odb/tracer/connection.cxx
new file mode 100644
index 0000000..516e36a
--- /dev/null
+++ b/odb/tracer/connection.cxx
@@ -0,0 +1,37 @@
+// file : odb/tracer/connection.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/transaction.hxx>
+
+#include <odb/tracer/database.hxx>
+#include <odb/tracer/connection.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ connection::
+ connection (database_type& db)
+ : odb::connection (db)
+ {
+ }
+
+ unsigned long long connection::
+ execute (const char*, std::size_t)
+ {
+ return 0;
+ }
+
+ transaction_impl* connection::
+ begin ()
+ {
+ if (odb::transaction::has_current ())
+ throw already_in_transaction ();
+
+ return new transaction_impl (
+ connection_ptr (inc_ref (this)));
+ }
+ }
+}
diff --git a/odb/tracer/connection.hxx b/odb/tracer/connection.hxx
new file mode 100644
index 0000000..743bf92
--- /dev/null
+++ b/odb/tracer/connection.hxx
@@ -0,0 +1,44 @@
+// file : odb/tracer/connection.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TRACER_CONNECTION_HXX
+#define ODB_TRACER_CONNECTION_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/connection.hxx>
+#include <odb/details/shared-ptr.hxx>
+
+#include <odb/tracer/transaction-impl.hxx>
+#include <odb/tracer/details/export.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ class database;
+
+ class connection;
+ typedef details::shared_ptr<connection> connection_ptr;
+
+ class LIBODB_TRACER_EXPORT connection: public odb::connection
+ {
+ public:
+ typedef tracer::database database_type;
+
+ connection (database_type&);
+
+ virtual unsigned long long
+ execute (const char* statement, std::size_t length);
+
+ virtual transaction_impl*
+ begin ();
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_TRACER_CONNECTION_HXX
diff --git a/odb/tracer/database.cxx b/odb/tracer/database.cxx
index 1359a26..90cfdfd 100644
--- a/odb/tracer/database.cxx
+++ b/odb/tracer/database.cxx
@@ -3,8 +3,8 @@
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-#include <odb/transaction.hxx>
#include <odb/tracer/database.hxx>
+#include <odb/tracer/connection.hxx>
namespace odb
{
@@ -15,19 +15,26 @@ namespace odb
{
}
- unsigned long long database::
- execute (const char*, std::size_t)
+ transaction_impl* database::
+ begin ()
{
- return 0;
+ return connection ()->begin ();
}
- transaction_impl* database::
- begin ()
+ inline connection_ptr database::
+ connection ()
{
- if (odb::transaction::has_current ())
- throw already_in_transaction ();
+ // Go through the virtual connection_() function instead of
+ // directly to allow overriding.
+ //
+ return connection_ptr (
+ static_cast<tracer::connection*> (connection_ ()));
+ }
- return new transaction_impl (*this);
+ odb::connection* database::
+ connection_ ()
+ {
+ return new (details::shared) connection_type (*this);
}
}
}
diff --git a/odb/tracer/database.hxx b/odb/tracer/database.hxx
index 7210681..2468583 100644
--- a/odb/tracer/database.hxx
+++ b/odb/tracer/database.hxx
@@ -9,8 +9,9 @@
#include <odb/pre.hxx>
#include <odb/database.hxx>
-#include <odb/tracer/transaction-impl.hxx>
+#include <odb/tracer/connection.hxx>
+#include <odb/tracer/transaction-impl.hxx>
#include <odb/tracer/details/export.hxx>
namespace odb
@@ -20,14 +21,20 @@ namespace odb
class LIBODB_TRACER_EXPORT database: public odb::database
{
public:
+ typedef tracer::connection connection_type;
+
virtual
~database ();
- virtual unsigned long long
- execute (const char* statement, std::size_t length);
-
- virtual transaction_impl*
+ transaction_impl*
begin ();
+
+ connection_ptr
+ connection ();
+
+ protected:
+ virtual odb::connection*
+ connection_ ();
};
}
}
diff --git a/odb/tracer/forward.hxx b/odb/tracer/forward.hxx
new file mode 100644
index 0000000..61f0eb7
--- /dev/null
+++ b/odb/tracer/forward.hxx
@@ -0,0 +1,35 @@
+// file : odb/tracer/forward.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TRACER_FORWARD_HXX
+#define ODB_TRACER_FORWARD_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/forward.hxx>
+
+namespace odb
+{
+ namespace tracer
+ {
+ class database;
+ class connection;
+ typedef details::shared_ptr<connection> connection_ptr;
+ class transaction;
+ }
+
+ namespace details
+ {
+ template <>
+ struct counter_type<tracer::connection>
+ {
+ typedef shared_base counter;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_TRACER_FORWARD_HXX
diff --git a/odb/tracer/makefile b/odb/tracer/makefile
index d7b4611..335e681 100644
--- a/odb/tracer/makefile
+++ b/odb/tracer/makefile
@@ -5,7 +5,12 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
-cxx := exceptions.cxx database.cxx transaction.cxx transaction-impl.cxx
+cxx := \
+exceptions.cxx \
+database.cxx \
+connection.cxx \
+transaction.cxx \
+transaction-impl.cxx
cxx_tun := $(cxx)
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
diff --git a/odb/tracer/transaction-impl.cxx b/odb/tracer/transaction-impl.cxx
index f8b90af..2069568 100644
--- a/odb/tracer/transaction-impl.cxx
+++ b/odb/tracer/transaction-impl.cxx
@@ -6,6 +6,7 @@
#include <iostream>
#include <odb/tracer/database.hxx>
+#include <odb/tracer/connection.hxx>
#include <odb/tracer/transaction-impl.hxx>
using std::cout;
@@ -16,8 +17,10 @@ namespace odb
namespace tracer
{
transaction_impl::
- transaction_impl (database_type& db)
- : odb::transaction_impl (db), finalized_ (false)
+ transaction_impl (connection_ptr c)
+ : odb::transaction_impl (c->database (), *c),
+ finalized_ (false),
+ connection_ (c)
{
cout << "begin transaction" << endl;
}
diff --git a/odb/tracer/transaction-impl.hxx b/odb/tracer/transaction-impl.hxx
index a4d2b40..f926183 100644
--- a/odb/tracer/transaction-impl.hxx
+++ b/odb/tracer/transaction-impl.hxx
@@ -9,25 +9,24 @@
#include <odb/pre.hxx>
#include <odb/transaction.hxx>
+#include <odb/details/shared-ptr.hxx>
+#include <odb/tracer/forward.hxx>
#include <odb/tracer/details/export.hxx>
namespace odb
{
namespace tracer
{
- class database;
- class transaction;
-
class LIBODB_TRACER_EXPORT transaction_impl: public odb::transaction_impl
{
protected:
- friend class database;
+ friend class connection;
friend class transaction;
typedef tracer::database database_type;
- transaction_impl (database_type&);
+ transaction_impl (connection_ptr);
virtual
~transaction_impl ();
@@ -40,6 +39,7 @@ namespace odb
private:
bool finalized_;
+ connection_ptr connection_;
};
}
}