CifSchemaMap.h

Go to the documentation of this file.
00001 /*$$FILE$$*/
00002 /*$$VERSION$$*/
00003 /*$$DATE$$*/
00004 /*$$LICENSE$$*/
00005 
00006 
00014 #ifndef CIFSCHEMAMAP_H
00015 #define CIFSCHEMAMAP_H
00016 
00017 
00018 #include <string>
00019 #include <ostream>
00020 #include <fstream>
00021 
00022 #include "CifFile.h"
00023 #include "SchemaMap.h"
00024 #include "Db.h"
00025 #include "DbOutput.h"
00026 
00027 
00028 
00036 class DbOracle : public Db
00037 {
00038 
00039   // Oracle 8.1.6 SQLLDR
00040 
00041   public:
00042     DbOracle(SchemaMap& schemaMapping,
00043       const string& dbName = DB_DEFAULT_NAME);
00044     ~DbOracle();
00045 
00046     void WriteSchemaStart(std::ostream& io);
00047 
00048     void WriteLoadingStart(std::ostream& io);
00049     void WriteLoadingTable(std::ostream& io, const string& tableName,
00050       const string& path);
00051 
00052     void GetDate(string& dType);
00053     void GetText(string& dType, const unsigned int width);
00054 
00055     void WriteNull(std::ostream& io, const int iNull,
00056       const unsigned int curr, const unsigned int attSize);
00057     void WriteTableIndex(std::ostream& io, const string& tableNameDb,
00058       const vector<string>& indexList);
00059 
00060     void WriteNewLine(std::ostream& io, bool special = false);
00061 };
00062 
00063 
00071 class DbDb2 : public Db
00072 {
00073 
00074   public:
00075     DbDb2(SchemaMap& schemaMapping,
00076       const string& dbName = DB_DEFAULT_NAME);
00077     ~DbDb2();
00078 
00079 
00080     void GetStart(string& start);
00081 
00082     void WriteSchemaStart(std::ostream& io);
00083 
00084     void WriteLoadingStart(std::ostream& io);
00085     void WriteLoadingEnd(std::ostream& io);
00086     void WriteLoadingTable(std::ostream& io, const string& tableName,
00087       const string& path);
00088 
00089     void GetFloat(string& dType);
00090     void GetDate(string& dType);
00091     void GetText(string& dType, const unsigned int width);
00092     void WriteNull(std::ostream& io, const int iNull,
00093       const unsigned int curr, const unsigned int attSize);
00094 
00095     void WriteTableIndex(std::ostream& io, const string& tableNameDb,
00096       const vector<string>& indexList);
00097 
00098     void WriteBcpDoubleQuotes(std::ostream& io);
00099 };
00100 
00101 
00109 class DbMySql : public Db
00110 {
00111 
00112   public:
00113     DbMySql(SchemaMap& schemaMapping,
00114       const string& dbName = DB_DEFAULT_NAME);
00115     ~DbMySql();
00116 
00117     void GetStart(string& start);
00118 
00119     void DropTableSql(std::ostream& io, const string& tableNameDb);
00120 
00121     void WriteLoad(std::ostream& io);
00122     void WriteLoadingStart(std::ostream& io);
00123     void WriteLoadingTable(std::ostream& io, const string& tableName,
00124       const string& path);
00125 
00126     void WriteTableIndex(std::ostream& io, const string& tableNameDb,
00127       const vector<string>& indexList);
00128 
00129     void WriteNull(std::ostream& io, const int iNull,
00130       const unsigned int curr, const unsigned int attSize);
00131 
00132     void WriteNewLine(std::ostream& io, bool special = false);
00133 
00134   private:
00135     static const string _SQL_LOADING_FILE;
00136 
00137 };
00138 
00139 
00147 class DbSybase : public Db
00148 {
00149   public:
00150     DbSybase(SchemaMap& schemaMapping,
00151       const string& dbName = DB_DEFAULT_NAME);
00152     ~DbSybase();
00153 
00154     void GetStart(string& start);
00155 
00156     void WriteLoadingStart(std::ostream& io);
00157     void WriteLoadingTable(std::ostream& io, const string& tableName,
00158       const string& path);
00159 
00160     void WritePrint(std::ostream& io, const string& tableNameDb);
00161     void WriteNull(std::ostream& io, const int iNull,
00162       const unsigned int curr, const unsigned int attSize);
00163 
00164     void WriteTableIndex(std::ostream& io, const string& tableNameDb,
00165       const vector<string>& indexList);
00166 
00167     void GetDateAndTime(string& dateAndTime);
00168 
00169 #ifdef VLAD_DATE_OBSOLETE
00170     void ConvertDate(string& dbDate, const string& cifDate);
00171 #endif
00172 };
00173 
00174 
00183 class BcpOutput : public DbOutput
00184 {
00185   public:
00186     BcpOutput(Db& db);
00187     virtual ~BcpOutput();
00188 
00189     void WriteDataLoadingScripts(const string& path = std::string());
00190     void WriteData(Block& block, const string& path = std::string());
00191 
00192   private:
00193     static const string _DATA_DELETE_FILE;
00194 
00195     void WriteDataLoadingScript(const string& path);
00196     void WriteDataLoadingFile(const string& path = std::string());
00197 
00198     void WriteDelete(std::ostream& io);
00199 
00200     void WriteEmptyString(std::ostream& io);
00201 
00202     void WriteSpecialDateChar(std::ostream& io, const char& specDateChar);
00203 };
00204  
00205 
00214 class SqlOutput : public DbOutput
00215 {
00216 
00217   public:
00218     SqlOutput(Db& db);
00219     virtual ~SqlOutput();
00220 
00221     void WriteSchema(const string& path = std::string());
00222     void WriteDataLoadingScripts(const string& path = std::string());
00223     void WriteData(Block& block, const string& path = std::string());
00224 
00225   protected:
00226     void WriteEmptyNumeric(std::ostream& io);
00227     bool IsFirstTextNewLineSpecial();
00228     void WriteNewLine(std::ostream& io, bool special = false);
00229     void GetTableStart(string& tableStart, const string& tableName);
00230     void GetTableEnd(string& tableEnd);
00231 
00232   private:
00233     static const unsigned int _MAX_SQL_NAME_LENGTH = 60;
00234     static const string _SCHEMA_LOADING_SCRIPT;
00235     static const string _SCHEMA_DELETE_FILE;
00236     static const string _DATA_FILE;
00237 
00238     void WriteSqlScriptSchemaInfo(std::ostream& io);
00239     void WriteDataLoadingScript(const string& path);
00240 
00241     void CreateTableSql(std::ostream& io, const string& tableName);
00242 
00243     void WriteAuxTables(std::ostream& io, ISTable* infoP,
00244       const vector<string>& tableNames);
00245 
00246     void WriteEmptyString(std::ostream& io);
00247     void WriteEmptyDate(std::ostream& io);
00248 };
00249 
00250 
00266 class DbLoader
00267 {
00268   public:
00269     enum eConvOpt
00270     {
00271         // Generate only data loading files
00272         eDATA_ONLY = 0,
00273 
00274         // Generate both data loading files and loading shell scripts
00275         eDATA_WITH_SCRIPTS,
00276 
00277         // Generate only loading shell scripts
00278         eSCRIPTS_ONLY
00279     };
00280 
00301     DbLoader(SchemaMap& schemaMapping, DbOutput& dbOutput,
00302       bool verbose = false, const string& workDir = std::string());
00303 
00317     virtual ~DbLoader();
00318 
00333     void SetWorkDir(const string& workDir);
00334 
00353     void AsciiFileToDb(const string& asciiFile, const eConvOpt convOpt);
00354 
00374     void SerFileToDb(const string& serFile, const eConvOpt convOpt);
00375 
00394     void FileObjToDb(CifFile& cifFile, const eConvOpt convOpt);
00395 
00396 #ifdef DB_HASH_ID
00397     void SetHashMode(int mode);
00398 #endif
00399 
00400   private:
00401     static const string _LOG_FILE;
00402 
00403     string _workDir; // Working directory for all generated files.
00404     string _INPUT_FILE;
00405 
00406 #ifdef DB_HASH_ID
00407     string _HASH_ID;
00408     int _hashMode;
00409 #endif
00410 
00411     // Block name of loadable data in mmCIF format
00412     string _blockName;
00413 
00414     bool _verbose;
00415 
00416     std::ofstream _log;
00417 
00418     SchemaMap& _schemaMapping;
00419     DbOutput& _dbOutput;
00420 
00421     void _LoadBlock(Block& rBlock, Block& wBlock);
00422 
00423     bool _Search(vector<vector<string> >& dMap, const unsigned int iAttr,
00424       ISTable* isTableP, const string& blockName,
00425       const vector<string>& cNameMap, const string& sItem,
00426       const string& sCnd, const string& sFnct);
00427  
00428     void _DoFunc(vector<string>& s, const vector<string>& r,
00429       const string& sFnct);
00430 
00431     void _OpenLog(const string& logName);
00432 
00433     int _GetMapColumnIndex(const vector<string>& cNameMap, const string& vOf);
00434     void _GetMapColumnValue(string& p, vector<string>& dMapVec,
00435       unsigned int irow);
00436 
00437     void CreateTables(CifFile& writeCifFile, CifFile& readCifFile);
00438 
00439 #ifdef VLAD_DATE_OBSOLETE
00440     void _dformat_1(const char *date, char *odate);
00441     void _dformat_2(const char *date, char *odate);
00442     void _dformat_3(const char *date, char *odate, int shortFlag);
00443     void _dformat_4(const char *date, char *odate);
00444     void _dformat_5(const char *date, char *odate);
00445 #endif
00446 
00447     void _ReorderName(string& res, char *string, int mode);
00448     void _ToUpperString(string& aString);
00449     void _StripString(string& aString, int mode);
00450 
00451 #ifdef DB_HASH_ID
00452     long long pdbIdHash(const string& id);
00453 #endif
00454 
00455     static void CleanString(string& aString);
00456 
00457     void Clear();
00458 };
00459 
00460 
00461 #endif

Generated on Thu Oct 6 10:15:51 2011 for db-loader-v4.1.0 by  doxygen 1.4.7