2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file contains the definition of feature dao class.
19 * @file widget_dao.cpp
20 * @author Jaroslaw Osmanski (j.osmanski@samsung.com)
21 * @author Pawel Sikorski (p.sikorski@samsung.com)
23 * @brief This file contains the definition of feature configuration.
26 #include <dpl/wrt-dao-rw/feature_dao.h>
27 #include <dpl/foreach.h>
28 #include <dpl/db/orm.h>
29 #include <orm_generator_wrt.h>
30 #include <dpl/wrt-dao-ro/webruntime_database.h>
33 namespace FeatureDAO {
35 const int STRANGE_FEATURE_PROPERTIES_ID = 0;
37 FeatureHandle RegisterFeature(const PluginMetafileData::Feature &feature,
38 const DbPluginHandle pluginHandle)
42 LogDebug("Registering Feature " << feature.m_name);
43 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
45 if (FeatureDAOReadOnly::isFeatureInstalled(feature.m_name)) {
46 LogError(" >> Feature " << feature.m_name <<
47 " is already registered.");
52 using namespace DPL::DB::ORM;
53 using namespace DPL::DB::ORM::wrt;
57 LogInfo(" |-- Registering feature " << feature.m_name);
59 FeaturesList::Row row;
60 row.Set_FeatureName(DPL::FromUTF8String(feature.m_name));
61 row.Set_PluginPropertiesId(pluginHandle);
63 WRT_DB_INSERT(insert, FeaturesList, &WrtDatabase::interface())
68 FeatureHandle featureHandle =
69 FeatureDAOReadOnly(feature.m_name).GetFeatureHandle();
71 //register device capabilities
72 // Device Capabilities is unused in current version
73 FOREACH(itdev, feature.m_deviceCapabilities)
77 if (FeatureDAOReadOnly::isDeviceCapabilityInstalled(*itdev)) {
78 LogInfo(" | |--DeviceCap " << *itdev <<
79 " already installed!");
81 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
83 select->Where(Equals<DeviceCapabilities::DeviceCapName>(
84 DPL::FromUTF8String(*itdev)));
87 select->GetSingleValue<DeviceCapabilities::DeviceCapID>();
89 LogInfo(" | |--Register DeviceCap: " << *itdev);
91 DeviceCapabilities::Row row;
92 row.Set_DeviceCapName(DPL::FromUTF8String(*itdev));
94 WRT_DB_INSERT(insert, DeviceCapabilities, &WrtDatabase::interface())
96 deviceCapID = insert->Execute();
99 FeatureDeviceCapProxy::Row row;
100 row.Set_FeatureUUID(featureHandle);
101 row.Set_DeviceCapID(deviceCapID);
103 WRT_DB_INSERT(insert, FeatureDeviceCapProxy, &WrtDatabase::interface())
108 transaction.Commit();
110 return featureHandle;
112 Catch(DPL::DB::SqlConnection::Exception::Base){
113 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
114 "Failure during Registering Feature");
118 FeatureHandle RegisterStrangeFeature(const std::string& featureName)
122 LogDebug("Registering Feature " << featureName);
123 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
125 if (FeatureDAOReadOnly::isFeatureInstalled(featureName)) {
126 LogError(" >> Feature " << featureName <<
127 " is already registered.");
128 transaction.Commit();
132 using namespace DPL::DB::ORM;
133 using namespace DPL::DB::ORM::wrt;
136 LogInfo(" |-- Registering feature " << featureName);
138 FeaturesList::Row row;
139 row.Set_FeatureName(DPL::FromUTF8String(featureName));
141 // PluginPropertiesId '0' is not used as PluginPropertiesId for normal features(calendar, contact....).
142 // PluginPropertiesId for normal features start from '1'
143 row.Set_PluginPropertiesId(STRANGE_FEATURE_PROPERTIES_ID);
145 WRT_DB_INSERT(insert, FeaturesList, &WrtDatabase::interface())
149 FeatureHandle featureHandle =
150 FeatureDAOReadOnly(featureName).GetFeatureHandle();
152 transaction.Commit();
154 return featureHandle;
156 Catch(DPL::DB::SqlConnection::Exception::Base){
157 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
158 "Failure during Registering Feature");
162 } // namespace FeatureDAO