| database.hxx | | database.hxx | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| #include <string> | | #include <string> | |
| #include <memory> // std::auto_ptr, std::unique_ptr | | #include <memory> // std::auto_ptr, std::unique_ptr | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| | | | |
| #ifdef ODB_CXX11 | | #ifdef ODB_CXX11 | |
| # include <functional> // std::function | | # include <functional> // std::function | |
| #endif | | #endif | |
| | | | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/forward.hxx> | | #include <odb/forward.hxx> | |
|
| | | #include <odb/schema-version.hxx> | |
| #include <odb/query.hxx> | | #include <odb/query.hxx> | |
| #include <odb/prepared-query.hxx> | | #include <odb/prepared-query.hxx> | |
| #include <odb/result.hxx> | | #include <odb/result.hxx> | |
| #include <odb/connection.hxx> | | #include <odb/connection.hxx> | |
| #include <odb/exceptions.hxx> | | #include <odb/exceptions.hxx> | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
|
| | | #include <odb/details/mutex.hxx> | |
| #include <odb/details/c-string.hxx> | | #include <odb/details/c-string.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class transaction_impl; | | class transaction_impl; | |
| | | | |
| class LIBODB_EXPORT database | | class LIBODB_EXPORT database | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| | | | |
| skipping to change at line 86 | | skipping to change at line 88 | |
| // Load an object. Throw object_not_persistent if not found. | | // Load an object. Throw object_not_persistent if not found. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
| load (const typename object_traits<T>::id_type& id); | | load (const typename object_traits<T>::id_type& id); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| load (const typename object_traits<T>::id_type& id, T& object); | | load (const typename object_traits<T>::id_type& id, T& object); | |
| | | | |
|
| | | // Load (or reload, if it is already loaded) a section of an object. | |
| | | // | |
| | | template <typename T> | |
| | | void | |
| | | load (T& object, section&); | |
| | | | |
| // Reload an object. | | // Reload an object. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| reload (T& object); | | reload (T& object); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| reload (T* obj_ptr); | | reload (T* obj_ptr); | |
| | | | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 164 | |
| update (P<T>& obj_ptr); | | update (P<T>& obj_ptr); | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class
P> | | template <typename T, typename A1, template <typename, typename> class
P> | |
| void | | void | |
| update (P<T, A1>& obj_ptr); | | update (P<T, A1>& obj_ptr); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| update (const typename object_traits<T>::pointer_type& obj_ptr); | | update (const typename object_traits<T>::pointer_type& obj_ptr); | |
| | | | |
|
| | | // Update a section of an object. Throws section_not_loaded exception | |
| | | // if section is not loaded. Note also that this function does not | |
| | | // clear the changed flag if it is set. | |
| | | // | |
| | | template <typename T> | |
| | | void | |
| | | update (const T& object, const section&); | |
| | | | |
| // Make the object transient. Throw object_not_persistent if not | | // Make the object transient. Throw object_not_persistent if not | |
| // found. | | // found. | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| erase (const typename object_traits<T>::id_type& id); | | erase (const typename object_traits<T>::id_type& id); | |
| | | | |
| template <typename T> | | template <typename T> | |
| void | | void | |
| erase (T& object); | | erase (T& object); | |
| | | | |
| skipping to change at line 320 | | skipping to change at line 336 | |
| | | | |
| void | | void | |
| tracer (tracer_type&); | | tracer (tracer_type&); | |
| | | | |
| void | | void | |
| tracer (tracer_type*); | | tracer (tracer_type*); | |
| | | | |
| tracer_type* | | tracer_type* | |
| tracer () const; | | tracer () const; | |
| | | | |
|
| | | // Database schema version. | |
| | | // | |
| | | public: | |
| | | typedef odb::schema_version schema_version_type; | |
| | | typedef odb::schema_version_migration schema_version_migration_type; | |
| | | | |
| | | schema_version_type | |
| | | schema_version (const std::string& schema_name = "") const; | |
| | | | |
| | | bool | |
| | | schema_migration (const std::string& schema_name = "") const; | |
| | | | |
| | | // Note that there is code that relies on the returned reference | |
| | | // being valid until the version is changed or the database instance | |
| | | // is destroyed. | |
| | | // | |
| | | const schema_version_migration_type& | |
| | | schema_version_migration (const std::string& schema_name = "") const; | |
| | | | |
| | | // Set schema version and migration state manually. | |
| | | // | |
| | | // Note that the modifier API is not thread-safe. That is, you should | |
| | | // not modify the schema version while other threads may be accessing | |
| | | // or modifying the same information. | |
| | | // | |
| | | void | |
| | | schema_version_migration (schema_version_type, | |
| | | bool migration, | |
| | | const std::string& schema_name = ""); | |
| | | | |
| | | void | |
| | | schema_version_migration (const schema_version_migration_type&, | |
| | | const std::string& schema_name = ""); | |
| | | | |
| | | // Set default schema version table for all the schema names. The table | |
| | | // name should already be quoted if necessary. | |
| | | // | |
| | | void | |
| | | schema_version_table (const std::string& table_name); | |
| | | | |
| | | // Set schema version table for a specific schema. | |
| | | // | |
| | | void | |
| | | schema_version_table (const std::string& table_name, | |
| | | const std::string& schema_name); | |
| | | | |
| | | // Schema version sequence number. It is incremented every time the | |
| | | // schema version or migration flag is changed and can be used to | |
| | | // detect overall version changes. The starting value is 1. | |
| | | // | |
| | | unsigned int | |
| | | schema_version_sequence () const; | |
| | | | |
| | | protected: | |
| | | struct schema_version_info: schema_version_migration_type | |
| | | { | |
| | | std::string version_table; | |
| | | }; | |
| | | | |
| | | virtual const schema_version_info& | |
| | | load_schema_version (const std::string& schema_name) const = 0; | |
| | | | |
| | | private: | |
| | | const schema_version_info& | |
| | | schema_version_migration_ (const std::string& schema_name) const; | |
| | | | |
| // Database id. | | // Database id. | |
| // | | // | |
| public: | | public: | |
| database_id | | database_id | |
| id () const; | | id () const; | |
| | | | |
| protected: | | protected: | |
| database (database_id); | | database (database_id); | |
| | | | |
| private: | | private: | |
| | | | |
| skipping to change at line 356 | | skipping to change at line 438 | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
| load_ (const typename object_traits<T>::id_type&); | | load_ (const typename object_traits<T>::id_type&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
| load_ (const typename object_traits<T>::id_type&, T&); | | load_ (const typename object_traits<T>::id_type&, T&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
|
| | | load_ (T&, section&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| reload_ (T&); | | reload_ (T&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| typename object_traits<T>::pointer_type | | typename object_traits<T>::pointer_type | |
| find_ (const typename object_traits<T>::id_type&); | | find_ (const typename object_traits<T>::id_type&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| bool | | bool | |
| find_ (const typename object_traits<T>::id_type&, T&); | | find_ (const typename object_traits<T>::id_type&, T&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
| update_ (T&); | | update_ (T&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
| update_ (const typename object_traits<T>::pointer_type&); | | update_ (const typename object_traits<T>::pointer_type&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
|
| | | update_ (const T&, const section&); | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void | |
| erase_ (const typename object_traits<T>::id_type&); | | erase_ (const typename object_traits<T>::id_type&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
| erase_ (T&); | | erase_ (T&); | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void | | void | |
| erase_ (const typename object_traits<T>::pointer_type&); | | erase_ (const typename object_traits<T>::pointer_type&); | |
| | | | |
| template <typename T, | | template <typename T, | |
| database_id DB, | | database_id DB, | |
| class_kind kind = class_traits<T>::kind> | | class_kind kind = class_traits<T>::kind> | |
| struct query_; | | struct query_; | |
| | | | |
| protected: | | protected: | |
| typedef | | typedef | |
| std::map<const char*, query_factory_type, details::c_string_comparator> | | std::map<const char*, query_factory_type, details::c_string_comparator> | |
| query_factory_map; | | query_factory_map; | |
| | | | |
|
| | | typedef std::map<std::string, schema_version_info> schema_version_map; | |
| | | | |
| database_id id_; | | database_id id_; | |
| tracer_type* tracer_; | | tracer_type* tracer_; | |
| query_factory_map query_factory_map_; | | query_factory_map query_factory_map_; | |
|
| | | | |
| | | mutable details::mutex mutex_; | |
| | | mutable schema_version_map schema_version_map_; | |
| | | std::string schema_version_table_; | |
| | | unsigned int schema_version_seq_; | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/database.ixx> | | #include <odb/database.ixx> | |
| #include <odb/database.txx> | | #include <odb/database.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_DATABASE_HXX | | #endif // ODB_DATABASE_HXX | |
| | | | |
End of changes. 9 change blocks. |
| 0 lines changed or deleted | | 97 lines changed or added | |
|
| database.ixx | | database.ixx | |
| | | | |
| skipping to change at line 14 | | skipping to change at line 14 | |
| | | | |
| #include <cstring> // std::strlen() | | #include <cstring> // std::strlen() | |
| #include <utility> // std::move | | #include <utility> // std::move | |
| | | | |
| #include <odb/transaction.hxx> | | #include <odb/transaction.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| inline database:: | | inline database:: | |
| database (database_id id) | | database (database_id id) | |
|
| : id_ (id), tracer_ (0) | | : id_ (id), tracer_ (0), schema_version_seq_ (1) | |
| { | | { | |
| } | | } | |
| | | | |
| inline database_id database:: | | inline database_id database:: | |
| id () const | | id () const | |
| { | | { | |
| return id_; | | return id_; | |
| } | | } | |
| | | | |
|
| | | inline database::schema_version_type database:: | |
| | | schema_version (const std::string& name) const | |
| | | { | |
| | | return schema_version_migration (name).version; | |
| | | } | |
| | | | |
| | | inline bool database:: | |
| | | schema_migration (const std::string& name) const | |
| | | { | |
| | | return schema_version_migration (name).migration; | |
| | | } | |
| | | | |
| | | inline void database:: | |
| | | schema_version_migration (schema_version_type v, | |
| | | bool m, | |
| | | const std::string& name) | |
| | | { | |
| | | schema_version_migration (schema_version_migration_type (v, m), name); | |
| | | } | |
| | | | |
| | | inline void database:: | |
| | | schema_version_table (const std::string& tname) | |
| | | { | |
| | | schema_version_table_ = tname; | |
| | | } | |
| | | | |
| | | inline void database:: | |
| | | schema_version_table (const std::string& tname, const std::string& sname) | |
| | | { | |
| | | schema_version_map_[sname].version_table = tname; | |
| | | } | |
| | | | |
| | | inline unsigned int database:: | |
| | | schema_version_sequence () const | |
| | | { | |
| | | return schema_version_seq_; | |
| | | } | |
| | | | |
| inline connection_ptr database:: | | inline connection_ptr database:: | |
| connection () | | connection () | |
| { | | { | |
| return connection_ptr (connection_ ()); | | return connection_ptr (connection_ ()); | |
| } | | } | |
| | | | |
| inline void database:: | | inline void database:: | |
| query_factory (const char* name, query_factory_type f) | | query_factory (const char* name, query_factory_type f) | |
| { | | { | |
| if (f) | | if (f) | |
| | | | |
| skipping to change at line 164 | | skipping to change at line 202 | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| load (const typename object_traits<T>::id_type& id, T& obj) | | load (const typename object_traits<T>::id_type& id, T& obj) | |
| { | | { | |
| return load_<T, id_common> (id, obj); | | return load_<T, id_common> (id, obj); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
|
| | | inline void database:: | |
| | | load (T& obj, section& s) | |
| | | { | |
| | | return load_<T, id_common> (obj, s); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| inline typename object_traits<T>::pointer_type database:: | | inline typename object_traits<T>::pointer_type database:: | |
| find (const typename object_traits<T>::id_type& id) | | find (const typename object_traits<T>::id_type& id) | |
| { | | { | |
| return find_<T, id_common> (id); | | return find_<T, id_common> (id); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline bool database:: | | inline bool database:: | |
| find (const typename object_traits<T>::id_type& id, T& obj) | | find (const typename object_traits<T>::id_type& id, T& obj) | |
| { | | { | |
| | | | |
| skipping to change at line 305 | | skipping to change at line 350 | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| update (const typename object_traits<T>::pointer_type& pobj) | | update (const typename object_traits<T>::pointer_type& pobj) | |
| { | | { | |
| update_<T, id_common> (pobj); | | update_<T, id_common> (pobj); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
|
| | | update (const T& obj, const section& s) | |
| | | { | |
| | | update_<T, id_common> (obj, s); | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | inline void database:: | |
| erase (const typename object_traits<T>::id_type& id) | | erase (const typename object_traits<T>::id_type& id) | |
| { | | { | |
| return erase_<T, id_common> (id); | | return erase_<T, id_common> (id); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| inline void database:: | | inline void database:: | |
| erase (T& obj) | | erase (T& obj) | |
| { | | { | |
| return erase_<T, id_common> (obj); | | return erase_<T, id_common> (obj); | |
| | | | |
End of changes. 4 change blocks. |
| 1 lines changed or deleted | | 53 lines changed or added | |
|
| database.txx | | database.txx | |
| // file : odb/database.txx | | // file : odb/database.txx | |
| // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
|
| | | #include <odb/section.hxx> | |
| #include <odb/exceptions.hxx> | | #include <odb/exceptions.hxx> | |
| #include <odb/no-op-cache-traits.hxx> | | #include <odb/no-op-cache-traits.hxx> | |
| #include <odb/pointer-traits.hxx> | | #include <odb/pointer-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename T> | | template <typename T> | |
| result<T> database:: | | result<T> database:: | |
| query (const odb::query<T>& q, bool cache) | | query (const odb::query<T>& q, bool cache) | |
| { | | { | |
| | | | |
| skipping to change at line 99 | | skipping to change at line 100 | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void database:: | | void database:: | |
| load_ (const typename object_traits<T>::id_type& id, T& obj) | | load_ (const typename object_traits<T>::id_type& id, T& obj) | |
| { | | { | |
| if (!find_<T, DB> (id, obj)) | | if (!find_<T, DB> (id, obj)) | |
| throw object_not_persistent (); | | throw object_not_persistent (); | |
| } | | } | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| void database:: | | void database:: | |
|
| | | load_ (T& obj, section& s) | |
| | | { | |
| | | connection_type& c (transaction::current ().connection ()); | |
| | | | |
| | | // T is always object_type. | |
| | | // | |
| | | if (object_traits_impl<T, DB>::load (c, obj, s)) | |
| | | s.reset (true, false); // Loaded, unchanged. | |
| | | else | |
| | | throw section_not_in_object (); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| | | void database:: | |
| reload_ (T& obj) | | reload_ (T& obj) | |
| { | | { | |
| // T should be object_type (cannot be const). We also don't need to | | // T should be object_type (cannot be const). We also don't need to | |
| // check for transaction here; object_traits::reload () does this. | | // check for transaction here; object_traits::reload () does this. | |
| // | | // | |
| if (!object_traits_impl<T, DB>::reload (*this, obj)) | | if (!object_traits_impl<T, DB>::reload (*this, obj)) | |
| throw object_not_persistent (); | | throw object_not_persistent (); | |
| } | | } | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
|
| | | void database:: | |
| | | update_ (const T& obj, const section& s) | |
| | | { | |
| | | if (!s.loaded ()) | |
| | | throw section_not_loaded (); | |
| | | | |
| | | transaction& t (transaction::current ()); | |
| | | | |
| | | // T is always object_type. | |
| | | // | |
| | | if (object_traits_impl<T, DB>::update (t.connection (), obj, s)) | |
| | | { | |
| | | if (s.changed ()) | |
| | | s.reset (true, false, &t); // Clear the change flag. | |
| | | } | |
| | | else | |
| | | throw section_not_in_object (); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB> | |
| struct database::query_<T, DB, class_object> | | struct database::query_<T, DB, class_object> | |
| { | | { | |
| template <typename Q> | | template <typename Q> | |
| static result<T> | | static result<T> | |
| call (database& db, const Q& q) | | call (database& db, const Q& q) | |
| { | | { | |
| return object_traits_impl<T, DB>::query (db, q); | | return object_traits_impl<T, DB>::query (db, q); | |
| } | | } | |
| }; | | }; | |
| | | | |
| | | | |
End of changes. 3 change blocks. |
| 0 lines changed or deleted | | 35 lines changed or added | |
|
| exceptions.hxx | | exceptions.hxx | |
| | | | |
| skipping to change at line 12 | | skipping to change at line 12 | |
| // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_EXCEPTIONS_HXX | | #ifndef ODB_EXCEPTIONS_HXX | |
| #define ODB_EXCEPTIONS_HXX | | #define ODB_EXCEPTIONS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <string> | | #include <string> | |
| | | | |
|
| #include <odb/forward.hxx> // odb::core | | #include <odb/forward.hxx> // schema_version, odb::core | |
| #include <odb/exception.hxx> | | #include <odb/exception.hxx> | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
|
| struct LIBODB_EXPORT null_pointer: exception | | struct LIBODB_EXPORT null_pointer: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| // Transaction exceptions. | | // Transaction exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT already_in_transaction: exception | | struct LIBODB_EXPORT already_in_transaction: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT not_in_transaction: exception | | struct LIBODB_EXPORT not_in_transaction: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT transaction_already_finalized: exception | | struct LIBODB_EXPORT transaction_already_finalized: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| // Session exceptions. | | // Session exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT already_in_session: exception | | struct LIBODB_EXPORT already_in_session: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT not_in_session: exception | | struct LIBODB_EXPORT not_in_session: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT session_required: exception | | struct LIBODB_EXPORT session_required: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| // Database operations exceptions. | | // Database operations exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT recoverable: exception | | struct LIBODB_EXPORT recoverable: odb::exception | |
| { | | { | |
| }; | | }; | |
| | | | |
| struct LIBODB_EXPORT connection_lost: recoverable | | struct LIBODB_EXPORT connection_lost: recoverable | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| struct LIBODB_EXPORT timeout: recoverable | | struct LIBODB_EXPORT timeout: recoverable | |
| | | | |
| skipping to change at line 89 | | skipping to change at line 89 | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| struct LIBODB_EXPORT deadlock: recoverable | | struct LIBODB_EXPORT deadlock: recoverable | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT object_not_persistent: exception | | struct LIBODB_EXPORT object_not_persistent: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT object_already_persistent: exception | | struct LIBODB_EXPORT object_already_persistent: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT object_changed: exception | | struct LIBODB_EXPORT object_changed: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT result_not_cached: exception | | struct LIBODB_EXPORT result_not_cached: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT database_exception: exception | | struct LIBODB_EXPORT database_exception: odb::exception | |
| { | | { | |
| }; | | }; | |
| | | | |
| // Polymorphism support exceptions. | | // Polymorphism support exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT abstract_class: exception | | struct LIBODB_EXPORT abstract_class: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT no_type_info: exception | | struct LIBODB_EXPORT no_type_info: odb::exception | |
| { | | { | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| // Prepared query support exceptions. | | // Prepared query support exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT prepared_already_cached: exception | | struct LIBODB_EXPORT prepared_already_cached: odb::exception | |
| { | | { | |
| prepared_already_cached (const char* name); | | prepared_already_cached (const char* name); | |
| ~prepared_already_cached () throw (); | | ~prepared_already_cached () throw (); | |
| | | | |
| const char* | | const char* | |
| name () const | | name () const | |
| { | | { | |
| return name_; | | return name_; | |
| } | | } | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| const char* name_; | | const char* name_; | |
| std::string what_; | | std::string what_; | |
| }; | | }; | |
| | | | |
|
| struct LIBODB_EXPORT prepared_type_mismatch: exception | | struct LIBODB_EXPORT prepared_type_mismatch: odb::exception | |
| { | | { | |
| prepared_type_mismatch (const char* name); | | prepared_type_mismatch (const char* name); | |
| ~prepared_type_mismatch () throw (); | | ~prepared_type_mismatch () throw (); | |
| | | | |
| const char* | | const char* | |
| name () const | | name () const | |
| { | | { | |
| return name_; | | return name_; | |
| } | | } | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| const char* name_; | | const char* name_; | |
| std::string what_; | | std::string what_; | |
| }; | | }; | |
| | | | |
| // Schema catalog exceptions. | | // Schema catalog exceptions. | |
| // | | // | |
|
| struct LIBODB_EXPORT unknown_schema: exception | | struct LIBODB_EXPORT unknown_schema: odb::exception | |
| { | | { | |
| unknown_schema (const std::string& name); | | unknown_schema (const std::string& name); | |
| ~unknown_schema () throw (); | | ~unknown_schema () throw (); | |
| | | | |
| const std::string& | | const std::string& | |
| name () const | | name () const | |
| { | | { | |
| return name_; | | return name_; | |
| } | | } | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string name_; | | std::string name_; | |
| std::string what_; | | std::string what_; | |
| }; | | }; | |
| | | | |
|
| | | struct LIBODB_EXPORT unknown_schema_version: odb::exception | |
| | | { | |
| | | unknown_schema_version (schema_version); | |
| | | ~unknown_schema_version () throw (); | |
| | | | |
| | | schema_version | |
| | | version () const | |
| | | { | |
| | | return version_; | |
| | | } | |
| | | | |
| | | virtual const char* | |
| | | what () const throw (); | |
| | | | |
| | | private: | |
| | | schema_version version_; | |
| | | std::string what_; | |
| | | }; | |
| | | | |
| | | // Section exceptions. | |
| | | // | |
| | | struct LIBODB_EXPORT section_not_loaded: odb::exception | |
| | | { | |
| | | virtual const char* | |
| | | what () const throw (); | |
| | | }; | |
| | | | |
| | | struct LIBODB_EXPORT section_not_in_object: odb::exception | |
| | | { | |
| | | virtual const char* | |
| | | what () const throw (); | |
| | | }; | |
| | | | |
| namespace common | | namespace common | |
| { | | { | |
| using odb::null_pointer; | | using odb::null_pointer; | |
| | | | |
| using odb::already_in_transaction; | | using odb::already_in_transaction; | |
| using odb::not_in_transaction; | | using odb::not_in_transaction; | |
| using odb::transaction_already_finalized; | | using odb::transaction_already_finalized; | |
| | | | |
| using odb::already_in_session; | | using odb::already_in_session; | |
| using odb::not_in_session; | | using odb::not_in_session; | |
| | | | |
| skipping to change at line 218 | | skipping to change at line 251 | |
| using odb::object_not_persistent; | | using odb::object_not_persistent; | |
| using odb::object_already_persistent; | | using odb::object_already_persistent; | |
| using odb::object_changed; | | using odb::object_changed; | |
| using odb::result_not_cached; | | using odb::result_not_cached; | |
| using odb::database_exception; | | using odb::database_exception; | |
| | | | |
| using odb::abstract_class; | | using odb::abstract_class; | |
| using odb::no_type_info; | | using odb::no_type_info; | |
| | | | |
| using odb::unknown_schema; | | using odb::unknown_schema; | |
|
| | | using odb::unknown_schema_version; | |
| | | | |
| | | using odb::section_not_loaded; | |
| | | using odb::section_not_in_object; | |
| } | | } | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_EXCEPTIONS_HXX | | #endif // ODB_EXCEPTIONS_HXX | |
| | | | |
End of changes. 21 change blocks. |
| 19 lines changed or deleted | | 56 lines changed or added | |
|
| lazy-ptr.hxx | | lazy-ptr.hxx | |
| | | | |
| skipping to change at line 75 | | skipping to change at line 75 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| T* load () const; | | T* load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| | | // Get the underlying eager pointer. If this is an unloaded pointer | |
| | | // to a persistent object, then the returned pointer will be NULL. | |
| | | // | |
| | | T* get_eager () const; | |
| | | | |
| template <class DB, class ID> lazy_ptr (DB&, const ID&); | | template <class DB, class ID> lazy_ptr (DB&, const ID&); | |
| template <class DB, class Y> lazy_ptr (DB&, Y*); | | template <class DB, class Y> lazy_ptr (DB&, Y*); | |
| | | | |
| template <class DB, class ID> void reset (DB&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class DB, class Y> void reset (DB&, Y*); | | template <class DB, class Y> void reset (DB&, Y*); | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| #else | | #else | |
| template <class O /* = T */> | | template <class O /* = T */> | |
| | | | |
| skipping to change at line 188 | | skipping to change at line 193 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::auto_ptr<T>& load () const; | | std::auto_ptr<T>& load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| | | // Get the underlying eager pointer. If this is an unloaded pointer | |
| | | // to a persistent object, then the returned pointer will be NULL. | |
| | | // | |
| | | std::auto_ptr<T>& get_eager () const; | |
| | | | |
| template <class DB, class ID> lazy_auto_ptr (DB&, const ID&); | | template <class DB, class ID> lazy_auto_ptr (DB&, const ID&); | |
| template <class DB> lazy_auto_ptr (DB&, T*); | | template <class DB> lazy_auto_ptr (DB&, T*); | |
| template <class DB, class Y> lazy_auto_ptr (DB&, std::auto_ptr<Y>&); | | template <class DB, class Y> lazy_auto_ptr (DB&, std::auto_ptr<Y>&); | |
| | | | |
| template <class DB, class ID> void reset (DB&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class DB> void reset (DB&, T*); | | template <class DB> void reset (DB&, T*); | |
| template <class DB, class Y> void reset (DB&, std::auto_ptr<Y>&); | | template <class DB, class Y> void reset (DB&, std::auto_ptr<Y>&); | |
| | | | |
| #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | | #ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT | |
| template <class O = T> | | template <class O = T> | |
| | | | |
| skipping to change at line 308 | | skipping to change at line 318 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::unique_ptr<T, D>& load () const; | | std::unique_ptr<T, D>& load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| | | // Get the underlying eager pointer. If this is an unloaded pointer | |
| | | // to a persistent object, then the returned pointer will be NULL. | |
| | | // | |
| | | std::unique_ptr<T, D>& get_eager () const; | |
| | | | |
| template <class DB, class ID> lazy_unique_ptr (DB&, const ID&); | | template <class DB, class ID> lazy_unique_ptr (DB&, const ID&); | |
| template <class DB> lazy_unique_ptr (DB&, pointer); | | template <class DB> lazy_unique_ptr (DB&, pointer); | |
| template <class DB> lazy_unique_ptr (DB&, pointer, const deleter_type&)
; | | template <class DB> lazy_unique_ptr (DB&, pointer, const deleter_type&)
; | |
| template <class DB> lazy_unique_ptr (DB&, pointer, deleter_type&&); | | template <class DB> lazy_unique_ptr (DB&, pointer, deleter_type&&); | |
| template <class DB, class T1, class D1> lazy_unique_ptr (DB&, std::uniq
ue_ptr<T1, D1>&&); | | template <class DB, class T1, class D1> lazy_unique_ptr (DB&, std::uniq
ue_ptr<T1, D1>&&); | |
| template <class DB, class T1> lazy_unique_ptr (DB&, std::auto_ptr<T1>&&
); | | template <class DB, class T1> lazy_unique_ptr (DB&, std::auto_ptr<T1>&&
); | |
| | | | |
| template <class DB, class ID> void reset (DB&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class DB> void reset (DB&, pointer); | | template <class DB> void reset (DB&, pointer); | |
| template <class DB, class T1, class D1> void reset (DB&, std::unique_pt
r<T1, D1>&&); | | template <class DB, class T1, class D1> void reset (DB&, std::unique_pt
r<T1, D1>&&); | |
| | | | |
| skipping to change at line 467 | | skipping to change at line 482 | |
| // | | // | |
| bool loaded () const; | | bool loaded () const; | |
| | | | |
| std::shared_ptr<T> load () const; | | std::shared_ptr<T> load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| | | // Get the underlying eager pointer. If this is an unloaded pointer | |
| | | // to a persistent object, then the returned pointer will be NULL. | |
| | | // | |
| | | std::shared_ptr<T> get_eager () const; | |
| | | | |
| template <class DB, class ID> lazy_shared_ptr (DB&, const ID&); | | template <class DB, class ID> lazy_shared_ptr (DB&, const ID&); | |
| template <class DB, class Y> lazy_shared_ptr (DB&, Y*); | | template <class DB, class Y> lazy_shared_ptr (DB&, Y*); | |
| template <class DB, class Y, class D> lazy_shared_ptr (DB&, Y*, D); | | template <class DB, class Y, class D> lazy_shared_ptr (DB&, Y*, D); | |
| template <class DB, class Y, class D, class A> lazy_shared_ptr (DB&, Y*
, D, A); | | template <class DB, class Y, class D, class A> lazy_shared_ptr (DB&, Y*
, D, A); | |
| template <class DB, class Y> lazy_shared_ptr (DB&, std::auto_ptr<Y>&&); | | template <class DB, class Y> lazy_shared_ptr (DB&, std::auto_ptr<Y>&&); | |
| template <class DB, class Y> lazy_shared_ptr (DB&, const std::shared_pt
r<Y>&); | | template <class DB, class Y> lazy_shared_ptr (DB&, const std::shared_pt
r<Y>&); | |
| template <class DB, class Y> lazy_shared_ptr (DB&, std::shared_ptr<Y>&&
); | | template <class DB, class Y> lazy_shared_ptr (DB&, std::shared_ptr<Y>&&
); | |
| template <class DB, class Y> lazy_shared_ptr (DB&, const std::weak_ptr<
Y>&); | | template <class DB, class Y> lazy_shared_ptr (DB&, const std::weak_ptr<
Y>&); | |
| | | | |
| template <class DB, class ID> void reset (DB&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| | | | |
| skipping to change at line 596 | | skipping to change at line 616 | |
| | | | |
| // Performs both lock and load. | | // Performs both lock and load. | |
| // | | // | |
| std::shared_ptr<T> load () const; | | std::shared_ptr<T> load () const; | |
| | | | |
| // Unload the pointer. For transient objects this function is | | // Unload the pointer. For transient objects this function is | |
| // equivalent to reset(). | | // equivalent to reset(). | |
| // | | // | |
| void unload () const; | | void unload () const; | |
| | | | |
|
| | | // Get the underlying eager pointer. If this is an unloaded pointer | |
| | | // to a persistent object, then the returned pointer will be NULL. | |
| | | // | |
| | | std::weak_ptr<T> get_eager () const; | |
| | | | |
| template <class DB, class ID> lazy_weak_ptr (DB&, const ID&); | | template <class DB, class ID> lazy_weak_ptr (DB&, const ID&); | |
| template <class DB, class Y> lazy_weak_ptr (DB&, const std::shared_ptr<
Y>&); | | template <class DB, class Y> lazy_weak_ptr (DB&, const std::shared_ptr<
Y>&); | |
| template <class DB, class Y> lazy_weak_ptr (DB&, const std::weak_ptr<Y>
&); | | template <class DB, class Y> lazy_weak_ptr (DB&, const std::weak_ptr<Y>
&); | |
| | | | |
| template <class DB, class ID> void reset (DB&, const ID&); | | template <class DB, class ID> void reset (DB&, const ID&); | |
| template <class DB, class Y> void reset (DB&, const std::shared_ptr<Y>&
); | | template <class DB, class Y> void reset (DB&, const std::shared_ptr<Y>&
); | |
| template <class DB, class Y> void reset (DB&, const std::weak_ptr<Y>&); | | template <class DB, class Y> void reset (DB&, const std::weak_ptr<Y>&); | |
| | | | |
| // The object_id() function can only be called when the object is | | // The object_id() function can only be called when the object is | |
| // persistent, or: expired() XOR loaded() (can use != for XOR). | | // persistent, or: expired() XOR loaded() (can use != for XOR). | |
| | | | |
End of changes. 5 change blocks. |
| 0 lines changed or deleted | | 25 lines changed or added | |
|
| lazy-ptr.ixx | | lazy-ptr.ixx | |
| | | | |
| skipping to change at line 118 | | skipping to change at line 118 | |
| loaded () const | | loaded () const | |
| { | | { | |
| bool i (i_); | | bool i (i_); | |
| return (p_ == 0) != i; // !p_ XOR i | | return (p_ == 0) != i; // !p_ XOR i | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline T* lazy_ptr<T>:: | | inline T* lazy_ptr<T>:: | |
| load () const | | load () const | |
| { | | { | |
|
| if (!loaded ()) | | if (p_ == 0 && i_) | |
| p_ = i_.template load<T> (true); // Reset id. | | p_ = i_.template load<T> (true); // Reset id. | |
| | | | |
| return p_; | | return p_; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline void lazy_ptr<T>:: | | inline void lazy_ptr<T>:: | |
| unload () const | | unload () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 140 | | skipping to change at line 140 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_ = 0; | | p_ = 0; | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | inline T* lazy_ptr<T>:: | |
| | | get_eager () const | |
| | | { | |
| | | return p_; | |
| | | } | |
| | | | |
| | | template <class T> | |
| template <class DB, class ID> | | template <class DB, class ID> | |
| inline lazy_ptr<T>:: | | inline lazy_ptr<T>:: | |
| lazy_ptr (DB& db, const ID& id): p_ (0), i_ (db, id) {} | | lazy_ptr (DB& db, const ID& id): p_ (0), i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
| template <class DB, class Y> | | template <class DB, class Y> | |
| inline lazy_ptr<T>:: | | inline lazy_ptr<T>:: | |
| lazy_ptr (DB& db, Y* r) | | lazy_ptr (DB& db, Y* r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| | | | |
| skipping to change at line 374 | | skipping to change at line 381 | |
| loaded () const | | loaded () const | |
| { | | { | |
| bool i (i_); | | bool i (i_); | |
| return (p_.get () == 0) != i; // XOR | | return (p_.get () == 0) != i; // XOR | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline std::auto_ptr<T>& lazy_auto_ptr<T>:: | | inline std::auto_ptr<T>& lazy_auto_ptr<T>:: | |
| load () const | | load () const | |
| { | | { | |
|
| if (!loaded ()) | | if (p_.get () == 0 && i_) | |
| { | | { | |
| std::auto_ptr<T> tmp (i_.template load<T> (true)); // Reset id. | | std::auto_ptr<T> tmp (i_.template load<T> (true)); // Reset id. | |
| p_ = tmp; | | p_ = tmp; | |
| } | | } | |
| | | | |
| return p_; | | return p_; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline void lazy_auto_ptr<T>:: | | inline void lazy_auto_ptr<T>:: | |
| | | | |
| skipping to change at line 399 | | skipping to change at line 406 | |
| if (p_.get () != 0) | | if (p_.get () != 0) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | inline std::auto_ptr<T>& lazy_auto_ptr<T>:: | |
| | | get_eager () const | |
| | | { | |
| | | return p_; | |
| | | } | |
| | | | |
| | | template <class T> | |
| template <class DB, class ID> | | template <class DB, class ID> | |
| inline lazy_auto_ptr<T>:: | | inline lazy_auto_ptr<T>:: | |
| lazy_auto_ptr (DB& db, const ID& id): i_ (db, id) {} | | lazy_auto_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
| template <class DB> | | template <class DB> | |
| inline lazy_auto_ptr<T>:: | | inline lazy_auto_ptr<T>:: | |
| lazy_auto_ptr (DB& db, T* p) | | lazy_auto_ptr (DB& db, T* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| | | | |
| skipping to change at line 648 | | skipping to change at line 662 | |
| loaded () const | | loaded () const | |
| { | | { | |
| bool i (i_); | | bool i (i_); | |
| return !p_ != i; // !p_ XOR i_ | | return !p_ != i; // !p_ XOR i_ | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
| inline std::unique_ptr<T, D>& lazy_unique_ptr<T, D>:: | | inline std::unique_ptr<T, D>& lazy_unique_ptr<T, D>:: | |
| load () const | | load () const | |
| { | | { | |
|
| if (!loaded ()) | | if (!p_ && i_) | |
| p_ = std::unique_ptr<T, D> (i_.template load<T> (true)); // Reset id. | | p_ = std::unique_ptr<T, D> (i_.template load<T> (true)); // Reset id. | |
| | | | |
| return p_; | | return p_; | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
| inline void lazy_unique_ptr<T, D>:: | | inline void lazy_unique_ptr<T, D>:: | |
| unload () const | | unload () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 670 | | skipping to change at line 684 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
|
| | | inline std::unique_ptr<T, D>& lazy_unique_ptr<T, D>:: | |
| | | get_eager () const | |
| | | { | |
| | | return p_; | |
| | | } | |
| | | | |
| | | template <class T, class D> | |
| template <class DB, class ID> | | template <class DB, class ID> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
| lazy_unique_ptr (DB& db, const ID& id): i_ (db, id) {} | | lazy_unique_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T, class D> | | template <class T, class D> | |
| template <class DB> | | template <class DB> | |
| inline lazy_unique_ptr<T, D>:: | | inline lazy_unique_ptr<T, D>:: | |
| lazy_unique_ptr (DB& db, T* p) | | lazy_unique_ptr (DB& db, T* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| | | | |
| skipping to change at line 1131 | | skipping to change at line 1152 | |
| loaded () const | | loaded () const | |
| { | | { | |
| bool i (i_); | | bool i (i_); | |
| return !p_ != i; // !p_ XOR i_ | | return !p_ != i; // !p_ XOR i_ | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline std::shared_ptr<T> lazy_shared_ptr<T>:: | | inline std::shared_ptr<T> lazy_shared_ptr<T>:: | |
| load () const | | load () const | |
| { | | { | |
|
| if (!loaded ()) | | if (!p_ && i_) | |
| p_ = i_.template load<T> (true); // Reset id. | | p_ = i_.template load<T> (true); // Reset id. | |
| | | | |
| return p_; | | return p_; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline void lazy_shared_ptr<T>:: | | inline void lazy_shared_ptr<T>:: | |
| unload () const | | unload () const | |
| { | | { | |
| typedef typename object_traits<T>::object_type object_type; | | typedef typename object_traits<T>::object_type object_type; | |
| | | | |
| skipping to change at line 1153 | | skipping to change at line 1174 | |
| if (p_) | | if (p_) | |
| { | | { | |
| if (i_.database () != 0) | | if (i_.database () != 0) | |
| i_.reset_id (object_traits<object_type>::id (*p_)); | | i_.reset_id (object_traits<object_type>::id (*p_)); | |
| | | | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | inline std::shared_ptr<T> lazy_shared_ptr<T>:: | |
| | | get_eager () const | |
| | | { | |
| | | return p_; | |
| | | } | |
| | | | |
| | | template <class T> | |
| template <class DB, class ID> | | template <class DB, class ID> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
| lazy_shared_ptr (DB& db, const ID& id): i_ (db, id) {} | | lazy_shared_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
| template <class DB, class Y> | | template <class DB, class Y> | |
| inline lazy_shared_ptr<T>:: | | inline lazy_shared_ptr<T>:: | |
| lazy_shared_ptr (DB& db, Y* p) | | lazy_shared_ptr (DB& db, Y* p) | |
| : p_ (p) | | : p_ (p) | |
| { | | { | |
| | | | |
| skipping to change at line 1520 | | skipping to change at line 1548 | |
| bool i (i_); | | bool i (i_); | |
| return expired () != i; // expired () XOR i_ | | return expired () != i; // expired () XOR i_ | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline std::shared_ptr<T> lazy_weak_ptr<T>:: | | inline std::shared_ptr<T> lazy_weak_ptr<T>:: | |
| load () const | | load () const | |
| { | | { | |
| std::shared_ptr<T> r (p_.lock ()); | | std::shared_ptr<T> r (p_.lock ()); | |
| | | | |
|
| if (r || !i_) | | if (!r && i_) | |
| return r; | | { | |
| | | r = i_.template load<T> (false); // Keep id. | |
| | | p_ = r; | |
| | | } | |
| | | | |
|
| r = i_.template load<T> (false); // Keep id. | | | |
| p_ = r; | | | |
| return r; | | return r; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline void lazy_weak_ptr<T>:: | | inline void lazy_weak_ptr<T>:: | |
| unload () const | | unload () const | |
| { | | { | |
| // With weak pointer we always keep i_ up to date. | | // With weak pointer we always keep i_ up to date. | |
| // | | // | |
| p_.reset (); | | p_.reset (); | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| | | inline std::weak_ptr<T> lazy_weak_ptr<T>:: | |
| | | get_eager () const | |
| | | { | |
| | | return p_; | |
| | | } | |
| | | | |
| | | template <class T> | |
| template <class DB, class ID> | | template <class DB, class ID> | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
| lazy_weak_ptr (DB& db, const ID& id): i_ (db, id) {} | | lazy_weak_ptr (DB& db, const ID& id): i_ (db, id) {} | |
| | | | |
| template <class T> | | template <class T> | |
| template <class DB, class Y> | | template <class DB, class Y> | |
| inline lazy_weak_ptr<T>:: | | inline lazy_weak_ptr<T>:: | |
| lazy_weak_ptr (DB& db, const std::shared_ptr<Y>& r) | | lazy_weak_ptr (DB& db, const std::shared_ptr<Y>& r) | |
| : p_ (r) | | : p_ (r) | |
| { | | { | |
| | | | |
End of changes. 11 change blocks. |
| 8 lines changed or deleted | | 44 lines changed or added | |
|
| polymorphic-info.hxx | | polymorphic-info.hxx | |
| // file : odb/polymorphic-info.hxx | | // file : odb/polymorphic-info.hxx | |
| // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_POLYMORPHIC_INFO_HXX | | #ifndef ODB_POLYMORPHIC_INFO_HXX | |
| #define ODB_POLYMORPHIC_INFO_HXX | | #define ODB_POLYMORPHIC_INFO_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <cstddef> // std::size_t | |
| #include <typeinfo> | | #include <typeinfo> | |
| | | | |
|
| #include <odb/forward.hxx> // database | | #include <odb/forward.hxx> // database, connection | |
| | | #include <odb/schema-version.hxx> | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename R> | | template <typename R> | |
| struct polymorphic_abstract_info | | struct polymorphic_abstract_info | |
| { | | { | |
|
| | | typedef void (*section_load) (odb::connection&, R&, bool top); | |
| | | typedef void (*section_update) (odb::connection&, const R&); | |
| | | | |
| | | struct section_functions | |
| | | { | |
| | | section_load load; | |
| | | section_update update; | |
| | | }; | |
| | | | |
| | | struct section_list | |
| | | { | |
| | | std::size_t count; | |
| | | const section_functions* functions; | |
| | | }; | |
| | | | |
| | | public: | |
| polymorphic_abstract_info (const std::type_info& t, | | polymorphic_abstract_info (const std::type_info& t, | |
|
| const polymorphic_abstract_info* b) | | const polymorphic_abstract_info* b, | |
| : type (t), base (b) {} | | const section_list* s) | |
| | | : type (t), base (b), sections (s) {} | |
| | | | |
| bool | | bool | |
| derived (const polymorphic_abstract_info& b) const | | derived (const polymorphic_abstract_info& b) const | |
| { | | { | |
| for (const polymorphic_abstract_info* p (base); p != 0; p = p->base) | | for (const polymorphic_abstract_info* p (base); p != 0; p = p->base) | |
| if (&b == p) | | if (&b == p) | |
| return true; | | return true; | |
| | | | |
| return false; | | return false; | |
| } | | } | |
| | | | |
|
| | | // Find the "most overridden" section functions. | |
| | | // | |
| | | section_load | |
| | | find_section_load (std::size_t index) const | |
| | | { | |
| | | for (const polymorphic_abstract_info* b (this); b != 0; b = b->base) | |
| | | if (b->sections != 0 && | |
| | | index < b->sections->count && | |
| | | b->sections->functions[index].load != 0) | |
| | | return b->sections->functions[index].load; | |
| | | | |
| | | return 0; | |
| | | } | |
| | | | |
| | | section_update | |
| | | find_section_update (std::size_t index) const | |
| | | { | |
| | | for (const polymorphic_abstract_info* b (this); b != 0; b = b->base) | |
| | | if (b->sections != 0 && | |
| | | index < b->sections->count && | |
| | | b->sections->functions[index].update != 0) | |
| | | return b->sections->functions[index].update; | |
| | | | |
| | | return 0; | |
| | | } | |
| | | | |
| | | bool | |
| | | final_section_update (const polymorphic_abstract_info& i, | |
| | | std::size_t index) const | |
| | | { | |
| | | return i.sections != 0 && | |
| | | index < i.sections->count && | |
| | | i.sections->functions[index].update != 0 && | |
| | | i.sections->functions[index].update == find_section_update (index); | |
| | | } | |
| | | | |
| public: | | public: | |
| const std::type_info& type; | | const std::type_info& type; | |
| const polymorphic_abstract_info* base; | | const polymorphic_abstract_info* base; | |
|
| | | | |
| | | // Sections. | |
| | | // | |
| | | // There could be "concrete" (i.e., not overridden) section in an | |
| | | // abstract class. Which means the section table has to be in | |
| | | // abstract_info. | |
| | | // | |
| | | const section_list* sections; | |
| }; | | }; | |
| | | | |
| template <typename R> | | template <typename R> | |
| struct polymorphic_concrete_info: polymorphic_abstract_info<R> | | struct polymorphic_concrete_info: polymorphic_abstract_info<R> | |
| { | | { | |
| // Have to use access::object_traits directly because of VC10. | | // Have to use access::object_traits directly because of VC10. | |
| // | | // | |
| typedef R root_type; | | typedef R root_type; | |
| typedef access::object_traits<root_type> root_traits; | | typedef access::object_traits<root_type> root_traits; | |
| typedef typename root_traits::id_type id_type; | | typedef typename root_traits::id_type id_type; | |
| typedef typename root_traits::pointer_type pointer_type; | | typedef typename root_traits::pointer_type pointer_type; | |
| typedef typename root_traits::discriminator_type discriminator_type; | | typedef typename root_traits::discriminator_type discriminator_type; | |
| | | | |
|
| | | typedef typename polymorphic_abstract_info<R>::section_list section_lis | |
| | | t; | |
| | | | |
| enum call_type | | enum call_type | |
| { | | { | |
| call_callback, // arg points to callback event. | | call_callback, // arg points to callback event. | |
| call_persist, // arg is not used. | | call_persist, // arg is not used. | |
| call_update, // arg is not used. | | call_update, // arg is not used. | |
| call_find, // arg points to object id. | | call_find, // arg points to object id. | |
| call_reload, // arg is not used. | | call_reload, // arg is not used. | |
| call_load, // arg points to depth. | | call_load, // arg points to depth. | |
| call_erase // arg points to object id. | | call_erase // arg points to object id. | |
| }; | | }; | |
| | | | |
| typedef pointer_type (*create_function) (); | | typedef pointer_type (*create_function) (); | |
| typedef bool (*dispatch_function) ( | | typedef bool (*dispatch_function) ( | |
| call_type, odb::database&, const root_type*, const void* arg); | | call_type, odb::database&, const root_type*, const void* arg); | |
| typedef void (*delayed_loader_function) ( | | typedef void (*delayed_loader_function) ( | |
|
| odb::database&, const id_type&, root_type&); | | odb::database&, | |
| | | const id_type&, | |
| | | root_type&, | |
| | | const schema_version_migration*); | |
| | | | |
| public: | | public: | |
| polymorphic_concrete_info (const std::type_info& t, | | polymorphic_concrete_info (const std::type_info& t, | |
| const polymorphic_abstract_info<R>* b, | | const polymorphic_abstract_info<R>* b, | |
|
| | | const section_list* s, | |
| const discriminator_type& d, | | const discriminator_type& d, | |
| create_function cf, | | create_function cf, | |
| dispatch_function df, | | dispatch_function df, | |
| delayed_loader_function dlf) | | delayed_loader_function dlf) | |
|
| : polymorphic_abstract_info<R> (t, b), | | : polymorphic_abstract_info<R> (t, b, s), | |
| discriminator (d), | | discriminator (d), | |
| create (cf), dispatch (df), delayed_loader (dlf) | | create (cf), dispatch (df), delayed_loader (dlf) | |
| { | | { | |
| } | | } | |
| | | | |
| public: | | public: | |
| discriminator_type discriminator; | | discriminator_type discriminator; | |
| create_function create; | | create_function create; | |
| dispatch_function dispatch; | | dispatch_function dispatch; | |
| delayed_loader_function delayed_loader; | | delayed_loader_function delayed_loader; | |
| | | | |
End of changes. 10 change blocks. |
| 5 lines changed or deleted | | 75 lines changed or added | |
|
| polymorphic-map.hxx | | polymorphic-map.hxx | |
| | | | |
| skipping to change at line 152 | | skipping to change at line 152 | |
| call (database& db, const T& obj) | | call (database& db, const T& obj) | |
| { | | { | |
| // Top-level call, no dynamic type checking. | | // Top-level call, no dynamic type checking. | |
| // | | // | |
| object_traits_impl<T, DB>::persist ( | | object_traits_impl<T, DB>::persist ( | |
| db, const_cast<T&> (obj), true, false); | | db, const_cast<T&> (obj), true, false); | |
| } | | } | |
| }; | | }; | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
|
| bool dispatch_impl ( | | bool | |
| | | dispatch_impl ( | |
| typename polymorphic_concrete_info< | | typename polymorphic_concrete_info< | |
| typename object_traits<T>::root_type>::call_type c, | | typename object_traits<T>::root_type>::call_type c, | |
| database& db, | | database& db, | |
| const typename object_traits<T>::root_type* pobj, | | const typename object_traits<T>::root_type* pobj, | |
| const void* arg) | | const void* arg) | |
| { | | { | |
| typedef object_traits_impl<T, DB> derived_traits; | | typedef object_traits_impl<T, DB> derived_traits; | |
| typedef typename derived_traits::root_type root_type; | | typedef typename derived_traits::root_type root_type; | |
| typedef object_traits_impl<root_type, DB> root_traits; | | typedef object_traits_impl<root_type, DB> root_traits; | |
| typedef typename root_traits::id_type id_type; | | typedef typename root_traits::id_type id_type; | |
| | | | |
| skipping to change at line 238 | | skipping to change at line 239 | |
| db, | | db, | |
| *static_cast<const id_type*> (arg), | | *static_cast<const id_type*> (arg), | |
| true, // Top-level call. | | true, // Top-level call. | |
| false); // No dynamic type checking. | | false); // No dynamic type checking. | |
| break; | | break; | |
| } | | } | |
| } | | } | |
| | | | |
| return r; | | return r; | |
| } | | } | |
|
| | | | |
| | | template <typename T, database_id DB, typename ST> | |
| | | void | |
| | | section_load_impl (odb::connection& conn, | |
| | | typename object_traits<T>::root_type& obj, | |
| | | bool top) | |
| | | { | |
| | | typedef object_traits_impl<T, DB> derived_traits; | |
| | | typedef typename derived_traits::statements_type statements_type; | |
| | | typedef typename statements_type::connection_type connection_type; | |
| | | | |
| | | connection_type& c (static_cast<connection_type&> (conn)); | |
| | | statements_type& sts (c.statement_cache ().template find_object<T> ()); | |
| | | | |
| | | ST::load (sts.extra_statement_cache (), static_cast<T&> (obj), top); | |
| | | } | |
| | | | |
| | | template <typename T, database_id DB, typename ST> | |
| | | void | |
| | | section_update_impl (odb::connection& conn, | |
| | | const typename object_traits<T>::root_type& obj) | |
| | | { | |
| | | typedef object_traits_impl<T, DB> derived_traits; | |
| | | typedef typename derived_traits::statements_type statements_type; | |
| | | typedef typename statements_type::connection_type connection_type; | |
| | | | |
| | | connection_type& c (static_cast<connection_type&> (conn)); | |
| | | statements_type& sts (c.statement_cache ().template find_object<T> ()); | |
| | | | |
| | | ST::update (sts.extra_statement_cache (), static_cast<const T&> (obj)); | |
| | | } | |
| } | | } | |
| | | | |
| #include <odb/polymorphic-map.ixx> | | #include <odb/polymorphic-map.ixx> | |
| #include <odb/polymorphic-map.txx> | | #include <odb/polymorphic-map.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_POLYMORPHIC_MAP_HXX | | #endif // ODB_POLYMORPHIC_MAP_HXX | |
| | | | |
End of changes. 2 change blocks. |
| 1 lines changed or deleted | | 33 lines changed or added | |
|
| query-dynamic.hxx | | query-dynamic.hxx | |
| | | | |
| skipping to change at line 138 | | skipping to change at line 138 | |
| op_add, // + (concatenation of two sub-expressions) | | op_add, // + (concatenation of two sub-expressions) | |
| | | | |
| op_and, // && | | op_and, // && | |
| op_or, // || | | op_or, // || | |
| op_not, // ! | | op_not, // ! | |
| | | | |
| op_null, // is_null () | | op_null, // is_null () | |
| op_not_null, // is_not_null () | | op_not_null, // is_not_null () | |
| | | | |
| op_in, // in(), data is the number of arguments | | op_in, // in(), data is the number of arguments | |
|
| | | op_like, // like(pattern) | |
| | | op_like_escape, // like(pattern, escape) | |
| | | | |
| op_eq, // == | | op_eq, // == | |
| op_ne, // != | | op_ne, // != | |
| op_lt, // < | | op_lt, // < | |
| op_gt, // > | | op_gt, // > | |
| op_le, // <= | | op_le, // <= | |
| op_ge // >= | | op_ge // >= | |
| }; | | }; | |
| | | | |
| kind_type kind; | | kind_type kind; | |
| | | | |
| skipping to change at line 418 | | skipping to change at line 420 | |
| query_base | | query_base | |
| in (const T&, const T&, const T&, const T&) const; | | in (const T&, const T&, const T&, const T&) const; | |
| | | | |
| query_base | | query_base | |
| in (const T&, const T&, const T&, const T&, const T&) const; | | in (const T&, const T&, const T&, const T&, const T&) const; | |
| | | | |
| template <typename I> | | template <typename I> | |
| query_base | | query_base | |
| in_range (I begin, I end) const; | | in_range (I begin, I end) const; | |
| | | | |
|
| | | // like | |
| | | // | |
| | | public: | |
| | | query_base | |
| | | like (const T& pattern) const | |
| | | { | |
| | | return like (val_bind<T> (pattern)); | |
| | | } | |
| | | | |
| | | query_base | |
| | | like (val_bind<T> pattern) const; | |
| | | | |
| | | template <typename T2> | |
| | | query_base | |
| | | like (val_bind<T2> pattern) const | |
| | | { | |
| | | return like (val_bind<T> (T (pattern.val))); | |
| | | } | |
| | | | |
| | | query_base | |
| | | like (ref_bind<T> pattern) const; | |
| | | | |
| | | query_base | |
| | | like (const T& pattern, const T& escape) const | |
| | | { | |
| | | return like (val_bind<T> (pattern), escape); | |
| | | } | |
| | | | |
| | | query_base | |
| | | like (val_bind<T> pattern, const T& escape) const; | |
| | | | |
| | | template <typename T2> | |
| | | query_base | |
| | | like (val_bind<T2> pattern, const T& escape) const | |
| | | { | |
| | | return like (val_bind<T> (T (pattern.val)), escape); | |
| | | } | |
| | | | |
| | | query_base | |
| | | like (ref_bind<T> pattern, const T& escape) const; | |
| | | | |
| // == | | // == | |
| // | | // | |
| public: | | public: | |
| query_base | | query_base | |
| equal (val_bind<T> v) const | | equal (val_bind<T> v) const | |
| { | | { | |
| query_base q (native_info); | | query_base q (native_info); | |
| q.append_val (v.val, native_info); | | q.append_val (v.val, native_info); | |
| q.append (query_base::clause_part::op_eq, 0); | | q.append (query_base::clause_part::op_eq, 0); | |
| return q; | | return q; | |
| | | | |
End of changes. 2 change blocks. |
| 0 lines changed or deleted | | 43 lines changed or added | |
|
| query-dynamic.txx | | query-dynamic.txx | |
| // file : odb/query-dynamic.txx | | // file : odb/query-dynamic.txx | |
| // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
|
| | | // | |
| // query_base | | // query_base | |
| // | | // | |
|
| | | | |
| template <typename T> | | template <typename T> | |
| void query_base:: | | void query_base:: | |
| append_val (const T& val, const native_column_info* c) | | append_val (const T& val, const native_column_info* c) | |
| { | | { | |
| clause_.push_back (clause_part ()); | | clause_.push_back (clause_part ()); | |
| clause_part& p (clause_.back ()); | | clause_part& p (clause_.back ()); | |
| | | | |
| p.kind = clause_part::kind_param_val; | | p.kind = clause_part::kind_param_val; | |
| p.data = 0; // In case new below throws. | | p.data = 0; // In case new below throws. | |
| p.native_info = c; | | p.native_info = c; | |
| | | | |
| query_param* qp (new (details::shared) val_query_param<T> (val)); | | query_param* qp (new (details::shared) val_query_param<T> (val)); | |
| p.data = reinterpret_cast<std::size_t> (qp); | | p.data = reinterpret_cast<std::size_t> (qp); | |
| } | | } | |
| | | | |
|
| | | // | |
| // query_column | | // query_column | |
| // | | // | |
|
| | | | |
| | | // in | |
| | | // | |
| template <typename T> | | template <typename T> | |
| query_base query_column<T>:: | | query_base query_column<T>:: | |
| in (const T& v1, const T& v2) const | | in (const T& v1, const T& v2) const | |
| { | | { | |
| query_base q (native_info); | | query_base q (native_info); | |
| q.append_val (v1, native_info); | | q.append_val (v1, native_info); | |
| q.append_val (v2, native_info); | | q.append_val (v2, native_info); | |
| q.append (query_base::clause_part::op_in, 2); | | q.append (query_base::clause_part::op_in, 2); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| skipping to change at line 90 | | skipping to change at line 96 | |
| { | | { | |
| query_base q (native_info); | | query_base q (native_info); | |
| | | | |
| std::size_t n (0); | | std::size_t n (0); | |
| for (; i != end; ++i, ++n) | | for (; i != end; ++i, ++n) | |
| q.append_val<T> (*i, native_info); // Force implicit conversion. | | q.append_val<T> (*i, native_info); // Force implicit conversion. | |
| | | | |
| q.append (query_base::clause_part::op_in, n); | | q.append (query_base::clause_part::op_in, n); | |
| return q; | | return q; | |
| } | | } | |
|
| | | | |
| | | // like | |
| | | // | |
| | | template <typename T> | |
| | | query_base query_column<T>:: | |
| | | like (val_bind<T> p) const | |
| | | { | |
| | | query_base q (native_info); | |
| | | q.append_val (p.val, native_info); | |
| | | q.append (query_base::clause_part::op_like, 0); | |
| | | return q; | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | query_base query_column<T>:: | |
| | | like (ref_bind<T> p) const | |
| | | { | |
| | | query_base q (native_info); | |
| | | q.append_ref (p.ptr (), native_info); | |
| | | q.append (query_base::clause_part::op_like, 0); | |
| | | return q; | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | query_base query_column<T>:: | |
| | | like (val_bind<T> p, const T& e) const | |
| | | { | |
| | | query_base q (native_info); | |
| | | q.append_val (p.val, native_info); | |
| | | q.append_val (e, native_info); | |
| | | q.append (query_base::clause_part::op_like_escape, 0); | |
| | | return q; | |
| | | } | |
| | | | |
| | | template <typename T> | |
| | | query_base query_column<T>:: | |
| | | like (ref_bind<T> p, const T& e) const | |
| | | { | |
| | | query_base q (native_info); | |
| | | q.append_ref (p.ptr (), native_info); | |
| | | q.append_val (e, native_info); | |
| | | q.append (query_base::clause_part::op_like_escape, 0); | |
| | | return q; | |
| | | } | |
| } | | } | |
| | | | |
End of changes. 5 change blocks. |
| 0 lines changed or deleted | | 50 lines changed or added | |
|
| schema-catalog.hxx | | schema-catalog.hxx | |
| // file : odb/schema-catalog.hxx | | // file : odb/schema-catalog.hxx | |
| // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_SCHEMA_CATALOG_HXX | | #ifndef ODB_SCHEMA_CATALOG_HXX | |
| #define ODB_SCHEMA_CATALOG_HXX | | #define ODB_SCHEMA_CATALOG_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| #include <string> | | #include <string> | |
|
| | | #include <cstddef> // std::size_t | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | # include <functional> // std::function | |
| | | #endif | |
| | | | |
|
| #include <odb/forward.hxx> // odb::core | | #include <odb/forward.hxx> // schema_version, odb::core | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
|
| | | #include <odb/details/unused.hxx> | |
| | | #include <odb/details/meta/static-assert.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class LIBODB_EXPORT schema_catalog | | class LIBODB_EXPORT schema_catalog | |
| { | | { | |
| public: | | public: | |
|
| | | // Schema creation. | |
| | | // | |
| static void | | static void | |
|
| create_schema (database&, const std::string& name = ""); | | create_schema (database&, const std::string& name = "", bool drop = tru
e); | |
| | | | |
|
| static bool | | static void | |
| exists (database_id, const std::string& name); | | drop_schema (database&, const std::string& name = ""); | |
| | | | |
| | | // Schema migration. | |
| | | // | |
| | | public: | |
| | | static void | |
| | | migrate_schema_pre (database& db, | |
| | | schema_version v, | |
| | | const std::string& name = "") | |
| | | { | |
| | | migrate_schema_impl (db, v, name, migrate_pre); | |
| | | } | |
| | | | |
|
| | | static void | |
| | | migrate_schema_post (database& db, | |
| | | schema_version v, | |
| | | const std::string& name = "") | |
| | | { | |
| | | migrate_schema_impl (db, v, name, migrate_post); | |
| | | } | |
| | | | |
| | | static void | |
| | | migrate_schema (database& db, | |
| | | schema_version v, | |
| | | const std::string& name = "") | |
| | | { | |
| | | migrate_schema_impl (db, v, name, migrate_both); | |
| | | } | |
| | | | |
| | | // Data migration. | |
| | | // | |
| | | public: | |
| | | // If version is 0, then use the current database version and also | |
| | | // check whether we are in migration. Returns the number of calls made. | |
| | | // | |
| | | static std::size_t | |
| | | migrate_data (database&, | |
| | | schema_version = 0, | |
| | | const std::string& name = ""); | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | typedef std::function<void (database&)> data_migration_function_type; | |
| | | #else | |
| | | typedef void (*data_migration_function_type) (database&); | |
| | | #endif | |
| | | | |
| | | // The following three variants of the registration functions make | |
| | | // sure that the version is greater that the base model version. | |
| | | // This helps with identifying and removing data migration function | |
| | | // that are no longer required. | |
| | | // | |
| | | // Data migration functions are called in the order of registration. | |
| | | // | |
| | | template <schema_version v, schema_version base> | |
| | | static void | |
| | | data_migration_function (data_migration_function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | data_migration_function<v, base> (id_common, f, name); | |
| | | } | |
| | | | |
| | | // Database-specific data migration. | |
| | | // | |
| | | template <schema_version v, schema_version base> | |
| | | static void | |
| | | data_migration_function (database& db, | |
| | | data_migration_function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | data_migration_function<v, base> (db.id (), f, name); | |
| | | } | |
| | | | |
| | | template <schema_version v, schema_version base> | |
| | | static void | |
| | | data_migration_function (database_id id, | |
| | | data_migration_function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | // If the data migration version is below the base model version | |
| | | // then it will never be called. | |
| | | // | |
| | | #ifdef ODB_CXX11 | |
| | | static_assert (v > base || base == 0, | |
| | | "data migration function is no longer necessary"); | |
| | | #else | |
| | | // Poor man's static_assert. | |
| | | // | |
| | | typedef details::meta::static_assert_test<(v > base || base == 0)> | |
| | | data_migration_function_is_no_longer_necessary; | |
| | | | |
| | | char sa [sizeof (data_migration_function_is_no_longer_necessary)]; | |
| | | ODB_POTENTIALLY_UNUSED (sa); | |
| | | #endif | |
| | | | |
| | | data_migration_function (id, v, f, name); | |
| | | } | |
| | | | |
| | | // The same as above but take the version as an argument and do | |
| | | // not check whether it is greater than the base model version. | |
| | | // | |
| | | static void | |
| | | data_migration_function (schema_version v, | |
| | | data_migration_function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | data_migration_function (id_common, v, f, name); | |
| | | } | |
| | | | |
| | | static void | |
| | | data_migration_function (database& db, | |
| | | schema_version v, | |
| | | data_migration_function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | data_migration_function (db.id (), v, f, name); | |
| | | } | |
| | | | |
| | | static void | |
| | | data_migration_function (database_id, | |
| | | schema_version, | |
| | | data_migration_function_type, | |
| | | const std::string& name = ""); | |
| | | | |
| | | // Combined schema and data migration. | |
| | | // | |
| | | public: | |
| | | // Migrate both schema and data to the specified version. If version | |
| | | // is not specified, then migrate to the current model version. | |
| | | // | |
| | | static void | |
| | | migrate (database&, schema_version = 0, const std::string& name = ""); | |
| | | | |
| | | // Schema version information. | |
| | | // | |
| | | public: | |
| | | // Return the base model version. | |
| | | // | |
| | | static schema_version | |
| | | base_version (const database& db, const std::string& name = "") | |
| | | { | |
| | | return base_version (db.id (), name); | |
| | | } | |
| | | | |
| | | static schema_version | |
| | | base_version (database_id, const std::string& name = ""); | |
| | | | |
| | | // Return the current model version. | |
| | | // | |
| | | static schema_version | |
| | | current_version (const database& db, const std::string& name = "") | |
| | | { | |
| | | return current_version (db.id (), name); | |
| | | } | |
| | | | |
| | | static schema_version | |
| | | current_version (database_id, const std::string& name = ""); | |
| | | | |
| | | // Return current model version + 1 (that is, one past current) if | |
| | | // the passed version is equal to or greater than current. If the | |
| | | // version is not specified, then use the current database version. | |
| | | // | |
| | | static schema_version | |
| | | next_version (const database& db, | |
| | | schema_version v = 0, | |
| | | const std::string& name = "") | |
| | | { | |
| | | return next_version (db.id (), v == 0 ? db.schema_version () : v, nam | |
| | | e); | |
| | | } | |
| | | | |
| | | static schema_version | |
| | | next_version (database_id, | |
| | | schema_version, | |
| | | const std::string& name = ""); | |
| | | | |
| | | // Schema existence. | |
| | | // | |
| | | public: | |
| | | // Test for presence of a schema with a specific name. | |
| | | // | |
| static bool | | static bool | |
|
| exists (const database& db, const std::string& name) | | exists (const database& db, const std::string& name = "") | |
| { | | { | |
| return exists (db.id (), name); | | return exists (db.id (), name); | |
| } | | } | |
|
| | | | |
| | | static bool | |
| | | exists (database_id, const std::string& name = ""); | |
| | | | |
| | | private: | |
| | | enum migrate_mode | |
| | | { | |
| | | migrate_pre, | |
| | | migrate_post, | |
| | | migrate_both | |
| | | }; | |
| | | | |
| | | static void | |
| | | migrate_schema_impl (database&, | |
| | | schema_version, | |
| | | const std::string& name, | |
| | | migrate_mode); | |
| | | }; | |
| | | | |
| | | // Static data migration function registration. | |
| | | // | |
| | | template <schema_version v, schema_version base> | |
| | | struct data_migration_entry | |
| | | { | |
| | | typedef schema_catalog::data_migration_function_type function_type; | |
| | | | |
| | | data_migration_entry (function_type f, const std::string& name = "") | |
| | | { | |
| | | schema_catalog::data_migration_function<v, base> (f, name); | |
| | | } | |
| | | | |
| | | data_migration_entry (database_id id, | |
| | | function_type f, | |
| | | const std::string& name = "") | |
| | | { | |
| | | schema_catalog::data_migration_function<v, base> (id, v, f, name); | |
| | | } | |
| }; | | }; | |
| | | | |
| namespace common | | namespace common | |
| { | | { | |
| using odb::schema_catalog; | | using odb::schema_catalog; | |
|
| | | using odb::data_migration_entry; | |
| } | | } | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_SCHEMA_CATALOG_HXX | | #endif // ODB_SCHEMA_CATALOG_HXX | |
| | | | |
End of changes. 11 change blocks. |
| 5 lines changed or deleted | | 232 lines changed or added | |
|
| statement.hxx | | statement.hxx | |
| // file : odb/statement.hxx | | // file : odb/statement.hxx | |
| // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_STATEMENT_HXX | | #ifndef ODB_STATEMENT_HXX | |
| #define ODB_STATEMENT_HXX | | #define ODB_STATEMENT_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <string> | |
| | | #include <cstddef> // std::size_t | |
| | | | |
| #include <odb/forward.hxx> // connection | | #include <odb/forward.hxx> // connection | |
| | | | |
| #include <odb/details/export.hxx> | | #include <odb/details/export.hxx> | |
| #include <odb/details/shared-ptr.hxx> | | #include <odb/details/shared-ptr.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| class LIBODB_EXPORT statement: public details::shared_base | | class LIBODB_EXPORT statement: public details::shared_base | |
| { | | { | |
| private: | | private: | |
| | | | |
| skipping to change at line 37 | | skipping to change at line 40 | |
| text () const = 0; | | text () const = 0; | |
| | | | |
| virtual connection_type& | | virtual connection_type& | |
| connection () = 0; | | connection () = 0; | |
| | | | |
| virtual | | virtual | |
| ~statement () = 0; | | ~statement () = 0; | |
| | | | |
| protected: | | protected: | |
| statement () {} | | statement () {} | |
|
| | | | |
| | | // Statement processing. Kept public only for testing. | |
| | | // | |
| | | public: | |
| | | // Expected statement structure: | |
| | | // | |
| | | // INSERT INTO table\n | |
| | | // [(a,\n | |
| | | // b)\n] | |
| | | // [OUTPUT ...\n] | |
| | | // [VALUES\n | |
| | | // ($1,\n | |
| | | // $2)[\n]] | |
| | | // [DEFAULT VALUES[\n]] | |
| | | // [RETURNING ...] | |
| | | // [; SELECT ...] | |
| | | // | |
| | | static void | |
| | | process_insert (const char* statement, | |
| | | const void* const* bind, // Array of bind buffer pointe | |
| | | rs. | |
| | | std::size_t bind_size, // Number of bind elements. | |
| | | std::size_t bind_skip, // Offset to the next bind. | |
| | | char param_symbol, // $, ?, :, etc. | |
| | | std::string& result); | |
| | | | |
| | | // Expected statement structure: | |
| | | // | |
| | | // UPDATE table\n | |
| | | // SET\n | |
| | | // a=$1,\n | |
| | | // b=$2[\n] | |
| | | // [OUTPUT ...] | |
| | | // [WHERE ...] | |
| | | // | |
| | | static void | |
| | | process_update (const char* statement, | |
| | | const void* const* bind, // Array of bind buffer pointe | |
| | | rs. | |
| | | std::size_t bind_size, // Number of bind elements. | |
| | | std::size_t bind_skip, // Offset to the next bind. | |
| | | char param_symbol, // $, ?, :, etc. | |
| | | std::string& result); | |
| | | | |
| | | // Expected statement structure: | |
| | | // | |
| | | // SELECT\n | |
| | | // [schema.]table.a,\n | |
| | | // alias.b\n | |
| | | // FROM [schema.]table[\n] | |
| | | // [LEFT JOIN [schema.]table [AS alias] ON ...[\n]]* | |
| | | // [WHERE ...] | |
| | | // | |
| | | static void | |
| | | process_select (const char* statement, | |
| | | const void* const* bind, // Array of bind buffer pointe | |
| | | rs. | |
| | | std::size_t bind_size, // Number of bind elements. | |
| | | std::size_t bind_skip, // Offset to the next bind. | |
| | | char quote_open, // Identifier opening quote. | |
| | | char quote_close, // Identifier closing quote. | |
| | | bool optimize, // Remove unused JOINs. | |
| | | std::string& result, | |
| | | bool as = true); // JOINs use AS keyword. | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
|
| #endif // ODB_MYSQL_STATEMENT_HXX | | #endif // ODB_STATEMENT_HXX | |
| | | | |
End of changes. 3 change blocks. |
| 0 lines changed or deleted | | 67 lines changed or added | |
|
| traits.hxx | | traits.hxx | |
| | | | |
| skipping to change at line 184 | | skipping to change at line 184 | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
| template <typename T, typename A1, template <typename, typename> class P> | | template <typename T, typename A1, template <typename, typename> class P> | |
| struct object_traits<const P<T, A1> > | | struct object_traits<const P<T, A1> > | |
| { | | { | |
| struct id_type {}; | | struct id_type {}; | |
| }; | | }; | |
| | | | |
|
| | | // Specialization for section to allow instantiation of all the load() | |
| | | // signature. | |
| | | // | |
| | | template <> | |
| | | struct object_traits<section> {}; | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| // | | // | |
| // If a C++ compiler issues an error pointing to this struct and | | // If a C++ compiler issues an error pointing to this struct and | |
| // saying that it is incomplete, then you are most likely trying to | | // saying that it is incomplete, then you are most likely trying to | |
| // perform a database operation on a C++ type that is not a persistent | | // perform a database operation on a C++ type that is not a persistent | |
| // object. Or you forgot to include the corresponding -odb.hxx file. | | // object. Or you forgot to include the corresponding -odb.hxx file. | |
| // | | // | |
| struct object_traits_impl: | | struct object_traits_impl: | |
| access::object_traits_impl<T, DB>, | | access::object_traits_impl<T, DB>, | |
| access::object_factory<T, typename access::object_traits<T>::pointer_ty
pe> | | access::object_factory<T, typename access::object_traits<T>::pointer_ty
pe> | |
| | | | |
| skipping to change at line 274 | | skipping to change at line 280 | |
| }; | | }; | |
| | | | |
| // | | // | |
| // composite_value_traits | | // composite_value_traits | |
| // | | // | |
| | | | |
| template <typename T, database_id DB> | | template <typename T, database_id DB> | |
| struct composite_value_traits: access::composite_value_traits<T, DB> | | struct composite_value_traits: access::composite_value_traits<T, DB> | |
| { | | { | |
| }; | | }; | |
|
| | | | |
| | | // | |
| | | // Get root image from a polymorphic image chain. | |
| | | // | |
| | | | |
| | | template <typename T, std::size_t d> | |
| | | struct root_image_impl | |
| | | { | |
| | | typedef root_image_impl<typename T::base_traits, d - 1> base_type; | |
| | | typedef typename base_type::image_type image_type; | |
| | | | |
| | | static image_type& | |
| | | get (typename T::image_type& i) {return base_type::get (*i.base);} | |
| | | }; | |
| | | | |
| | | template <typename T> | |
| | | struct root_image_impl<T, 1> | |
| | | { | |
| | | typedef typename T::image_type image_type; | |
| | | | |
| | | static image_type& | |
| | | get (image_type& i) {return i;} | |
| | | }; | |
| | | | |
| | | template <typename T, bool p> | |
| | | struct root_image | |
| | | { | |
| | | typedef root_image_impl<T, T::depth> impl_type; | |
| | | typedef typename impl_type::image_type image_type; | |
| | | | |
| | | static image_type& | |
| | | get (typename T::image_type& i) {return impl_type::get (i);} | |
| | | }; | |
| | | | |
| | | template <typename T> | |
| | | struct root_image<T, false> | |
| | | { | |
| | | typedef typename T::image_type image_type; | |
| | | | |
| | | static image_type& | |
| | | get (image_type& i) {return i;} | |
| | | }; | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_TRAITS_HXX | | #endif // ODB_TRAITS_HXX | |
| | | | |
End of changes. 2 change blocks. |
| 0 lines changed or deleted | | 48 lines changed or added | |
|