aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-28 10:51:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-28 10:51:12 +0200
commite28fe11ef1a582f14261e063f162e6088a6816a0 (patch)
tree84bc636d15d722f134f5c76cec7429d34e1f4c18
parent2159b67ef61613b365deabcfbb7f224438612a54 (diff)
Make schema version access (but not modification) thread-safe
Also cache the version in statements so that we don't have to lock the mutex (slow) every time we need to check the version.
-rw-r--r--odb/oracle/section-statements.hxx13
-rw-r--r--odb/oracle/section-statements.txx1
-rw-r--r--odb/oracle/statements-base.hxx24
3 files changed, 33 insertions, 5 deletions
diff --git a/odb/oracle/section-statements.hxx b/odb/oracle/section-statements.hxx
index 47e3bb7..ac8672a 100644
--- a/odb/oracle/section-statements.hxx
+++ b/odb/oracle/section-statements.hxx
@@ -10,12 +10,15 @@
#include <cstddef> // std::size_t
#include <odb/forward.hxx>
+#include <odb/schema-version.hxx>
#include <odb/traits.hxx>
#include <odb/oracle/version.hxx>
#include <odb/oracle/oracle-types.hxx>
#include <odb/oracle/binding.hxx>
#include <odb/oracle/statement.hxx>
+#include <odb/oracle/connection.hxx>
+#include <odb/oracle/database.hxx>
#include <odb/oracle/details/export.hxx>
namespace odb
@@ -46,6 +49,15 @@ namespace odb
connection_type&
connection () {return conn_;}
+ const schema_version_migration&
+ version_migration (const char* name = "") const
+ {
+ if (svm_ == 0)
+ svm_ = &conn_.database ().schema_version_migration (name);
+
+ return *svm_;
+ }
+
image_type&
image () {return image_;}
@@ -136,6 +148,7 @@ namespace odb
protected:
connection_type& conn_;
+ mutable const schema_version_migration* svm_;
// These come from object_statements.
//
diff --git a/odb/oracle/section-statements.txx b/odb/oracle/section-statements.txx
index a393d80..a56b3ba 100644
--- a/odb/oracle/section-statements.txx
+++ b/odb/oracle/section-statements.txx
@@ -14,6 +14,7 @@ namespace odb
image_type& im,
binding& id, binding& idv)
: conn_ (conn),
+ svm_ (0),
image_ (im),
id_binding_ (id),
idv_binding_ (idv),
diff --git a/odb/oracle/statements-base.hxx b/odb/oracle/statements-base.hxx
index c7227bf..b4cad98 100644
--- a/odb/oracle/statements-base.hxx
+++ b/odb/oracle/statements-base.hxx
@@ -7,10 +7,12 @@
#include <odb/pre.hxx>
+#include <odb/schema-version.hxx>
#include <odb/details/shared-ptr.hxx>
#include <odb/oracle/version.hxx>
-#include <odb/oracle/forward.hxx> // connection
+#include <odb/oracle/connection.hxx>
+#include <odb/oracle/database.hxx>
#include <odb/oracle/details/export.hxx>
@@ -29,18 +31,30 @@ namespace odb
return conn_;
}
+ // Schema version. database::schema_version_migration() is thread-
+ // safe which means it is also slow. Cache the result in statements
+ // so we can avoid the mutex lock. This is thread-safe since if the
+ // version is updated, then the statements cache will be expired.
+ //
+ const schema_version_migration&
+ version_migration (const char* name = "") const
+ {
+ if (svm_ == 0)
+ svm_ = &conn_.database ().schema_version_migration (name);
+
+ return *svm_;
+ }
+
public:
virtual
~statements_base ();
protected:
- statements_base (connection_type& conn)
- : conn_ (conn)
- {
- }
+ statements_base (connection_type& conn): conn_ (conn), svm_ (0) {}
protected:
connection_type& conn_;
+ mutable const schema_version_migration* svm_;
};
}
}