フルアップデート(更新チェックなし)
クライアントから送信されたキーと値のペアで、サーバー上のデータを完全に上書きする方法です。サーバーにあった値は、上書きによって失われます。
更新の際、サーバー上で他のクライアントから更新があったかどうかはチェックせずにそのまま上書きします。
更新のコード例を以下に挙げます。
-
// Instantiate a KiiObject. Uri objUri = Uri.parse("Set the URI of an existing KiiObject here"); KiiObject object = KiiObject.createByUri(objUri); try { // Update key-value pairs. object.set("myid", 1); object.set("name", "John Doe Jr"); object.set("email", "john_jr@example.com"); object.remove("address"); // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. object.saveAllFields(true); } catch (AppException e) { // Handle the error. } catch (IOException e) { // Handle the error. }
-
// Instantiate a KiiObject. Uri objUri = Uri.parse("Set the URI of an existing KiiObject here"); KiiObject object = KiiObject.createByUri(objUri); // Update key-value pairs. object.set("myid", 1); object.set("name", "John Doe Jr"); object.set("email", "john_jr@example.com"); object.remove("address"); // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. object.saveAllFields(new KiiObjectCallBack() { @Override public void onSaveCompleted(int token, KiiObject object, Exception exception) { if (exception != null) { // Handle the error. return; } } }, true);
ここでは以下の処理を行っています。
- 更新対象の KiiObject を用意します。ここでは、URI からの生成によって、既存の KiiObject を作成しています。コード上の URI は、事前に取得しておいたものに置き換えてください。
set()
メソッドでキーと値のペアの追加を、remove()
メソッドでキーと値のペアの削除を行います。更新後はここでobject
に設定されている値だけになります。必要に応じて、事前にrefresh()
メソッドを呼び出して、すべてのキーと値のペアをサーバーから取得しておくこともできます(実装方法は KiiObject の取得 を参照してください)。saveAllFields()
メソッドにより更新します。上記のコードでは、引数値 true によって更新チェックを行わないため、そのまま強制的に上書きします。