1 /* Copyright (c) 2014, 2018, 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__CHARSET_IMPL_INCLUDED 24 #define DD__CHARSET_IMPL_INCLUDED 25 26 #include <stdio.h> 27 #include <sys/types.h> 28 #include <new> 29 30 #include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_imp 31 #include "sql/dd/impl/types/weak_object_impl.h" 32 #include "sql/dd/object_id.h" 33 #include "sql/dd/string_type.h" 34 #include "sql/dd/types/charset.h" // dd::Charset 35 36 namespace dd { 37 38 /////////////////////////////////////////////////////////////////////////// 39 40 class Object_table; 41 class Open_dictionary_tables_ctx; 42 class Raw_record; 43 class Weak_object; 44 class Object_table; 45 46 /////////////////////////////////////////////////////////////////////////// 47 48 class Charset_impl : public Entity_object_impl, public Charset { 49 public: Charset_impl()50 Charset_impl() 51 : m_mb_max_length(0), m_default_collation_id(INVALID_OBJECT_ID) {} 52 53 public: 54 virtual const Object_table &object_table() const; 55 56 static void register_tables(Open_dictionary_tables_ctx *otx); 57 58 virtual bool validate() const; 59 60 virtual bool restore_attributes(const Raw_record &r); 61 62 virtual bool store_attributes(Raw_record *r); 63 64 public: 65 ///////////////////////////////////////////////////////////////////////// 66 // Default collation. 67 ///////////////////////////////////////////////////////////////////////// 68 default_collation_id()69 virtual Object_id default_collation_id() const { 70 return m_default_collation_id; 71 } 72 set_default_collation_id(Object_id collation_id)73 virtual void set_default_collation_id(Object_id collation_id) { 74 m_default_collation_id = collation_id; 75 } 76 77 ///////////////////////////////////////////////////////////////////////// 78 // mb_max_length 79 ///////////////////////////////////////////////////////////////////////// 80 mb_max_length()81 virtual uint mb_max_length() const { return m_mb_max_length; } 82 set_mb_max_length(uint mb_max_length)83 virtual void set_mb_max_length(uint mb_max_length) { 84 m_mb_max_length = mb_max_length; 85 } 86 87 ///////////////////////////////////////////////////////////////////////// 88 // comment 89 ///////////////////////////////////////////////////////////////////////// 90 comment()91 virtual const String_type &comment() const { return m_comment; } 92 set_comment(const String_type & comment)93 virtual void set_comment(const String_type &comment) { m_comment = comment; } 94 95 // Fix "inherits ... via dominance" warnings impl()96 virtual Entity_object_impl *impl() { return Entity_object_impl::impl(); } impl()97 virtual const Entity_object_impl *impl() const { 98 return Entity_object_impl::impl(); 99 } id()100 virtual Object_id id() const { return Entity_object_impl::id(); } is_persistent()101 virtual bool is_persistent() const { 102 return Entity_object_impl::is_persistent(); 103 } name()104 virtual const String_type &name() const { return Entity_object_impl::name(); } set_name(const String_type & name)105 virtual void set_name(const String_type &name) { 106 Entity_object_impl::set_name(name); 107 } 108 109 public: debug_print(String_type & outb)110 virtual void debug_print(String_type &outb) const { 111 char outbuf[1024]; 112 sprintf(outbuf, 113 "CHARSET OBJECT: {OID: %lld}, name= %s, " 114 "collation_id= {OID: %lld}, mb_max_length= %u, " 115 "comment= %s", 116 id(), name().c_str(), m_default_collation_id, m_mb_max_length, 117 m_comment.c_str()); 118 outb = String_type(outbuf); 119 } 120 121 private: 122 uint m_mb_max_length; 123 String_type m_comment; 124 125 Object_id m_default_collation_id; 126 clone()127 Charset *clone() const { return new Charset_impl(*this); } 128 }; 129 130 /////////////////////////////////////////////////////////////////////////// 131 132 } // namespace dd 133 134 #endif // DD__CHARSET_IMPL_INCLUDED 135