1 /* Copyright (c) 2010, 2011, 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 RPL_INFO_TABLE_H
24 #define RPL_INFO_TABLE_H
25 
26 #include "rpl_info_handler.h"
27 #include "rpl_info_table_access.h"
28 
29 /**
30   Methods to find information in a table:
31 
32   FIND_SCAN does a index scan and stops at n-th occurrence.
33 
34   FIND_KEY retrieves the index entry previous populated at
35   values if there is any.
36 */
37 enum enum_find_method { FIND_SCAN, FIND_KEY };
38 
39 class Rpl_info_table : public Rpl_info_handler
40 {
41   friend class Rpl_info_factory;
42 
43 public:
44   virtual ~Rpl_info_table();
45 
46 private:
47   /**
48     This property identifies the name of the schema where a
49     replication table is created.
50   */
51   LEX_STRING str_schema;
52 
53   /**
54     This property identifies the name of a replication
55     table.
56   */
57   LEX_STRING str_table;
58 
59   /**
60     This property represents a description of the repository.
61     Speciffically, "schema"."table".
62   */
63   char *description;
64 
65   /**
66     This is a pointer to a class that facilitates manipulation
67     of replication tables.
68   */
69   Rpl_info_table_access *access;
70 
71   /**
72     Identifies if a table is transactional or non-transactional.
73     This is used to provide a crash-safe behaviour.
74   */
75   bool is_transactional;
76 
77   int do_init_info();
78   int do_init_info(uint instance);
79   int do_init_info(enum_find_method method, uint instance);
80   enum_return_check do_check_info();
81   enum_return_check do_check_info(uint instance);
82   void do_end_info();
83   int do_flush_info(const bool force);
84   int do_remove_info();
85   int do_clean_info();
86   /**
87     Returns the number of entries in the table identified by:
88     param_schema.param_table.
89 
90     @param[in]  nparam           Number of fields in the table.
91     @param[in]  param_schema     Table's schema.
92     @param[in]  param_table      Table's name.
93     @param[out] counter          Number of entries found.
94 
95     @retval false Success
96     @retval true  Error
97   */
98   static bool do_count_info(uint nparam, const char* param_schema,
99                             const char* param_table,  uint* counter);
100   static int do_reset_info(uint nparam, const char* param_schema,
101                            const char *param_table);
102   int do_prepare_info_for_read();
103   int do_prepare_info_for_write();
104 
105   bool do_set_info(const int pos, const char *value);
106   bool do_set_info(const int pos, const uchar *value,
107                    const size_t size);
108   bool do_set_info(const int pos, const int value);
109   bool do_set_info(const int pos, const ulong value);
110   bool do_set_info(const int pos, const float value);
111   bool do_set_info(const int pos, const Dynamic_ids *value);
112   bool do_get_info(const int pos, char *value, const size_t size,
113                    const char *default_value);
114   bool do_get_info(const int pos, uchar *value, const size_t size,
115                    const uchar *default_value);
116   bool do_get_info(const int pos, int *value,
117                    const int default_value);
118   bool do_get_info(const int pos, ulong *value,
119                    const ulong default_value);
120   bool do_get_info(const int pos, float *value,
121                    const float default_value);
122   bool do_get_info(const int pos, Dynamic_ids *value,
123                    const Dynamic_ids *default_value);
124   char* do_get_description_info();
125 
126   bool do_is_transactional();
127   bool do_update_is_transactional();
128   uint do_get_rpl_info_type();
129 
130   Rpl_info_table(uint nparam,
131                  const char* param_schema,
132                  const char *param_table);
133 
134   Rpl_info_table(const Rpl_info_table& info);
135   Rpl_info_table& operator=(const Rpl_info_table& info);
136 };
137 #endif /* RPL_INFO_TABLE_H */
138