File: db_conn_be.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (185 lines) | stat: -rw-r--r-- 5,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* 
 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */
#ifndef _DB_CONN_BE_H_
#define _DB_CONN_BE_H_

#include "grts/structs.db.mgmt.h"
#include "cppdbc.h"
#include <vector>
#include <map>

#include "wbpublic_public_interface.h"
#include "base/geometry.h"

class DbDriverParam;
class DbDriverParams;
class DbConnection;

enum ControlType {
  ctUnknown,
  ctLabel,
  ctDescriptionLabel,
  ctTextBox,
  ctKeychainPassword,
  ctCheckBox,
  ctNumericUpDown,
  ctButton,
  ctDirSelector,
  ctFileSelector,
  ctEnumSelector,
  ctText
};


class WBPUBLICBACKEND_PUBLIC_FUNC DbDriverParam
{
public:
  enum ParamType {
    ptUnknown,
    ptInt,
    ptString,
    ptPassword,
    ptKeychainPassword,
    ptBoolean,
    ptTristate,
    ptDir,
    ptFile,
    ptEnum,
    ptIntEnum,
    ptText,
    ptButton
  };

private:
  static ParamType decode_param_type(std::string type_name, std::string real_type);

  db_mgmt_DriverParameterRef _inner;
  ParamType _type;
  grt::ValueRef _value;

  DbDriverParam(const DbDriverParam&) {}
  DbDriverParam(
    const db_mgmt_DriverParameterRef &driver_param,
    const db_mgmt_ConnectionRef &stored_conn);
  DbDriverParam(const db_mgmt_DriverParameterRef &driver_param, const grt::ValueRef &value);

  ControlType get_control_type() const;

  friend class DbDriverParams;

public:
  const db_mgmt_DriverParameterRef & object() const { return _inner; }

  ParamType get_type() const { return _type; }
  grt::StringRef get_control_name() const;
  const grt::ValueRef & get_value() const { return _value; }
  const grt::StringRef get_value_repr() const { return _value.toString(); }
  void set_value(const grt::ValueRef &value);
  std::vector<std::pair<std::string, std::string> > get_enum_options();
};


class WBPUBLICBACKEND_PUBLIC_FUNC DbDriverParams
{
private:
  typedef std::vector<DbDriverParam *> Collection;
  typedef std::map<std::string, DbDriverParam *> String_index;

  Collection _collection;
  String_index _control_name_index;
  db_mgmt_DriverRef _driver;

  DbDriverParams(const DbDriverParams&) {}
  void free_dyn_mem();

  bool parameter_not_valid(const db_mgmt_DriverRef& driver, const std::string& param);

public:
  DbDriverParams() {}
  ~DbDriverParams() { free_dyn_mem(); }

  void init(
    const db_mgmt_DriverRef &driver,
    const db_mgmt_ConnectionRef &stored_conn,
    const boost::function<void (bool)> &suspend_layout,
    const boost::function<void ()> &begin_layout,
    const boost::function<void (DbDriverParam*, ControlType, const base::ControlBounds&,
      const std::string &)> &create_control,
    const boost::function<void ()> &end_layout,
    bool skip_schema=false,
    int first_row_label_width= 100,
    int hmargin= 10,
    int vmargin= 10);
  grt::DictRef get_params() const;
  std::string validate() const;

  size_t count() const { return _collection.size(); }
  DbDriverParam * get(std::string control_name);
};

class WBPUBLICBACKEND_PUBLIC_FUNC DbConnection
{
private:
  db_mgmt_ManagementRef _mgmt;
  DbDriverParams _db_driver_param_handles;
  db_mgmt_DriverRef _active_driver;
  db_mgmt_ConnectionRef _connection;
  bool _skip_schema;
  
  boost::function<void ()> _begin_layout;
  boost::function<void ()> _end_layout;
  boost::function<void (bool)> _suspend_layout;
  boost::function<void (DbDriverParam*, ControlType, const base::ControlBounds&,
    const std::string &)> _create_control;

  void init_dbc_connection(sql::Connection* dbc_conn, const db_mgmt_ConnectionRef& connectionProperties);

public:
  DbConnection(const db_mgmt_ManagementRef &mgmt, const db_mgmt_DriverRef &driver, bool skip_schema);
  
  ~DbConnection();
  grt::GRT * get_grt() const { return _mgmt.get_grt(); }
  
  void set_control_callbacks(
    const boost::function<void (bool)> &suspend_layout,
    const boost::function<void ()> &begin_layout,
    const boost::function<void (DbDriverParam*, ControlType, const base::ControlBounds&,
      const std::string &)> &create_control,
    const boost::function<void ()> &end_layout);

  DbDriverParams *get_db_driver_param_handles() { return &_db_driver_param_handles; }
  
  void update();
  void set_connection_and_update(const db_mgmt_ConnectionRef &connection);
  void set_connection_keeping_parameters(const db_mgmt_ConnectionRef &connection);
  db_mgmt_ConnectionRef get_connection();
  
  void save_changes();
  
  sql::ConnectionWrapper get_dbc_connection();
  db_mgmt_ManagementRef get_db_mgmt() { return _mgmt; }
  db_mgmt_DriverRef driver() { return _active_driver; }

  void set_driver_and_update(db_mgmt_DriverRef);

  bool test_connection();
  std::string validate_driver_params() const;
};

#endif /* _DB_CONN_BE_H_ */