My Project
ndb_table_guard.h
00001 /*
00002    Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; version 2 of the License.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
00016 */
00017 
00018 #ifndef NDB_TABLE_GUARD_H
00019 #define NDB_TABLE_GUARD_H
00020 
00021 #include <ndbapi/NdbDictionary.hpp>
00022 
00023 class Ndb_table_guard
00024 {
00025 public:
00026   Ndb_table_guard(NdbDictionary::Dictionary *dict)
00027     : m_dict(dict), m_ndbtab(NULL), m_invalidate(0)
00028   {}
00029   Ndb_table_guard(NdbDictionary::Dictionary *dict, const char *tabname)
00030     : m_dict(dict), m_ndbtab(NULL), m_invalidate(0)
00031   {
00032     DBUG_ENTER("Ndb_table_guard");
00033     init(tabname);
00034     DBUG_VOID_RETURN;
00035   }
00036   ~Ndb_table_guard()
00037   {
00038     DBUG_ENTER("~Ndb_table_guard");
00039     reinit();
00040     DBUG_VOID_RETURN;
00041   }
00042   void init(const char *tabname)
00043   {
00044     DBUG_ENTER("Ndb_table_guard::init");
00045     /* must call reinit() if already initialized */
00046     DBUG_ASSERT(m_ndbtab == NULL);
00047     m_ndbtab= m_dict->getTableGlobal(tabname);
00048     m_invalidate= 0;
00049     DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
00050     DBUG_VOID_RETURN;
00051   }
00052   void reinit(const char *tabname= 0)
00053   {
00054     DBUG_ENTER("Ndb_table_guard::reinit");
00055     if (m_ndbtab)
00056     {
00057       DBUG_PRINT("info", ("m_ndbtab: %p  m_invalidate: %d",
00058                           m_ndbtab, m_invalidate));
00059       m_dict->removeTableGlobal(*m_ndbtab, m_invalidate);
00060       m_ndbtab= NULL;
00061       m_invalidate= 0;
00062     }
00063     if (tabname)
00064       init(tabname);
00065     DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
00066     DBUG_VOID_RETURN;
00067   }
00068   const NdbDictionary::Table *get_table() { return m_ndbtab; }
00069   void invalidate() { m_invalidate= 1; }
00070   const NdbDictionary::Table *release()
00071   {
00072     DBUG_ENTER("Ndb_table_guard::release");
00073     const NdbDictionary::Table *tmp= m_ndbtab;
00074     DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
00075     m_ndbtab = 0;
00076     DBUG_RETURN(tmp);
00077   }
00078 private:
00079   NdbDictionary::Dictionary *m_dict;
00080   const NdbDictionary::Table *m_ndbtab;
00081   int m_invalidate;
00082 };
00083 
00084 #endif
00085 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines