From 81b72f9e45fbb05214663dcf63e99fed0624a634 Mon Sep 17 00:00:00 2001 From: Janusz Majnert Date: Mon, 3 Dec 2012 10:46:55 +0100 Subject: [PATCH] Replacing widget handle with tizenid in property DAO [Issue#] LINUXNGWAP-576 [Feature] Remove DbWidgetHandle from usage in PropertyDAO [Cause] N/A [Solution] Replace widget handle with package name (Tizen ID) [Verification] Build, Run DAO and DPL tests. Change-Id: Id33c672cd1c574ea22b5b685dc519cec246602c4 --- modules/widget_dao/dao/property_dao.cpp | 42 +++++++--- modules/widget_dao/dao/property_dao_read_only.cpp | 89 +++++++++++++++------- modules/widget_dao/dao/widget_dao_read_only.cpp | 50 +++++++++++- .../dpl/wrt-dao-ro/property_dao_read_only.h | 31 +++++++- .../include/dpl/wrt-dao-ro/widget_dao_read_only.h | 11 +++ .../include/dpl/wrt-dao-rw/property_dao.h | 22 ++++++ modules/widget_dao/orm/wrt_db | 6 +- 7 files changed, 204 insertions(+), 47 deletions(-) diff --git a/modules/widget_dao/dao/property_dao.cpp b/modules/widget_dao/dao/property_dao.cpp index 9193b46..b509118 100644 --- a/modules/widget_dao/dao/property_dao.cpp +++ b/modules/widget_dao/dao/property_dao.cpp @@ -30,20 +30,26 @@ namespace WrtDB { namespace PropertyDAO { - +//deprecated void RemoveProperty(DbWidgetHandle widgetHandle, const PropertyDAOReadOnly::WidgetPropertyKey &key) { + RemoveProperty(WidgetDAOReadOnly::getPkgName(widgetHandle),key); +} + +void RemoveProperty(WidgetPkgName pkgName, + const PropertyDAOReadOnly::WidgetPropertyKey &key) +{ //TODO below there are two queries. // First query asks if given property can be removed, // Second removes it. Maybe it should be combined two one. - LogDebug("Removing Property. Handle: " << widgetHandle << ", key: " << key); + LogDebug("Removing Property. pkgName: " << pkgName << ", key: " << key); Try { DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface()); DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag( - widgetHandle, + pkgName, key); if (!readonly.IsNull() && *readonly == 1) { LogError("'" << key << @@ -58,7 +64,7 @@ void RemoveProperty(DbWidgetHandle widgetHandle, using namespace DPL::DB::ORM::wrt; WRT_DB_DELETE(del, WidgetPreference, &WrtDatabase::interface()) del->Where(And( - Equals(widgetHandle), + Equals(pkgName), Equals(key))); del->Execute(); @@ -70,12 +76,21 @@ void RemoveProperty(DbWidgetHandle widgetHandle, } } +//deprecated void SetProperty(DbWidgetHandle widgetHandle, const PropertyDAOReadOnly::WidgetPropertyKey &key, const PropertyDAOReadOnly::WidgetPropertyValue &value, bool readOnly) { - LogDebug("Setting/updating Property. Handle: " << widgetHandle << + SetProperty(WidgetDAOReadOnly::getPkgName(widgetHandle),key,value,readOnly); +} + +void SetProperty(WidgetPkgName pkgName, + const PropertyDAOReadOnly::WidgetPropertyKey &key, + const PropertyDAOReadOnly::WidgetPropertyValue &value, + bool readOnly) +{ + LogDebug("Setting/updating Property. pkgName: " << pkgName << ", key: " << key); Try { using namespace DPL::DB::ORM; @@ -83,7 +98,7 @@ void SetProperty(DbWidgetHandle widgetHandle, DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface()); DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag( - widgetHandle, + pkgName, key); if (!readonly.IsNull() && *readonly == 1) { LogError("'" << key << @@ -94,7 +109,7 @@ void SetProperty(DbWidgetHandle widgetHandle, if (readonly.IsNull()) { WidgetPreference::Row row; - row.Set_app_id(widgetHandle); + row.Set_pkgname(pkgName); row.Set_key_name(key); row.Set_key_value(value); row.Set_readonly(readOnly ? 1 : 0); @@ -108,7 +123,7 @@ void SetProperty(DbWidgetHandle widgetHandle, WRT_DB_UPDATE(update, WidgetPreference, &WrtDatabase::interface()) update->Where(And( - Equals(widgetHandle), + Equals(pkgName), Equals(key))); update->Values(row); @@ -122,10 +137,17 @@ void SetProperty(DbWidgetHandle widgetHandle, } } +//deprecated void RegisterProperties(DbWidgetHandle widgetHandle, const WidgetRegisterInfo ®Info) { - LogDebug("Registering proferences for widget. Handle: " << widgetHandle); + RegisterProperties(WidgetDAOReadOnly::getPkgName(widgetHandle),regInfo); +} + +void RegisterProperties(WidgetPkgName pkgName, + const WidgetRegisterInfo ®Info) +{ + LogDebug("Registering proferences for widget. pkgName: " << pkgName); // Try-Catch in WidgetDAO @@ -137,7 +159,7 @@ void RegisterProperties(DbWidgetHandle widgetHandle, { { // Insert into table Widget Preferences WidgetPreference::Row row; - row.Set_app_id(widgetHandle); + row.Set_pkgname(pkgName); row.Set_key_name(it->name); row.Set_key_value(it->value); int readonly = true == it->readonly ? 1 : 0; diff --git a/modules/widget_dao/dao/property_dao_read_only.cpp b/modules/widget_dao/dao/property_dao_read_only.cpp index 2e6c121..1bc172c 100644 --- a/modules/widget_dao/dao/property_dao_read_only.cpp +++ b/modules/widget_dao/dao/property_dao_read_only.cpp @@ -21,6 +21,7 @@ */ #include #include +#include #include #include #include @@ -58,7 +59,7 @@ void convertWidgetPreferenceRow(const ORMWidgetPreferenceList& ormWidgetPrefRow, FOREACH(it, ormWidgetPrefRow) { WidgetPreferenceRow row; - row.app_id = it->Get_app_id(); + row.pkgname = it->Get_pkgname(); row.key_name = it->Get_key_name(); row.key_value = it->Get_key_value(); row.readonly = it->Get_readonly(); @@ -78,15 +79,50 @@ void convertWidgetPropertyKeyList(const ORMWidgetPropertyKeyList& propKeyList, } +//deprecated +DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle, + const WidgetPropertyKey &key) +{ + return CheckPropertyReadFlag(WidgetDAOReadOnly::getPkgName(widgetHandle), + key); +} + +DPL::OptionalInt CheckPropertyReadFlag(WidgetPkgName pkgName, + const WidgetPropertyKey &key) +{ + LogDebug("Checking Property flag. pkgName: " << pkgName << + ", key: " << key); + + Try { + using namespace DPL::DB::ORM; + using namespace DPL::DB::ORM::wrt; + WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) + select->Where(And(Equals(pkgName), + Equals(key))); + + return select->GetSingleValue(); + } + Catch(DPL::DB::SqlConnection::Exception::Base){ + ReThrowMsg(Exception::DatabaseError, + "Failure during checking readonly flag for property"); + } +} + +//deprecated WidgetPropertyKeyList GetPropertyKeyList(DbWidgetHandle widgetHandle) { - LogDebug("Get PropertyKey list. Handle: " << widgetHandle); + return GetPropertyKeyList(WidgetDAOReadOnly::getPkgName(widgetHandle)); +} + +WidgetPropertyKeyList GetPropertyKeyList(WidgetPkgName pkgName) +{ + LogDebug("Get PropertyKey list. pkgName: " << pkgName); Try { using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt; ORMWidgetPropertyKeyList keyList; WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) - select->Where(Equals(widgetHandle)); + select->Where(Equals(pkgName)); keyList = select->GetValueList(); WidgetPropertyKeyList retKeyList; @@ -100,14 +136,26 @@ WidgetPropertyKeyList GetPropertyKeyList(DbWidgetHandle widgetHandle) } } +//deprecated WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle) { - LogDebug("Get Property list. Handle: " << widgetHandle); + Try{ + WidgetPkgName pkgName=WidgetDAOReadOnly::getPkgName(widgetHandle); + return GetPropertyList(pkgName); + }Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){ + WidgetPreferenceList empty; + return empty; + } +} + +WidgetPreferenceList GetPropertyList(WidgetPkgName pkgName) +{ + LogDebug("Get Property list. pkgName: " << pkgName); Try { using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt; WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) - select->Where(Equals(widgetHandle)); + select->Where(Equals(pkgName)); ORMWidgetPreferenceList ormPrefList = select->GetRowList(); WidgetPreferenceList prefList; @@ -121,16 +169,23 @@ WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle) } } +//deprecated WidgetPropertyValue GetPropertyValue(DbWidgetHandle widgetHandle, const WidgetPropertyKey &key) { - LogDebug("Get Property value. Handle: " << widgetHandle << + return GetPropertyValue(WidgetDAOReadOnly::getPkgName(widgetHandle),key); +} + +WidgetPropertyValue GetPropertyValue(WidgetPkgName pkgName, + const WidgetPropertyKey &key) +{ + LogDebug("Get Property value. pkgName: " << pkgName << ", key: " << key); Try { using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt; WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) - select->Where(And(Equals(widgetHandle), + select->Where(And(Equals(pkgName), Equals(key))); ORMWidgetPropertyValue ormPropValue = @@ -148,25 +203,5 @@ WidgetPropertyValue GetPropertyValue(DbWidgetHandle widgetHandle, } } -DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle, - const WidgetPropertyKey &key) -{ - LogDebug("Checking Property flag. Handle: " << widgetHandle << - ", key: " << key); - Try { - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::wrt; - WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) - select->Where(And(Equals(widgetHandle), - Equals(key))); - - return select->GetSingleValue(); - } - Catch(DPL::DB::SqlConnection::Exception::Base){ - ReThrowMsg(Exception::DatabaseError, - "Failure during checking readonly flag for property"); - } -} - } // namespace PropertyDAOReadOnly } // namespace WrtDB diff --git a/modules/widget_dao/dao/widget_dao_read_only.cpp b/modules/widget_dao/dao/widget_dao_read_only.cpp index ca047c3..3fb817a 100644 --- a/modules/widget_dao/dao/widget_dao_read_only.cpp +++ b/modules/widget_dao/dao/widget_dao_read_only.cpp @@ -113,6 +113,33 @@ WidgetSecuritySettingsRow getWidgetSecuritySettingsRow(int widgetHandle) const int MAX_TIZENID_LENGTH = 10; +WidgetPkgName getPkgNameByHandle(const DbWidgetHandle handle) +{ + LogDebug("Getting WidgetPkgName by DbWidgetHandle: " << handle); + + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface()) + select->Where(Equals(handle)); + WidgetInfo::Select::RowList rowList = select->GetRowList(); + + if (rowList.empty()) { + ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, + "Failed to get widget by package name"); + } + DPL::OptionalString pkgname = rowList.front().Get_pkgname(); + if(pkgname.IsNull()){ + ThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError, + "PkgName is null for this widget"); + } + return *pkgname; + + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle") + + ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, + "Failed to get widget by handle"); +} } // namespace @@ -189,28 +216,43 @@ DbWidgetHandle WidgetDAOReadOnly::getHandle(const DPL::String pkgName) "Failed to get widget by package name"); } +WidgetPkgName WidgetDAOReadOnly::getPkgName() const +{ + return getPkgNameByHandle(m_widgetHandle); +} + +WidgetPkgName WidgetDAOReadOnly::getPkgName(const WidgetGUID GUID) +{ + return getPkgNameByHandle(getHandle(GUID)); +} + +WidgetPkgName WidgetDAOReadOnly::getPkgName(const DbWidgetHandle handle) +{ + return getPkgNameByHandle(handle); +} + PropertyDAOReadOnly::WidgetPropertyKeyList WidgetDAOReadOnly::getPropertyKeyList() const { - return PropertyDAOReadOnly::GetPropertyKeyList(m_widgetHandle); + return PropertyDAOReadOnly::GetPropertyKeyList(getPkgName()); } PropertyDAOReadOnly::WidgetPreferenceList WidgetDAOReadOnly::getPropertyList() const { - return PropertyDAOReadOnly::GetPropertyList(m_widgetHandle); + return PropertyDAOReadOnly::GetPropertyList(getPkgName()); } PropertyDAOReadOnly::WidgetPropertyValue WidgetDAOReadOnly::getPropertyValue( const PropertyDAOReadOnly::WidgetPropertyKey &key) const { - return PropertyDAOReadOnly::GetPropertyValue(m_widgetHandle, key); + return PropertyDAOReadOnly::GetPropertyValue(getPkgName(), key); } DPL::OptionalInt WidgetDAOReadOnly::checkPropertyReadFlag( const PropertyDAOReadOnly::WidgetPropertyKey &key) const { - return PropertyDAOReadOnly::CheckPropertyReadFlag(m_widgetHandle, key); + return PropertyDAOReadOnly::CheckPropertyReadFlag(getPkgName(), key); } DPL::String WidgetDAOReadOnly::getPath() const diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/property_dao_read_only.h b/modules/widget_dao/include/dpl/wrt-dao-ro/property_dao_read_only.h index 50b3dab..4c5a283 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/property_dao_read_only.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/property_dao_read_only.h @@ -38,7 +38,7 @@ typedef DPL::OptionalString WidgetPropertyValue; typedef std::list WidgetPropertyKeyList; struct WidgetPreferenceRow { - int app_id; + WidgetPkgName pkgname; WidgetPropertyKey key_name; WidgetPropertyValue key_value; DPL::OptionalInt readonly; @@ -57,24 +57,49 @@ class Exception DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty) }; +//deprecated /* This method checks read only flag for given property */ DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle, + const WidgetPropertyKey &key) + __attribute__((deprecated)); + +/* This method checks read only flag for given property + */ +DPL::OptionalInt CheckPropertyReadFlag(WidgetPkgName pkgName, const WidgetPropertyKey &key); +//deprecated /* This method gets widget property key list */ -WidgetPropertyKeyList GetPropertyKeyList(DbWidgetHandle widgetHandle); +WidgetPropertyKeyList GetPropertyKeyList(DbWidgetHandle widgetHandle) + __attribute__((deprecated)); +/* This method gets widget property key list + */ +WidgetPropertyKeyList GetPropertyKeyList(WidgetPkgName pkgName); + +//deprecated /* This method gets widget property list */ -WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle); +WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle) + __attribute__((deprecated)); +/* This method gets widget property list + */ +WidgetPreferenceList GetPropertyList(WidgetPkgName pkgName); + +//deprecated /* This method get widget property value */ WidgetPropertyValue GetPropertyValue(DbWidgetHandle widgetHandle, const WidgetPropertyKey &key); +/* This method get widget property value + */ +WidgetPropertyValue GetPropertyValue(WidgetPkgName pkgName, + const WidgetPropertyKey &key); + } // PropertyDAOReadOnly } // namespace WrtDB diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h b/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h index d658e50..37a7138 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h @@ -317,6 +317,17 @@ class WidgetDAOReadOnly static DbWidgetHandle getHandle(const DPL::String pkgName); /** + * Returns pkgname for the specified widget + * + * @return pkgname + * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table. + * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table. + */ + WidgetPkgName getPkgName() const; + static WidgetPkgName getPkgName(const WidgetGUID GUID); + static WidgetPkgName getPkgName(const DbWidgetHandle handle); + + /** * This method returns the root directory of widget resource. * * @return path name of root directory. diff --git a/modules/widget_dao/include/dpl/wrt-dao-rw/property_dao.h b/modules/widget_dao/include/dpl/wrt-dao-rw/property_dao.h index d75dc59..7046042 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-rw/property_dao.h +++ b/modules/widget_dao/include/dpl/wrt-dao-rw/property_dao.h @@ -31,20 +31,42 @@ struct WidgetRegisterInfo; //forward declaration namespace PropertyDAO { +//deprecated void RemoveProperty(DbWidgetHandle widgetHandle, + const PropertyDAOReadOnly::WidgetPropertyKey &key) + __attribute__((deprecated)); + +void RemoveProperty(WidgetPkgName pkgName, const PropertyDAOReadOnly::WidgetPropertyKey &key); +//deprecated /* This method sets widget property */ void SetProperty(DbWidgetHandle widgetHandle, const PropertyDAOReadOnly::WidgetPropertyKey &key, const PropertyDAOReadOnly::WidgetPropertyValue &value, + bool readOnly = false) + __attribute__((deprecated)); + +/* This method sets widget property + */ +void SetProperty(WidgetPkgName pkgName, + const PropertyDAOReadOnly::WidgetPropertyKey &key, + const PropertyDAOReadOnly::WidgetPropertyValue &value, bool readOnly = false); +//deprecated /* This method registers properties for widget. * Properties unregistering is done via "delete cascade" mechanism in SQL */ void RegisterProperties(DbWidgetHandle widgetHandle, + const WidgetRegisterInfo ®Info) + __attribute__((deprecated)); + +/* This method registers properties for widget. + * Properties unregistering is done via "delete cascade" mechanism in SQL + */ +void RegisterProperties(WidgetPkgName pkgName, const WidgetRegisterInfo ®Info); } // namespace PropertyDAO diff --git a/modules/widget_dao/orm/wrt_db b/modules/widget_dao/orm/wrt_db index 73d2a89..9f35e25 100644 --- a/modules/widget_dao/orm/wrt_db +++ b/modules/widget_dao/orm/wrt_db @@ -98,14 +98,14 @@ CREATE_TABLE(WidgetExtendedInfo) CREATE_TABLE_END() CREATE_TABLE(WidgetPreference) - COLUMN_NOT_NULL(app_id, INT,) + COLUMN_NOT_NULL(pkgname, VARCHAR(256), DEFAULT 0) COLUMN_NOT_NULL(key_name, VARCHAR(256),) COLUMN(key_value, VARCHAR(8000), DEFAULT '') COLUMN(readonly, INT, DEFAULT 0) TABLE_CONSTRAINTS( - PRIMARY KEY(app_id, key_name), - FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE + PRIMARY KEY(pkgname, key_name), + FOREIGN KEY(pkgname) REFERENCES WidgetInfo (pkgname) ON DELETE CASCADE ) CREATE_TABLE_END() -- 2.7.4