MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbInfo.hpp
1 /*
2  Copyright 2009, 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef NDBINFO_HPP
20 #define NDBINFO_HPP
21 
22 #include <ndb_global.h>
23 #include <ndb_types.h>
24 #include <ndb_version.h>
25 
26 #include <util/Vector.hpp>
27 #include <util/BaseString.hpp>
28 #include <util/HashMap.hpp>
29 
30 class NdbInfo
31 {
32 public:
33 
34  enum Error
35  {
36  ERR_NoError = 0,
37  ERR_NoSuchTable = 40,
38  ERR_OutOfMemory = 41,
39  ERR_ClusterFailure = 42,
40  ERR_WrongState = 43
41  };
42 
43  struct Column
44  {
45  public:
46 
47  enum Type
48  {
49  String = 1,
50  Number = 2,
51  Number64 = 3
52  } m_type;
53 
54  Uint32 m_column_id;
55  BaseString m_name;
56 
57  Column(const char* name, Uint32 col_id, Type type);
58  Column(const Column & col);
59  Column & operator=(const Column & col);
60  };
61 
62  class Table
63  {
64  public:
65 
66  Table(const char *name, Uint32 id);
67  Table(const Table& tab);
68  const Table & operator=(const Table& tab);
69  ~Table();
70 
71  const char * getName() const;
72  Uint32 getTableId() const;
73 
74  bool addColumn(const Column aCol);
75  unsigned columns(void) const;
76  const Column* getColumn(const unsigned attributeId) const;
77  const Column* getColumn(const char * name) const;
78 
79  private:
80  friend class NdbInfo;
81  BaseString m_name;
82  Uint32 m_table_id;
83  Vector<Column*> m_columns;
84  };
85 
86  NdbInfo(class Ndb_cluster_connection* connection,
87  const char* prefix, const char* dbname = "",
88  const char* table_prefix = "");
89  bool init(void);
90  ~NdbInfo();
91 
92  int openTable(const char* table_name, const Table**);
93  int openTable(Uint32 tableId, const Table**);
94  void closeTable(const Table* table);
95 
96  int createScanOperation(const Table*,
97  class NdbInfoScanOperation**,
98  Uint32 max_rows = 256, Uint32 max_bytes = 0);
99  void releaseScanOperation(class NdbInfoScanOperation*) const;
100 
101 private:
102  static const size_t NUM_HARDCODED_TABLES = 2;
103  unsigned m_connect_count;
104  unsigned m_min_db_version;
105  class Ndb_cluster_connection* m_connection;
106  pthread_mutex_t m_mutex;
108  Table* m_tables_table;
109  Table* m_columns_table;
110  BaseString m_prefix;
111  BaseString m_dbname;
112  BaseString m_table_prefix;
113  Uint32 m_id_counter;
114 
115  bool addColumn(Uint32 tableId, const Column aCol);
116 
117  bool load_ndbinfo_tables();
118  bool load_hardcoded_tables(void);
119  bool load_tables();
120  bool check_tables();
121  void flush_tables();
122 
123  BaseString mysql_table_name(const char* table_name) const;
124 
125 };
126 
127 #include "NdbInfoScanOperation.hpp"
128 #include "NdbInfoRecAttr.hpp"
129 
130 #endif