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 //TODO in current solution in each getter there exists a check
41 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
42 //differently (check in WidgetDAO constructor)
44 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
46 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
47 Catch(DPL::DB::SqlConnection::Exception::Base) { \
49 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
53 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
54 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
57 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
58 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
61 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
62 WidgetDAOReadOnly(handle)
65 WidgetDAO::~WidgetDAO()
68 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
70 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
72 using namespace DPL::DB::ORM;
73 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
75 if (!isWidgetInstalled(getHandle())) {
76 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
77 "Cannot find widget. Handle: " << getHandle());
80 wrt::WidgetInfo::Row row;
81 row.Set_tizen_appid(*tzAppId);
83 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
85 Equals<wrt::WidgetInfo::app_id>(getHandle()));
91 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
94 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
96 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
98 using namespace DPL::DB::ORM;
99 using namespace DPL::DB::ORM::wrt;
101 ScopedTransaction transaction(&WrtDatabase::interface());
102 if (!isWidgetInstalled(getHandle())) {
103 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
104 "Cannot find widget. Handle: " << getHandle());
107 WidgetSecuritySettings::Row row;
108 row.Set_security_popup_usage(value);
110 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
111 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
115 transaction.Commit();
117 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
120 void WidgetDAO::setGeolocationUsage(const SettingsType value)
122 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
124 using namespace DPL::DB::ORM;
125 using namespace DPL::DB::ORM::wrt;
127 ScopedTransaction transaction(&WrtDatabase::interface());
128 if (!isWidgetInstalled(getHandle())) {
129 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
130 "Cannot find widget. Handle: " << getHandle());
133 WidgetSecuritySettings::Row row;
134 row.Set_geolocation_usage(value);
136 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
137 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
141 transaction.Commit();
143 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
146 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
148 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
150 using namespace DPL::DB::ORM;
151 using namespace DPL::DB::ORM::wrt;
153 ScopedTransaction transaction(&WrtDatabase::interface());
154 if (!isWidgetInstalled(getHandle())) {
155 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
156 "Cannot find widget. Handle: " << getHandle());
159 WidgetSecuritySettings::Row row;
160 row.Set_web_notification_usage(value);
162 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
163 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
167 transaction.Commit();
169 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
172 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
174 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
176 using namespace DPL::DB::ORM;
177 using namespace DPL::DB::ORM::wrt;
179 ScopedTransaction transaction(&WrtDatabase::interface());
180 if (!isWidgetInstalled(getHandle())) {
181 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
182 "Cannot find widget. Handle: " << getHandle());
185 WidgetSecuritySettings::Row row;
186 row.Set_web_database_usage(value);
188 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
189 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
193 transaction.Commit();
195 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
198 void WidgetDAO::setFileSystemUsage(const SettingsType value)
200 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
202 using namespace DPL::DB::ORM;
203 using namespace DPL::DB::ORM::wrt;
205 ScopedTransaction transaction(&WrtDatabase::interface());
206 if (!isWidgetInstalled(getHandle())) {
207 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
208 "Cannot find widget. Handle: " << getHandle());
211 WidgetSecuritySettings::Row row;
212 row.Set_file_system_usage(value);
214 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
215 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
219 transaction.Commit();
221 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
224 void WidgetDAO::registerWidget(
225 const TizenAppId & tzAppId,
226 const WidgetRegisterInfo &widgetRegInfo,
227 const IWacSecurity &wacSecurity)
229 LogDebug("Registering widget");
230 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
232 DPL::DB::ORM::wrt::ScopedTransaction transaction(
233 &WrtDatabase::interface());
234 registerWidgetInternal(tzAppId, widgetRegInfo, wacSecurity);
235 transaction.Commit();
237 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
240 DbWidgetHandle WidgetDAO::registerWidget(
241 const WidgetRegisterInfo &pWidgetRegisterInfo,
242 const IWacSecurity &wacSecurity)
244 //make it more precise due to very fast tests
246 gettimeofday(&tv, NULL);
247 srand(time(NULL) + tv.tv_usec);
248 DbWidgetHandle widgetHandle;
250 widgetHandle = rand();
251 } while (isWidgetInstalled(widgetHandle));
253 registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId,
259 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
260 const WidgetRegisterInfo &pWidgetRegisterInfo,
261 const IWacSecurity &wacSecurity)
263 TizenAppId tzAppId = generatePkgId();
264 registerWidget(tzAppId, pWidgetRegisterInfo, wacSecurity);
268 void WidgetDAO::registerWidgetInternal(
269 const TizenAppId & tzAppId,
270 const WidgetRegisterInfo &widgetRegInfo,
271 const IWacSecurity &wacSecurity,
272 const DPL::Optional<DbWidgetHandle> handle)
274 //Register into WidgetInfo has to be first
275 //as all other tables depend upon that
276 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId,
281 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
283 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
285 registerWidgetIcons(widgetHandle, widgetRegInfo);
287 registerWidgetStartFile(widgetHandle, widgetRegInfo);
289 PropertyDAO::RegisterProperties(tzAppId, widgetRegInfo);
291 registerWidgetFeatures(widgetHandle, widgetRegInfo);
293 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
295 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
297 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
299 registerWidgetCertificates(widgetHandle, wacSecurity);
301 CertificateChainList list;
302 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
303 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
306 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
307 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
309 registerWidgetSettings(widgetHandle, widgetRegInfo);
311 registerAppService(widgetHandle, widgetRegInfo);
313 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
315 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
317 registerWidgetSecuritySettings(widgetHandle);
320 void WidgetDAO::registerOrUpdateWidget(
321 const TizenAppId & widgetName,
322 const WidgetRegisterInfo &widgetRegInfo,
323 const IWacSecurity &wacSecurity)
325 LogDebug("Reregistering widget");
326 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
328 DPL::DB::ORM::wrt::ScopedTransaction transaction(
329 &WrtDatabase::interface());
331 unregisterWidgetInternal(widgetName);
332 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
333 transaction.Commit();
335 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
338 #define DO_INSERT(row, table) \
340 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
341 insert->Values(row); \
345 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
346 const WidgetRegisterInfo ®Info)
348 //Try and transaction not needed
349 using namespace DPL::DB::ORM;
350 using namespace DPL::DB::ORM::wrt;
352 WidgetExtendedInfo::Row row;
353 row.Set_app_id(widgetHandle);
354 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
355 row.Set_signature_type(regInfo.signatureType);
356 row.Set_test_widget(regInfo.isTestWidget);
357 row.Set_install_time(regInfo.installedTime);
358 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
359 row.Set_background_page(regInfo.configInfo.backgroundPage);
360 row.Set_installed_path(regInfo.widgetInstalledPath);
362 DO_INSERT(row, WidgetExtendedInfo)
365 DbWidgetHandle WidgetDAO::registerWidgetInfo(
366 const TizenAppId & tzAppId,
367 const WidgetRegisterInfo ®Info,
368 const IWacSecurity &wacSecurity,
369 const DPL::Optional<DbWidgetHandle> handle)
371 using namespace DPL::DB::ORM;
372 using namespace DPL::DB::ORM::wrt;
373 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
375 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
376 // Because of that, "Optional" is not used there
380 row.Set_app_id(*handle);
383 row.Set_widget_type(regInfo.webAppType.appType);
385 row.Set_widget_id(widgetConfigurationInfo.widget_id);
386 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
387 row.Set_widget_version(widgetConfigurationInfo.version);
388 row.Set_widget_width(widgetConfigurationInfo.width);
389 row.Set_widget_height(widgetConfigurationInfo.height);
390 row.Set_author_name(widgetConfigurationInfo.authorName);
391 row.Set_author_email(widgetConfigurationInfo.authorEmail);
392 row.Set_author_href(widgetConfigurationInfo.authorHref);
393 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
394 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
395 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
396 row.Set_recognized(wacSecurity.isRecognized());
397 row.Set_wac_signed(wacSecurity.isWacSigned());
398 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
399 row.Set_tizen_appid(tzAppId);
400 row.Set_tizen_pkgid(regInfo.tzPkgid);
402 std::stringstream tmp;
403 tmp << regInfo.minVersion;
404 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
406 row.Set_back_supported(widgetConfigurationInfo.backSupported);
407 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
408 row.Set_pkg_type(regInfo.packagingType.pkgType);
412 DO_INSERT(row, WidgetInfo);
414 Catch(DPL::DB::SqlConnection::Exception::Base)
416 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
417 "Failed to register widget info.");
421 //get autoincremented value of widgetHandle
422 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
423 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
424 return select->GetSingleValue<WidgetInfo::app_id>();
430 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
431 const WidgetRegisterInfo ®Info)
433 using namespace DPL::DB::ORM;
434 using namespace DPL::DB::ORM::wrt;
436 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
438 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
440 const DPL::String& locale = it->first;
441 const ConfigParserData::LocalizedData& data = it->second;
443 LocalizedWidgetInfo::Row row;
444 row.Set_app_id(widgetHandle);
445 row.Set_widget_locale(locale);
446 row.Set_widget_name(data.name);
447 row.Set_widget_shortname(data.shortName);
448 row.Set_widget_description(data.description);
449 row.Set_widget_license(data.license);
450 row.Set_widget_license_file(data.licenseFile);
451 row.Set_widget_license_href(data.licenseHref);
453 DO_INSERT(row, LocalizedWidgetInfo)
457 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
458 const WidgetRegisterInfo ®Info)
460 using namespace DPL::DB::ORM;
461 using namespace DPL::DB::ORM::wrt;
463 FOREACH(i, regInfo.localizationData.icons)
465 wrt::WidgetIcon::icon_id::ColumnType icon_id;
467 wrt::WidgetIcon::Row row;
468 row.Set_app_id(widgetHandle);
469 row.Set_icon_src(i->src);
470 row.Set_icon_width(i->width);
471 row.Set_icon_height(i->height);
473 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
475 icon_id = static_cast<int>(insert->Execute());
478 FOREACH(j, i->availableLocales)
480 WidgetLocalizedIcon::Row row;
481 row.Set_app_id(widgetHandle);
482 row.Set_icon_id(icon_id);
483 row.Set_widget_locale(*j);
484 DO_INSERT(row, WidgetLocalizedIcon)
489 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
490 const WidgetRegisterInfo ®Info)
492 using namespace DPL::DB::ORM;
493 using namespace DPL::DB::ORM::wrt;
495 FOREACH(i, regInfo.localizationData.startFiles)
497 WidgetStartFile::start_file_id::ColumnType startFileID;
499 WidgetStartFile::Row row;
500 row.Set_app_id(widgetHandle);
501 row.Set_src(i->path);
503 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
505 startFileID = static_cast<int>(insert->Execute());
508 FOREACH(j, i->propertiesForLocales)
510 WidgetLocalizedStartFile::Row row;
511 row.Set_app_id(widgetHandle);
512 row.Set_start_file_id(startFileID);
513 row.Set_widget_locale(j->first);
514 row.Set_type(j->second.type);
515 row.Set_encoding(j->second.encoding);
517 DO_INSERT(row, WidgetLocalizedStartFile)
522 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
523 const WidgetRegisterInfo ®Info)
525 using namespace DPL::DB::ORM;
526 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
528 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
530 wrt::WidgetFeature::Row widgetFeature;
531 widgetFeature.Set_app_id(widgetHandle);
532 widgetFeature.Set_name(pWidgetFeature->name);
533 widgetFeature.Set_required(pWidgetFeature->required);
534 widgetFeature.Set_rejected(false);
536 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
538 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
539 insert->Values(widgetFeature);
540 widgetFeatureID = static_cast<int>(insert->Execute());
543 // Insert into table FeatureParam
544 wrt::FeatureParam::Row featureParam;
545 featureParam.Set_widget_feature_id(widgetFeatureID);
547 FOREACH(iter, pWidgetFeature->paramsList)
549 featureParam.Set_name(iter->name);
550 featureParam.Set_value(iter->value);
552 DO_INSERT(featureParam, wrt::FeatureParam)
557 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
558 const WidgetRegisterInfo ®Info)
560 using namespace DPL::DB::ORM;
561 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
563 FOREACH(it, widgetConfigurationInfo.privilegeList)
565 wrt::WidgetPrivilege::Row widgetPrivilege;
566 widgetPrivilege.Set_app_id(widgetHandle);
567 widgetPrivilege.Set_name(it->name);
569 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
573 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature)
575 // This function could be merged with registerWidgetFeature but it requires
577 // 1. Check "ace step" in installer must be done before "update database
580 // ConfigurationParserData shouldn't be called "ParserData" any more.
581 using namespace DPL::DB::ORM;
583 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
584 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
585 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
586 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
588 auto row = select->GetSingleRow();
589 row.Set_rejected(widgetFeature.rejected);
591 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
592 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
593 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
596 transaction.Commit();
599 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
600 const WidgetRegisterInfo ®Info)
602 using namespace DPL::DB::ORM;
603 using namespace DPL::DB::ORM::wrt;
604 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
606 FOREACH(i, widgetConfigurationInfo.windowModes)
608 wrt::WidgetWindowModes::Row windowMode;
609 windowMode.Set_app_id(widgetHandle);
610 windowMode.Set_window_mode(*i);
612 DO_INSERT(windowMode, wrt::WidgetWindowModes)
616 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
617 const WidgetRegisterInfo ®Info)
619 using namespace DPL::DB::ORM;
620 using namespace DPL::DB::ORM::wrt;
621 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
623 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
625 WidgetWARPInfo::Row row;
626 row.Set_app_id(widgetHandle);
627 row.Set_iri(AccIt->m_strIRI);
628 row.Set_subdomain_access(static_cast <int>(
629 AccIt->m_bSubDomainAccess));
631 DO_INSERT(row, WidgetWARPInfo)
635 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
636 const IWacSecurity &wacSecurity)
638 using namespace DPL::DB::ORM;
639 using namespace DPL::DB::ORM::wrt;
641 FOREACH(it, wacSecurity.getCertificateList())
643 WidgetCertificateFingerprint::Row row;
644 row.Set_app_id(widgetHandle);
645 row.Set_owner(it->owner);
646 row.Set_chainid(it->chainId);
647 row.Set_type(it->type);
648 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
649 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
650 row.Set_common_name(it->strCommonName);
652 DO_INSERT(row, WidgetCertificateFingerprint)
656 void WidgetDAO::registerCertificatesChains(
657 DbWidgetHandle widgetHandle,
658 CertificateSource certificateSource,
659 const CertificateChainList &
660 certificateChainList)
662 using namespace DPL::DB::ORM;
663 using namespace DPL::DB::ORM::wrt;
664 FOREACH(certChain, certificateChainList)
666 WidgetCertificate::Row row;
667 row.Set_app_id(widgetHandle);
668 row.Set_cert_source(certificateSource);
669 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
671 DO_INSERT(row, WidgetCertificate);
675 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
676 const WidgetRegisterInfo ®Info)
678 using namespace DPL::DB::ORM;
679 using namespace DPL::DB::ORM::wrt;
681 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
683 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
685 SettingsList::Row row;
686 row.Set_appId(widgetHandle);
687 row.Set_settingName(pWidgetSetting->m_name);
688 row.Set_settingValue(pWidgetSetting->m_value);
690 DO_INSERT(row, SettingsList)
694 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
695 const WidgetRegisterInfo ®Info)
697 using namespace DPL::DB::ORM;
698 using namespace DPL::DB::ORM::wrt;
699 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
701 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
703 ApplicationServiceInfo::Row row;
704 row.Set_app_id(widgetHandle);
705 row.Set_src(ASIt->m_src);
706 row.Set_operation(ASIt->m_operation);
707 row.Set_scheme(ASIt->m_scheme);
708 row.Set_mime(ASIt->m_mime);
710 DO_INSERT(row, ApplicationServiceInfo)
714 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
715 const WidgetRegisterInfo ®Info)
717 using namespace DPL::DB::ORM;
718 using namespace DPL::DB::ORM::wrt;
720 FOREACH(it, regInfo.encryptedFiles)
722 EncryptedResourceList::Row row;
723 row.Set_app_id(widgetHandle);
724 row.Set_resource(it->fileName);
725 row.Set_size(it->fileSize);
727 DO_INSERT(row, EncryptedResourceList)
731 void WidgetDAO::registerExternalLocations(
732 DbWidgetHandle widgetHandle,
733 const ExternalLocationList &
736 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
738 using namespace DPL::DB::ORM;
739 using namespace DPL::DB::ORM::wrt;
740 DPL::DB::ORM::wrt::ScopedTransaction transaction(
741 &WrtDatabase::interface());
742 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
743 FOREACH(it, externals)
745 WidgetExternalLocations::Row row;
746 row.Set_app_id(widgetHandle);
747 row.Set_path(DPL::FromUTF8String(*it));
749 DO_INSERT(row, WidgetExternalLocations)
751 transaction.Commit();
753 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
756 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
758 using namespace DPL::DB::ORM;
759 using namespace DPL::DB::ORM::wrt;
760 WidgetSecuritySettings::Row row;
761 row.Set_app_id(widgetHandle);
762 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
763 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
764 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
765 row.Set_web_database_usage(SETTINGS_TYPE_ON);
766 row.Set_file_system_usage(SETTINGS_TYPE_ON);
768 DO_INSERT(row, WidgetSecuritySettings)
771 void WidgetDAO::unregisterAllExternalLocations()
773 using namespace DPL::DB::ORM;
774 using namespace DPL::DB::ORM::wrt;
775 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
776 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
777 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
781 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
783 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
784 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
786 DPL::DB::ORM::wrt::ScopedTransaction transaction(
787 &WrtDatabase::interface());
788 unregisterWidgetInternal(tzAppId);
789 transaction.Commit();
791 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
794 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
796 LogDebug("Unregistering widget from DB. Handle: " << handle);
797 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
799 using namespace DPL::DB::ORM;
800 using namespace DPL::DB::ORM::wrt;
801 ScopedTransaction transaction(&WrtDatabase::interface());
803 // Delete from table Widget Info
804 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
805 del->Where(Equals<WidgetInfo::app_id>(handle));
808 transaction.Commit();
810 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
813 void WidgetDAO::unregisterWidgetInternal(
814 const TizenAppId & tzAppId)
816 using namespace DPL::DB::ORM;
817 using namespace DPL::DB::ORM::wrt;
819 DbWidgetHandle handle = getHandle(tzAppId);
821 // Delete from table Widget Info
822 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
823 del->Where(Equals<WidgetInfo::app_id>(handle));
826 // Deleting in other tables is done via "delete cascade" in SQL
831 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
832 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END