Drizzled Public API Documentation

concurrent.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  *  Copyright (C) 2011 Vijay Samuel, vjsamuel1990@gmail.com
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/plugin/client.h>
00024 #include <drizzled/execute/context.h>
00025 #include <drizzled/execute/parser.h>
00026 #include <drizzled/util/string.h>
00027 #include <vector>
00028 #include <queue>
00029 #include <string>
00030 #include <cstdio>
00031 
00032 using namespace std;
00033 
00034 namespace drizzled {
00035 namespace plugin {
00036 namespace client {
00037 
00041 class Concurrent: public Client
00042 {
00043   typedef std::queue < drizzled::util::String > Queue;
00044   Queue to_execute;
00045   bool is_dead;
00046   drizzled::util::String packet_buffer;
00047 
00048 public:
00049 
00050   Concurrent() :
00051     is_dead(false)
00052   {
00053   }
00054 
00055   virtual int getFileDescriptor(void) { return -1; }
00056   virtual bool isConnected(void) { return true; }
00057   virtual bool flush(void) { return false; }
00058   virtual void close(void) {}
00059   virtual bool authenticate(void) { return true; }
00060 
00061   virtual bool readCommand(char **packet, uint32_t& packet_length)
00062   {
00063     while(not to_execute.empty())
00064     {
00065       Queue::value_type next= to_execute.front();
00066       packet_buffer= next;
00067 
00068       *packet= packet_buffer.data();
00069       packet_length= next.size();
00070 
00071       to_execute.pop();
00072 
00073       return true;
00074     }
00075 
00076     if (not is_dead)
00077     {
00078       packet_buffer.clear();
00079       packet_length= 1;
00080       *packet= packet_buffer.data();
00081       is_dead= true;
00082 
00083       return true;
00084     }
00085 
00086     packet_length= 0;
00087     return false;
00088   }
00089 
00090   virtual void sendOK(void) {}
00091   virtual void sendEOF(void) {}
00092   virtual void sendError(const drizzled::error_t, const char*) {}
00093   virtual void sendFields(List<Item>&) {}
00094   virtual void store(Field*) {}
00095   virtual void store() {}
00096   virtual void store(int32_t) {}
00097   virtual void store(uint32_t) {}
00098   virtual void store(int64_t) {}
00099   virtual void store(uint64_t) {}
00100   virtual void store(double, uint32_t, String*) {}
00101   virtual void store(const type::Time*) {}
00102   virtual void store(const char*) {}
00103   virtual void store(const char*, size_t) {}
00104   virtual void store(str_ref) {}
00105   virtual bool haveError(void) { return false; }
00106   virtual bool wasAborted(void) { return false; }
00107 
00108   void pushSQL(str_ref arg)
00109   {
00110     ::drizzled::error_t err_msg;
00111     ::drizzled::execute::Context context(arg.data(), arg.size(), err_msg);
00112     std::vector<std::string> parsed_tokens= context.start();
00113 
00114     {
00115       drizzled::util::String byte;
00116       byte.assign(1, COM_QUERY); // Insert our COM_QUERY
00117       byte.append(drizzle_literal_parameter("START TRANSACTION")); // +1 for the COM_QUERY, provided by null count from sizeof()
00118       to_execute.push(byte);
00119     }
00120     
00121     BOOST_FOREACH(const string& iter, parsed_tokens)
00122     {
00123       drizzled::util::String byte;
00124       byte.assign(1, COM_QUERY); // Insert our COM_QUERY
00125       byte.append(iter.data(), iter.size());
00126       to_execute.push(byte);
00127     }
00128 
00129     {
00130       drizzled::util::String byte;
00131       byte.assign(1, COM_QUERY); // Insert our COM_QUERY
00132       byte.append(drizzle_literal_parameter("COMMIT")); // +1 for the COM_QUERY, provided by null count from sizeof()
00133       to_execute.push(byte);
00134     }
00135   }
00136 };
00137 
00138 } /* namespace client */
00139 } /* namespace plugin */
00140 } /* namespace drizzled */
00141