aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/simple-object-statements.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/pgsql/simple-object-statements.hxx')
-rw-r--r--odb/pgsql/simple-object-statements.hxx112
1 files changed, 73 insertions, 39 deletions
diff --git a/odb/pgsql/simple-object-statements.hxx b/odb/pgsql/simple-object-statements.hxx
index f7e3949..5840c26 100644
--- a/odb/pgsql/simple-object-statements.hxx
+++ b/odb/pgsql/simple-object-statements.hxx
@@ -29,60 +29,70 @@ namespace odb
{
namespace pgsql
{
- // The container_statement_cache class is only defined (and used) in
+ // The extra_statement_cache class is only defined (and used) in
// the generated source file. However, object_statements may be
// referenced from another source file in the case of a polymorphic
- // hierarchy (though in this case the container statement cache is
+ // hierarchy (though in this case the extra statement cache is
// not used). As a result, we cannot have a by-value member and
// instead will store a pointer and lazily allocate the cache if
// and when needed. We will also need to store a pointer to the
// deleter function which will be initialized during allocation
// (at that point we know that the cache class is defined).
//
- template <typename T>
- struct container_statement_cache_ptr
+ template <typename T, typename I>
+ struct extra_statement_cache_ptr
{
+ typedef I image_type;
typedef pgsql::connection connection_type;
- container_statement_cache_ptr (): p_ (0) {}
- ~container_statement_cache_ptr ()
+ extra_statement_cache_ptr (): p_ (0) {}
+ ~extra_statement_cache_ptr ()
{
if (p_ != 0)
- (this->*deleter_) (0, 0, 0, 0);
+ (this->*deleter_) (0, 0, 0, 0, 0, 0);
}
T&
get (connection_type& c,
- binding& id, native_binding& idn, const Oid* idt)
+ image_type& im,
+ binding& id,
+ binding* idv,
+ native_binding& idn,
+ const Oid* idt)
{
if (p_ == 0)
- allocate (&c, &id, &idn, idt);
+ allocate (&c, &im, &id, (idv != 0 ? idv : &id), &idn, idt);
return *p_;
}
private:
void
- allocate (connection_type*, binding*, native_binding*, const Oid*);
+ allocate (connection_type*,
+ image_type*,
+ binding*, binding*, native_binding*, const Oid*);
private:
T* p_;
- void (container_statement_cache_ptr::*deleter_) (
- connection_type*, binding*, native_binding*, const Oid*);
+ void (extra_statement_cache_ptr::*deleter_) (
+ connection_type*,
+ image_type*,
+ binding*, binding*, native_binding*, const Oid*);
};
- template <typename T>
- void container_statement_cache_ptr<T>::
+ template <typename T, typename I>
+ void extra_statement_cache_ptr<T, I>::
allocate (connection_type* c,
- binding* id, native_binding* idn, const Oid* idt)
+ image_type* im,
+ binding* id, binding* idv, native_binding* idn, const Oid* idt)
{
// To reduce object code size, this function acts as both allocator
// and deleter.
//
if (p_ == 0)
{
- p_ = new T (*c, *id, *idn, idt);
- deleter_ = &container_statement_cache_ptr<T>::allocate;
+ p_ = new T (*c, *im, *id, *idv, *idn, idt);
+ deleter_ = &extra_statement_cache_ptr<T, I>::allocate;
}
else
delete p_;
@@ -158,9 +168,18 @@ namespace odb
optimistic_data (bind*, char** nv, int* nl, int* nf);
+ binding*
+ id_image_binding () {return &id_image_binding_;}
+
+ native_binding*
+ id_image_native_binding () {return &id_image_native_binding_;}
+
+ const Oid*
+ id_image_types ()
+ {return object_traits::optimistic_erase_statement_types;}
+
// The id + optimistic column binding.
//
- std::size_t id_image_version_;
binding id_image_binding_;
native_binding id_image_native_binding_;
@@ -171,6 +190,15 @@ namespace odb
struct optimistic_data<T, false>
{
optimistic_data (bind*, char**, int*, int*) {}
+
+ binding*
+ id_image_binding () {return 0;}
+
+ native_binding*
+ id_image_native_binding () {return 0;}
+
+ const Oid*
+ id_image_types () {return 0;}
};
template <typename T>
@@ -189,8 +217,8 @@ namespace odb
pointer_cache_traits;
typedef
- typename object_traits::container_statement_cache_type
- container_statement_cache_type;
+ typename object_traits::extra_statement_cache_type
+ extra_statement_cache_type;
typedef pgsql::insert_statement insert_statement_type;
typedef pgsql::select_statement select_statement_type;
@@ -329,14 +357,10 @@ namespace odb
binding&
id_image_binding () {return id_image_binding_;}
- // Optimistic id + managed column image binding.
+ // Optimistic id + managed column image binding. It points to
+ // the same suffix as id binding and they are always updated
+ // at the same time.
//
- std::size_t
- optimistic_id_image_version () const {return od_.id_image_version_;}
-
- void
- optimistic_id_image_version (std::size_t v) {od_.id_image_version_ = v;}
-
binding&
optimistic_id_image_binding () {return od_.id_image_binding_;}
@@ -434,37 +458,44 @@ namespace odb
return *od_.erase_;
}
- // Container statement cache.
+ // Extra (container, section) statement cache.
//
- container_statement_cache_type&
- container_statment_cache ()
+ extra_statement_cache_type&
+ extra_statement_cache ()
{
- return container_statement_cache_.get (
+ return extra_statement_cache_.get (
conn_,
+ image_,
id_image_binding_,
+ od_.id_image_binding (),
id_image_native_binding_,
object_traits::find_statement_types);
}
public:
- // select = total
+ // select = total - separate_load
// insert = total - inverse - managed_optimistic - auto_id
- // update = total - inverse - managed_optimistic - id - readonly
+ // update = total - inverse - managed_optimistic - id - readonly -
+ // separate_update
//
static const std::size_t select_column_count =
- object_traits::column_count;
+ object_traits::column_count -
+ object_traits::separate_load_column_count;
static const std::size_t id_column_count =
object_traits::id_column_count;
static const std::size_t insert_column_count =
- object_traits::column_count - object_traits::inverse_column_count -
+ object_traits::column_count -
+ object_traits::inverse_column_count -
object_traits::managed_optimistic_column_count -
(object_traits::auto_id ? id_column_count : 0);
- static const std::size_t update_column_count = insert_column_count -
+ static const std::size_t update_column_count =
+ insert_column_count -
(object_traits::auto_id ? 0 : id_column_count) -
- object_traits::readonly_column_count;
+ object_traits::readonly_column_count -
+ object_traits::separate_update_column_count;
static const std::size_t managed_optimistic_column_count =
object_traits::managed_optimistic_column_count;
@@ -481,8 +512,11 @@ namespace odb
clear_delayed_ ();
protected:
- container_statement_cache_ptr<container_statement_cache_type>
- container_statement_cache_;
+ template <typename T1>
+ friend class polymorphic_derived_object_statements;
+
+ extra_statement_cache_ptr<extra_statement_cache_type, image_type>
+ extra_statement_cache_;
image_type image_;