diff options
Diffstat (limited to 'project2/common/rowSetCache.cpp')
-rw-r--r-- | project2/common/rowSetCache.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/project2/common/rowSetCache.cpp b/project2/common/rowSetCache.cpp new file mode 100644 index 0000000..23ae177 --- /dev/null +++ b/project2/common/rowSetCache.cpp @@ -0,0 +1,50 @@ +#include <pch.hpp> +#include "rowSetCache.h" +#include "rowSet.h" +#include "rowProcessor.h" +#include "logger.h" +#include <boost/foreach.hpp> +#include <glibmm/exception.h> + +RowSetCache::RowSetCache(ScriptNodePtr p) : + IHaveParameters(p), + SourceObject(p), + inherit(p->value("inherit", true, NULL).as<bool>()) +{ +} + +bool RowSetCache::checkAndExecute(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * p, const RowProcessorCallback & rp) +{ + RowSetCPtr cached = getCachedRowSet(ec, n, f, p); + if (cached) { + try { + Logger()->messagebf(LOG_DEBUG, "Executing from cache '%s'", name); + cached->execute(f, rp, ec); + return true; + } + catch (const Glib::Exception & e) { + Logger()->messagebf(LOG_WARNING, "Cache failed (%s)", e.what()); + } + catch (const std::exception & e) { + Logger()->messagef(LOG_WARNING, "Cache failed (%s)", e.what()); + } + catch (...) { + Logger()->message(LOG_WARNING, "Cache failed"); + } + } + return false; +} + +void +RowSetCache::applyKeys(ExecContext * ec, const KeyApplier & f, const IHaveParameters * ps) const +{ + BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, allParameters()) { + f(p.first, p.second(ec)); + } + if (inherit) { + BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) { + f(p.first, p.second(ec)); + } + } +} + |