summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-03-30 12:37:01 +0000
committerrandomdan <randomdan@localhost>2011-03-30 12:37:01 +0000
commit664871d6b2982a9cd0ac960356b297daa28f1be7 (patch)
tree73573493a6f9192f1fd9928700a5ec449f09256a
parentAdd native conversion of VariableTypes to int32_t (diff)
downloadproject2-664871d6b2982a9cd0ac960356b297daa28f1be7.tar.bz2
project2-664871d6b2982a9cd0ac960356b297daa28f1be7.tar.xz
project2-664871d6b2982a9cd0ac960356b297daa28f1be7.zip
Pass XML node to XML storer
Add storer to split tasks by their onerror value
-rw-r--r--project2/cgi/cgiStageRequest.cpp2
-rw-r--r--project2/console/consoleAppEngine.cpp2
-rw-r--r--project2/if.cpp14
-rw-r--r--project2/if.h3
-rw-r--r--project2/iterate.cpp26
-rw-r--r--project2/iterate.h3
-rw-r--r--project2/noOutputExecute.cpp22
-rw-r--r--project2/noOutputExecute.h9
-rw-r--r--project2/requestHost.cpp6
-rw-r--r--project2/requestHost.h3
-rw-r--r--project2/sqlMergeTask.cpp6
-rw-r--r--project2/xmlObjectLoader.cpp2
-rw-r--r--project2/xmlStorage.h4
13 files changed, 59 insertions, 43 deletions
diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp
index 6f877f7..774b67d 100644
--- a/project2/cgi/cgiStageRequest.cpp
+++ b/project2/cgi/cgiStageRequest.cpp
@@ -16,7 +16,7 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, const
LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
loader.supportedStorers.insert(Storer::into(&parameterChecks));
loader.supportedStorers.insert(Storer::into(&rowSets));
- loader.supportedStorers.insert(Storer::into(&tasks));
+ loader.supportedStorers.insert(new NOEErrorStorer(&normTasks, &errorTasks));
loader.collectAll(this, requestRoot, true);
}
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index 769add6..645fde3 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -66,7 +66,7 @@ ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * en
LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
loader.supportedStorers.insert(Storer::into(&parameterChecks));
- loader.supportedStorers.insert(Storer::into(&tasks));
+ loader.supportedStorers.insert(new NOEErrorStorer(&normTasks, &errorTasks));
loader.supportedStorers.insert(Storer::into(&rowSets));
loader.supportedStorers.insert(Storer::into(&views));
loader.collectAll(this, request.get_document()->get_root_node(), true);
diff --git a/project2/if.cpp b/project2/if.cpp
index 01368cc..3474815 100644
--- a/project2/if.cpp
+++ b/project2/if.cpp
@@ -46,7 +46,7 @@ If::If(const xmlpp::Element * e) :
localErrorHandling(e->get_attribute_value("errorHandling") == "local")
{
LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
- loader.supportedStorers.insert(Storer::into(&subNOEs));
+ loader.supportedStorers.insert(new NOEErrorStorer(&normNOEs, &errorNOEs));
loader.supportedStorers.insert(Storer::into(&subViews));
loader.collectAll(e, true, IgnoreUnsupported);
}
@@ -73,17 +73,13 @@ If::execute() const
if (passes()) {
Logger()->message(LOG_DEBUG, "IfSet passed");
try {
- BOOST_FOREACH(const SubNOEs::value_type & sq, subNOEs.get<bySOOrder>()) {
- if (!sq->isErrorHandler) {
- sq->execute();
- }
+ BOOST_FOREACH(const SubNOEs::value_type & sq, normNOEs.get<bySOOrder>()) {
+ sq->execute();
}
}
catch (...) {
- BOOST_FOREACH(const SubNOEs::value_type & sq, subNOEs.get<bySOOrder>()) {
- if (sq->isErrorHandler) {
- sq->execute();
- }
+ BOOST_FOREACH(const SubNOEs::value_type & sq, errorNOEs.get<bySOOrder>()) {
+ sq->execute();
}
if (!localErrorHandling) {
throw;
diff --git a/project2/if.h b/project2/if.h
index 0a262c2..6482d7c 100644
--- a/project2/if.h
+++ b/project2/if.h
@@ -33,7 +33,8 @@ class If : public NoOutputExecute, public View, public IfSet {
typedef Storage<View>::Objects SubViews;
SubViews subViews;
typedef Storage<NoOutputExecute>::Objects SubNOEs;
- SubNOEs subNOEs;
+ SubNOEs normNOEs;
+ SubNOEs errorNOEs;
const std::string & getName() const;
};
diff --git a/project2/iterate.cpp b/project2/iterate.cpp
index b06d7e1..569bb3d 100644
--- a/project2/iterate.cpp
+++ b/project2/iterate.cpp
@@ -12,7 +12,7 @@ Iterate::Iterate(const xmlpp::Element * p) :
localErrorHandling(p->get_attribute_value("errorHandling") == "local")
{
LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
- loader.supportedStorers.insert(Storer::into(&subNOEs));
+ loader.supportedStorers.insert(new NOEErrorStorer(&normNOEs, &errorNOEs));
loader.collectAll(p, true, IgnoreUnsupported);
}
@@ -56,21 +56,19 @@ Iterate::execute() const
void
Iterate::executeChildren(bool errs) const
{
- BOOST_FOREACH(const SubNOEs::value_type & sq, subNOEs.get<bySOOrder>()) {
- if (sq->isErrorHandler == errs) {
- if (dynamic_cast<const RowProcessor *>(sq.get())) {
+ BOOST_FOREACH(const SubNOEs::value_type & sq, (errs ? errorNOEs : normNOEs).get<bySOOrder>()) {
+ if (dynamic_cast<const RowProcessor *>(sq.get())) {
+ sq->execute();
+ }
+ else {
+ RowSet::beginRow(NULL);
+ try {
sq->execute();
+ RowSet::endRow(NULL);
}
- else {
- RowSet::beginRow(NULL);
- try {
- sq->execute();
- RowSet::endRow(NULL);
- }
- catch (...) {
- RowSet::endRow(NULL);
- throw;
- }
+ catch (...) {
+ RowSet::endRow(NULL);
+ throw;
}
}
}
diff --git a/project2/iterate.h b/project2/iterate.h
index 54ddabf..e4cd3fe 100644
--- a/project2/iterate.h
+++ b/project2/iterate.h
@@ -20,7 +20,8 @@ class Iterate : public NoOutputExecute, public RowProcessor {
void execute() const;
typedef Storage<NoOutputExecute>::Objects SubNOEs;
- SubNOEs subNOEs;
+ SubNOEs normNOEs;
+ SubNOEs errorNOEs;
const bool localErrorHandling;
diff --git a/project2/noOutputExecute.cpp b/project2/noOutputExecute.cpp
index 7608329..4416933 100644
--- a/project2/noOutputExecute.cpp
+++ b/project2/noOutputExecute.cpp
@@ -1,14 +1,28 @@
#include "noOutputExecute.h"
NoOutputExecute::NoOutputExecute(const xmlpp::Element * p) :
- SourceObject(p),
- isErrorHandler(p->get_attribute_value("onerror") == "true")
+ SourceObject(p)
{
}
NoOutputExecute::NoOutputExecute(const std::string & n) :
- SourceObject(n),
- isErrorHandler(false)
+ SourceObject(n)
{
}
+NOEErrorStorer::NOEErrorStorer(Map m, Map em) :
+ map(m), errorMap(em)
+{
+}
+
+bool
+NOEErrorStorer::save(SourceObjectPtr obj, const xmlpp::Element * p) const {
+ boost::intrusive_ptr<NoOutputExecute> O = boost::dynamic_pointer_cast<NoOutputExecute>(obj);
+ if (O) {
+ if (((p->get_attribute_value("onerror") == "true") ? errorMap : map)->insert(O).second) {
+ return true;
+ }
+ throw StoreFailed(obj->name);
+ }
+ return false;
+}
diff --git a/project2/noOutputExecute.h b/project2/noOutputExecute.h
index 0e84fd1..87c17a7 100644
--- a/project2/noOutputExecute.h
+++ b/project2/noOutputExecute.h
@@ -2,6 +2,7 @@
#define NOOUTPUTEXECUTE_H
#include "sourceObject.h"
+#include "xmlStorage.h"
class NoOutputExecute;
typedef boost::intrusive_ptr<NoOutputExecute> NoOutputExecutePtr;
@@ -14,8 +15,14 @@ class NoOutputExecute : public virtual SourceObject {
virtual ~NoOutputExecute() { }
virtual void execute() const = 0;
+};
- const bool isErrorHandler;
+class NOEErrorStorer : public Storer {
+ public:
+ typedef Storage<NoOutputExecute>::ObjectsPtr Map;
+ NOEErrorStorer(Map m, Map em);
+ bool save(SourceObjectPtr obj, const xmlpp::Element *) const;
+ Map map, errorMap;
};
#endif
diff --git a/project2/requestHost.cpp b/project2/requestHost.cpp
index 09de71f..7cb3d9c 100644
--- a/project2/requestHost.cpp
+++ b/project2/requestHost.cpp
@@ -38,10 +38,8 @@ RequestHost::run() const
void
RequestHost::run(bool errs) const
{
- BOOST_FOREACH(const Tasks::value_type & t, tasks.get<bySOOrder>()) {
- if (t->isErrorHandler == errs) {
- t->execute();
- }
+ BOOST_FOREACH(const Tasks::value_type & t, (errs ? errorTasks : normTasks).get<bySOOrder>()) {
+ t->execute();
}
}
diff --git a/project2/requestHost.h b/project2/requestHost.h
index 7610ac1..bf0e9f0 100644
--- a/project2/requestHost.h
+++ b/project2/requestHost.h
@@ -17,7 +17,8 @@ class RequestHost : virtual CommonObjects {
void run() const;
- Tasks tasks;
+ Tasks normTasks;
+ Tasks errorTasks;
bool rollbackBeforeHandle;
bool localErrorHandling;
diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp
index ab8546b..84feb18 100644
--- a/project2/sqlMergeTask.cpp
+++ b/project2/sqlMergeTask.cpp
@@ -288,11 +288,11 @@ attach(IteratePtr i, ModifyCommand * insert)
if (!i) {
return;
}
- if (i->subNOEs.empty()) {
- i->subNOEs.insert(new Populate(insert));
+ if (i->normNOEs.empty()) {
+ i->normNOEs.insert(new Populate(insert));
}
else {
- BOOST_FOREACH(const Iterate::SubNOEs::value_type & n, i->subNOEs.get<bySOOrder>()) {
+ BOOST_FOREACH(const Iterate::SubNOEs::value_type & n, i->normNOEs.get<bySOOrder>()) {
attach(boost::dynamic_pointer_cast<Iterate>(n), insert);
attach(boost::dynamic_pointer_cast<SqlMergeInsert>(n), insert);
}
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 2745d61..30e2865 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -79,7 +79,7 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport
created += 1;
loadedObjects.insert(o);
BOOST_FOREACH(std::set<boost::intrusive_ptr<Storer> >::value_type s, supportedStorers) {
- if (s->save(o)) {
+ if (s->save(o, node)) {
stored += 1;
}
}
diff --git a/project2/xmlStorage.h b/project2/xmlStorage.h
index d35a182..443ad81 100644
--- a/project2/xmlStorage.h
+++ b/project2/xmlStorage.h
@@ -33,7 +33,7 @@ class Storer : public virtual IntrusivePtrBase {
template <class X>
static StorerPtr into(X * map);
- virtual bool save(SourceObjectPtr o) const = 0;
+ virtual bool save(SourceObjectPtr o, const xmlpp::Element *) const = 0;
};
template <class X>
@@ -43,7 +43,7 @@ class StorerImpl : public Storer {
{
}
- bool save(SourceObjectPtr obj) const {
+ bool save(SourceObjectPtr obj, const xmlpp::Element *) const {
boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(obj);
if (O) {
if (map->insert(O).second) {