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 global_dao.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains the definition of global dao class.
23 #include <dpl/wrt-dao-rw/global_dao.h>
24 #include <dpl/log/log.h>
25 #include <dpl/string.h>
26 #include <dpl/db/orm.h>
27 #include <orm_generator_wrt.h>
28 #include <dpl/wrt-dao-ro/webruntime_database.h>
29 #include <dpl/wrt-dao-ro/WrtDatabase.h>
32 void GlobalDAO::SetSecureByDefault(bool secure)
34 //If secure == true -> widget does not need to be signed
36 using namespace DPL::DB::ORM;
37 using namespace DPL::DB::ORM::wrt;
38 GlobalProperties::Row row;
39 row.Set_secure_by_default(secure);
40 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
44 Catch(DPL::DB::SqlConnection::Exception::Base) {
45 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
46 "Failed to update secureByDefault");
50 void GlobalDAO::setComplianceMode(bool mode)
52 LogDebug("Updating compliance mode to:" << mode);
54 using namespace DPL::DB::ORM;
55 using namespace DPL::DB::ORM::wrt;
56 GlobalProperties::Row row;
57 row.Set_compliance_mode(mode);
59 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
63 Catch(DPL::DB::SqlConnection::Exception::Base){
64 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
65 "Failed to update compliance mode");
69 void GlobalDAO::setComplianceFakeImei(const std::string &imei)
71 LogDebug("Setting compliance fake IMEI: " << imei);
73 using namespace DPL::DB::ORM;
74 using namespace DPL::DB::ORM::wrt;
75 GlobalProperties::Row row;
76 row.Set_compliance_fake_imei(DPL::FromASCIIString(imei));
78 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
82 Catch(DPL::DB::SqlConnection::Exception::Base){
83 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
84 "Failed to update compliance fake IMEI");
88 void GlobalDAO::setComplianceFakeMeid(const std::string &meid)
90 LogDebug("Setting compliance fake MEID: " << meid);
92 using namespace DPL::DB::ORM;
93 using namespace DPL::DB::ORM::wrt;
94 GlobalProperties::Row row;
95 row.Set_compliance_fake_meid(DPL::FromASCIIString(meid));
97 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
101 Catch(DPL::DB::SqlConnection::Exception::Base){
102 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
103 "Failed to update compliance fake MEID");
107 void GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::NetworkAccessMode newMode)
109 LogDebug("updating home network data usage to:" << newMode);
111 using namespace DPL::DB::ORM;
112 using namespace DPL::DB::ORM::wrt;
113 GlobalProperties::Row row;
114 row.Set_home_network_data_usage(static_cast<int>(newMode));
116 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
120 Catch(DPL::DB::SqlConnection::Exception::Base){
121 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
122 "Failed to update home network data usage");
126 void GlobalDAO::SetRoamingDataUsage(GlobalDAO::NetworkAccessMode newMode)
128 LogDebug("updating roaming network data usage to:" << newMode);
130 using namespace DPL::DB::ORM;
131 using namespace DPL::DB::ORM::wrt;
132 GlobalProperties::Row row;
133 row.Set_roaming_data_usage(static_cast<int>(newMode));
135 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
139 Catch(DPL::DB::SqlConnection::Exception::Base){
140 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
141 "Failed to update roaming network data usage");
145 void GlobalDAO::AddWhiteURI(const std::string &uri, bool subDomain)
147 LogDebug("Add White URI : " << uri);
149 using namespace DPL::DB::ORM;
150 using namespace DPL::DB::ORM::wrt;
151 WidgetWhiteURIList::Row row;
152 row.Set_uri(DPL::FromASCIIString(uri));
153 row.Set_subdomain_access(static_cast<int>(subDomain));
154 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
156 WRT_DB_INSERT(insert, WidgetWhiteURIList, &WrtDatabase::interface())
160 transaction.Commit();
162 Catch(DPL::DB::SqlConnection::Exception::Base){
163 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
164 "Failed to add white URI");
168 void GlobalDAO::RemoveWhiteURI(const std::string &uri)
170 LogDebug("Remove White URI : " << uri);
172 using namespace DPL::DB::ORM;
173 using namespace DPL::DB::ORM::wrt;
175 WRT_DB_DELETE(deleteFrom, WidgetWhiteURIList, &WrtDatabase::interface())
176 deleteFrom->Where(Equals<WidgetWhiteURIList::uri>(DPL::FromASCIIString(
178 deleteFrom->Execute();
179 } Catch(DPL::DB::SqlConnection::Exception::Base) {
180 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
181 "Failed to removed white URI from AdultBlackList");
185 void GlobalDAO::SetCookieSharingMode(bool mode)
187 LogDebug("updating Cookie Sharing mode to:" << mode);
189 using namespace DPL::DB::ORM;
190 using namespace DPL::DB::ORM::wrt;
191 GlobalProperties::Row row;
192 row.Set_cookie_sharing_mode(mode);
194 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
198 Catch(DPL::DB::SqlConnection::Exception::Base){
199 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
200 "Failed to update Cookie Sharing Mode");