summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-11-23 20:25:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-11-23 20:25:42 +0000
commit1aa32835ea71dfd634bc25a7d47e0780ea35baf6 (patch)
tree58726b2a349d89219f3eb3504493a2adf7a77ce7
parentMake source object a virtual base of row set cache (diff)
downloadproject2-1aa32835ea71dfd634bc25a7d47e0780ea35baf6.tar.bz2
project2-1aa32835ea71dfd634bc25a7d47e0780ea35baf6.tar.xz
project2-1aa32835ea71dfd634bc25a7d47e0780ea35baf6.zip
Move common code for database references into SqlBase
-rw-r--r--project2/sql/sqlBase.cpp17
-rw-r--r--project2/sql/sqlBase.h22
-rw-r--r--project2/sql/sqlBulkLoad.cpp16
-rw-r--r--project2/sql/sqlRows.cpp11
-rw-r--r--project2/sql/sqlRows.h7
-rw-r--r--project2/sql/sqlTask.cpp11
-rw-r--r--project2/sql/sqlTask.h7
-rw-r--r--project2/sql/sqlTest.cpp11
-rw-r--r--project2/sql/sqlTest.h7
9 files changed, 55 insertions, 54 deletions
diff --git a/project2/sql/sqlBase.cpp b/project2/sql/sqlBase.cpp
new file mode 100644
index 0000000..608842c
--- /dev/null
+++ b/project2/sql/sqlBase.cpp
@@ -0,0 +1,17 @@
+#include "sqlBase.h"
+#include <commonObjects.h>
+#include "rdbmsDataSource.h"
+
+SqlBase::SqlBase(ScriptNodePtr p) :
+ SourceObject(p),
+ dataSource(p, "datasource"),
+ db(NULL)
+{
+}
+
+void
+SqlBase::loadComplete(const CommonObjects * co)
+{
+ db = co->dataSource<RdbmsDataSource>(dataSource(NULL));
+}
+
diff --git a/project2/sql/sqlBase.h b/project2/sql/sqlBase.h
new file mode 100644
index 0000000..9266ae3
--- /dev/null
+++ b/project2/sql/sqlBase.h
@@ -0,0 +1,22 @@
+#ifndef SQLBASE_H
+#define SQLBASE_H
+
+#include <sourceObject.h>
+#include <variables.h>
+
+class RdbmsDataSource;
+
+class SqlBase : public virtual SourceObject {
+ public:
+ SqlBase(ScriptNodePtr);
+
+ virtual void loadComplete(const CommonObjects *) override;
+
+ const Variable dataSource;
+
+ protected:
+ const RdbmsDataSource * db;
+};
+
+#endif
+
diff --git a/project2/sql/sqlBulkLoad.cpp b/project2/sql/sqlBulkLoad.cpp
index 4f17837..f905a68 100644
--- a/project2/sql/sqlBulkLoad.cpp
+++ b/project2/sql/sqlBulkLoad.cpp
@@ -4,25 +4,20 @@
#include "rdbmsDataSource.h"
#include <scopeExit.h>
#include "stream.h"
+#include "sqlBase.h"
-class SqlBulkLoad : public Task {
+class SqlBulkLoad : public Task, SqlBase {
public:
SqlBulkLoad(ScriptNodePtr p) :
SourceObject(p),
Task(p),
- dataSource(p, "datasource"),
+ SqlBase(p),
targetTable(p, "targettable"),
- extras(p, "extras"),
- db(NULL)
+ extras(p, "extras")
{
p->script->loader.addLoadTarget(p, Storer::into<StreamFactory>(&stream));
}
- void loadComplete(const CommonObjects * co)
- {
- db = co->dataSource<RdbmsDataSource>(dataSource(NULL));
- }
-
void execute(ExecContext * ec) const
{
auto wdb = db->getWritable();
@@ -33,12 +28,9 @@ class SqlBulkLoad : public Task {
stream->runStream(boost::bind(&DB::Connection::bulkUploadData, wdb.get(), _1, _2), ec);
}
- const Variable dataSource;
const Variable targetTable;
const Variable extras;
StreamPtr stream;
- protected:
- const RdbmsDataSource * db;
};
NAMEDFACTORY("sqlbulkload", SqlBulkLoad, TaskFactory);
diff --git a/project2/sql/sqlRows.cpp b/project2/sql/sqlRows.cpp
index 918a502..22f6b35 100644
--- a/project2/sql/sqlRows.cpp
+++ b/project2/sql/sqlRows.cpp
@@ -15,9 +15,8 @@ NAMEDFACTORY("sqlrows", SqlRows, RowSetFactory);
SqlRows::SqlRows(ScriptNodePtr p) :
SourceObject(p),
RowSet(p),
- dataSource(p, "datasource"),
- sqlCommand(p->child("sql")),
- db(NULL)
+ SqlBase(p),
+ sqlCommand(p->child("sql"))
{
}
@@ -25,12 +24,6 @@ SqlRows::~SqlRows()
{
}
-void
-SqlRows::loadComplete(const CommonObjects * co)
-{
- db = co->dataSource<RdbmsDataSource>(dataSource(NULL));
-}
-
SqlRows::SqlState::SqlState(SelectPtr s) :
query(s)
{
diff --git a/project2/sql/sqlRows.h b/project2/sql/sqlRows.h
index 46f3972..aec233e 100644
--- a/project2/sql/sqlRows.h
+++ b/project2/sql/sqlRows.h
@@ -7,19 +7,17 @@
#include "iHaveParameters.h"
#include "rowSet.h"
#include "sqlWriter.h"
+#include "sqlBase.h"
class RdbmsDataSource;
/// Project2 component to create a row set based on an SQL SELECT statement issued against an RDBMS data source
-class SqlRows : public RowSet {
+class SqlRows : public RowSet, SqlBase {
public:
SqlRows(ScriptNodePtr p);
~SqlRows();
void execute(const Glib::ustring &, const RowProcessorCallback &, ExecContext *) const;
- virtual void loadComplete(const CommonObjects *);
-
- const Variable dataSource;
private:
const DynamicSql::SqlCommand sqlCommand;
@@ -32,7 +30,6 @@ class SqlRows : public RowSet {
Columns columns;
friend class SqlRows;
};
- const RdbmsDataSource * db;
};
#endif
diff --git a/project2/sql/sqlTask.cpp b/project2/sql/sqlTask.cpp
index 78c6d81..bf8929f 100644
--- a/project2/sql/sqlTask.cpp
+++ b/project2/sql/sqlTask.cpp
@@ -12,10 +12,9 @@ StaticMessageException(RunOnNotSpecified, "runon attribute must be specified");
SqlTask::SqlTask(ScriptNodePtr p) :
SourceObject(p),
Task(p),
- dataSource(p, "datasource"),
+ SqlBase(p),
filter(p, "filter", ""),
- sqlCommand(p->child("sql")),
- db(NULL)
+ sqlCommand(p->child("sql"))
{
p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into<TaskFactory>(&changesTasks));
p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into<TaskFactory>(&noChangesTasks));
@@ -26,12 +25,6 @@ SqlTask::~SqlTask()
}
void
-SqlTask::loadComplete(const CommonObjects * co)
-{
- db = co->dataSource<RdbmsDataSource>(dataSource(NULL));
-}
-
-void
SqlTask::execute(ExecContext * ec) const
{
auto con = db->getWritable();
diff --git a/project2/sql/sqlTask.h b/project2/sql/sqlTask.h
index 20f7415..224d108 100644
--- a/project2/sql/sqlTask.h
+++ b/project2/sql/sqlTask.h
@@ -4,22 +4,20 @@
#include <boost/intrusive_ptr.hpp>
#include <map>
#include "task.h"
+#include "sqlBase.h"
#include "variables.h"
#include "sqlWriter.h"
#include <scriptStorage.h>
namespace DB { class ModifyCommand; }
-class RdbmsDataSource;
/// Project2 component to execute a modifying SQL statement against an RDBMS data source
-class SqlTask : public Task {
+class SqlTask : public Task, SqlBase {
public:
SqlTask(ScriptNodePtr p);
virtual ~SqlTask();
- virtual void loadComplete(const CommonObjects *);
virtual void execute(ExecContext * ec) const;
- const Variable dataSource;
const Variable filter;
typedef ANONORDEREDSTORAGEOF(Task) SubTasks;
@@ -28,7 +26,6 @@ class SqlTask : public Task {
protected:
const DynamicSql::SqlCommand sqlCommand;
- const RdbmsDataSource * db;
};
#endif
diff --git a/project2/sql/sqlTest.cpp b/project2/sql/sqlTest.cpp
index f3a5516..705a58b 100644
--- a/project2/sql/sqlTest.cpp
+++ b/project2/sql/sqlTest.cpp
@@ -15,12 +15,11 @@ class CantCompareNulls : public std::exception { };
SqlTest::SqlTest(ScriptNodePtr p) :
SourceObject(p),
Test(p),
- dataSource(p, "datasource"),
+ SqlBase(p),
filter(p, "filter", ""),
testOp(p, "testOp", "=="),
testValue(p, "testValue"),
- sqlCommand(p->child("sql")),
- db(NULL)
+ sqlCommand(p->child("sql"))
{
}
@@ -28,12 +27,6 @@ SqlTest::~SqlTest()
{
}
-void
-SqlTest::loadComplete(const CommonObjects * co)
-{
- db = co->dataSource<RdbmsDataSource>(dataSource(NULL));
-}
-
class HandleDoCompare : public DB::HandleField {
public:
HandleDoCompare(const VariableType & tV, const std::string & tO) :
diff --git a/project2/sql/sqlTest.h b/project2/sql/sqlTest.h
index af843d1..45e7836 100644
--- a/project2/sql/sqlTest.h
+++ b/project2/sql/sqlTest.h
@@ -3,27 +3,24 @@
#include "test.h"
#include "sqlWriter.h"
+#include "sqlBase.h"
namespace DB { class SelectCommand; }
-class RdbmsDataSource;
/// Project2 component to test the value of a variable against an RDBMS data source
-class SqlTest : public Test {
+class SqlTest : public Test, SqlBase {
public:
SqlTest(ScriptNodePtr p);
virtual ~SqlTest();
- virtual void loadComplete(const CommonObjects *);
bool passes(ExecContext *) const;
- const Variable dataSource;
const Variable filter;
const Variable testOp;
const Variable testValue;
private:
DynamicSql::SqlCommand sqlCommand;
- const RdbmsDataSource * db;
};
#endif