diff options
-rw-r--r-- | odb/pgsql/section-statements.hxx | 13 | ||||
-rw-r--r-- | odb/pgsql/section-statements.txx | 1 | ||||
-rw-r--r-- | odb/pgsql/statements-base.hxx | 24 |
3 files changed, 33 insertions, 5 deletions
diff --git a/odb/pgsql/section-statements.hxx b/odb/pgsql/section-statements.hxx index d75fd66..e7dcd9e 100644 --- a/odb/pgsql/section-statements.hxx +++ b/odb/pgsql/section-statements.hxx @@ -10,11 +10,14 @@ #include <cstddef> // std::size_t #include <odb/forward.hxx> +#include <odb/schema-version.hxx> #include <odb/traits.hxx> #include <odb/pgsql/version.hxx> #include <odb/pgsql/binding.hxx> #include <odb/pgsql/statement.hxx> +#include <odb/pgsql/connection.hxx> +#include <odb/pgsql/database.hxx> #include <odb/pgsql/pgsql-fwd.hxx> // Oid #include <odb/pgsql/details/export.hxx> @@ -49,6 +52,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_;} @@ -152,6 +164,7 @@ namespace odb protected: connection_type& conn_; + mutable const schema_version_migration* svm_; // These come from object_statements. // diff --git a/odb/pgsql/section-statements.txx b/odb/pgsql/section-statements.txx index d4463d1..592db7b 100644 --- a/odb/pgsql/section-statements.txx +++ b/odb/pgsql/section-statements.txx @@ -17,6 +17,7 @@ namespace odb native_binding& idn, const Oid* idt) : conn_ (conn), + svm_ (0), image_ (im), id_binding_ (id), idv_binding_ (idv), diff --git a/odb/pgsql/statements-base.hxx b/odb/pgsql/statements-base.hxx index 9647984..efb5753 100644 --- a/odb/pgsql/statements-base.hxx +++ b/odb/pgsql/statements-base.hxx @@ -7,10 +7,12 @@ #include <odb/pre.hxx> +#include <odb/schema-version.hxx> #include <odb/details/shared-ptr.hxx> #include <odb/pgsql/version.hxx> -#include <odb/pgsql/forward.hxx> // connection +#include <odb/pgsql/connection.hxx> +#include <odb/pgsql/database.hxx> #include <odb/pgsql/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_; }; } } |