diff options
author | randomdan <randomdan@localhost> | 2010-08-12 19:31:46 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-08-12 19:31:46 +0000 |
commit | ed9f706d181b174ff8cec211ff2c0563020820f5 (patch) | |
tree | 45f0b63e8df81072e956916b0d502c7504aa66b5 | |
parent | Add gcc attrib to stringf (diff) | |
download | project2-ed9f706d181b174ff8cec211ff2c0563020820f5.tar.bz2 project2-ed9f706d181b174ff8cec211ff2c0563020820f5.tar.xz project2-ed9f706d181b174ff8cec211ff2c0563020820f5.zip |
Bind merge populators recursively to leafs
Make path in file based rows a variable
Fix variable cache invalidation on parent row change
Use new features to only load new files
-rw-r--r-- | project2/console/p2consoleMain.cpp | 18 | ||||
-rw-r--r-- | project2/fileRows.cpp | 2 | ||||
-rw-r--r-- | project2/fileRows.h | 3 | ||||
-rw-r--r-- | project2/perRowValues.h | 2 | ||||
-rw-r--r-- | project2/procRows.cpp | 2 | ||||
-rw-r--r-- | project2/sqlMergeTask.cpp | 29 | ||||
-rw-r--r-- | project2/sqlMergeTask.h | 4 | ||||
-rw-r--r-- | project2/variables.cpp | 10 | ||||
-rw-r--r-- | project2/variables.h | 1 |
9 files changed, 40 insertions, 31 deletions
diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index 3bc95e7..25c06fa 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -7,22 +7,8 @@ int main(int argc, char ** argv) { ConsoleEnvironment env(argc, argv); BOOST_FOREACH(const boost::filesystem::path & file, env.todolist) { -#if DEBUG - try { -#endif - ConsoleApplicationEngine app(&env, file); - app.process(); -#if DEBUG - } - catch (const std::exception & e) { - std::cerr << "Kaboom!" << std::endl << std::endl << e.what() << std::endl; - throw; - } - catch (...) { - std::cerr << "Kaboom!" << std::endl << std::endl << "Unknown exception." << std::endl; - throw; - } -#endif + ConsoleApplicationEngine app(&env, file); + app.process(); } } diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index d9c26bc..5c499ff 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -130,7 +130,7 @@ _FileRows::addColumn(const Glib::ustring & rawtok) const FileStarChannel _FileRows::doOpen() const { - FILE * f = fopen(path.c_str(), "r"); + FILE * f = fopen(path->c_str(), "r"); if (!f) { throw std::runtime_error("Could not open file"); } diff --git a/project2/fileRows.h b/project2/fileRows.h index cf1158e..ca94510 100644 --- a/project2/fileRows.h +++ b/project2/fileRows.h @@ -5,6 +5,7 @@ #include <boost/shared_ptr.hpp> #include <map> #include "view.h" +#include "variables.h" #include "iterate.h" #include "fileStarGlibIoChannel.h" @@ -21,7 +22,7 @@ class _FileRows : public PerRowValues { virtual void rowReady() const = 0; typedef std::set<gunichar> CharSet; - const Glib::ustring path; + const Variable path; protected: virtual FileStarChannel doOpen() const; diff --git a/project2/perRowValues.h b/project2/perRowValues.h index 4d898ff..46445ee 100644 --- a/project2/perRowValues.h +++ b/project2/perRowValues.h @@ -10,7 +10,7 @@ class RowUser { RowUser(); ~RowUser(); - void rowChanged() const; + virtual void rowChanged() const = 0; }; class PerRowValues { diff --git a/project2/procRows.cpp b/project2/procRows.cpp index e83d05c..fdeca88 100644 --- a/project2/procRows.cpp +++ b/project2/procRows.cpp @@ -13,7 +13,7 @@ _ProcRows::~_ProcRows() FileStarChannel _ProcRows::doOpen() const { - FILE * f = popen(path.c_str(), "re"); + FILE * f = popen(path->c_str(), "re"); if (!f) { throw std::runtime_error("Could not open file"); } diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index d69d837..2fef9e1 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -6,6 +6,7 @@ #include <stdexcept> bool _SqlMergeTask::defaultUseTempTable = true; +static void attach(Iterate i, ModifyCommand * insert); // Conversion logic _SqlMergeTask::_SqlMergeTask(const xmlpp::Element * p) : @@ -39,10 +40,15 @@ _SqlMergeTask::_SqlMergeTask(const xmlpp::Element * p) : BOOST_FOREACH(xmlpp::Node * psi, p->find("sql")) { sqls.push_back(static_cast<xmlpp::Element *>(psi)->get_child_text()->get_content()); } + insCmd = insertCommand(); + BOOST_FOREACH(const Iterates::value_type & i, sources) { + attach(i.second, insCmd); + } } _SqlMergeTask::~_SqlMergeTask() { + delete insCmd; } _SqlMergeTask::TargetColumn::TargetColumn(const Column & c) : @@ -78,7 +84,7 @@ _SqlMergeTask::execute() const foreach(Keys::const_iterator, keys, k) { tp.addKey(*k); } - tp.patch(updateWhere.empty() ? NULL : updateWhere.c_str(), + tp.patch(updateWhere->empty() ? NULL : updateWhere->c_str(), patchOrder.empty() ? NULL : patchOrder.c_str()); dropTempTable(); } @@ -190,17 +196,28 @@ class _Populate : public _NoOutputExecute { }; typedef boost::shared_ptr<_Populate> Populate; +static void attach(Iterate i, ModifyCommand * insert) +{ + if (!i) { + return; + } + if (i->subNOEs.empty()) { + Populate p(new _Populate(i, insert)); + i->subNOEs.insert(NoOutputExecutes::value_type(0, p)); + } + else { + BOOST_FOREACH(const NoOutputExecutes::value_type & n, i->subNOEs) { + attach(boost::dynamic_pointer_cast<_Iterate>(n.second), insert); + } + } +} + void _SqlMergeTask::copyToTempTable() const { - ModifyCommand * insert = insertCommand(); BOOST_FOREACH(const Iterates::value_type & i, sources) { - Populate p(new _Populate(i.second, insert)); - i.second->subNOEs.insert(NoOutputExecutes::value_type(0, p)); i.second->execute(); - i.second->subNOEs.erase(0); } - delete insert; BOOST_FOREACH(const std::string & sql, sqls) { Buffer insC; Buffer insV; diff --git a/project2/sqlMergeTask.h b/project2/sqlMergeTask.h index 61cbe4e..968e284 100644 --- a/project2/sqlMergeTask.h +++ b/project2/sqlMergeTask.h @@ -8,6 +8,7 @@ #include "tablepatch.h" #include "task.h" #include "iterate.h" +#include "variables.h" #include <string> #include <set> #include <map> @@ -43,7 +44,7 @@ class _SqlMergeTask : public _Task { Columns cols; Keys keys; Keys indexes; - const std::string updateWhere; + const Variable updateWhere; const std::string patchOrder; bool earlyKeys; @@ -58,6 +59,7 @@ class _SqlMergeTask : public _Task { std::list<std::string> sqls; protected: ModifyCommand * insertCommand() const; + ModifyCommand * insCmd; public: mutable ODBC::Connection * destdb; diff --git a/project2/variables.cpp b/project2/variables.cpp index 07d30aa..a4a064f 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -143,8 +143,7 @@ class VariableParse : public VariableImplDyn, public RowUser { VariableParse(const Glib::ustring & src) : VariableImplDyn(src) { - boost::char_separator<char> sep(" "); - boost::tokenizer<boost::char_separator<char> > tokens(source.raw(), sep); + boost::tokenizer<boost::char_separator<char> > tokens(source.raw(), boost::char_separator<char>(" ")); BOOST_FOREACH(std::string t, tokens) { vars.push_back(Variable::create(t, this)); } @@ -156,6 +155,7 @@ class VariableParse : public VariableImplDyn, public RowUser { BOOST_FOREACH(Variable::VariableImplPtr vip, vars) { len += vip->value().length() + 1; } + cache.clear(); cache.reserve(len); BOOST_FOREACH(Variable::VariableImplPtr v, vars) { if (cache.length()) { @@ -193,6 +193,9 @@ Variable::Variable(xmlpp::Element * e) : Variable::VariableImplPtr Variable::create(const Glib::ustring & s, RowUser * dep) { + if (s.empty()) { + return VariableImplPtr(new VariableLiteral(s)); + } switch (s[0]) { case '$': // param return VariableImplPtr(new VariableParam(s)); @@ -203,9 +206,8 @@ Variable::create(const Glib::ustring & s, RowUser * dep) case '/': // uri return VariableImplPtr(new VariableUri(s)); case '*': // parser - return VariableImplPtr(new VariableParse(s)); - case '=': // literal (explicit) return VariableImplPtr(new VariableParse(s.substr(1))); + case '=': // literal (explicit) default: return VariableImplPtr(new VariableLiteral(s)); } diff --git a/project2/variables.h b/project2/variables.h index ae3d3c6..f3f8668 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -30,6 +30,7 @@ class Variable { operator const Glib::ustring & () const { return var->value(); } const Glib::ustring & operator()() const { return var->value(); } + const Glib::ustring * operator->() const { return &var->value(); } private: friend class VariableParse; |