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 {
34 FeatureHandle RegisterFeature(const PluginMetafileData::Feature &feature,
35 const DbPluginHandle pluginHandle)
39 LogDebug("Registering Feature " << feature.m_name);
40 DPL::DB::ORM::wrt::ScopedTransaction transaction(
41 &WrtDatabase::interface());
43 if (FeatureDAOReadOnly::isFeatureInstalled(feature.m_name)) {
44 LogError(" >> Feature " << feature.m_name <<
45 " is already registered.");
50 using namespace DPL::DB::ORM;
51 using namespace DPL::DB::ORM::wrt;
55 LogDebug(" |-- Registering feature " << feature.m_name);
57 FeaturesList::Row row;
58 row.Set_FeatureName(DPL::FromUTF8String(feature.m_name));
59 row.Set_PluginPropertiesId(pluginHandle);
61 WRT_DB_INSERT(insert, FeaturesList, &WrtDatabase::interface())
66 FeatureHandle featureHandle =
67 FeatureDAOReadOnly(feature.m_name).GetFeatureHandle();
69 //register device capabilities
70 // Device Capabilities is unused in current version
71 FOREACH(itdev, feature.m_deviceCapabilities)
75 if (FeatureDAOReadOnly::isDeviceCapabilityInstalled(*itdev)) {
76 LogDebug(" | |--DeviceCap " << *itdev <<
77 " already installed!");
81 &WrtDatabase::interface())
83 select->Where(Equals<DeviceCapabilities::DeviceCapName>(
84 DPL::FromUTF8String(*itdev)));
87 select->GetSingleValue<DeviceCapabilities::DeviceCapID>();
89 LogDebug(" | |--Register DeviceCap: " << *itdev);
91 DeviceCapabilities::Row row;
92 row.Set_DeviceCapName(DPL::FromUTF8String(*itdev));
96 &WrtDatabase::interface())
98 deviceCapID = static_cast<int>(insert->Execute());
101 FeatureDeviceCapProxy::Row row;
102 row.Set_FeatureUUID(featureHandle);
103 row.Set_DeviceCapID(deviceCapID);
105 WRT_DB_INSERT(insert,
106 FeatureDeviceCapProxy,
107 &WrtDatabase::interface())
112 transaction.Commit();
114 return featureHandle;
116 Catch(DPL::DB::SqlConnection::Exception::Base){
117 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
118 "Failure during Registering Feature");
122 void UnregisterFeature(FeatureHandle featureHandle)
126 LogDebug("Unregistering Feature " << featureHandle);
127 DPL::DB::ORM::wrt::ScopedTransaction transaction(
128 &WrtDatabase::interface());
130 if (FeatureDAOReadOnly::isFeatureInstalled(featureHandle)) {
131 LogError("Feature handle is invalid");
135 using namespace DPL::DB::ORM;
136 using namespace DPL::DB::ORM::wrt;
138 // Unregister DeviceCapabilities
139 FeatureDAOReadOnly::DeviceCapabilitiesList capabilitiesList =
140 FeatureDAOReadOnly(featureHandle).GetDeviceCapabilities();
142 FOREACH(it, capabilitiesList) {
143 WRT_DB_DELETE(del, DeviceCapabilities, &WrtDatabase::interface())
145 Equals<DeviceCapabilities::DeviceCapName>(
146 DPL::FromUTF8String(*it)));
150 // Unregister Feature
151 WRT_DB_DELETE(del, FeaturesList, &WrtDatabase::interface())
152 del->Where(Equals<FeaturesList::FeatureUUID>(featureHandle));
154 transaction.Commit();
158 Catch(DPL::DB::SqlConnection::Exception::Base){
159 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
160 "Fail to unregister Feature");
163 } // namespace FeatureDAO