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>
40 unsigned int seed = time(NULL);
44 //TODO in current solution in each getter there exists a check
45 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
46 //differently (check in WidgetDAO constructor)
48 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
50 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
51 Catch(DPL::DB::SqlConnection::Exception::Base) { \
53 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
57 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
58 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
61 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
62 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
65 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
66 WidgetDAOReadOnly(handle)
69 WidgetDAO::~WidgetDAO()
72 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
74 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
76 using namespace DPL::DB::ORM;
77 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
79 if (!isWidgetInstalled(getHandle())) {
80 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
81 "Cannot find widget. Handle: " << getHandle());
84 wrt::WidgetInfo::Row row;
85 row.Set_tizen_appid(*tzAppId);
87 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
89 Equals<wrt::WidgetInfo::app_id>(getHandle()));
95 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
98 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
100 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
102 using namespace DPL::DB::ORM;
103 using namespace DPL::DB::ORM::wrt;
105 ScopedTransaction transaction(&WrtDatabase::interface());
106 if (!isWidgetInstalled(getHandle())) {
107 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
108 "Cannot find widget. Handle: " << getHandle());
111 WidgetSecuritySettings::Row row;
112 row.Set_security_popup_usage(value);
114 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
115 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
119 transaction.Commit();
121 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
124 void WidgetDAO::setGeolocationUsage(const SettingsType value)
126 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
128 using namespace DPL::DB::ORM;
129 using namespace DPL::DB::ORM::wrt;
131 ScopedTransaction transaction(&WrtDatabase::interface());
132 if (!isWidgetInstalled(getHandle())) {
133 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
134 "Cannot find widget. Handle: " << getHandle());
137 WidgetSecuritySettings::Row row;
138 row.Set_geolocation_usage(value);
140 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
141 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
145 transaction.Commit();
147 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
150 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
152 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
154 using namespace DPL::DB::ORM;
155 using namespace DPL::DB::ORM::wrt;
157 ScopedTransaction transaction(&WrtDatabase::interface());
158 if (!isWidgetInstalled(getHandle())) {
159 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
160 "Cannot find widget. Handle: " << getHandle());
163 WidgetSecuritySettings::Row row;
164 row.Set_web_notification_usage(value);
166 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
167 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
171 transaction.Commit();
173 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
176 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
178 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
180 using namespace DPL::DB::ORM;
181 using namespace DPL::DB::ORM::wrt;
183 ScopedTransaction transaction(&WrtDatabase::interface());
184 if (!isWidgetInstalled(getHandle())) {
185 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
186 "Cannot find widget. Handle: " << getHandle());
189 WidgetSecuritySettings::Row row;
190 row.Set_web_database_usage(value);
192 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
193 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
197 transaction.Commit();
199 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
202 void WidgetDAO::setFileSystemUsage(const SettingsType value)
204 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
206 using namespace DPL::DB::ORM;
207 using namespace DPL::DB::ORM::wrt;
209 ScopedTransaction transaction(&WrtDatabase::interface());
210 if (!isWidgetInstalled(getHandle())) {
211 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
212 "Cannot find widget. Handle: " << getHandle());
215 WidgetSecuritySettings::Row row;
216 row.Set_file_system_usage(value);
218 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
219 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
223 transaction.Commit();
225 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
228 void WidgetDAO::registerWidget(
229 const TizenAppId & tzAppId,
230 const WidgetRegisterInfo &widgetRegInfo,
231 const IWacSecurity &wacSecurity)
233 LogDebug("Registering widget");
234 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
236 DPL::DB::ORM::wrt::ScopedTransaction transaction(
237 &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 DbWidgetHandle widgetHandle;
253 widgetHandle = rand_r(&seed);
254 } while (isWidgetInstalled(widgetHandle));
256 registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId,
262 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
263 const WidgetRegisterInfo &pWidgetRegisterInfo,
264 const IWacSecurity &wacSecurity)
266 TizenAppId tzAppId = generatePkgId();
267 registerWidget(tzAppId, pWidgetRegisterInfo, wacSecurity);
271 void WidgetDAO::registerWidgetInternal(
272 const TizenAppId & tzAppId,
273 const WidgetRegisterInfo &widgetRegInfo,
274 const IWacSecurity &wacSecurity,
275 const DPL::Optional<DbWidgetHandle> handle)
277 //Register into WidgetInfo has to be first
278 //as all other tables depend upon that
279 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId,
284 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
286 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
288 registerWidgetIcons(widgetHandle, widgetRegInfo);
290 registerWidgetStartFile(widgetHandle, widgetRegInfo);
292 PropertyDAO::RegisterProperties(tzAppId, widgetRegInfo);
294 registerWidgetFeatures(widgetHandle, widgetRegInfo);
296 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
298 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
300 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
302 registerWidgetCertificates(widgetHandle, wacSecurity);
304 CertificateChainList list;
305 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
306 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
309 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
310 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
312 registerWidgetSettings(widgetHandle, widgetRegInfo);
314 registerAppService(widgetHandle, widgetRegInfo);
316 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
318 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
320 registerWidgetSecuritySettings(widgetHandle);
323 void WidgetDAO::registerOrUpdateWidget(
324 const TizenAppId & widgetName,
325 const WidgetRegisterInfo &widgetRegInfo,
326 const IWacSecurity &wacSecurity)
328 LogDebug("Reregistering widget");
329 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
331 DPL::DB::ORM::wrt::ScopedTransaction transaction(
332 &WrtDatabase::interface());
334 unregisterWidgetInternal(widgetName);
335 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
336 transaction.Commit();
338 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
341 #define DO_INSERT(row, table) \
343 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
344 insert->Values(row); \
348 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
349 const WidgetRegisterInfo ®Info)
351 //Try and transaction not needed
352 using namespace DPL::DB::ORM;
353 using namespace DPL::DB::ORM::wrt;
355 WidgetExtendedInfo::Row row;
356 row.Set_app_id(widgetHandle);
357 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
358 row.Set_signature_type(regInfo.signatureType);
359 row.Set_test_widget(regInfo.isTestWidget);
360 row.Set_install_time(regInfo.installedTime);
361 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
362 row.Set_background_page(regInfo.configInfo.backgroundPage);
363 row.Set_installed_path(regInfo.widgetInstalledPath);
365 DO_INSERT(row, WidgetExtendedInfo)
368 DbWidgetHandle WidgetDAO::registerWidgetInfo(
369 const TizenAppId & tzAppId,
370 const WidgetRegisterInfo ®Info,
371 const IWacSecurity &wacSecurity,
372 const DPL::Optional<DbWidgetHandle> handle)
374 using namespace DPL::DB::ORM;
375 using namespace DPL::DB::ORM::wrt;
376 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
378 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
379 // Because of that, "Optional" is not used there
383 row.Set_app_id(*handle);
386 row.Set_widget_type(regInfo.webAppType.appType);
388 row.Set_widget_id(widgetConfigurationInfo.widget_id);
389 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
390 row.Set_widget_version(widgetConfigurationInfo.version);
391 row.Set_widget_width(widgetConfigurationInfo.width);
392 row.Set_widget_height(widgetConfigurationInfo.height);
393 row.Set_author_name(widgetConfigurationInfo.authorName);
394 row.Set_author_email(widgetConfigurationInfo.authorEmail);
395 row.Set_author_href(widgetConfigurationInfo.authorHref);
396 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
397 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
398 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
399 row.Set_recognized(wacSecurity.isRecognized());
400 row.Set_wac_signed(wacSecurity.isWacSigned());
401 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
402 row.Set_tizen_appid(tzAppId);
403 row.Set_tizen_pkgid(regInfo.tzPkgid);
405 std::stringstream tmp;
406 tmp << regInfo.minVersion;
407 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
409 row.Set_back_supported(widgetConfigurationInfo.backSupported);
410 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
411 row.Set_pkg_type(regInfo.packagingType.pkgType);
415 DO_INSERT(row, WidgetInfo);
417 Catch(DPL::DB::SqlConnection::Exception::Base)
419 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
420 "Failed to register widget info.");
424 //get autoincremented value of widgetHandle
425 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
426 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
427 return select->GetSingleValue<WidgetInfo::app_id>();
433 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
434 const WidgetRegisterInfo ®Info)
436 using namespace DPL::DB::ORM;
437 using namespace DPL::DB::ORM::wrt;
439 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
441 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
443 const DPL::String& locale = it->first;
444 const ConfigParserData::LocalizedData& data = it->second;
446 LocalizedWidgetInfo::Row row;
447 row.Set_app_id(widgetHandle);
448 row.Set_widget_locale(locale);
449 row.Set_widget_name(data.name);
450 row.Set_widget_shortname(data.shortName);
451 row.Set_widget_description(data.description);
452 row.Set_widget_license(data.license);
453 row.Set_widget_license_file(data.licenseFile);
454 row.Set_widget_license_href(data.licenseHref);
456 DO_INSERT(row, LocalizedWidgetInfo)
460 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
461 const WidgetRegisterInfo ®Info)
463 using namespace DPL::DB::ORM;
464 using namespace DPL::DB::ORM::wrt;
466 FOREACH(i, regInfo.localizationData.icons)
468 wrt::WidgetIcon::icon_id::ColumnType icon_id;
470 wrt::WidgetIcon::Row row;
471 row.Set_app_id(widgetHandle);
472 row.Set_icon_src(i->src);
473 row.Set_icon_width(i->width);
474 row.Set_icon_height(i->height);
476 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
478 icon_id = static_cast<int>(insert->Execute());
481 FOREACH(j, i->availableLocales)
483 WidgetLocalizedIcon::Row row;
484 row.Set_app_id(widgetHandle);
485 row.Set_icon_id(icon_id);
486 row.Set_widget_locale(*j);
487 DO_INSERT(row, WidgetLocalizedIcon)
492 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
493 const WidgetRegisterInfo ®Info)
495 using namespace DPL::DB::ORM;
496 using namespace DPL::DB::ORM::wrt;
498 FOREACH(i, regInfo.localizationData.startFiles)
500 WidgetStartFile::start_file_id::ColumnType startFileID;
502 WidgetStartFile::Row row;
503 row.Set_app_id(widgetHandle);
504 row.Set_src(i->path);
506 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
508 startFileID = static_cast<int>(insert->Execute());
511 FOREACH(j, i->propertiesForLocales)
513 WidgetLocalizedStartFile::Row row;
514 row.Set_app_id(widgetHandle);
515 row.Set_start_file_id(startFileID);
516 row.Set_widget_locale(j->first);
517 row.Set_type(j->second.type);
518 row.Set_encoding(j->second.encoding);
520 DO_INSERT(row, WidgetLocalizedStartFile)
525 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
526 const WidgetRegisterInfo ®Info)
528 using namespace DPL::DB::ORM;
529 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
531 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
533 wrt::WidgetFeature::Row widgetFeature;
534 widgetFeature.Set_app_id(widgetHandle);
535 widgetFeature.Set_name(pWidgetFeature->name);
536 widgetFeature.Set_required(pWidgetFeature->required);
537 widgetFeature.Set_rejected(false);
539 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
541 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
542 insert->Values(widgetFeature);
543 widgetFeatureID = static_cast<int>(insert->Execute());
546 // Insert into table FeatureParam
547 wrt::FeatureParam::Row featureParam;
548 featureParam.Set_widget_feature_id(widgetFeatureID);
550 FOREACH(iter, pWidgetFeature->paramsList)
552 featureParam.Set_name(iter->name);
553 featureParam.Set_value(iter->value);
555 DO_INSERT(featureParam, wrt::FeatureParam)
560 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
561 const WidgetRegisterInfo ®Info)
563 using namespace DPL::DB::ORM;
564 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
566 FOREACH(it, widgetConfigurationInfo.privilegeList)
568 wrt::WidgetPrivilege::Row widgetPrivilege;
569 widgetPrivilege.Set_app_id(widgetHandle);
570 widgetPrivilege.Set_name(it->name);
572 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
576 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature)
578 // This function could be merged with registerWidgetFeature but it requires
580 // 1. Check "ace step" in installer must be done before "update database
583 // ConfigurationParserData shouldn't be called "ParserData" any more.
584 using namespace DPL::DB::ORM;
586 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
587 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
588 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
589 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
591 auto row = select->GetSingleRow();
592 row.Set_rejected(widgetFeature.rejected);
594 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
595 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
596 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
599 transaction.Commit();
602 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
603 const WidgetRegisterInfo ®Info)
605 using namespace DPL::DB::ORM;
606 using namespace DPL::DB::ORM::wrt;
607 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
609 FOREACH(i, widgetConfigurationInfo.windowModes)
611 wrt::WidgetWindowModes::Row windowMode;
612 windowMode.Set_app_id(widgetHandle);
613 windowMode.Set_window_mode(*i);
615 DO_INSERT(windowMode, wrt::WidgetWindowModes)
619 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
620 const WidgetRegisterInfo ®Info)
622 using namespace DPL::DB::ORM;
623 using namespace DPL::DB::ORM::wrt;
624 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
626 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
628 WidgetWARPInfo::Row row;
629 row.Set_app_id(widgetHandle);
630 row.Set_iri(AccIt->m_strIRI);
631 row.Set_subdomain_access(static_cast <int>(
632 AccIt->m_bSubDomainAccess));
634 DO_INSERT(row, WidgetWARPInfo)
638 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
639 const IWacSecurity &wacSecurity)
641 using namespace DPL::DB::ORM;
642 using namespace DPL::DB::ORM::wrt;
644 FOREACH(it, wacSecurity.getCertificateList())
646 WidgetCertificateFingerprint::Row row;
647 row.Set_app_id(widgetHandle);
648 row.Set_owner(it->owner);
649 row.Set_chainid(it->chainId);
650 row.Set_type(it->type);
651 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
652 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
653 row.Set_common_name(it->strCommonName);
655 DO_INSERT(row, WidgetCertificateFingerprint)
659 void WidgetDAO::registerCertificatesChains(
660 DbWidgetHandle widgetHandle,
661 CertificateSource certificateSource,
662 const CertificateChainList &
663 certificateChainList)
665 using namespace DPL::DB::ORM;
666 using namespace DPL::DB::ORM::wrt;
667 FOREACH(certChain, certificateChainList)
669 WidgetCertificate::Row row;
670 row.Set_app_id(widgetHandle);
671 row.Set_cert_source(certificateSource);
672 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
674 DO_INSERT(row, WidgetCertificate);
678 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
679 const WidgetRegisterInfo ®Info)
681 using namespace DPL::DB::ORM;
682 using namespace DPL::DB::ORM::wrt;
684 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
686 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
688 SettingsList::Row row;
689 row.Set_appId(widgetHandle);
690 row.Set_settingName(pWidgetSetting->m_name);
691 row.Set_settingValue(pWidgetSetting->m_value);
693 DO_INSERT(row, SettingsList)
697 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
698 const WidgetRegisterInfo ®Info)
700 using namespace DPL::DB::ORM;
701 using namespace DPL::DB::ORM::wrt;
702 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
704 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
706 ApplicationServiceInfo::Row row;
707 row.Set_app_id(widgetHandle);
708 row.Set_src(ASIt->m_src);
709 row.Set_operation(ASIt->m_operation);
710 row.Set_scheme(ASIt->m_scheme);
711 row.Set_mime(ASIt->m_mime);
713 DO_INSERT(row, ApplicationServiceInfo)
717 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
718 const WidgetRegisterInfo ®Info)
720 using namespace DPL::DB::ORM;
721 using namespace DPL::DB::ORM::wrt;
723 FOREACH(it, regInfo.encryptedFiles)
725 EncryptedResourceList::Row row;
726 row.Set_app_id(widgetHandle);
727 row.Set_resource(it->fileName);
728 row.Set_size(it->fileSize);
730 DO_INSERT(row, EncryptedResourceList)
734 void WidgetDAO::registerExternalLocations(
735 DbWidgetHandle widgetHandle,
736 const ExternalLocationList &
739 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
741 using namespace DPL::DB::ORM;
742 using namespace DPL::DB::ORM::wrt;
743 DPL::DB::ORM::wrt::ScopedTransaction transaction(
744 &WrtDatabase::interface());
745 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
746 FOREACH(it, externals)
748 WidgetExternalLocations::Row row;
749 row.Set_app_id(widgetHandle);
750 row.Set_path(DPL::FromUTF8String(*it));
752 DO_INSERT(row, WidgetExternalLocations)
754 transaction.Commit();
756 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
759 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
761 using namespace DPL::DB::ORM;
762 using namespace DPL::DB::ORM::wrt;
763 WidgetSecuritySettings::Row row;
764 row.Set_app_id(widgetHandle);
765 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
766 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
767 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
768 row.Set_web_database_usage(SETTINGS_TYPE_ON);
769 row.Set_file_system_usage(SETTINGS_TYPE_ON);
771 DO_INSERT(row, WidgetSecuritySettings)
774 void WidgetDAO::unregisterAllExternalLocations()
776 using namespace DPL::DB::ORM;
777 using namespace DPL::DB::ORM::wrt;
778 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
779 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
780 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
784 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
786 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
787 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
789 DPL::DB::ORM::wrt::ScopedTransaction transaction(
790 &WrtDatabase::interface());
791 unregisterWidgetInternal(tzAppId);
792 transaction.Commit();
794 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
797 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
799 LogDebug("Unregistering widget from DB. Handle: " << handle);
800 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
802 using namespace DPL::DB::ORM;
803 using namespace DPL::DB::ORM::wrt;
804 ScopedTransaction transaction(&WrtDatabase::interface());
806 // Delete from table Widget Info
807 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
808 del->Where(Equals<WidgetInfo::app_id>(handle));
811 transaction.Commit();
813 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
816 void WidgetDAO::unregisterWidgetInternal(
817 const TizenAppId & tzAppId)
819 using namespace DPL::DB::ORM;
820 using namespace DPL::DB::ORM::wrt;
822 DbWidgetHandle handle = getHandle(tzAppId);
824 // Delete from table Widget Info
825 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
826 del->Where(Equals<WidgetInfo::app_id>(handle));
829 // Deleting in other tables is done via "delete cascade" in SQL
834 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
835 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END