From: Soyoung Kim Date: Fri, 3 May 2013 11:16:38 +0000 (+0900) Subject: Add backup api for update X-Git-Tag: 2.2.1_release~9^2~105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a3027a28e336d33b58e163c607e8c938b585e2e;p=framework%2Fweb%2Fwrt-commons.git Add backup api for update [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] add backup api and restore api for update [SCMRequest] N/A Change-Id: I3c4c52a3566b737124ae06c214b096d24b94ce16 --- diff --git a/modules/widget_dao/dao/widget_dao.cpp b/modules/widget_dao/dao/widget_dao.cpp index 53a340b..250e8f5 100644 --- a/modules/widget_dao/dao/widget_dao.cpp +++ b/modules/widget_dao/dao/widget_dao.cpp @@ -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(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 diff --git a/modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h b/modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h index 3647d4e..c7d8e94 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h +++ b/modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h @@ -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,