~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to sql/si_objects.h

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
  Obj defines the basic set of operations for each database object.
20
20
*/
21
21
 
22
 
class Obj { public:
23
 
  /**
24
 
    Serialize object state into a buffer. The buffer actually should be a
25
 
    binary buffer. String class is used here just because we don't have
26
 
    convenient primitive for binary buffers.
27
 
 
28
 
    Serialization format is opaque to the client, i.e. the client should
29
 
    not make any assumptions about the format or the content of the
30
 
    returned buffer.
31
 
 
32
 
    Serialization format can be changed in the future versions. However,
33
 
    the server must be able to materialize objects coded in any previous
34
 
    formats.
35
 
 
36
 
    @param[in] thd              Server thread context.
37
 
    @param[in] serialialization Buffer to serialize the object
38
 
 
39
 
    @return error status.
40
 
      @retval FALSE on success.
41
 
      @retval TRUE on error.
42
 
  */
43
 
  virtual bool serialize(THD *thd, String *serialialization) = 0;
44
 
 
 
22
class Obj { 
 
23
public:
 
24
 
 
25
  bool serialize(THD *thd, String *serialialization);
45
26
 
46
27
  /**
47
28
    Return the name of the object.
57
38
  */
58
39
  virtual const String *get_db_name() = 0;
59
40
 
60
 
  /**
61
 
    Create the object in the database.
62
 
 
63
 
    @param[in] thd              Server thread context.
64
 
 
65
 
    @return error status.
66
 
      @retval FALSE on success.
67
 
      @retval TRUE on error.
68
 
  */
69
 
