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 property_dao.h
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains the definition of property dao class.
23 #include <dpl/wrt-dao-rw/property_dao.h>
24 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
25 #include <dpl/log/wrt_log.h>
26 #include <dpl/foreach.h>
27 #include <dpl/wrt-dao-ro/webruntime_database.h>
28 #include <dpl/wrt-dao-ro/WrtDatabase.h>
29 #include <orm_generator_wrt.h>
32 namespace PropertyDAO {
33 void RemoveProperty(TizenAppId tzAppid,
34 const PropertyDAOReadOnly::WidgetPropertyKey &key)
36 //TODO below there are two queries.
37 // First query asks if given property can be removed,
38 // Second removes it. Maybe it should be combined two one.
40 WrtLogD("Removing Property. appid: %ls, key: %ls",
41 tzAppid.c_str(), key.c_str());
43 DPL::DB::ORM::wrt::ScopedTransaction transaction(
44 &WrtDatabase::interface());
46 DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag(
49 if (!!readonly && *readonly == 1) {
50 WrtLogE("'%ls' key is readonly. Cannot remove property !",
52 ThrowMsg(PropertyDAOReadOnly::Exception::ReadOnlyProperty,
53 "Property is readonly");
56 // Key is not readonly, or has no flag defined
58 using namespace DPL::DB::ORM;
59 using namespace DPL::DB::ORM::wrt;
60 WRT_DB_DELETE(del, WidgetPreference, &WrtDatabase::interface())
62 Equals<WidgetPreference::tizen_appid>(tzAppid),
63 Equals<WidgetPreference::key_name>(key)));
68 Catch(DPL::DB::SqlConnection::Exception::Base){
69 ReThrowMsg(PropertyDAOReadOnly::Exception::DatabaseError,
70 "Failure during removing property");
75 void SetProperty(DbWidgetHandle widgetHandle,
76 const PropertyDAOReadOnly::WidgetPropertyKey &key,
77 const PropertyDAOReadOnly::WidgetPropertyValue &value,
80 SetProperty(WidgetDAOReadOnly::getTizenAppId(
81 widgetHandle), key, value, readOnly);
84 void SetProperty(TizenAppId tzAppid,
85 const PropertyDAOReadOnly::WidgetPropertyKey &key,
86 const PropertyDAOReadOnly::WidgetPropertyValue &value,
89 WrtLogD("Setting/updating Property. appid: %ls, key: %ls",
90 tzAppid.c_str(), key.c_str());
92 using namespace DPL::DB::ORM;
93 using namespace DPL::DB::ORM::wrt;
94 DPL::DB::ORM::wrt::ScopedTransaction transaction(
95 &WrtDatabase::interface());
97 DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag(
100 if (!!readonly && *readonly == 1) {
101 WrtLogE("'%ls' key is readonly. Cannot remove property !",
103 ThrowMsg(PropertyDAOReadOnly::Exception::ReadOnlyProperty,
104 "Property is readonly");
106 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
109 WidgetPreference::Row row;
110 row.Set_app_id(widgetHandle);
111 row.Set_tizen_appid(tzAppid);
112 row.Set_key_name(key);
113 row.Set_key_value(value);
114 row.Set_readonly(readOnly ? 1 : 0);
116 WRT_DB_INSERT(insert, WidgetPreference, &WrtDatabase::interface())
120 WidgetPreference::Row row;
121 row.Set_key_value(value);
123 WRT_DB_UPDATE(update, WidgetPreference, &WrtDatabase::interface())
125 Equals<WidgetPreference::tizen_appid>(tzAppid),
126 Equals<WidgetPreference::key_name>(key)));
131 transaction.Commit();
133 Catch(DPL::DB::SqlConnection::Exception::Base){
134 ReThrowMsg(PropertyDAOReadOnly::Exception::DatabaseError,
135 "Failure during setting/updating property");
139 void RegisterProperties(DbWidgetHandle widgetHandle, TizenAppId tzAppid,
140 const WidgetRegisterInfo ®Info)
142 WrtLogD("Registering proferences for widget. appid: %ls", tzAppid.c_str());
144 // Try-Catch in WidgetDAO
146 using namespace DPL::DB::ORM;
147 using namespace DPL::DB::ORM::wrt;
148 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
150 FOREACH(it, widgetConfigurationInfo.preferencesList)
152 { // Insert into table Widget Preferences
153 WidgetPreference::Row row;
154 row.Set_app_id(widgetHandle);
155 row.Set_tizen_appid(tzAppid);
156 row.Set_key_name(it->name);
157 row.Set_key_value(it->value);
158 int readonly = true == it->readonly ? 1 : 0;
159 row.Set_readonly(readonly);
161 WRT_DB_INSERT(insert, WidgetPreference, &WrtDatabase::interface())
167 } // namespace PropertyDAO