~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/command.h

Updates based on code review from Jay.

- modified the SqlCommand base class to be abstract
- created new directory (command) where each command implementation will be
  placed in a separate file
- created namespace for various commands (drizzled::command)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#ifndef DRIZZLE_SERVER_SQL_COMMANDS_H
22
 
#define DRIZZLE_SERVER_SQL_COMMANDS_H
 
21
#ifndef DRIZZLED_COMMAND_H
 
22
#define DRIZZLED_COMMAND_H
23
23
 
24
24
#include <drizzled/server_includes.h>
25
25
#include <drizzled/definitions.h>
26
 
#include <drizzled/logging.h>
27
 
#include <drizzled/db.h>
28
26
#include <drizzled/error.h>
29
 
#include <drizzled/query_id.h>
30
27
#include <drizzled/sql_parse.h>
31
28
#include <drizzled/sql_base.h>
32
29
#include <drizzled/show.h>
33
 
#include <drizzled/rename.h>
34
 
#include <drizzled/function/time/unix_timestamp.h>
35
 
#include <drizzled/function/get_system_var.h>
36
 
#include <drizzled/item/null.h>
37
 
#include <drizzled/sql_load.h>
38
 
#include <drizzled/connect.h>
39
 
#include <drizzled/lock.h>
40
30
 
41
31
class Session;
42
32
class TableList;
44
34
 
45
35
namespace drizzled
46
36
{
 
37
namespace command
 
38
{
47
39
 
48
40
/**
49
41
 * @class SqlCommand
56
48
             Session *in_session)
57
49
    :
58
50
      comm_type(in_comm_type),
59
 
      session(in_session),
60
 
      all_tables(NULL),
61
 
      first_table(NULL),
62
 
      show_lock(NULL),
63
 
      need_start_waiting(NULL)
64
 
  {}
65
 
 
66
 
  SqlCommand(enum enum_sql_command in_comm_type,
67
 
             Session *in_session,
68
 
             TableList *in_all_tables)
69
 
    :
70
 
      comm_type(in_comm_type),
71
 
      session(in_session),
72
 
      all_tables(in_all_tables),
73
 
      first_table(NULL),
74
 
      show_lock(NULL),
75
 
      need_start_waiting(NULL)
 
51
      session(in_session)
76
52
  {}
77
53
 
78
54
  virtual ~SqlCommand() {}
82
58
   *
83
59
   * @return 1 on failure; 0 on success
84
60
   */
85
 
  virtual int execute();
86
 
 
87
 
  void setTableList(TableList *in_all_tables)
88
 
  {
89
 
    all_tables= in_all_tables;
90
 
  }
91
 
 
92
 
  void setFirstTable(TableList *in_first_table)
93
 
  {
94
 
    first_table= in_first_table;
95
 
  }
96
 
 
97
 
  void setShowLock(pthread_mutex_t *in_lock)
98
 
  {
99
 
    show_lock= in_lock;
100
 
  }
101
 
 
102
 
  void setNeedStartWaiting(bool *in_need_start_waiting)
103
 
  {
104
 
    need_start_waiting= in_need_start_waiting;
105
 
  }
 
61
  virtual int execute()= 0;
106
62
 
107
63
protected:
108
64
 
115
71
   * A session handler.
116
72
   */
117
73
  Session *session;
118
 
 
119
 
  /**
120
 
   * List of all the tables for this command.
121
 
   */
122
 
  TableList *all_tables;
123
 
 
124
 
  /**
125
 
   * First table for this command.
126
 
   */
127
 
  TableList *first_table;
128
 
 
129
 
  /**
130
 
   * A mutex that is only needed by the SHOW STATUS
131
 
   * command but declare it in the base class since
132
 
   * we will not know what command we are working with
133
 
   * at runtime.
134
 
   */
135
 
  pthread_mutex_t *show_lock;
136
 
 
137
 
  /**
138
 
   * A boolean that is needed by some commands. Again, we 
139
 
   * declare it here since we will not know what command is 
140
 
   * being executed until runtime. Once we have the switch
141
 
   * statement removed in sql_parse.cc we will be able to
142
 
   * make this variable only a private member of the classes
143
 
   * which actually need it I believe.
144
 
   */
145
 
  bool *need_start_waiting;
146
 
};
147
 
 
148
 
/**
149
 
 * @class ShowStatusCommand
150
 
 * @brief Represents the SHOW STATUS command
151
 
 */
152
 
class ShowStatusCommand : public SqlCommand
153
 
{
154
 
public:
155
 
  ShowStatusCommand(enum enum_sql_command in_comm_type,
156
 
                    Session *in_session)
157
 
    :
158
 
      SqlCommand(in_comm_type, in_session)
159
 
  {}
160
 
 
161
 
  int execute();
162
 
};
 
74
};
 
75
 
 
76
} /* end namespace command */
163
77
 
164
78
} /* end namespace drizzled */
165
79
 
166
 
#endif /* DRIZZLE_SERVER_SQL_COMMANDS_H */
 
80
#endif /* DRIZZLED_COMMAND_H */