summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKevin Simons <kevin.simons@nokia.com>2012-04-27 13:46:48 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-27 14:34:34 +0200
commit8a8416cb191ccbbae9a85b1b0f19f9945a497d02 (patch)
tree2a7c298b49af0bf091b8e12b33394369fff2abb2 /tools
parent3b05ad5ea5b2ef8f6ebbcc0d455c6d63e9a1dc23 (diff)
Add support for specifying the default partition to jsondb-client
Specifying -partition has no effect when loading a .qml file with -load. Change-Id: I1398208ca15d6c3ac39726393d86d48c0a069312 Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/jsondb-client/client.cpp7
-rw-r--r--tools/jsondb-client/client.h2
-rw-r--r--tools/jsondb-client/jsondbproxy.cpp20
-rw-r--r--tools/jsondb-client/jsondbproxy.h3
-rw-r--r--tools/jsondb-client/main.cpp15
5 files changed, 40 insertions, 7 deletions
diff --git a/tools/jsondb-client/client.cpp b/tools/jsondb-client/client.cpp
index bb646a46..ccb9d43a 100644
--- a/tools/jsondb-client/client.cpp
+++ b/tools/jsondb-client/client.cpp
@@ -381,6 +381,8 @@ void Client::aboutToRemove(void)
InputThread::print("The object(s) matching your query are about to be removed.");
//we get the objects, remove them now
QtJsonDb::QJsonDbRemoveRequest* request = new QtJsonDb::QJsonDbRemoveRequest(objects);
+ request->setPartition(queryRequest->partition());
+
connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
connect(request, SIGNAL(finished()), this, SLOT(popRequest()));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
@@ -458,6 +460,8 @@ bool Client::processCommand(const QString &command)
rest.remove(0, partition.size());
partition.remove(0, 10);
rest = rest.trimmed();
+ } else {
+ partition = mDefaultPartition;
}
if (cmd == "quit") {
@@ -683,6 +687,7 @@ void Client::loadJsonFile(const QString &jsonFile)
}
QtJsonDb::QJsonDbCreateRequest *write = new QtJsonDb::QJsonDbCreateRequest(objects, this);
+ write->setPartition(mDefaultPartition);
connect(write, SIGNAL(finished()), this, SLOT(fileLoadSuccess()));
connect(write, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
this, SLOT(fileLoadError()));
@@ -739,7 +744,7 @@ void Client::loadJavaScriptFile(const QString &jsFile)
QJSEngine *scriptEngine = new QJSEngine(this);
QJSValue globalObject = scriptEngine->globalObject();
- QJSValue proxy = scriptEngine->newQObject(new JsonDbProxy(mConnection, this));
+ QJSValue proxy = scriptEngine->newQObject(new JsonDbProxy(mConnection, mDefaultPartition, this));
globalObject.setProperty("jsondb", proxy);
globalObject.setProperty("console", proxy);
diff --git a/tools/jsondb-client/client.h b/tools/jsondb-client/client.h
index f12cfa8d..5d1735d9 100644
--- a/tools/jsondb-client/client.h
+++ b/tools/jsondb-client/client.h
@@ -84,6 +84,7 @@ public:
void interactiveMode();
void loadFiles(const QStringList &files);
+ inline void setDefaultPartition(const QString &partition) { mDefaultPartition = partition; }
inline void setTerminateOnCompleted(bool terminate) { mTerminate = terminate; }
inline void setDebug(bool debug) { mDebug = debug; }
@@ -128,6 +129,7 @@ private:
bool mTerminate;
bool mDebug;
QStringList mFilesToLoad;
+ QString mDefaultPartition;
QQmlEngine *mEngine;
};
diff --git a/tools/jsondb-client/jsondbproxy.cpp b/tools/jsondb-client/jsondbproxy.cpp
index 650f9105..ba24311c 100644
--- a/tools/jsondb-client/jsondbproxy.cpp
+++ b/tools/jsondb-client/jsondbproxy.cpp
@@ -75,15 +75,17 @@ QVariantMap _waitForResponse(QtJsonDb::QJsonDbRequest *request) {
}
-JsonDbProxy::JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, QObject *parent) :
+JsonDbProxy::JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, const QString &partition, QObject *parent) :
QObject(parent)
, mConnection(conn)
+ , mPartition(partition)
{
}
QVariantMap JsonDbProxy::find(QVariantMap object)
{
QtJsonDb::QJsonDbReadRequest *request = new QtJsonDb::QJsonDbReadRequest(this);
+ request->setPartition(mPartition);
request->setQuery(object.value(QLatin1String("query")).toString());
if (object.contains(QLatin1String("limit")))
request->setQueryLimit(object.value(QLatin1String("limit")).toInt());
@@ -100,7 +102,9 @@ QVariantMap JsonDbProxy::create(QVariantMap object)
obj.remove(QLatin1String("_id"));
}
QtJsonDb::QJsonDbCreateRequest *request = new QtJsonDb::QJsonDbCreateRequest(QList<QJsonObject>() << obj,
- this);
+ this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
@@ -108,7 +112,9 @@ QVariantMap JsonDbProxy::create(QVariantMap object)
QVariantMap JsonDbProxy::update(QVariantMap object)
{
QtJsonDb::QJsonDbUpdateRequest *request = new QtJsonDb::QJsonDbUpdateRequest(QList<QJsonObject>() << QJsonObject::fromVariantMap(object),
- this);
+ this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
@@ -117,6 +123,8 @@ QVariantMap JsonDbProxy::remove(QVariantMap object )
{
QtJsonDb::QJsonDbRemoveRequest *request = new QtJsonDb::QJsonDbRemoveRequest(QList<QJsonObject>() << QJsonObject::fromVariantMap(object),
this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
@@ -133,6 +141,8 @@ QVariantMap JsonDbProxy::createList(QVariantList list)
objects << obj;
}
QtJsonDb::QJsonDbCreateRequest *request = new QtJsonDb::QJsonDbCreateRequest(objects, this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
@@ -143,6 +153,8 @@ QVariantMap JsonDbProxy::updateList(QVariantList list)
foreach (const QVariant &obj, list)
objects << QJsonObject::fromVariantMap(obj.toMap());
QtJsonDb::QJsonDbUpdateRequest *request = new QtJsonDb::QJsonDbUpdateRequest(objects, this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
@@ -153,6 +165,8 @@ QVariantMap JsonDbProxy::removeList(QVariantList list)
foreach (const QVariant &obj, list)
objects << QJsonObject::fromVariantMap(obj.toMap());
QtJsonDb::QJsonDbRemoveRequest *request = new QtJsonDb::QJsonDbRemoveRequest(objects, this);
+ request->setPartition(mPartition);
+
mConnection->send(request);
return _waitForResponse(request);
}
diff --git a/tools/jsondb-client/jsondbproxy.h b/tools/jsondb-client/jsondbproxy.h
index 28a2657d..b74e507f 100644
--- a/tools/jsondb-client/jsondbproxy.h
+++ b/tools/jsondb-client/jsondbproxy.h
@@ -49,7 +49,7 @@ class JsonDbProxy : public QObject
{
Q_OBJECT
public:
- explicit JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, QObject *parent = 0);
+ explicit JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, const QString &partition, QObject *parent = 0);
Q_SCRIPTABLE QVariantMap find(QVariantMap object);
Q_SCRIPTABLE QVariantMap create(QVariantMap object);
Q_SCRIPTABLE QVariantMap update(QVariantMap object);
@@ -64,6 +64,7 @@ public:
private:
QtJsonDb::QJsonDbConnection *mConnection;
+ QString mPartition;
};
#endif // JSONDBPROXY_H
diff --git a/tools/jsondb-client/main.cpp b/tools/jsondb-client/main.cpp
index 385e0a58..4002fc03 100644
--- a/tools/jsondb-client/main.cpp
+++ b/tools/jsondb-client/main.cpp
@@ -51,8 +51,9 @@ static void usage(const QString &name, int exitCode = 0)
cout << "Usage: " << qPrintable(name) << " [OPTIONS] [command]" << endl
<< endl
<< " -debug" << endl
- << " -load FILE Load the specified .json or .qml file" << endl
- << " -terminate Terminate after processing any -load parameters" << endl
+ << " -load FILE Load the specified .json or .qml file" << endl
+ << " -partition PARTITION Set the specified partition as the default" << endl
+ << " -terminate Terminate after processing any -load parameters" << endl
<< endl
<< " where command is valid JsonDb command object" << endl;
exit(exitCode);
@@ -72,6 +73,7 @@ int main(int argc, char * argv[])
QString progname = args.takeFirst();
QStringList command;
QStringList filesToLoad;
+ QString partition;
bool terminate = false;
bool debug = false;
@@ -92,6 +94,12 @@ int main(int argc, char * argv[])
usage(progname, 1);
}
filesToLoad << args.takeFirst();
+ } else if (arg == QLatin1String("-partition")) {
+ if (args.isEmpty()) {
+ cout << "Must specify a partition" << endl;
+ usage(progname, 1);
+ }
+ partition = args.takeFirst();
} else if (arg == QLatin1String("-terminate")) {
terminate = true;
} else {
@@ -108,6 +116,9 @@ int main(int argc, char * argv[])
if (!client.connectToServer())
return 1;
+ if (!partition.isEmpty())
+ client.setDefaultPartition(partition);
+
if (!filesToLoad.isEmpty()) {
client.loadFiles(filesToLoad);
} else if (command.size()) {