File: autocomplete_object_name_cache.h

package info (click to toggle)
mysql-workbench 6.2.3%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 102,612 kB
  • ctags: 84,593
  • sloc: ansic: 804,682; cpp: 438,759; yacc: 59,129; python: 54,293; xml: 48,851; sql: 5,512; objc: 1,414; makefile: 505; sh: 455; java: 237; ruby: 6; perl: 5; php: 1
file content (102 lines) | stat: -rw-r--r-- 4,189 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
/* 
 * Copyright (c) 2013, 2014, 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 _AUTOCOMPLETE_OBJECT_NAME_CACHE_H_
#define _AUTOCOMPLETE_OBJECT_NAME_CACHE_H_

#include "wbpublic_public_interface.h"
#include <sqlite/connection.hpp>
#include "grts/structs.db.mgmt.h"
#include "base/threading.h"
#include "cppdbc.h"

class WBPUBLICBACKEND_PUBLIC_FUNC AutoCompleteCache
{
public:
  // Note: feedback can be called from the worker thread. Make the necessary arrangements.
  //       It comes with parameter true if the cache update is going on, otherwise false.
  AutoCompleteCache(const std::string &connection_id,
                    boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &)> get_connection,
                    const std::string &cache_dir,
                    boost::function<void (bool)> feedback);

  std::vector<std::string> get_matching_schema_names(const std::string &prefix = "");
  std::vector<std::string> get_matching_table_names(const std::string &schema = "", const std::string &prefix = "");
  std::vector<std::string> get_matching_column_names(const std::string &schema, const std::string &table, const std::string &prefix = "");
  std::vector<std::string> get_matching_procedure_names(const std::string &schema = "", const std::string &prefix = "");
  std::vector<std::string> get_matching_function_names(const std::string &schema = "", const std::string &prefix = "");

  bool refresh_schema_cache_if_needed(const std::string &schema);
  void refresh_schema_list_cache_if_needed();
  void refresh_schema_cache(const std::string &schema);
  void refresh_table_cache(const std::string &schema, const std::string &table);
  
  void update_schemas(const std::vector<std::string> &schemas);
  void update_schema_tables(const std::string &schema,
                            const std::vector<std::pair<std::string, bool> > &tables, bool just_append); 
  void update_schema_routines(const std::string &schema,
                              const std::vector<std::pair<std::string, bool> > &routines, bool just_append);
  void update_table_columns(const std::string &schema, const std::string &table,
                            const std::vector<std::string> &columns);
  
  bool is_schema_list_fetch_done();
  bool is_schema_tables_fetch_done(const std::string &schema);
  bool is_schema_table_columns_fetch_done(const std::string &schema, const std::string &table);
  bool is_schema_routines_fetch_done(const std::string &schema);

  void shutdown();
  
  ~AutoCompleteCache();
private:
  void init_db();

  static void *_refresh_cache_thread(void *);
  void refresh_cache_thread();
  void refresh_schemas_w();
  void refresh_tables_w(const std::string &schema);
  void refresh_columns_w(const std::string &schema, const std::string &table);
  void refresh_routines_w(const std::string &schema);

  void touch_schema_record(const std::string &schema);

  bool get_pending_refresh(std::string &task);
  void add_pending_refresh(const std::string& task);
  void create_worker_thread();
  
  base::RecMutex _sqconn_mutex;
  sqlite::connection *_sqconn;

  GThread *_refresh_thread;
  base::Semaphore _cache_working;

  base::RecMutex _shutdown_mutex;

  base::RecMutex _pending_mutex;

  std::list<std::string> _pending_refresh_schema;

  std::string _connection_id;
  boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &)> _get_connection;
  boost::function<void (bool)> _feedback;

  bool _schema_list_fetched;
  bool _shutdown;
};

#endif