Add "GetDeviceCapability" to FeatureDAO
authorJihoon Chung <jihoon.chung@samsaung.com>
Mon, 21 Oct 2013 07:50:18 +0000 (16:50 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 22 Oct 2013 06:44:56 +0000 (06:44 +0000)
* "GetDeviceCapability" moves from GlobalDAO to FeatureDAO

[Issue#]     LINUXWRT-1020
[Problem]    GlobalDAO has unnecessary API.
[Cause]      N/A
[Solution]   Add GetDeviceCapability to FeatureDAO
             - As GlobalDAO is deprecated, move GetDeviceCapability to FeatureDAO.
             - This commit add new API to FeatureDAO.

[Verification] Build repos.
[SCMRequest] Needed by https://review.tizendev.org/gerrit/#/c/93617/

Change-Id: Idb9cb6f94d258a0d6758ea55b6fc5b86319fb4b3

modules/widget_dao/dao/feature_dao_read_only.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/feature_dao_read_only.h

index cab3fba..ee188bd 100644 (file)
@@ -370,6 +370,49 @@ FeatureDAOReadOnly::GetDevCapWithFeatureHandle()
     }
 }
 
+DeviceCapabilitySet FeatureDAOReadOnly::GetDeviceCapability(
+    const DPL::String &apifeature)
+{
+    // This could be done with one simply sql query but support for join is
+    // needed in orm.
+    Try {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        int featureUUID;
+        FeatureDeviceCapProxy::Select::RowList rows;
+        DeviceCapabilitySet result;
+
+        {
+            WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
+            select->Where(Equals<FeaturesList::FeatureName>(apifeature));
+            featureUUID = select->GetSingleValue<FeaturesList::FeatureUUID>();
+        }
+
+        {
+            WRT_DB_SELECT(select,
+                          FeatureDeviceCapProxy,
+                          &WrtDatabase::interface())
+            select->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
+                              featureUUID));
+            rows = select->GetRowList();
+        }
+
+        FOREACH(it, rows){
+            WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
+            select->Where(Equals<DeviceCapabilities::DeviceCapID>(
+                              it->Get_DeviceCapID()));
+            result.insert(select->
+                              GetSingleValue<DeviceCapabilities::DeviceCapName>());
+        }
+
+        return result;
+    } Catch(DPL::DB::SqlConnection::Exception::Base){
+        ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
+                   "Failed to get device capability");
+    }
+}
+
 FeatureDAOReadOnly::FeatureMap
 FeatureDAOReadOnly::GetFeatures(const std::list<std::string>& featureNames)
 {
index 14aec55..f366012 100644 (file)
@@ -32,6 +32,9 @@
 #include <dpl/wrt-dao-ro/WrtDatabase.h>
 
 namespace WrtDB {
+// TODO: Move to feature_model.h
+typedef std::set<DPL::String> DeviceCapabilitySet;
+
 class FeatureDAOReadOnly
 {
   public:
@@ -46,6 +49,7 @@ class FeatureDAOReadOnly
         DECLARE_EXCEPTION_TYPE(Base, FeatureNotExist)
     };
 
+    // TODO: Move to feature_model.h
     typedef std::set<std::string> DeviceCapabilitiesList;
     typedef std::multimap<FeatureHandle, std::string> DeviceCapabilitiesMap;
     typedef std::map<FeatureHandle, std::string> NameMap;
@@ -72,6 +76,7 @@ class FeatureDAOReadOnly
 
     static NameMap                 GetNames();
     static DeviceCapabilitiesMap   GetDevCapWithFeatureHandle();
+    static DeviceCapabilitySet GetDeviceCapability(const DPL::String &apifeature);
 
     static FeatureMap GetFeatures(const std::list<std::string>& featureNames);