support save/load 20/920/2
authorTasuku Suzuki <stasuku@gmail.com>
Wed, 18 Mar 2015 03:25:02 +0000 (12:25 +0900)
committerstasuku <stasuku@gmail.com>
Sat, 30 Apr 2016 03:03:25 +0000 (12:03 +0900)
Change-Id: Ifa43c4f0021391cf42e1d8d2b777c9899c3c857e
Reviewed-on: http://codereview.qt-users.jp/920
Reviewed-by: <stasuku@gmail.com>
Tested-by: <stasuku@gmail.com>
src/jubatus/client/qjubatusclient.cpp
src/jubatus/client/qjubatusclient.h

index aa47e02..83bed9a 100644 (file)
@@ -111,6 +111,20 @@ void QJubatusClient::setTimeout(double timeout)
     emit timeoutChanged(timeout);
 }
 
+bool QJubatusClient::save(const QString &id)
+{
+    bool ret = false;
+    EXEC_JUBATUS_COMMAND_PRIVATE( ret = m_client->save(convert(id));, m_client )
+    return ret;
+}
+
+bool QJubatusClient::load(const QString &id)
+{
+    bool ret = false;
+    EXEC_JUBATUS_COMMAND_PRIVATE( ret = m_client->load(convert(id));, m_client )
+    return ret;
+}
+
 std::string QJubatusClient::convert(const QString &data) const
 {
     return data.toStdString();
@@ -149,12 +163,21 @@ jubatus::client::common::datum QJubatusClient::convert(const QVariantMap &data)
         case QVariant::String:
             ret.add_string(key.toStdString(), value.toString().toStdString());
             break;
+        case QVariant::ByteArray:
+            ret.add_string(key.toStdString(), value.toByteArray().toStdString());
+            break;
         case QVariant::Int:
             ret.add_number(key.toStdString(), value.toInt());
             break;
         case QVariant::UInt:
             ret.add_number(key.toStdString(), value.toUInt());
             break;
+        case QVariant::LongLong:
+            ret.add_number(key.toStdString(), value.toLongLong());
+            break;
+        case QVariant::ULongLong:
+            ret.add_number(key.toStdString(), value.toULongLong());
+            break;
         case QMetaType::Float:
             ret.add_number(key.toStdString(), value.toFloat());
             break;
index 2cb63ce..6ed2c83 100644 (file)
@@ -56,6 +56,9 @@ public:
     const QString &name() const;
     double timeout() const;
 
+    bool save(const QString &id);
+    bool load(const QString &id);
+
 public slots:
     void setHost(const QString &host);
     void setPort(int port);
@@ -96,6 +99,9 @@ private:
 };
 
 #define EXEC_JUBATUS_COMMAND(COMMAND) \
+    EXEC_JUBATUS_COMMAND_PRIVATE(COMMAND, client())
+
+#define EXEC_JUBATUS_COMMAND_PRIVATE(COMMAND, CLIENT) \
     try { \
         bool done = false; \
         for (int i = 0; i < 3; i++) { \
@@ -104,11 +110,11 @@ private:
                 done = true; \
                 break; \
             } catch (msgpack::rpc::connection_closed_error &e) { \
-                client()->get_client().close(); \
+                CLIENT->get_client().close(); \
             } catch (msgpack::rpc::system_error &e) { \
-                client()->get_client().close(); \
+                CLIENT->get_client().close(); \
             } catch (msgpack::rpc::timeout_error &e) { \
-                client()->get_client().close(); \
+                CLIENT->get_client().close(); \
             } \
             ::sleep(1); \
         } \