aboutsummaryrefslogtreecommitdiff
path: root/bulk/oracle/auto/person-odb.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bulk/oracle/auto/person-odb.cxx')
-rw-r--r--bulk/oracle/auto/person-odb.cxx580
1 files changed, 580 insertions, 0 deletions
diff --git a/bulk/oracle/auto/person-odb.cxx b/bulk/oracle/auto/person-odb.cxx
new file mode 100644
index 0000000..360e1b9
--- /dev/null
+++ b/bulk/oracle/auto/person-odb.cxx
@@ -0,0 +1,580 @@
+// This file was generated by ODB, object-relational mapping (ORM)
+// compiler for C++.
+//
+
+#include <odb/pre.hxx>
+
+#include "person-odb.hxx"
+
+#include <cassert>
+#include <cstring> // std::memcpy
+#include <iostream>
+
+
+#include <odb/oracle/traits.hxx>
+#include <odb/oracle/database.hxx>
+#include <odb/oracle/transaction.hxx>
+#include <odb/oracle/connection.hxx>
+#include <odb/oracle/statement.hxx>
+#include <odb/oracle/statement-cache.hxx>
+#include <odb/oracle/simple-object-statements.hxx>
+#include <odb/oracle/container-statements.hxx>
+#include <odb/oracle/exceptions.hxx>
+
+namespace odb
+{
+ // person
+ //
+
+ struct access::object_traits_impl< ::person, id_oracle >::extra_statement_cache_type
+ {
+ extra_statement_cache_type (
+ oracle::connection&,
+ image_type&,
+ oracle::binding&,
+ oracle::binding&)
+ {
+ }
+ };
+
+ access::object_traits_impl< ::person, id_oracle >::id_type
+ access::object_traits_impl< ::person, id_oracle >::
+ id (const id_image_type& i)
+ {
+ oracle::database* db (0);
+ ODB_POTENTIALLY_UNUSED (db);
+
+ id_type id;
+ {
+ oracle::value_traits<
+ long unsigned int,
+ oracle::id_big_int >::set_value (
+ id,
+ i.id_value,
+ i.id_size,
+ i.id_indicator == -1);
+ }
+
+ return id;
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ bind (oracle::bind* b,
+ image_type& i,
+ oracle::statement_kind sk)
+ {
+ ODB_POTENTIALLY_UNUSED (sk);
+
+ using namespace oracle;
+
+ std::size_t n (0);
+
+ // id
+ //
+ if (sk != statement_insert && sk != statement_update)
+ {
+ b[n].type = oracle::bind::number;
+ b[n].buffer = i.id_value;
+ b[n].capacity = static_cast<ub4> (sizeof (i.id_value));
+ b[n].size = &i.id_size;
+ b[n].indicator = &i.id_indicator;
+ n++;
+ }
+
+ // num
+ //
+ b[n].type = oracle::bind::uinteger;
+ b[n].buffer = &i.num_value;
+ b[n].capacity = 4;
+ b[n].size = 0;
+ b[n].indicator = &i.num_indicator;
+ n++;
+
+ // str
+ //
+ b[n].type = oracle::bind::clob;
+ b[n].buffer = &i.str_lob;
+ b[n].indicator = &i.str_indicator;
+ b[n].callback = &i.str_callback;
+
+ n++;
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ bind (oracle::bind* b, id_image_type& i)
+ {
+ std::size_t n (0);
+ b[n].type = oracle::bind::number;
+ b[n].buffer = i.id_value;
+ b[n].capacity = static_cast<ub4> (sizeof (i.id_value));
+ b[n].size = &i.id_size;
+ b[n].indicator = &i.id_indicator;
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ init (image_type& i,
+ const object_type& o,
+ oracle::statement_kind sk)
+ {
+ ODB_POTENTIALLY_UNUSED (i);
+ ODB_POTENTIALLY_UNUSED (o);
+ ODB_POTENTIALLY_UNUSED (sk);
+
+ using namespace oracle;
+
+ // num
+ //
+ {
+ unsigned int const& v =
+ o.num;
+
+ bool is_null (false);
+ oracle::value_traits<
+ unsigned int,
+ oracle::id_int32 >::set_image (
+ i.num_value, is_null, v);
+ i.num_indicator = is_null ? -1 : 0;
+ }
+
+ // str
+ //
+ {
+ ::std::string const& v =
+ o.str;
+
+ bool is_null (false);
+ i.str_lob.position = 0;
+ oracle::value_traits<
+ ::std::string,
+ oracle::id_clob >::set_image (
+ i.str_callback.callback.param,
+ i.str_callback.context.param,
+ is_null,
+ v);
+ i.str_indicator = is_null ? -1 : 0;
+ }
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ init (object_type& o,
+ const image_type& i,
+ database* db)
+ {
+ ODB_POTENTIALLY_UNUSED (o);
+ ODB_POTENTIALLY_UNUSED (i);
+ ODB_POTENTIALLY_UNUSED (db);
+
+ // id
+ //
+ {
+ long unsigned int& v =
+ o.id;
+
+ oracle::value_traits<
+ long unsigned int,
+ oracle::id_big_int >::set_value (
+ v,
+ i.id_value,
+ i.id_size,
+ i.id_indicator == -1);
+ }
+
+ // num
+ //
+ {
+ unsigned int& v =
+ o.num;
+
+ oracle::value_traits<
+ unsigned int,
+ oracle::id_int32 >::set_value (
+ v,
+ i.num_value,
+ i.num_indicator == -1);
+ }
+
+ // str
+ //
+ {
+ ::std::string& v =
+ o.str;
+
+ oracle::value_traits<
+ ::std::string,
+ oracle::id_clob >::set_value (
+ v,
+ i.str_callback.callback.result,
+ i.str_callback.context.result,
+ i.str_indicator == -1);
+ }
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ init (id_image_type& i, const id_type& id)
+ {
+ {
+ bool is_null (false);
+ std::size_t size (0);
+ oracle::value_traits<
+ long unsigned int,
+ oracle::id_big_int >::set_image (
+ i.id_value,
+ size,
+ is_null,
+ id);
+ i.id_indicator = is_null ? -1 : 0;
+ i.id_size = static_cast<ub2> (size);
+ }
+ }
+
+ const char access::object_traits_impl< ::person, id_oracle >::persist_statement[] =
+ "INSERT INTO \"person\" "
+ "(\"id\", "
+ "\"num\", "
+ "\"str\") "
+ "VALUES "
+ "(\"person_seq\".nextval, :1, :2) "
+ "RETURNING \"id\" INTO :3";
+
+ const char access::object_traits_impl< ::person, id_oracle >::find_statement[] =
+ "SELECT "
+ "\"person\".\"id\", "
+ "\"person\".\"num\", "
+ "\"person\".\"str\" "
+ "FROM \"person\" "
+ "WHERE \"person\".\"id\"=:1";
+
+ const char access::object_traits_impl< ::person, id_oracle >::update_statement[] =
+ "UPDATE \"person\" "
+ "SET "
+ "\"num\"=:1, "
+ "\"str\"=:2 "
+ "WHERE \"id\"=:3";
+
+ const char access::object_traits_impl< ::person, id_oracle >::erase_statement[] =
+ "DELETE FROM \"person\" "
+ "WHERE \"id\"=:1";
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ persist (database& db, object_type** objs, std::size_t n,
+ multiple_exceptions* mex)
+ {
+ ODB_POTENTIALLY_UNUSED (db);
+ assert (n <= batch);
+
+ using namespace oracle;
+
+ oracle::connection& conn (
+ oracle::transaction::current ().connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ for (std::size_t i (0); i != n; ++i)
+ {
+ object_type& obj (*objs[i]);
+
+ callback (db,
+ static_cast<const object_type&> (obj),
+ callback_event::pre_persist);
+
+ init (sts.image (i), obj, statement_insert);
+ }
+
+ image_type& im (sts.image (0));
+ binding& imb (sts.insert_image_binding ());
+
+ if (im.version != sts.insert_image_version () ||
+ imb.version == 0)
+ {
+ bind (imb.bind, im, statement_insert);
+ sts.insert_image_version (im.version);
+ imb.version++;
+ }
+
+ // @@ TMP. Why tmp?
+ bind (sts.id_image_binding ().bind, sts.id_image ());
+
+ insert_statement& st (sts.persist_statement ());
+ n = st.execute (n, mex); // Set to actual number of rows attempted.
+
+ for (std::size_t i (0); i != n; ++i)
+ {
+ bool r (st.result (i)); // Sets current in mex.
+
+ if (mex != 0)
+ {
+ if ((*mex)[i] != 0) // Pending exception.
+ continue;
+
+ if (!r)
+ {
+ mex->insert (i, object_already_persistent ());
+ continue;
+ }
+
+ if (mex->fatal ()) // Don't do any extra work.
+ continue;
+ }
+ else if (!r)
+ throw object_already_persistent ();
+
+ object_type& obj (*objs[i]);
+
+ obj.id = id (sts.id_image (i));
+
+ callback (db,
+ static_cast<const object_type&> (obj),
+ callback_event::post_persist);
+ }
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ update (database& db, const object_type& obj)
+ {
+ ODB_POTENTIALLY_UNUSED (db);
+
+ using namespace oracle;
+ using oracle::update_statement;
+
+ callback (db, obj, callback_event::pre_update);
+
+ oracle::transaction& tr (oracle::transaction::current ());
+ oracle::connection& conn (tr.connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ const id_type& id (
+ obj.id);
+ id_image_type& idi (sts.id_image ());
+ init (idi, id);
+
+ image_type& im (sts.image ());
+ init (im, obj, statement_update);
+
+ bool u (false);
+ binding& imb (sts.update_image_binding ());
+ if (im.version != sts.update_image_version () ||
+ imb.version == 0)
+ {
+ bind (imb.bind, im, statement_update);
+ sts.update_image_version (im.version);
+ imb.version++;
+ u = true;
+ }
+
+ binding& idb (sts.id_image_binding ());
+ if (idi.version != sts.update_id_image_version () ||
+ idb.version == 0)
+ {
+ if (idi.version != sts.id_image_version () ||
+ idb.version == 0)
+ {
+ bind (idb.bind, idi);
+ sts.id_image_version (idi.version);
+ idb.version++;
+ }
+
+ sts.update_id_image_version (idi.version);
+
+ if (!u)
+ imb.version++;
+ }
+
+ update_statement& st (sts.update_statement ());
+ if (st.execute () == 0)
+ throw object_not_persistent ();
+
+ callback (db, obj, callback_event::post_update);
+ pointer_cache_traits::update (db, obj);
+ }
+
+ void access::object_traits_impl< ::person, id_oracle >::
+ erase (database& db, const id_type& id)
+ {
+ using namespace oracle;
+
+ ODB_POTENTIALLY_UNUSED (db);
+
+ oracle::connection& conn (
+ oracle::transaction::current ().connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ id_image_type& i (sts.id_image ());
+ init (i, id);
+
+ binding& idb (sts.id_image_binding ());
+ if (i.version != sts.id_image_version () || idb.version == 0)
+ {
+ bind (idb.bind, i);
+ sts.id_image_version (i.version);
+ idb.version++;
+ }
+
+ if (sts.erase_statement ().execute () != 1)
+ throw object_not_persistent ();
+
+ pointer_cache_traits::erase (db, id);
+ }
+
+ access::object_traits_impl< ::person, id_oracle >::pointer_type
+ access::object_traits_impl< ::person, id_oracle >::
+ find (database& db, const id_type& id)
+ {
+ using namespace oracle;
+
+ {
+ pointer_type p (pointer_cache_traits::find (db, id));
+
+ if (!pointer_traits::null_ptr (p))
+ return p;
+ }
+
+ oracle::connection& conn (
+ oracle::transaction::current ().connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ statements_type::auto_lock l (sts);
+
+ if (l.locked ())
+ {
+ if (!find_ (sts, &id))
+ return pointer_type ();
+ }
+
+ pointer_type p (
+ access::object_factory<object_type, pointer_type>::create ());
+ pointer_traits::guard pg (p);
+
+ pointer_cache_traits::insert_guard ig (
+ pointer_cache_traits::insert (db, id, p));
+
+ object_type& obj (pointer_traits::get_ref (p));
+
+ if (l.locked ())
+ {
+ select_statement& st (sts.find_statement ());
+ ODB_POTENTIALLY_UNUSED (st);
+
+ callback (db, obj, callback_event::pre_load);
+ init (obj, sts.image (), &db);
+ st.stream_result ();
+ load_ (sts, obj, false);
+ sts.load_delayed (0);
+ l.unlock ();
+ callback (db, obj, callback_event::post_load);
+ pointer_cache_traits::load (ig.position ());
+ }
+ else
+ sts.delay_load (id, obj, ig.position ());
+
+ ig.release ();
+ pg.release ();
+ return p;
+ }
+
+ bool access::object_traits_impl< ::person, id_oracle >::
+ find (database& db, const id_type& id, object_type& obj)
+ {
+ using namespace oracle;
+
+ oracle::connection& conn (
+ oracle::transaction::current ().connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ statements_type::auto_lock l (sts);
+
+ if (!find_ (sts, &id))
+ return false;
+
+ select_statement& st (sts.find_statement ());
+ ODB_POTENTIALLY_UNUSED (st);
+
+ reference_cache_traits::position_type pos (
+ reference_cache_traits::insert (db, id, obj));
+ reference_cache_traits::insert_guard ig (pos);
+
+ callback (db, obj, callback_event::pre_load);
+ init (obj, sts.image (), &db);
+ st.stream_result ();
+ load_ (sts, obj, false);
+ sts.load_delayed (0);
+ l.unlock ();
+ callback (db, obj, callback_event::post_load);
+ reference_cache_traits::load (pos);
+ ig.release ();
+ return true;
+ }
+
+ bool access::object_traits_impl< ::person, id_oracle >::
+ reload (database& db, object_type& obj)
+ {
+ using namespace oracle;
+
+ oracle::connection& conn (
+ oracle::transaction::current ().connection ());
+ statements_type& sts (
+ conn.statement_cache ().find_object<object_type> ());
+
+ statements_type::auto_lock l (sts);
+
+ const id_type& id (
+ obj.id);
+
+ if (!find_ (sts, &id))
+ return false;
+
+ select_statement& st (sts.find_statement ());
+ ODB_POTENTIALLY_UNUSED (st);
+
+ callback (db, obj, callback_event::pre_load);
+ init (obj, sts.image (), &db);
+ st.stream_result ();
+ load_ (sts, obj, true);
+ sts.load_delayed (0);
+ l.unlock ();
+ callback (db, obj, callback_event::post_load);
+ return true;
+ }
+
+ bool access::object_traits_impl< ::person, id_oracle >::
+ find_ (statements_type& sts,
+ const id_type* id)
+ {
+ using namespace oracle;
+
+ id_image_type& i (sts.id_image ());
+ init (i, *id);
+
+ binding& idb (sts.id_image_binding ());
+ if (i.version != sts.id_image_version () || idb.version == 0)
+ {
+ bind (idb.bind, i);
+ sts.id_image_version (i.version);
+ idb.version++;
+ }
+
+ image_type& im (sts.image ());
+ binding& imb (sts.select_image_binding ());
+
+ if (im.version != sts.select_image_version () ||
+ imb.version == 0)
+ {
+ bind (imb.bind, im, statement_select);
+ sts.select_image_version (im.version);
+ imb.version++;
+ }
+
+ select_statement& st (sts.find_statement ());
+
+ st.execute ();
+ auto_result ar (st);
+ select_statement::result r (st.fetch ());
+
+ return r != select_statement::no_data;
+ }
+}
+
+#include <odb/post.hxx>