// This file was generated by ODB, object-relational mapping (ORM) // compiler for C++. // #include #include "Agent-odb.hxx" #include #include // std::memcpy #include #include #include #include #include #include #include #include #include #include namespace odb { // Agent // const char access::object_traits_impl< ::models::Agent, id_pgsql >:: persist_statement_name[] = "persist_models_Agent"; const char access::object_traits_impl< ::models::Agent, id_pgsql >:: find_statement_name[] = "find_models_Agent"; const char access::object_traits_impl< ::models::Agent, id_pgsql >:: update_statement_name[] = "update_models_Agent"; const char access::object_traits_impl< ::models::Agent, id_pgsql >:: erase_statement_name[] = "erase_models_Agent"; const char access::object_traits_impl< ::models::Agent, id_pgsql >:: query_statement_name[] = "query_models_Agent"; const char access::object_traits_impl< ::models::Agent, id_pgsql >:: erase_query_statement_name[] = "erase_query_models_Agent"; const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: persist_statement_types[] = { pgsql::text_oid, pgsql::text_oid, pgsql::bool_oid, pgsql::text_oid, pgsql::int4_oid }; const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: find_statement_types[] = { pgsql::text_oid }; const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: update_statement_types[] = { pgsql::text_oid, pgsql::bool_oid, pgsql::text_oid, pgsql::int4_oid, pgsql::text_oid }; struct access::object_traits_impl< ::models::Agent, id_pgsql >::extra_statement_cache_type { extra_statement_cache_type ( pgsql::connection&, image_type&, id_image_type&, pgsql::binding&, pgsql::binding&, pgsql::native_binding&, const unsigned int*) { } }; access::object_traits_impl< ::models::Agent, id_pgsql >::id_type access::object_traits_impl< ::models::Agent, id_pgsql >:: id (const image_type& i) { pgsql::database* db (0); ODB_POTENTIALLY_UNUSED (db); id_type id; { pgsql::value_traits< ::std::string, pgsql::id_string >::set_value ( id, i.id_value, i.id_size, i.id_null); } return id; } bool access::object_traits_impl< ::models::Agent, id_pgsql >:: grow (image_type& i, bool* t) { ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (t); bool grew (false); // id // if (t[0UL]) { i.id_value.capacity (i.id_size); grew = true; } // role // if (t[1UL]) { i.role_value.capacity (i.role_size); grew = true; } // persistent // t[2UL] = 0; // displayName // if (t[3UL]) { i.displayName_value.capacity (i.displayName_size); grew = true; } // trustScore // t[4UL] = 0; return grew; } void access::object_traits_impl< ::models::Agent, id_pgsql >:: bind (pgsql::bind* b, image_type& i, pgsql::statement_kind sk) { ODB_POTENTIALLY_UNUSED (sk); using namespace pgsql; std::size_t n (0); // id // if (sk != statement_update) { b[n].type = pgsql::bind::text; b[n].buffer = i.id_value.data (); b[n].capacity = i.id_value.capacity (); b[n].size = &i.id_size; b[n].is_null = &i.id_null; n++; } // role // b[n].type = pgsql::bind::text; b[n].buffer = i.role_value.data (); b[n].capacity = i.role_value.capacity (); b[n].size = &i.role_size; b[n].is_null = &i.role_null; n++; // persistent // b[n].type = pgsql::bind::boolean_; b[n].buffer = &i.persistent_value; b[n].is_null = &i.persistent_null; n++; // displayName // b[n].type = pgsql::bind::text; b[n].buffer = i.displayName_value.data (); b[n].capacity = i.displayName_value.capacity (); b[n].size = &i.displayName_size; b[n].is_null = &i.displayName_null; n++; // trustScore // b[n].type = pgsql::bind::integer; b[n].buffer = &i.trustScore_value; b[n].is_null = &i.trustScore_null; n++; } void access::object_traits_impl< ::models::Agent, id_pgsql >:: bind (pgsql::bind* b, id_image_type& i) { std::size_t n (0); b[n].type = pgsql::bind::text; b[n].buffer = i.id_value.data (); b[n].capacity = i.id_value.capacity (); b[n].size = &i.id_size; b[n].is_null = &i.id_null; } bool access::object_traits_impl< ::models::Agent, id_pgsql >:: init (image_type& i, const object_type& o, pgsql::statement_kind sk) { ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (o); ODB_POTENTIALLY_UNUSED (sk); using namespace pgsql; bool grew (false); // id // if (sk == statement_insert) { ::std::string const& v = o.id; bool is_null (false); std::size_t size (0); std::size_t cap (i.id_value.capacity ()); pgsql::value_traits< ::std::string, pgsql::id_string >::set_image ( i.id_value, size, is_null, v); i.id_null = is_null; i.id_size = size; grew = grew || (cap != i.id_value.capacity ()); } // role // { ::std::string const& v = o.role; bool is_null (false); std::size_t size (0); std::size_t cap (i.role_value.capacity ()); pgsql::value_traits< ::std::string, pgsql::id_string >::set_image ( i.role_value, size, is_null, v); i.role_null = is_null; i.role_size = size; grew = grew || (cap != i.role_value.capacity ()); } // persistent // { bool const& v = o.persistent; bool is_null (false); pgsql::value_traits< bool, pgsql::id_boolean >::set_image ( i.persistent_value, is_null, v); i.persistent_null = is_null; } // displayName // { ::std::string const& v = o.displayName; bool is_null (false); std::size_t size (0); std::size_t cap (i.displayName_value.capacity ()); pgsql::value_traits< ::std::string, pgsql::id_string >::set_image ( i.displayName_value, size, is_null, v); i.displayName_null = is_null; i.displayName_size = size; grew = grew || (cap != i.displayName_value.capacity ()); } // trustScore // { ::int32_t const& v = o.trustScore; bool is_null (false); pgsql::value_traits< ::int32_t, pgsql::id_integer >::set_image ( i.trustScore_value, is_null, v); i.trustScore_null = is_null; } return grew; } void access::object_traits_impl< ::models::Agent, id_pgsql >:: init (object_type& o, const image_type& i, database* db) { ODB_POTENTIALLY_UNUSED (o); ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (db); // id // { ::std::string& v = o.id; pgsql::value_traits< ::std::string, pgsql::id_string >::set_value ( v, i.id_value, i.id_size, i.id_null); } // role // { ::std::string& v = o.role; pgsql::value_traits< ::std::string, pgsql::id_string >::set_value ( v, i.role_value, i.role_size, i.role_null); } // persistent // { bool& v = o.persistent; pgsql::value_traits< bool, pgsql::id_boolean >::set_value ( v, i.persistent_value, i.persistent_null); } // displayName // { ::std::string& v = o.displayName; pgsql::value_traits< ::std::string, pgsql::id_string >::set_value ( v, i.displayName_value, i.displayName_size, i.displayName_null); } // trustScore // { ::int32_t& v = o.trustScore; pgsql::value_traits< ::int32_t, pgsql::id_integer >::set_value ( v, i.trustScore_value, i.trustScore_null); } } void access::object_traits_impl< ::models::Agent, id_pgsql >:: init (id_image_type& i, const id_type& id) { bool grew (false); { bool is_null (false); std::size_t size (0); std::size_t cap (i.id_value.capacity ()); pgsql::value_traits< ::std::string, pgsql::id_string >::set_image ( i.id_value, size, is_null, id); i.id_null = is_null; i.id_size = size; grew = grew || (cap != i.id_value.capacity ()); } if (grew) i.version++; } const char access::object_traits_impl< ::models::Agent, id_pgsql >::persist_statement[] = "INSERT INTO \"Agent\" " "(\"id\", " "\"role\", " "\"persistent\", " "\"displayName\", " "\"trustScore\") " "VALUES " "($1, $2, $3, $4, $5)"; const char access::object_traits_impl< ::models::Agent, id_pgsql >::find_statement[] = "SELECT " "\"Agent\".\"id\", " "\"Agent\".\"role\", " "\"Agent\".\"persistent\", " "\"Agent\".\"displayName\", " "\"Agent\".\"trustScore\" " "FROM \"Agent\" " "WHERE \"Agent\".\"id\"=$1"; const char access::object_traits_impl< ::models::Agent, id_pgsql >::update_statement[] = "UPDATE \"Agent\" " "SET " "\"role\"=$1, " "\"persistent\"=$2, " "\"displayName\"=$3, " "\"trustScore\"=$4 " "WHERE \"id\"=$5"; const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_statement[] = "DELETE FROM \"Agent\" " "WHERE \"id\"=$1"; const char access::object_traits_impl< ::models::Agent, id_pgsql >::query_statement[] = "SELECT " "\"Agent\".\"id\", " "\"Agent\".\"role\", " "\"Agent\".\"persistent\", " "\"Agent\".\"displayName\", " "\"Agent\".\"trustScore\" " "FROM \"Agent\""; const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_query_statement[] = "DELETE FROM \"Agent\""; const char access::object_traits_impl< ::models::Agent, id_pgsql >::table_name[] = "\"Agent\""; void access::object_traits_impl< ::models::Agent, id_pgsql >:: persist (database& db, const object_type& obj) { ODB_POTENTIALLY_UNUSED (db); using namespace pgsql; pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); callback (db, obj, callback_event::pre_persist); image_type& im (sts.image ()); binding& imb (sts.insert_image_binding ()); if (init (im, obj, statement_insert)) im.version++; if (im.version != sts.insert_image_version () || imb.version == 0) { bind (imb.bind, im, statement_insert); sts.insert_image_version (im.version); imb.version++; } insert_statement& st (sts.persist_statement ()); if (!st.execute ()) throw object_already_persistent (); callback (db, obj, callback_event::post_persist); } void access::object_traits_impl< ::models::Agent, id_pgsql >:: update (database& db, const object_type& obj) { ODB_POTENTIALLY_UNUSED (db); using namespace pgsql; using pgsql::update_statement; callback (db, obj, callback_event::pre_update); pgsql::transaction& tr (pgsql::transaction::current ()); pgsql::connection& conn (tr.connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); const id_type& id ( obj.id); id_image_type& idi (sts.id_image ()); init (idi, id); image_type& im (sts.image ()); if (init (im, obj, statement_update)) im.version++; 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< ::models::Agent, id_pgsql >:: erase (database& db, const id_type& id) { using namespace pgsql; ODB_POTENTIALLY_UNUSED (db); pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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< ::models::Agent, id_pgsql >::pointer_type access::object_traits_impl< ::models::Agent, id_pgsql >:: find (database& db, const id_type& id) { using namespace pgsql; { pointer_type p (pointer_cache_traits::find (db, id)); if (!pointer_traits::null_ptr (p)) return p; } pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); statements_type::auto_lock l (sts); if (l.locked ()) { if (!find_ (sts, &id)) return pointer_type (); } pointer_type p ( access::object_factory::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); 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< ::models::Agent, id_pgsql >:: find (database& db, const id_type& id, object_type& obj) { using namespace pgsql; pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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); 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< ::models::Agent, id_pgsql >:: reload (database& db, object_type& obj) { using namespace pgsql; pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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); load_ (sts, obj, true); sts.load_delayed (0); l.unlock (); callback (db, obj, callback_event::post_load); return true; } bool access::object_traits_impl< ::models::Agent, id_pgsql >:: find_ (statements_type& sts, const id_type* id) { using namespace pgsql; 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 ()); if (r == select_statement::truncated) { if (grow (im, sts.select_image_truncated ())) im.version++; if (im.version != sts.select_image_version ()) { bind (imb.bind, im, statement_select); sts.select_image_version (im.version); imb.version++; st.refetch (); } } return r != select_statement::no_data; } result< access::object_traits_impl< ::models::Agent, id_pgsql >::object_type > access::object_traits_impl< ::models::Agent, id_pgsql >:: query (database&, const query_base_type& q) { using namespace pgsql; using odb::details::shared; using odb::details::shared_ptr; pgsql::connection& conn ( pgsql::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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++; } std::string text (query_statement); if (!q.empty ()) { text += " "; text += q.clause (); } q.init_parameters (); shared_ptr st ( new (shared) select_statement ( sts.connection (), query_statement_name, text, false, true, q.parameter_types (), q.parameter_count (), q.parameters_binding (), imb)); st->execute (); st->deallocate (); shared_ptr< odb::object_result_impl > r ( new (shared) pgsql::object_result_impl ( q, st, sts, 0)); return result (r); } unsigned long long access::object_traits_impl< ::models::Agent, id_pgsql >:: erase_query (database&, const query_base_type& q) { using namespace pgsql; pgsql::connection& conn ( pgsql::transaction::current ().connection ()); std::string text (erase_query_statement); if (!q.empty ()) { text += ' '; text += q.clause (); } q.init_parameters (); delete_statement st ( conn, erase_query_statement_name, text, q.parameter_types (), q.parameter_count (), q.parameters_binding ()); return st.execute (); } } #include