COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libremotesql/include/coopy/RemoteSqlTextBook.h
Go to the documentation of this file.
00001 #ifndef COOPY_REMOTESQLTEXTBOOK
00002 #define COOPY_REMOTESQLTEXTBOOK
00003 
00004 #include <coopy/TextBook.h>
00005 #include <coopy/Property.h>
00006 #include <coopy/TextBookFactory.h>
00007 
00008 namespace coopy {
00009   namespace store {
00015     namespace remotesql {
00016       class RemoteSqlTextBook;
00017       class RemoteSqlTextBookFactory;
00018     }
00019   }
00020 }
00021 
00022 class coopy::store::remotesql::RemoteSqlTextBook : public TextBook {
00023 public:
00024   RemoteSqlTextBook();
00025   virtual ~RemoteSqlTextBook();
00026 
00027   void clear();
00028 
00029   bool open(const Property& config);
00030 
00031   std::vector<std::string> getNames();
00032 
00033   PolySheet readSheet(const std::string& name);
00034 
00035   virtual bool inplace() const {
00036     return true;
00037   }
00038 
00039   void *getSqlInterface() {
00040     return implementation;
00041   }
00042 
00043   std::string getDatabaseName() {
00044     return database_name;
00045   }
00046 
00047 private:
00048   void *implementation;
00049   std::string database_name;
00050   std::vector<std::string> names_cache;
00051   bool dirty;
00052 };
00053 
00054 
00055 class coopy::store::remotesql::RemoteSqlTextBookFactory : public TextBookFactory {
00056 private:
00057   std::string name;
00058 public:
00059   RemoteSqlTextBookFactory(const char *name = "mysql") : name(name) {
00060   }
00061   
00062   virtual std::string getName() {
00063     return name;
00064   }
00065 
00066   virtual TextBook *open(AttachConfig& config, AttachReport& report) {
00067     if (config.shouldCreate) {
00068       report.errorCreateNotImplemented("mysql");
00069       return NULL;
00070     }
00071     RemoteSqlTextBook *book = new RemoteSqlTextBook();
00072     if (book==NULL) return NULL;
00073     if (!book->open(config.options)) {
00074       delete book;
00075       book = NULL;
00076     }
00077     if (config.prevBook!=NULL) {
00078       if (config.shouldWrite) {
00079         book->copy(*config.prevBook,config.options);
00080       }
00081     }
00082     if (book!=NULL) {
00083       report.success = true;
00084     }
00085     return book;
00086   }
00087 };
00088 
00089 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines