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::AddDefferedWidgetPackageInstallation(const DPL::String &path)
34 LogDebug("Adding widget package as defered. Path: " << path);
36 using namespace DPL::DB::ORM;
37 using namespace DPL::DB::ORM::wrt;
38 DefferedWidgetPackageInstallation::Row row;
41 WRT_DB_INSERT(insert, DefferedWidgetPackageInstallation, &WrtDatabase::interface())
45 Catch(DPL::DB::SqlConnection::Exception::Base){
46 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
47 "Failed to add defered widget package");
51 void GlobalDAO::RemoveDefferedWidgetPackageInstallation(const DPL::String &path)
53 LogDebug("Remove widget package from differed list. Path: " << path);
55 using namespace DPL::DB::ORM;
56 using namespace DPL::DB::ORM::wrt;
57 WRT_DB_DELETE(del, DefferedWidgetPackageInstallation, &WrtDatabase::interface())
58 del->Where(Equals<DefferedWidgetPackageInstallation::path>(path));
61 Catch(DPL::DB::SqlConnection::Exception::Base){
62 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
63 "Failed to remove defered widget package");
67 void GlobalDAO::SetDeveloperMode(bool mode)
69 LogDebug("updating Developer mode to:" << mode);
71 using namespace DPL::DB::ORM;
72 using namespace DPL::DB::ORM::wrt;
73 GlobalProperties::Row row;
74 row.Set_developer_mode(mode);
76 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
80 Catch(DPL::DB::SqlConnection::Exception::Base){
81 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
82 "Failed to update Developer Mode");
86 void GlobalDAO::SetSecureByDefault(bool secure)
88 //If secure == true -> widget does not need to be signed
90 using namespace DPL::DB::ORM;
91 using namespace DPL::DB::ORM::wrt;
92 GlobalProperties::Row row;
93 row.Set_secure_by_default(secure);
94 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
98 Catch(DPL::DB::SqlConnection::Exception::Base) {
99 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
100 "Failed to update secureByDefault");
104 void GlobalDAO::setComplianceMode(bool mode)
106 LogDebug("Updating compliance mode to:" << mode);
108 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
109 GlobalProperties::Row row;
110 row.Set_compliance_mode(mode);
112 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
116 Catch (DPL::DB::SqlConnection::Exception::Base){
117 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
118 "Failed to update compliance mode");
122 void GlobalDAO::setComplianceFakeImei(const std::string &imei)
124 LogDebug("Setting compliance fake IMEI: " << imei);
126 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
127 GlobalProperties::Row row;
128 row.Set_compliance_fake_imei(DPL::FromASCIIString(imei));
130 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
134 Catch (DPL::DB::SqlConnection::Exception::Base){
135 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
136 "Failed to update compliance fake IMEI");
140 void GlobalDAO::setComplianceFakeMeid(const std::string &meid)
142 LogDebug("Setting compliance fake MEID: " << meid);
144 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
145 GlobalProperties::Row row;
146 row.Set_compliance_fake_meid(DPL::FromASCIIString(meid));
148 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
152 Catch (DPL::DB::SqlConnection::Exception::Base){
153 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
154 "Failed to update compliance fake MEID");
158 void GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::NetworkAccessMode newMode)
160 LogDebug("updating home network data usage to:" << newMode);
162 using namespace DPL::DB::ORM;
163 using namespace DPL::DB::ORM::wrt;
164 GlobalProperties::Row row;
165 row.Set_home_network_data_usage(static_cast<int>(newMode));
167 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
171 Catch(DPL::DB::SqlConnection::Exception::Base){
172 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
173 "Failed to update home network data usage");
177 void GlobalDAO::SetRoamingDataUsage(GlobalDAO::NetworkAccessMode newMode)
179 LogDebug("updating roaming network data usage to:" << newMode);
181 using namespace DPL::DB::ORM;
182 using namespace DPL::DB::ORM::wrt;
183 GlobalProperties::Row row;
184 row.Set_roaming_data_usage(static_cast<int>(newMode));
186 WRT_DB_UPDATE(update, GlobalProperties, &WrtDatabase::interface())
190 Catch(DPL::DB::SqlConnection::Exception::Base){
191 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
192 "Failed to update roaming network data usage");
196 void GlobalDAO::AddWhiteURI(const std::string &uri, bool subDomain)
198 LogDebug("Add White URI : " << uri);
200 using namespace DPL::DB::ORM;
201 using namespace DPL::DB::ORM::wrt;
202 WidgetWhiteURIList::Row row;
203 row.Set_uri(DPL::FromASCIIString(uri));
204 row.Set_subdomain_access(static_cast<int>(subDomain));
205 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
207 WRT_DB_INSERT(insert, WidgetWhiteURIList, &WrtDatabase::interface())
211 transaction.Commit();
213 Catch(DPL::DB::SqlConnection::Exception::Base){
214 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
215 "Failed to add white URI");
219 void GlobalDAO::RemoveWhiteURI(const std::string &uri)
221 LogDebug("Remove White URI : " << uri);
223 using namespace DPL::DB::ORM;
224 using namespace DPL::DB::ORM::wrt;
226 WRT_DB_DELETE(deleteFrom, WidgetWhiteURIList, &WrtDatabase::interface())
227 deleteFrom->Where(Equals<WidgetWhiteURIList::uri>(DPL::FromASCIIString(uri)));
228 deleteFrom->Execute();
229 } Catch(DPL::DB::SqlConnection::Exception::Base) {
230 ReThrowMsg(GlobalDAO::Exception::DatabaseError,
231 "Failed to removed white URI from AdultBlackList");