  virtual bool execute(THD *thd) = 0;
 
41
  bool execute(THD *thd);
70
42
 
71
43
public:
72
44
  virtual ~Obj()
73
45
  { }
74
46
 
75
47
private:
 
48
 
76
49
  /**
77
50
    Read the object state from a given buffer and restores object state to
78
51
    the point, where it can be executed.
87
60
  virtual bool materialize(uint serialization_version,
88
61
                           const String *serialialization) = 0;
89
62
 
 
63
  /// Primitive implementing @c serialize() method.
 
64
  virtual bool do_serialize(THD *thd, String *serialialization) = 0;
 
65
 
 
66
  /// Primitive implementing @c execute() method.
 
67
  virtual bool do_execute(THD *thd) = 0;
 
68
 
90
69
  /**
91
70
    Drop the object.
92
71
 
133
112
                                uint,
134
113
                                const String *);
135
114
 
 
115
  friend Obj *materialize_tablespace(const String *,
 
116
                                     uint,
 
117
                                     const String *);
136
118
};
137
119
 
 
120
 
 
121
/**
 
122
  Create the object in the database.
 
123
 
 
124
  @param[in] thd              Server thread context.
 
125
 
 
126
  @return error status.
 
127
    @retval FALSE on success.
 
128
    @retval TRUE on error.
 
129
 
 
130
  @note The real work is done inside @c do_execute() primitive which should be
 
131
  defied in derived classes. This method prepares appropriate context and calls
 
132
  the primitive.
 
133
*/
 
134
inline
 
135
bool Obj::execute(THD *thd)
 
136
{
 
137
  ulong saved_sql_mode= thd->variables.sql_mode;
 
138
  thd->variables.sql_mode= 0;
 
139
 
 
140
  set_var_collation_client saved_charset_settings(
 
141
                             thd->variables.character_set_client,
 
142
                             thd->variables.character_set_results,
 
143
                             thd->variables.collation_connection);
 
144
 
 
145
  set_var_collation_client new_charset_settings(::system_charset_info,
 
146
                                                ::system_charset_info,
 
147
                                                ::system_charset_info);
 
148
  new_charset_settings.update(thd);
 
149
 
 
150
  bool ret= do_execute(thd);
 
151
 
 
152
  saved_charset_settings.update(thd);
 
153
  thd->variables.sql_mode= saved_sql_mode;
 
154
 
 
155
  return ret;
 
156
}
 
157
 
 
158
/**
 
159
  Serialize object state into a buffer. The buffer actually should be a
 
160
  binary buffer. String class is used here just because we don't have
 
161
  convenient primitive for binary buffers.
 
162
 
 
163
  Serialization format is opaque to the client, i.e. the client should
 
164
  not make any assumptions about the format or the content of the
 
165
  returned buffer.
 
166
 
 
167
  Serialization format can be changed in the future versions. However,
 
168
  the server must be able to materialize objects coded in any previous
 
169
  formats.
 
170
 
 
171
  @param[in] thd              Server thread context.
 
172
  @param[in] serialialization Buffer to serialize the object
 
173
 
 
174
  @return error status.
 
175
    @retval FALSE on success.
 
176
    @retval TRUE on error.
 
177
 
 
178
  @note The real work is done inside @c do_serialize() primitive which should be
 
179
  defied in derived classes. This method prepares appropriate context and calls
 
180
  the primitive.
 
181
*/
 
182
inline
 
183
bool Obj::serialize(THD *thd, String *serialization)
 
184
{
 
185
  ulong saved_sql_mode= thd->variables.sql_mode;
 
186
  thd->variables.sql_mode= 0;
 
187
  
 
188
  bool ret= do_serialize(thd, serialization);
 
189
 
 
190
  thd->variables.sql_mode= saved_sql_mode;
 
191
 
 
192
  return ret;
 
193
}
 
194
 
138
195
///////////////////////////////////////////////////////////////////////////
139
196
 
140
197
/**
445
502
                       uint serialization_version,
446
503
                       const String *serialialization);
447
504
 
 
505
Obj *materialize_tablespace(const String *ts_name,
 
506
                            uint serialization_version,
 
507
                            const String *serialialization);
 
508
 
448
509
///////////////////////////////////////////////////////////////////////////
449
510
 
450
511
bool is_internal_db_name(const String *db_name);
460
521
*/
461
522
bool check_db_existence(const String *db_name);
462
523
 
 
524
/*
 
525
  This method returns a @c TablespaceObj object if the table has a tablespace.
 
526
*/
 
527
Obj *get_tablespace_for_table(THD *thd, 
 
528
                              const String *db_name, 
 
529
                              const String *tbl_name);
 
530
 
 
531
/*
 
532
  This method determines if a materialized tablespace exists on the
 
533
  system. This compares the name and all saved attributes of the 
 
534
  tablespace. A FALSE return would mean either the tablespace does
 
535
  not exist or the tablespace attributes are different.
 
536
*/
 
537
bool tablespace_exists(THD *thd,
 
538
                       Obj *ts);
 
539
 
 
540
/*
 
541
  This method determines if the tablespace referenced by name exists on the
 
542
  system. Returns a TablespaceObj if it exists or NULL if it doesn't.
 
543
*/
 
544
Obj *is_tablespace(THD *thd,
 
545
                   const String *ts_name);
 
546
 
 
547
/*
 
548
  This method returns a description of the tablespace useful for communicating
 
549
  with the user.
 
550
*/
 
551
const String *describe_tablespace(Obj *ts);
 
552
 
463
553
///////////////////////////////////////////////////////////////////////////
464
554
 
465
555
//
514
604
                                 TABLE *t,
515
605
                                 List<LEX_STRING> *db_list);
516
606
 
 
607
/*
 
608
  The following class is used to manage name locks on a list of tables.
 
609
 
 
610
  This class uses a list of type List<Obj> to establish the table list 
 
611
  that will be used to manage locks on the tables.
 
612
*/
 
613
class Name_locker
 
614
{
 
615
public:
 
616
  Name_locker(THD *thd) { m_thd= thd; }
 
617
  ~Name_locker() 
 
618
  { 
 
619
    free_table_list(m_table_list);
 
620
    m_table_list= NULL;
 
621
  }
 
622
 
 
623
  /*
 
624
    Gets name locks on table list.
 
625
  */
 
626
  int get_name_locks(List<Obj> *tables, thr_lock_type lock);
 
627
 
 
628
  /*
 
629
    Releases name locks on table list.
 
630
  */
 
631
  int release_name_locks();
 
632
 
 
633
private:
 
634
  TABLE_LIST *m_table_list; ///< The list of tables to obtain locks on.
 
635
  THD *m_thd;               ///< Thread context.
 
636
 
 
637
  /*
 
638
    Builds a table list from the list of objects passed to constructor.
 
639
  */
 
640
  TABLE_LIST *build_table_list(List<Obj> *tables, thr_lock_type lock);
 
641
  void free_table_list(TABLE_LIST*);
 
642
};
 
643
 
517
644
} // obs namespace
518
645
 
519
646
#endif // SI_OBJECTS_H_