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 * @file feature_dao_read_only.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
20 * @brief This file contains the implementation of feature dao read only
23 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
25 #include <dpl/log/log.h>
26 #include <dpl/foreach.h>
27 #include <dpl/db/orm.h>
28 #include <orm_generator_wrt.h>
29 #include <dpl/wrt-dao-ro/webruntime_database.h>
30 #include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
34 FeatureDAOReadOnly::FeatureDAOReadOnly(FeatureHandle featureHandle) :
35 m_featureHandle(featureHandle)
37 if (!isFeatureInstalled(m_featureHandle)) {
38 std::ostringstream exc;
39 exc << "Feature " << m_featureHandle << " not installed.";
41 ThrowMsg(FeatureDAOReadOnly::Exception::FeatureNotExist, exc.str());
45 FeatureDAOReadOnly::FeatureDAOReadOnly(const std::string &featureName)
47 LogDebug("FeatureDAOReadOnly ( " << featureName << " )");
49 using namespace DPL::DB::ORM;
50 using namespace DPL::DB::ORM::wrt;
51 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
52 select->Where(Equals<FeaturesList::FeatureName>(
53 DPL::FromUTF8String(featureName)));
55 m_featureHandle = select->GetSingleValue<FeaturesList::FeatureUUID>();
56 LogDebug(" >> FeatureHandle retrieved: " << m_featureHandle);
58 Catch(DPL::DB::SqlConnection::Exception::Base){
59 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
60 "Failure during creating FeatureDAOReadOnly");
64 #define GET_PLUGIN_DATA(func) \
66 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface()); \
67 LogDebug(# func << ". FeatureHandle: " << m_featureHandle); \
68 std::string ret = PluginDAOReadOnly(GetPluginHandle()).func(); \
69 transaction.Commit(); \
72 Catch(DPL::DB::SqlConnection::Exception::Base) { \
73 std::ostringstream failure("Failure during "); \
75 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError, \
79 std::string FeatureDAOReadOnly::GetLibraryPath() const
81 GET_PLUGIN_DATA(getLibraryPath)
84 std::string FeatureDAOReadOnly::GetLibraryName() const
86 GET_PLUGIN_DATA(getLibraryName)
89 #undef GET_PLUGIN_DATA
91 FeatureHandle FeatureDAOReadOnly::GetFeatureHandle() const
93 return m_featureHandle;
96 std::string FeatureDAOReadOnly::GetName() const
98 LogDebug("Getting Feature Name. Handle: " << m_featureHandle);
100 using namespace DPL::DB::ORM;
101 using namespace DPL::DB::ORM::wrt;
102 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
103 select->Where(Equals<FeaturesList::FeatureUUID>(m_featureHandle));
105 std::string ret = DPL::ToUTF8String(
106 select->GetSingleValue< FeaturesList::FeatureName>());
108 LogDebug(" >> Feature name: " << ret);
111 Catch(DPL::DB::SqlConnection::Exception::Base){
112 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
113 "Failure during getting GetName");
117 DbPluginHandle FeatureDAOReadOnly::GetPluginHandle() const
119 LogDebug("Getting Plugin handle. FHandle: " << m_featureHandle);
121 using namespace DPL::DB::ORM;
122 using namespace DPL::DB::ORM::wrt;
123 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
124 select->Where(Equals<FeaturesList::FeatureUUID>(m_featureHandle));
126 DbPluginHandle pluginHandle =
127 select->GetSingleValue< FeaturesList::PluginPropertiesId>();
129 LogDebug(" >> Plugin Handle: " << pluginHandle);
132 Catch(DPL::DB::SqlConnection::Exception::Base){
133 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
134 "Failure during getting Plugin Handle");
138 FeatureHandleList FeatureDAOReadOnly::GetHandleList()
140 LogDebug("Getting FeatureHandle list.");
142 using namespace DPL::DB::ORM;
143 using namespace DPL::DB::ORM::wrt;
144 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
146 FeatureHandleList ret =
147 select->GetValueList<FeaturesList::FeatureUUID>();
149 std::ostringstream handles;
151 handles << *it << " ";
152 LogDebug(" >> FeatureHandle list retrieved: (" << handles << ")");
156 Catch(DPL::DB::SqlConnection::Exception::Base){
157 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
158 "Failure during getting FeatureHandle list");
162 bool FeatureDAOReadOnly::isFeatureInstalled(const std::string &featureName)
164 LogDebug("Check if Feature is installed. Name: " << featureName);
166 using namespace DPL::DB::ORM;
167 using namespace DPL::DB::ORM::wrt;
168 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
169 select->Where(Equals<FeaturesList::FeatureName>(
170 DPL::FromUTF8String(featureName)));
172 FeaturesList::Select::RowList rows = select->GetRowList();
174 bool flag = !rows.empty();
175 LogDebug(" >> Feature " << featureName <<
176 (flag ? " found." : " not found."));
180 Catch(DPL::DB::SqlConnection::Exception::Base) {
181 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
182 "Failure during checking if Feature is installed");
186 bool FeatureDAOReadOnly::isFeatureInstalled(FeatureHandle handle)
188 LogDebug("Check if Feature is installed. Handle: " << handle);
191 using namespace DPL::DB::ORM;
192 using namespace DPL::DB::ORM::wrt;
193 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
194 select->Where(Equals<FeaturesList::FeatureUUID>(handle));
196 FeaturesList::Select::RowList rows = select->GetRowList();
198 bool flag = !rows.empty();
199 LogDebug(" >> Feature " << handle <<
200 (flag ? " found." : " not found."));
204 Catch(DPL::DB::SqlConnection::Exception::Base){
205 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
206 "Failure during checking if Feature is installed");
210 bool FeatureDAOReadOnly::isDeviceCapabilityInstalled(
211 const std::string &deviceCapName)
213 LogDebug("Check if DeviceCap is installed. Name: " << deviceCapName);
215 using namespace DPL::DB::ORM;
216 using namespace DPL::DB::ORM::wrt;
217 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
218 select->Where(Equals<DeviceCapabilities::DeviceCapName>(
219 DPL::FromUTF8String(deviceCapName)));
221 DeviceCapabilities::Select::RowList rows = select->GetRowList();
223 bool flag = !rows.empty();
224 LogDebug(" >> Device Cap " << deviceCapName <<
225 (flag ? "found." : "not found."));
229 Catch(DPL::DB::SqlConnection::Exception::Base){
230 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
231 "Failure during checking if DeviceCap is installed");
235 FeatureDAOReadOnly::DeviceCapabilitiesList
236 FeatureDAOReadOnly::GetDeviceCapabilities() const
239 LogDebug("Get DeviceCap. FeatureHandle: " << m_featureHandle);
240 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
242 using namespace DPL::DB::ORM;
243 using namespace DPL::DB::ORM::wrt;
244 WRT_DB_SELECT(selectDevCP, FeatureDeviceCapProxy, &WrtDatabase::interface())
245 selectDevCP->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
248 DeviceCapabilitiesList devCap;
250 std::list<int> deviceIDs =
251 selectDevCP->GetValueList<FeatureDeviceCapProxy::DeviceCapID>();
252 FOREACH(devCId, deviceIDs)
254 WRT_DB_SELECT(selectDevC, DeviceCapabilities, &WrtDatabase::interface())
255 selectDevC->Where(Equals<DeviceCapabilities::DeviceCapID>(*devCId));
257 DPL::String devNames =
258 selectDevC->GetSingleValue<DeviceCapabilities::DeviceCapName>();
260 devCap.insert(DPL::ToUTF8String(devNames));
263 transaction.Commit();
266 Catch(DPL::DB::SqlConnection::Exception::Base){
267 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
268 "Failure during getting DeviceCapabilities names");
272 FeatureHandleListPtr FeatureDAOReadOnly::GetFeatureHandleListForPlugin(
273 DbPluginHandle pluginHandle)
275 LogDebug("Getting FeatureHandle list for pluginHandle: " << pluginHandle);
277 using namespace DPL::DB::ORM;
278 using namespace DPL::DB::ORM::wrt;
280 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
281 select->Where(Equals<FeaturesList::PluginPropertiesId>(pluginHandle));
283 FeatureHandleListPtr handles(new FeatureHandleList);
284 FeatureHandleList ret =
285 select->GetValueList<FeaturesList::FeatureUUID>();
289 LogDebug("feature handle: " << *it);
290 handles->push_back(*it);
295 Catch(DPL::DB::SqlConnection::Exception::Base){
297 FeatureDAOReadOnly::Exception::DatabaseError,
298 "Failure during getting FeatureHandle Set for plugin handle");
302 FeatureDAOReadOnly::NameMap
303 FeatureDAOReadOnly::GetNames()
306 using namespace DPL::DB::ORM;
307 using namespace DPL::DB::ORM::wrt;
308 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
312 FeaturesList::Select::RowList rows = select->GetRowList();
315 nameMap.insert(std::pair<FeatureHandle, std::string>(rowIt->Get_FeatureUUID(), DPL::ToUTF8String(rowIt->Get_FeatureName())));
320 Catch(DPL::DB::SqlConnection::Exception::Base){
321 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
322 "Failure during getting GetNames");
326 FeatureDAOReadOnly::DeviceCapabilitiesMap
327 FeatureDAOReadOnly::GetDevCapWithFeatureHandle()
330 using namespace DPL::DB::ORM;
331 using namespace DPL::DB::ORM::wrt;
333 DECLARE_COLUMN_TYPE_LIST()
334 SELECTED_COLUMN(FeatureDeviceCapProxy, FeatureUUID)
335 SELECTED_COLUMN(DeviceCapabilities, DeviceCapName)
336 DECLARE_COLUMN_TYPE_LIST_END(DevCapNameList)
338 WRT_DB_SELECT(select, FeatureDeviceCapProxy, &WrtDatabase::interface())
339 select->Join<DevCapNameList>(Equal<FeatureDeviceCapProxy::DeviceCapID, DeviceCapabilities::DeviceCapID>());
341 DeviceCapabilitiesMap devCap;
343 std::list< CustomRow<DevCapNameList> > rowList = select->GetCustomRowList< DevCapNameList, CustomRow<DevCapNameList> >();
344 FOREACH(rowIt, rowList)
346 FeatureHandle featureHandle = (*rowIt).GetColumnData<FeatureDeviceCapProxy::FeatureUUID>();
347 std::string devName = DPL::ToUTF8String((*rowIt).GetColumnData<DeviceCapabilities::DeviceCapName>());
348 devCap.insert(std::pair<FeatureHandle, std::string>(featureHandle, devName));
353 Catch(DPL::DB::SqlConnection::Exception::Base){
354 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
355 "Failure during getting DeviceCapabilities names");