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 widget dao class.
19 * @file widget_dao.cpp
20 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @author Bartosz Janiak (b.janiak@samsung.com)
22 * @author Yang Jie (jie2.yang@samsung.com)
23 * @author Koeun Choi(koeun.choi@samsung.com)
24 * @author Pawel Sikorski(p.sikorski@samsung.com)
26 * @brief This file contains the definition of Configuration.
29 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/log/log.h>
33 #include <dpl/foreach.h>
34 #include <dpl/wrt-dao-ro/webruntime_database.h>
35 #include <dpl/wrt-dao-rw/property_dao.h>
36 #include <orm_generator_wrt.h>
37 #include <dpl/wrt-dao-ro/WrtDatabase.h>
41 //TODO in current solution in each getter there exists a check
42 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
43 //differently (check in WidgetDAO constructor)
45 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
47 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
48 Catch(DPL::DB::SqlConnection::Exception::Base) { \
50 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
54 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
55 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
59 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
60 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
64 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
65 WidgetDAOReadOnly(handle)
69 WidgetDAO::~WidgetDAO()
73 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
75 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
77 using namespace DPL::DB::ORM;
78 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
80 if (!isWidgetInstalled(getHandle())) {
81 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
82 "Cannot find widget. Handle: " << getHandle());
85 wrt::WidgetInfo::Row row;
86 row.Set_tizen_appid(*tzAppId);
88 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
90 Equals<wrt::WidgetInfo::app_id>(getHandle()));
96 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
99 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
101 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
103 using namespace DPL::DB::ORM;
104 using namespace DPL::DB::ORM::wrt;
106 ScopedTransaction transaction(&WrtDatabase::interface());
107 if (!isWidgetInstalled(getHandle())) {
108 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
109 "Cannot find widget. Handle: " << getHandle());
112 WidgetSecuritySettings::Row row;
113 row.Set_security_popup_usage(value);
115 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
116 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
120 transaction.Commit();
122 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
125 void WidgetDAO::setGeolocationUsage(const SettingsType value)
127 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
129 using namespace DPL::DB::ORM;
130 using namespace DPL::DB::ORM::wrt;
132 ScopedTransaction transaction(&WrtDatabase::interface());
133 if (!isWidgetInstalled(getHandle())) {
134 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
135 "Cannot find widget. Handle: " << getHandle());
138 WidgetSecuritySettings::Row row;
139 row.Set_geolocation_usage(value);
141 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
142 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
146 transaction.Commit();
148 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
151 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
153 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
155 using namespace DPL::DB::ORM;
156 using namespace DPL::DB::ORM::wrt;
158 ScopedTransaction transaction(&WrtDatabase::interface());
159 if (!isWidgetInstalled(getHandle())) {
160 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
161 "Cannot find widget. Handle: " << getHandle());
164 WidgetSecuritySettings::Row row;
165 row.Set_web_notification_usage(value);
167 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
168 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
172 transaction.Commit();
174 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
177 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
179 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
181 using namespace DPL::DB::ORM;
182 using namespace DPL::DB::ORM::wrt;
184 ScopedTransaction transaction(&WrtDatabase::interface());
185 if (!isWidgetInstalled(getHandle())) {
186 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
187 "Cannot find widget. Handle: " << getHandle());
190 WidgetSecuritySettings::Row row;
191 row.Set_web_database_usage(value);
193 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
194 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
198 transaction.Commit();
200 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
203 void WidgetDAO::setFileSystemUsage(const SettingsType value)
205 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
207 using namespace DPL::DB::ORM;
208 using namespace DPL::DB::ORM::wrt;
210 ScopedTransaction transaction(&WrtDatabase::interface());
211 if (!isWidgetInstalled(getHandle())) {
212 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
213 "Cannot find widget. Handle: " << getHandle());
216 WidgetSecuritySettings::Row row;
217 row.Set_file_system_usage(value);
219 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
220 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
224 transaction.Commit();
226 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
229 void WidgetDAO::registerWidget(
230 const TizenAppId & tzAppId,
231 const WidgetRegisterInfo &widgetRegInfo,
232 const IWacSecurity &wacSecurity)
234 LogDebug("Registering widget");
235 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
237 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
238 registerWidgetInternal(tzAppId, widgetRegInfo, wacSecurity);
239 transaction.Commit();
241 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
244 DbWidgetHandle WidgetDAO::registerWidget(
245 const WidgetRegisterInfo &pWidgetRegisterInfo,
246 const IWacSecurity &wacSecurity)
248 //make it more precise due to very fast tests
250 gettimeofday(&tv, NULL);
251 srand(time(NULL) + tv.tv_usec);
252 DbWidgetHandle widgetHandle;
254 widgetHandle = rand();
255 } while (isWidgetInstalled(widgetHandle));
257 registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId, pWidgetRegisterInfo, wacSecurity);
261 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
262 const WidgetRegisterInfo &pWidgetRegisterInfo,
263 const IWacSecurity &wacSecurity)
265 TizenAppId tzAppId = generatePkgId();
266 registerWidget(tzAppId, pWidgetRegisterInfo, wacSecurity);
270 void WidgetDAO::registerWidgetInternal(
271 const TizenAppId & tzAppId,
272 const WidgetRegisterInfo &widgetRegInfo,
273 const IWacSecurity &wacSecurity,
274 const DPL::Optional<DbWidgetHandle> handle)
276 //Register into WidgetInfo has to be first
277 //as all other tables depend upon that
278 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId, widgetRegInfo, wacSecurity, handle);
280 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
282 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
284 registerWidgetIcons(widgetHandle, widgetRegInfo);
286 registerWidgetStartFile(widgetHandle, widgetRegInfo);
288 PropertyDAO::RegisterProperties(tzAppId, widgetRegInfo);
290 registerWidgetFeatures(widgetHandle, widgetRegInfo);
292 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
294 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
296 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
298 registerWidgetCertificates(widgetHandle, wacSecurity);
300 CertificateChainList list;
301 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
302 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
305 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
306 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
308 registerWidgetSettings(widgetHandle, widgetRegInfo);
310 registerAppService(widgetHandle, widgetRegInfo);
312 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
314 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
316 registerWidgetSecuritySettings(widgetHandle);
319 void WidgetDAO::registerOrUpdateWidget(
320 const TizenAppId & widgetName,
321 const WidgetRegisterInfo &widgetRegInfo,
322 const IWacSecurity &wacSecurity)
324 LogDebug("Reregistering widget");
325 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
327 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
329 unregisterWidgetInternal(widgetName);
330 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
331 transaction.Commit();
333 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
336 #define DO_INSERT(row, table) \
338 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
339 insert->Values(row); \
343 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
344 const WidgetRegisterInfo ®Info)
346 //Try and transaction not needed
347 using namespace DPL::DB::ORM;
348 using namespace DPL::DB::ORM::wrt;
351 WidgetExtendedInfo::Row row;
352 row.Set_app_id(widgetHandle);
353 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
354 row.Set_signature_type(regInfo.signatureType);
355 row.Set_test_widget(regInfo.isTestWidget);
356 row.Set_install_time(regInfo.installedTime);
357 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
358 row.Set_background_page(regInfo.configInfo.backgroundPage);
359 row.Set_installed_path(regInfo.widgetInstalledPath);
361 DO_INSERT(row, WidgetExtendedInfo)
364 DbWidgetHandle WidgetDAO::registerWidgetInfo(
365 const TizenAppId & tzAppId,
366 const WidgetRegisterInfo ®Info,
367 const IWacSecurity &wacSecurity,
368 const DPL::Optional<DbWidgetHandle> handle)
370 using namespace DPL::DB::ORM;
371 using namespace DPL::DB::ORM::wrt;
372 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
374 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
375 // Because of that, "Optional" is not used there
380 row.Set_app_id(*handle);
383 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
385 // TODO : regInfo.type is temporary code for security.
386 // This code will be removed.
387 row.Set_widget_type(regInfo.type.appType);
389 row.Set_widget_type(regInfo.webAppType.appType);
391 row.Set_widget_id(widgetConfigurationInfo.widget_id);
392 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
393 row.Set_widget_version(widgetConfigurationInfo.version);
394 row.Set_widget_width(widgetConfigurationInfo.width);
395 row.Set_widget_height(widgetConfigurationInfo.height);
396 row.Set_author_name(widgetConfigurationInfo.authorName);
397 row.Set_author_email(widgetConfigurationInfo.authorEmail);
398 row.Set_author_href(widgetConfigurationInfo.authorHref);
399 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
400 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
401 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
402 row.Set_recognized(wacSecurity.isRecognized());
403 row.Set_wac_signed(wacSecurity.isWacSigned());
404 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
405 row.Set_tizen_appid(tzAppId);
406 row.Set_tizen_pkgid(regInfo.tzPkgid);
408 std::stringstream tmp;
409 tmp << regInfo.minVersion;
410 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
412 row.Set_back_supported(widgetConfigurationInfo.backSupported);
413 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
414 row.Set_pkg_type(regInfo.packagingType.pkgType);
418 DO_INSERT(row, WidgetInfo);
420 Catch(DPL::DB::SqlConnection::Exception::Base)
422 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
423 "Failed to register widget info.");
428 //get autoincremented value of widgetHandle
429 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
430 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
431 return select->GetSingleValue<WidgetInfo::app_id>();
439 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
440 const WidgetRegisterInfo ®Info)
442 using namespace DPL::DB::ORM;
443 using namespace DPL::DB::ORM::wrt;
445 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
447 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
449 const DPL::String& locale = it->first;
450 const ConfigParserData::LocalizedData& data = it->second;
452 LocalizedWidgetInfo::Row row;
453 row.Set_app_id(widgetHandle);
454 row.Set_widget_locale(locale);
455 row.Set_widget_name(data.name);
456 row.Set_widget_shortname(data.shortName);
457 row.Set_widget_description(data.description);
458 row.Set_widget_license(data.license);
459 row.Set_widget_license_file(data.licenseFile);
460 row.Set_widget_license_href(data.licenseHref);
462 DO_INSERT(row, LocalizedWidgetInfo)
466 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
467 const WidgetRegisterInfo ®Info)
469 using namespace DPL::DB::ORM;
470 using namespace DPL::DB::ORM::wrt;
473 FOREACH(i, regInfo.localizationData.icons)
475 wrt::WidgetIcon::icon_id::ColumnType icon_id;
477 wrt::WidgetIcon::Row row;
478 row.Set_app_id(widgetHandle);
479 row.Set_icon_src(i->src);
480 row.Set_icon_width(i->width);
481 row.Set_icon_height(i->height);
483 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
485 icon_id = static_cast<int>(insert->Execute());
488 FOREACH(j, i->availableLocales)
490 WidgetLocalizedIcon::Row row;
491 row.Set_app_id(widgetHandle);
492 row.Set_icon_id(icon_id);
493 row.Set_widget_locale(*j);
494 DO_INSERT(row, WidgetLocalizedIcon)
499 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
500 const WidgetRegisterInfo ®Info)
502 using namespace DPL::DB::ORM;
503 using namespace DPL::DB::ORM::wrt;
506 FOREACH(i, regInfo.localizationData.startFiles)
508 WidgetStartFile::start_file_id::ColumnType startFileID;
510 WidgetStartFile::Row row;
511 row.Set_app_id(widgetHandle);
512 row.Set_src(i->path);
514 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
516 startFileID = static_cast<int>(insert->Execute());
519 FOREACH(j, i->propertiesForLocales)
521 WidgetLocalizedStartFile::Row row;
522 row.Set_app_id(widgetHandle);
523 row.Set_start_file_id(startFileID);
524 row.Set_widget_locale(j->first);
525 row.Set_type(j->second.type);
526 row.Set_encoding(j->second.encoding);
528 DO_INSERT(row, WidgetLocalizedStartFile)
533 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
534 const WidgetRegisterInfo ®Info)
536 using namespace DPL::DB::ORM;
537 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
540 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
542 wrt::WidgetFeature::Row widgetFeature;
543 widgetFeature.Set_app_id(widgetHandle);
544 widgetFeature.Set_name(pWidgetFeature->name);
545 widgetFeature.Set_required(pWidgetFeature->required);
546 widgetFeature.Set_rejected(false);
548 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
550 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
551 insert->Values(widgetFeature);
552 widgetFeatureID = static_cast<int>(insert->Execute());
555 // Insert into table FeatureParam
556 wrt::FeatureParam::Row featureParam;
557 featureParam.Set_widget_feature_id(widgetFeatureID);
559 FOREACH(iter, pWidgetFeature->paramsList)
561 featureParam.Set_name(iter->name);
562 featureParam.Set_value(iter->value);
564 DO_INSERT(featureParam, wrt::FeatureParam)
569 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
570 const WidgetRegisterInfo ®Info)
572 using namespace DPL::DB::ORM;
573 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
575 FOREACH(it, widgetConfigurationInfo.privilegeList)
577 wrt::WidgetPrivilege::Row widgetPrivilege;
578 widgetPrivilege.Set_app_id(widgetHandle);
579 widgetPrivilege.Set_name(it->name);
581 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
585 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
586 // This function could be merged with registerWidgetFeature but it requires desing change:
587 // 1. Check "ace step" in installer must be done before "update database step"
589 // ConfigurationParserData shouldn't be called "ParserData" any more.
590 using namespace DPL::DB::ORM;
592 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
593 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
594 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
595 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
597 auto row = select->GetSingleRow();
598 row.Set_rejected(widgetFeature.rejected);
600 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
601 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
602 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
605 transaction.Commit();
608 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
609 const WidgetRegisterInfo ®Info)
611 using namespace DPL::DB::ORM;
612 using namespace DPL::DB::ORM::wrt;
613 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
616 FOREACH(i, widgetConfigurationInfo.windowModes)
618 wrt::WidgetWindowModes::Row windowMode;
619 windowMode.Set_app_id(widgetHandle);
620 windowMode.Set_window_mode(*i);
622 DO_INSERT(windowMode, wrt::WidgetWindowModes)
626 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
627 const WidgetRegisterInfo ®Info)
629 using namespace DPL::DB::ORM;
630 using namespace DPL::DB::ORM::wrt;
631 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
634 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
636 WidgetWARPInfo::Row row;
637 row.Set_app_id(widgetHandle);
638 row.Set_iri(AccIt->m_strIRI);
639 row.Set_subdomain_access(static_cast <int>(
640 AccIt->m_bSubDomainAccess));
642 DO_INSERT(row, WidgetWARPInfo)
646 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
647 const IWacSecurity &wacSecurity)
649 using namespace DPL::DB::ORM;
650 using namespace DPL::DB::ORM::wrt;
653 FOREACH(it, wacSecurity.getCertificateList())
655 WidgetCertificateFingerprint::Row row;
656 row.Set_app_id(widgetHandle);
657 row.Set_owner(it->owner);
658 row.Set_chainid(it->chainId);
659 row.Set_type(it->type);
660 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
661 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
662 row.Set_common_name(it->strCommonName);
664 DO_INSERT(row, WidgetCertificateFingerprint)
668 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
669 CertificateSource certificateSource,
670 const CertificateChainList &certificateChainList)
672 using namespace DPL::DB::ORM;
673 using namespace DPL::DB::ORM::wrt;
674 FOREACH(certChain, certificateChainList)
676 WidgetCertificate::Row row;
677 row.Set_app_id(widgetHandle);
678 row.Set_cert_source(certificateSource);
679 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
681 DO_INSERT(row, WidgetCertificate);
685 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
686 const WidgetRegisterInfo ®Info)
688 using namespace DPL::DB::ORM;
689 using namespace DPL::DB::ORM::wrt;
691 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
693 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
695 SettingsList::Row row;
696 row.Set_appId(widgetHandle);
697 row.Set_settingName(pWidgetSetting->m_name);
698 row.Set_settingValue(pWidgetSetting->m_value);
700 DO_INSERT(row, SettingsList)
704 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
705 const WidgetRegisterInfo ®Info)
707 using namespace DPL::DB::ORM;
708 using namespace DPL::DB::ORM::wrt;
709 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
711 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
713 ApplicationServiceInfo::Row row;
714 row.Set_app_id(widgetHandle);
715 row.Set_src(ASIt->m_src);
716 row.Set_operation(ASIt->m_operation);
717 row.Set_scheme(ASIt->m_scheme);
718 row.Set_mime(ASIt->m_mime);
720 DO_INSERT(row, ApplicationServiceInfo)
724 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
725 const WidgetRegisterInfo ®Info)
727 using namespace DPL::DB::ORM;
728 using namespace DPL::DB::ORM::wrt;
730 FOREACH(it, regInfo.encryptedFiles)
732 EncryptedResourceList::Row row;
733 row.Set_app_id(widgetHandle);
734 row.Set_resource(it->fileName);
735 row.Set_size(it->fileSize);
737 DO_INSERT(row, EncryptedResourceList)
741 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
742 const ExternalLocationList & externals)
744 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
746 using namespace DPL::DB::ORM;
747 using namespace DPL::DB::ORM::wrt;
748 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
749 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
750 FOREACH(it, externals)
752 WidgetExternalLocations::Row row;
753 row.Set_app_id(widgetHandle);
754 row.Set_path(DPL::FromUTF8String(*it));
756 DO_INSERT(row, WidgetExternalLocations)
758 transaction.Commit();
760 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
763 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
765 using namespace DPL::DB::ORM;
766 using namespace DPL::DB::ORM::wrt;
767 WidgetSecuritySettings::Row row;
768 row.Set_app_id(widgetHandle);
769 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
770 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
771 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
772 row.Set_web_database_usage(SETTINGS_TYPE_ON);
773 row.Set_file_system_usage(SETTINGS_TYPE_ON);
775 DO_INSERT(row, WidgetSecuritySettings)
778 void WidgetDAO::unregisterAllExternalLocations()
780 using namespace DPL::DB::ORM;
781 using namespace DPL::DB::ORM::wrt;
782 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
783 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
784 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
788 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
790 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
791 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
793 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
794 unregisterWidgetInternal(tzAppId);
795 transaction.Commit();
797 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
800 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
802 LogDebug("Unregistering widget from DB. Handle: " << handle);
803 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
805 using namespace DPL::DB::ORM;
806 using namespace DPL::DB::ORM::wrt;
807 ScopedTransaction transaction(&WrtDatabase::interface());
809 // Delete from table Widget Info
810 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
811 del->Where(Equals<WidgetInfo::app_id>(handle));
814 transaction.Commit();
816 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
819 void WidgetDAO::unregisterWidgetInternal(
820 const TizenAppId & tzAppId)
822 using namespace DPL::DB::ORM;
823 using namespace DPL::DB::ORM::wrt;
825 DbWidgetHandle handle = getHandle(tzAppId);
827 // Delete from table Widget Info
828 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
829 del->Where(Equals<WidgetInfo::app_id>(handle));
832 // Deleting in other tables is done via "delete cascade" in SQL
837 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
838 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END