aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-27 15:16:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-27 15:16:49 +0200
commitc9fa9d93a0db446eb8a85d62b106bff5e045ff28 (patch)
tree37b5f1ad7e814c3002211664a2334fea7d9d4213
parentb2d84383f0bdc81e690e53c700ec8c5fe8cd84e1 (diff)
Add support for persistent classes without object ids
New pragma id (object). New test: common/no-id.
-rw-r--r--odb/oracle/forward.hxx6
-rw-r--r--odb/oracle/object-result.hxx51
-rw-r--r--odb/oracle/object-result.txx94
-rw-r--r--odb/oracle/object-statements.hxx121
-rw-r--r--odb/oracle/object-statements.txx29
-rw-r--r--odb/oracle/result.hxx9
-rw-r--r--odb/oracle/statement-cache.hxx10
-rw-r--r--odb/oracle/view-result.hxx12
-rw-r--r--odb/oracle/view-result.txx20
9 files changed, 304 insertions, 48 deletions
diff --git a/odb/oracle/forward.hxx b/odb/oracle/forward.hxx
index c4fb40b..ae45ed4 100644
--- a/odb/oracle/forward.hxx
+++ b/odb/oracle/forward.hxx
@@ -37,6 +37,12 @@ namespace odb
class object_statements;
template <typename T>
+ class object_statements_no_id;
+
+ template <typename T>
+ class view_statements;
+
+ template <typename T>
class container_statements;
}
diff --git a/odb/oracle/object-result.hxx b/odb/oracle/object-result.hxx
index aa20615..5e23978 100644
--- a/odb/oracle/object-result.hxx
+++ b/odb/oracle/object-result.hxx
@@ -22,11 +22,10 @@ namespace odb
namespace oracle
{
template <typename T>
- class result_impl<T, class_object>:
- public odb::result_impl<T, class_object>
+ class object_result_impl: public odb::object_result_impl<T>
{
public:
- typedef odb::result_impl<T, class_object> base_type;
+ typedef odb::object_result_impl<T> base_type;
typedef typename base_type::object_type object_type;
typedef typename base_type::object_traits object_traits;
@@ -36,11 +35,11 @@ namespace odb
typedef typename base_type::pointer_traits pointer_traits;
virtual
- ~result_impl ();
+ ~object_result_impl ();
- result_impl (const query&,
- details::shared_ptr<select_statement>,
- object_statements<object_type>&);
+ object_result_impl (const query&,
+ details::shared_ptr<select_statement>,
+ object_statements<object_type>&);
virtual void
load (object_type&);
@@ -63,6 +62,44 @@ namespace odb
details::shared_ptr<select_statement> statement_;
object_statements<object_type>& statements_;
};
+
+ template <typename T>
+ class object_result_impl_no_id: public odb::object_result_impl_no_id<T>
+ {
+ public:
+ typedef odb::object_result_impl_no_id<T> base_type;
+
+ typedef typename base_type::object_type object_type;
+ typedef typename base_type::object_traits object_traits;
+
+ typedef typename base_type::pointer_type pointer_type;
+ typedef typename base_type::pointer_traits pointer_traits;
+
+ virtual
+ ~object_result_impl_no_id ();
+
+ object_result_impl_no_id (const query&,
+ details::shared_ptr<select_statement>,
+ object_statements_no_id<object_type>&);
+
+ virtual void
+ load (object_type&);
+
+ virtual void
+ next ();
+
+ virtual void
+ cache ();
+
+ virtual std::size_t
+ size ();
+
+ using base_type::current;
+
+ private:
+ details::shared_ptr<select_statement> statement_;
+ object_statements_no_id<object_type>& statements_;
+ };
}
}
diff --git a/odb/oracle/object-result.txx b/odb/oracle/object-result.txx
index 5048601..e3eeca4 100644
--- a/odb/oracle/object-result.txx
+++ b/odb/oracle/object-result.txx
@@ -12,17 +12,21 @@ namespace odb
{
namespace oracle
{
+ //
+ // object_result_impl
+ //
+
template <typename T>
- result_impl<T, class_object>::
- ~result_impl ()
+ object_result_impl<T>::
+ ~object_result_impl ()
{
}
template <typename T>
- result_impl<T, class_object>::
- result_impl (const query&,
- details::shared_ptr<select_statement> statement,
- object_statements<object_type>& statements)
+ object_result_impl<T>::
+ object_result_impl (const query&,
+ details::shared_ptr<select_statement> statement,
+ object_statements<object_type>& statements)
: base_type (statements.connection ().database ()),
statement_ (statement),
statements_ (statements)
@@ -30,7 +34,7 @@ namespace odb
}
template <typename T>
- void result_impl<T, class_object>::
+ void object_result_impl<T>::
load (object_type& obj)
{
// This is a top-level call so the statements cannot be locked.
@@ -66,15 +70,81 @@ namespace odb
}
template <typename T>
- typename result_impl<T, class_object>::id_type
- result_impl<T, class_object>::
+ typename object_result_impl<T>::id_type
+ object_result_impl<T>::
load_id ()
{
return object_traits::id (statements_.image ());
}
template <typename T>
- void result_impl<T, class_object>::
+ void object_result_impl<T>::
+ next ()
+ {
+ this->current (pointer_type ());
+
+ typename object_traits::image_type& im (statements_.image ());
+
+ if (im.version != statements_.select_image_version ())
+ {
+ binding& b (statements_.select_image_binding ());
+ object_traits::bind (b.bind, im, statement_select);
+ statements_.select_image_version (im.version);
+ b.version++;
+ }
+
+ if (statement_->fetch () == select_statement::no_data)
+ this->end_ = true;
+ }
+
+ template <typename T>
+ void object_result_impl<T>::
+ cache ()
+ {
+ }
+
+ template <typename T>
+ std::size_t object_result_impl<T>::
+ size ()
+ {
+ throw result_not_cached ();
+ }
+
+ //
+ // object_result_impl_no_id
+ //
+
+ template <typename T>
+ object_result_impl_no_id<T>::
+ ~object_result_impl_no_id ()
+ {
+ }
+
+ template <typename T>
+ object_result_impl_no_id<T>::
+ object_result_impl_no_id (const query&,
+ details::shared_ptr<select_statement> statement,
+ object_statements_no_id<object_type>& statements)
+ : base_type (statements.connection ().database ()),
+ statement_ (statement),
+ statements_ (statements)
+ {
+ }
+
+ template <typename T>
+ void object_result_impl_no_id<T>::
+ load (object_type& obj)
+ {
+ odb::database& db (this->database ());
+
+ object_traits::callback (db, obj, callback_event::pre_load);
+ object_traits::init (obj, statements_.image (), db);
+ statement_->stream_result ();
+ object_traits::callback (db, obj, callback_event::post_load);
+ }
+
+ template <typename T>
+ void object_result_impl_no_id<T>::
next ()
{
this->current (pointer_type ());
@@ -94,13 +164,13 @@ namespace odb
}
template <typename T>
- void result_impl<T, class_object>::
+ void object_result_impl_no_id<T>::
cache ()
{
}
template <typename T>
- std::size_t result_impl<T, class_object>::
+ std::size_t object_result_impl_no_id<T>::
size ()
{
throw result_not_cached ();
diff --git a/odb/oracle/object-statements.hxx b/odb/oracle/object-statements.hxx
index cc10d54..807bb1e 100644
--- a/odb/oracle/object-statements.hxx
+++ b/odb/oracle/object-statements.hxx
@@ -30,6 +30,28 @@ namespace odb
{
namespace oracle
{
+ template <typename T>
+ class object_statements;
+
+ template <typename T>
+ class object_statements_no_id;
+
+ template <typename T, typename ID = typename object_traits<T>::id_type>
+ struct object_statements_selector
+ {
+ typedef object_statements<T> type;
+ };
+
+ template <typename T>
+ struct object_statements_selector<T, void>
+ {
+ typedef object_statements_no_id<T> type;
+ };
+
+ //
+ // Implementation for objects with object id.
+ //
+
class LIBODB_ORACLE_EXPORT object_statements_base: public statements_base
{
// Locking.
@@ -401,6 +423,105 @@ namespace odb
delayed_loads& dl_;
};
};
+
+ //
+ // Implementation for objects without object id.
+ //
+
+ template <typename T>
+ class object_statements_no_id: public statements_base
+ {
+ public:
+ typedef T object_type;
+ typedef odb::object_traits<object_type> object_traits;
+ typedef typename object_traits::pointer_type pointer_type;
+ typedef typename object_traits::image_type image_type;
+
+ typedef oracle::insert_statement insert_statement_type;
+
+ public:
+ object_statements_no_id (connection_type&);
+
+ virtual
+ ~object_statements_no_id ();
+
+ // Object image.
+ //
+ image_type&
+ image ()
+ {
+ return image_;
+ }
+
+ // Insert binding.
+ //
+ std::size_t
+ insert_image_version () const { return insert_image_version_;}
+
+ void
+ insert_image_version (std::size_t v) {insert_image_version_ = v;}
+
+ binding&
+ insert_image_binding () {return insert_image_binding_;}
+
+ // Select binding (needed for query support).
+ //
+ std::size_t
+ select_image_version () const { return select_image_version_;}
+
+ void
+ select_image_version (std::size_t v) {select_image_version_ = v;}
+
+ binding&
+ select_image_binding () {return select_image_binding_;}
+
+ // Statements.
+ //
+ insert_statement_type&
+ persist_statement ()
+ {
+ if (persist_ == 0)
+ persist_.reset (
+ new (details::shared) insert_statement_type (
+ conn_,
+ object_traits::persist_statement,
+ insert_image_binding_,
+ false));
+
+ return *persist_;
+ }
+
+ private:
+ object_statements_no_id (const object_statements_no_id&);
+ object_statements_no_id& operator= (const object_statements_no_id&);
+
+ private:
+ // select = total
+ // insert = total - inverse; inverse == 0 for object without id
+ //
+ static const std::size_t insert_column_count =
+ object_traits::column_count;
+
+ static const std::size_t select_column_count =
+ object_traits::column_count;
+
+ private:
+ image_type image_;
+
+ // Select binding.
+ //
+ std::size_t select_image_version_;
+ binding select_image_binding_;
+ bind select_image_bind_[select_column_count];
+
+ // Insert binding.
+ //
+ std::size_t insert_image_version_;
+ binding insert_image_binding_;
+ bind insert_image_bind_[insert_column_count];
+
+ details::shared_ptr<insert_statement_type> persist_;
+ };
}
}
diff --git a/odb/oracle/object-statements.txx b/odb/oracle/object-statements.txx
index 5fb186a..037d82c 100644
--- a/odb/oracle/object-statements.txx
+++ b/odb/oracle/object-statements.txx
@@ -16,6 +16,10 @@ namespace odb
{
namespace oracle
{
+ //
+ // object_statements
+ //
+
template <typename T>
object_statements<T>::
~object_statements ()
@@ -111,5 +115,30 @@ namespace odb
delayed_.clear ();
}
+
+ //
+ // object_statements_no_id
+ //
+
+ template <typename T>
+ object_statements_no_id<T>::
+ ~object_statements_no_id ()
+ {
+ }
+
+ template <typename T>
+ object_statements_no_id<T>::
+ object_statements_no_id (connection_type& conn)
+ : statements_base (conn),
+ select_image_binding_ (select_image_bind_, select_column_count),
+ insert_image_binding_ (insert_image_bind_, insert_column_count)
+ {
+ image_.version = 0;
+ select_image_version_ = 0;
+ insert_image_version_ = 0;
+
+ std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_));
+ std::memset (select_image_bind_, 0, sizeof (select_image_bind_));
+ }
}
}
diff --git a/odb/oracle/result.hxx b/odb/oracle/result.hxx
index 88b6aaa..df6ff5e 100644
--- a/odb/oracle/result.hxx
+++ b/odb/oracle/result.hxx
@@ -14,15 +14,6 @@
#include <odb/oracle/version.hxx>
#include <odb/oracle/forward.hxx>
-namespace odb
-{
- namespace oracle
- {
- template <typename T, class_kind kind>
- class result_impl;
- }
-}
-
#include <odb/post.hxx>
#endif // ODB_ORACLE_RESULT_HXX
diff --git a/odb/oracle/statement-cache.hxx b/odb/oracle/statement-cache.hxx
index 92254b1..7480eb2 100644
--- a/odb/oracle/statement-cache.hxx
+++ b/odb/oracle/statement-cache.hxx
@@ -38,16 +38,18 @@ namespace odb
}
template <typename T>
- object_statements<T>&
+ typename object_statements_selector<T>::type&
find_object ()
{
+ typedef typename object_statements_selector<T>::type object_statements;
+
map::iterator i (map_.find (&typeid (T)));
if (i != map_.end ())
- return static_cast<object_statements<T>&> (*i->second);
+ return static_cast<object_statements&> (*i->second);
- details::shared_ptr<object_statements<T> > p (
- new (details::shared) object_statements<T> (conn_));
+ details::shared_ptr<object_statements> p (
+ new (details::shared) object_statements (conn_));
map_.insert (map::value_type (&typeid (T), p));
return *p;
diff --git a/odb/oracle/view-result.hxx b/odb/oracle/view-result.hxx
index abc0aff..ec70194 100644
--- a/odb/oracle/view-result.hxx
+++ b/odb/oracle/view-result.hxx
@@ -22,10 +22,10 @@ namespace odb
namespace oracle
{
template <typename T>
- class result_impl<T, class_view>: public odb::result_impl<T, class_view>
+ class view_result_impl: public odb::view_result_impl<T>
{
public:
- typedef odb::result_impl<T, class_view> base_type;
+ typedef odb::view_result_impl<T> base_type;
typedef typename base_type::view_type view_type;
typedef typename base_type::view_traits view_traits;
@@ -34,11 +34,11 @@ namespace odb
typedef typename base_type::pointer_traits pointer_traits;
virtual
- ~result_impl ();
+ ~view_result_impl ();
- result_impl (const query&,
- details::shared_ptr<select_statement>,
- view_statements<view_type>&);
+ view_result_impl (const query&,
+ details::shared_ptr<select_statement>,
+ view_statements<view_type>&);
virtual void
load (view_type&);
diff --git a/odb/oracle/view-result.txx b/odb/oracle/view-result.txx
index e29f533..8f2262b 100644
--- a/odb/oracle/view-result.txx
+++ b/odb/oracle/view-result.txx
@@ -13,16 +13,16 @@ namespace odb
namespace oracle
{
template <typename T>
- result_impl<T, class_view>::
- ~result_impl ()
+ view_result_impl<T>::
+ ~view_result_impl ()
{
}
template <typename T>
- result_impl<T, class_view>::
- result_impl (const query&,
- details::shared_ptr<select_statement> statement,
- view_statements<view_type>& statements)
+ view_result_impl<T>::
+ view_result_impl (const query&,
+ details::shared_ptr<select_statement> statement,
+ view_statements<view_type>& statements)
: base_type (statements.connection ().database ()),
statement_ (statement),
statements_ (statements)
@@ -30,7 +30,7 @@ namespace odb
}
template <typename T>
- void result_impl<T, class_view>::
+ void view_result_impl<T>::
load (view_type& view)
{
odb::database& db (this->database ());
@@ -42,7 +42,7 @@ namespace odb
}
template <typename T>
- void result_impl<T, class_view>::
+ void view_result_impl<T>::
next ()
{
this->current (pointer_type ());
@@ -62,13 +62,13 @@ namespace odb
}
template <typename T>
- void result_impl<T, class_view>::
+ void view_result_impl<T>::
cache ()
{
}
template <typename T>
- std::size_t result_impl<T, class_view>::
+ std::size_t view_result_impl<T>::
size ()
{
throw result_not_cached ();