1 /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef DD__WEAK_OBJECT_IMPL_INCLUDED 24 #define DD__WEAK_OBJECT_IMPL_INCLUDED 25 26 #include "sql/dd/object_id.h" // Object_id 27 #include "sql/dd/types/weak_object.h" // dd::Weak_object 28 29 namespace dd { 30 31 /////////////////////////////////////////////////////////////////////////// 32 33 class Entity_object; 34 class Entity_object_impl; 35 class Object_key; 36 class Object_table; 37 class Open_dictionary_tables_ctx; 38 class Raw_new_record; 39 class Raw_record; 40 41 /////////////////////////////////////////////////////////////////////////// 42 43 class Weak_object_impl : virtual public Weak_object { 44 public: Weak_object_impl()45 Weak_object_impl() {} 46 ~Weak_object_impl()47 virtual ~Weak_object_impl() {} 48 49 public: 50 virtual const Object_table &object_table() const = 0; 51 52 virtual bool validate() const = 0; 53 54 // NOTE: the store() operation can not be made constant as 55 // the object state is modified when storing a newly created object 56 // (object id is assigned using auto-increment). 57 virtual bool store(Open_dictionary_tables_ctx *otx); 58 59 bool drop(Open_dictionary_tables_ctx *otx) const; 60 61 public: 62 virtual bool restore_attributes(const Raw_record &r) = 0; 63 64 virtual bool store_attributes(Raw_record *r) = 0; 65 66 public: 67 // Restore's all the related collections. 68 // There are 2 scenarions when collection is filled. 69 // 1) Parent object is retrieved using restore() 70 // and then restore collections. 71 // Eg: Tablespace (Parent object) invoked restore() 72 // and then call restore_children() to fetch 73 // Tablespace_file objects. 74 // 75 // 2) Parent object is fetched using Raw_record_set->next() 76 // and then restore collections is called for each 77 // parent object fetched. 78 // Eg. Indexes (Parent object) that belong to a Table object 79 // is fetched and then Index_element collections per 80 // index is restored using restore_children(). 81 // restore_children(Open_dictionary_tables_ctx *)82 virtual bool restore_children(Open_dictionary_tables_ctx *) { return false; } 83 store_children(Open_dictionary_tables_ctx *)84 virtual bool store_children(Open_dictionary_tables_ctx *) { return false; } 85 drop_children(Open_dictionary_tables_ctx *)86 virtual bool drop_children(Open_dictionary_tables_ctx *) const { 87 return false; 88 } 89 90 /** 91 Indicates that object is guaranteed to have primary key value which 92 doesn't exist in database (e.g. because it only will be generated 93 using auto-increment at store() time). So it is ok for store() method 94 to skip lookup of existing object with the same primary key and simply 95 try to insert new object into the table. 96 */ 97 virtual bool has_new_primary_key() const = 0; 98 99 protected: 100 virtual Object_key *create_primary_key() const = 0; 101 102 // set_primary_key_value() is called after new object has been inserted into 103 // the table, giving the chance to get inserted values of AUTO_INCREMENT 104 // columns. It gives a chance for Entity_object to override it. set_primary_key_value(const Raw_new_record &)105 virtual void set_primary_key_value(const Raw_new_record &) {} 106 107 /* 108 Called by store() method to allow resetting of has_new_primary_key() 109 property after we completed loading of object and its children. 110 */ fix_has_new_primary_key()111 virtual void fix_has_new_primary_key() {} 112 113 protected: 114 // Check if the parent object id matches with this object. 115 bool check_parent_consistency(Entity_object_impl *parent, 116 Object_id parent_id) const; 117 }; 118 119 /////////////////////////////////////////////////////////////////////////// 120 121 } // namespace dd 122 123 #endif // DD__WEAK_OBJECT_IMPL_INCLUDED 124