Add backup api for update
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 3 May 2013 11:16:38 +0000 (20:16 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Sat, 4 May 2013 13:29:03 +0000 (22:29 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] add backup api and restore api for update
[SCMRequest] N/A

Change-Id: I3c4c52a3566b737124ae06c214b096d24b94ce16

modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h

index 53a340b..250e8f5 100644 (file)
@@ -337,6 +337,42 @@ void WidgetDAO::registerOrUpdateWidget(
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
 }
 
+void WidgetDAO::backupAndUpdateWidget(
+    const TizenAppId & oldAppId,
+    const TizenAppId & newAppId,
+    const WidgetRegisterInfo &widgetRegInfo,
+    const IWacSecurity &wacSecurity)
+{
+    LogDebug("Backup and Register widget");
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        DPL::DB::ORM::wrt::ScopedTransaction transaction(
+            &WrtDatabase::interface());
+
+        updateWidgetAppIdInternal(newAppId, oldAppId);
+        registerWidgetInternal(newAppId, widgetRegInfo, wacSecurity);
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
+}
+
+void WidgetDAO::restoreUpdateWidget(
+    const TizenAppId & oldAppId,
+    const TizenAppId & newAppId)
+{
+    LogDebug("restore widget");
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        DPL::DB::ORM::wrt::ScopedTransaction transaction(
+            &WrtDatabase::interface());
+
+        unregisterWidgetInternal(newAppId);
+        updateWidgetAppIdInternal(oldAppId, newAppId);
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
+}
+
 #define DO_INSERT(row, table)                              \
     {                                                      \
         WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
@@ -896,6 +932,34 @@ void WidgetDAO::unregisterWidgetInternal(
     // Deleting in other tables is done via "delete cascade" in SQL
 }
 
+void WidgetDAO::updateWidgetAppIdInternal(
+    const TizenAppId & fromAppId,
+    const TizenAppId & toAppId)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(fromAppId)) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                     "Cannot find widget. tzAppId: " << fromAppId);
+        }
+
+        WidgetInfo::Row row;
+        row.Set_tizen_appid(toAppId);
+
+        WRT_DB_UPDATE(update, WidgetInfo, &WrtDatabase::interface())
+        update->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to update appid")
+}
+
 #undef DO_INSERT
 
 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
index 3647d4e..c7d8e94 100644 (file)
@@ -105,6 +105,19 @@ class WidgetDAO : public WidgetDAOReadOnly
         const WidgetRegisterInfo &widgetRegInfo,
         const IWacSecurity &wacSecurity);
 
+    /* This method backup widget information and update new widget information
+     * for restore widget information
+     */
+    static void backupAndUpdateWidget(
+        const TizenAppId & oldAppId,
+        const TizenAppId & newAppId,
+        const WidgetRegisterInfo &widgetRegInfo,
+        const IWacSecurity &wacSecurity);
+
+    static void restoreUpdateWidget(
+        const TizenAppId & oldAppId,
+        const TizenAppId & newAppId);
+
     /**
      * This method removes a widget's information from EmDB.
      *
@@ -225,6 +238,10 @@ class WidgetDAO : public WidgetDAOReadOnly
     static void unregisterWidgetInternal(
         const TizenAppId & tzAppId);
 
+    static void updateWidgetAppIdInternal(
+        const TizenAppId & fromAppId,
+        const TizenAppId & toAppId);
+
     static void insertAppControlInfo(DbWidgetHandle handle,
                                              DPL::String src,
                                              DPL::String operation,