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 #pragma once
00021 
00022 #include <drizzled/common_fwd.h>
00023 #include <drizzled/lock.h>
00024 
00025 namespace drizzled {
00026 
00027 extern uint64_t g_refresh_version;
00028 
00034 class Open_tables_state
00035 {
00036 public:
00041   Table *open_tables_;
00042 
00050   Table *temporary_tables;
00051 
00052   Table *getTemporaryTables()
00053   {
00054     return temporary_tables;
00055   }
00056 
00066   void mark_temp_tables_as_free_for_reuse();
00067   void close_temporary_tables();
00068   void close_temporary_table(Table*);
00069   void nukeTable(Table*);
00070   void close_open_tables();
00071   bool free_cached_table();
00072 
00073   /* Work with temporary tables */
00074   Table *find_temporary_table(const identifier::Table &identifier);
00075 
00076   void dumpTemporaryTableNames(const char *id);
00077   int drop_temporary_table(const identifier::Table&);
00078   bool rm_temporary_table(plugin::StorageEngine&, const identifier::Table&);
00079   bool rm_temporary_table(const identifier::Table &identifier, bool best_effort= false);
00080 
00081 private:
00082   Table *derived_tables;
00083 public:
00084 
00085 
00086   Table *getDerivedTables()
00087   {
00088     return derived_tables;
00089   }
00090 
00091   void setDerivedTables(Table *arg)
00092   {
00093     derived_tables= arg;
00094   }
00095 
00096   void clearDerivedTables()
00097   {
00098     derived_tables= NULL; // They should all be invalid by this point
00099   }
00100 
00101   /*
00102     During a MySQL session, one can lock tables in two modes: automatic
00103     or manual. In automatic mode all necessary tables are locked just before
00104     statement execution, and all acquired locks are stored in 'lock'
00105     member. Unlocking takes place automatically as well, when the
00106     statement ends.
00107     Manual mode comes into play when a user issues a 'LOCK TABLES'
00108     statement. In this mode the user can only use the locked tables.
00109     Trying to use any other tables will give an error. The locked tables are
00110     stored in 'locked_tables' member.  Manual locking is described in
00111     the 'LOCK_TABLES' chapter of the MySQL manual.
00112     See also lock_tables() for details.
00113   */
00114   DrizzleLock *lock;
00115 
00116   /*
00117     CREATE-SELECT keeps an extra lock for the table being
00118     created. This field is used to keep the extra lock available for
00119     lower level routines, which would otherwise miss that lock.
00120    */
00121   DrizzleLock *extra_lock;
00122 
00123   uint64_t version;
00124   uint32_t current_tablenr;
00125 
00126   Open_tables_state(Session&, uint64_t version_arg);
00127   void doGetTableNames(CachedDirectory&, const identifier::Schema&, std::set<std::string>&);
00128   void doGetTableNames(const identifier::Schema&, std::set<std::string>&);
00129   void doGetTableIdentifiers(CachedDirectory&, const identifier::Schema&, identifier::table::vector&);
00130   void doGetTableIdentifiers(const identifier::Schema&, identifier::table::vector&);
00131   int doGetTableDefinition(const drizzled::identifier::Table&, message::Table&);
00132   bool doDoesTableExist(const drizzled::identifier::Table&);
00133 private:
00134   Session& session_;
00135 };
00136 
00137 } /* namespace drizzled */
00138