Drizzled Public API Documentation

open_tables_state.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <drizzled/lock.h>
00024 #include <drizzled/query_id.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 class CachedDirectory;
00030 
00037 class Open_tables_state
00038 {
00039 public:
00044   Table *open_tables;
00045 
00053 private:
00054   Table *temporary_tables;
00055 
00056 public:
00057 
00058   Table *getTemporaryTables()
00059   {
00060     return temporary_tables;
00061   }
00062 
00072   void mark_temp_tables_as_free_for_reuse();
00073 
00074 protected:
00075   void close_temporary_tables();
00076 
00077 public:
00078   void close_temporary_table(Table *table);
00079   
00080 private:
00081   // The method below just handles the de-allocation of the table. In
00082   // a better memory type world, this would not be needed.
00083   void nukeTable(Table *table);
00084 
00085 public:
00086   /* Work with temporary tables */
00087   Table *find_temporary_table(const identifier::Table &identifier);
00088 
00089   void dumpTemporaryTableNames(const char *id);
00090   int drop_temporary_table(const drizzled::identifier::Table &identifier);
00091   bool rm_temporary_table(plugin::StorageEngine *base, const identifier::Table &identifier);
00092   bool rm_temporary_table(const drizzled::identifier::Table &identifier, bool best_effort= false);
00093   Table *open_temporary_table(const drizzled::identifier::Table &identifier,
00094                               bool link_in_list= true);
00095 
00096   virtual query_id_t getQueryId()  const= 0;
00097 
00098 private:
00099   Table *derived_tables;
00100 public:
00101 
00102 
00103   Table *getDerivedTables()
00104   {
00105     return derived_tables;
00106   }
00107 
00108   void setDerivedTables(Table *arg)
00109   {
00110     derived_tables= arg;
00111   }
00112 
00113   void clearDerivedTables()
00114   {
00115     if (derived_tables)
00116       derived_tables= NULL; // They should all be invalid by this point
00117   }
00118 
00119   /*
00120     During a MySQL session, one can lock tables in two modes: automatic
00121     or manual. In automatic mode all necessary tables are locked just before
00122     statement execution, and all acquired locks are stored in 'lock'
00123     member. Unlocking takes place automatically as well, when the
00124     statement ends.
00125     Manual mode comes into play when a user issues a 'LOCK TABLES'
00126     statement. In this mode the user can only use the locked tables.
00127     Trying to use any other tables will give an error. The locked tables are
00128     stored in 'locked_tables' member.  Manual locking is described in
00129     the 'LOCK_TABLES' chapter of the MySQL manual.
00130     See also lock_tables() for details.
00131   */
00132   DrizzleLock *lock;
00133 
00134   /*
00135     CREATE-SELECT keeps an extra lock for the table being
00136     created. This field is used to keep the extra lock available for
00137     lower level routines, which would otherwise miss that lock.
00138    */
00139   DrizzleLock *extra_lock;
00140 
00141   uint64_t version;
00142   uint32_t current_tablenr;
00143 
00144   /*
00145     This constructor serves for creation of Open_tables_state instances
00146     which are used as backup storage.
00147   */
00148   Open_tables_state() :
00149     open_tables(0),
00150     temporary_tables(0),
00151     derived_tables(0),
00152     lock(0),
00153     extra_lock(0),
00154     version(0),
00155     current_tablenr(0)
00156   { }
00157   virtual ~Open_tables_state() {}
00158 
00159   void doGetTableNames(CachedDirectory &directory,
00160                        const identifier::Schema &schema_identifier,
00161                        std::set<std::string>& set_of_names);
00162   void doGetTableNames(const identifier::Schema &schema_identifier,
00163                        std::set<std::string>& set_of_names);
00164 
00165   void doGetTableIdentifiers(CachedDirectory &directory,
00166                              const identifier::Schema &schema_identifier,
00167                              identifier::Table::vector &set_of_identifiers);
00168   void doGetTableIdentifiers(const identifier::Schema &schema_identifier,
00169                              identifier::Table::vector &set_of_identifiers);
00170 
00171   int doGetTableDefinition(const drizzled::identifier::Table &identifier,
00172                            message::Table &table_proto);
00173   bool doDoesTableExist(const drizzled::identifier::Table &identifier);
00174 
00175 
00176   Open_tables_state(uint64_t version_arg);
00177 };
00178 
00179 } /* namespace drizzled */
00180