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/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 LogDebug("Removing Property. appid: " << tzAppid << ", key: " << key);
42 DPL::DB::ORM::wrt::ScopedTransaction transaction(
43 &WrtDatabase::interface());
45 DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag(
48 if (!readonly.IsNull() && *readonly == 1) {
49 LogError("'" << key <<
50 "' key is readonly. Cannot remove property !");
51 ThrowMsg(PropertyDAOReadOnly::Exception::ReadOnlyProperty,
52 "Property is readonly");
55 // Key is not readonly, or has no flag defined
57 using namespace DPL::DB::ORM;
58 using namespace DPL::DB::ORM::wrt;
59 WRT_DB_DELETE(del, WidgetPreference, &WrtDatabase::interface())
61 Equals<WidgetPreference::tizen_appid>(tzAppid),
62 Equals<WidgetPreference::key_name>(key)));
67 Catch(DPL::DB::SqlConnection::Exception::Base){
68 ReThrowMsg(PropertyDAOReadOnly::Exception::DatabaseError,
69 "Failure during removing property");
74 void SetProperty(DbWidgetHandle widgetHandle,
75 const PropertyDAOReadOnly::WidgetPropertyKey &key,
76 const PropertyDAOReadOnly::WidgetPropertyValue &value,
79 SetProperty(WidgetDAOReadOnly::getTzAppId(
80 widgetHandle), key, value, readOnly);
83 void SetProperty(TizenAppId tzAppid,
84 const PropertyDAOReadOnly::WidgetPropertyKey &key,
85 const PropertyDAOReadOnly::WidgetPropertyValue &value,
88 LogDebug("Setting/updating Property. appid: " << tzAppid <<
91 using namespace DPL::DB::ORM;
92 using namespace DPL::DB::ORM::wrt;
93 DPL::DB::ORM::wrt::ScopedTransaction transaction(
94 &WrtDatabase::interface());
96 DPL::OptionalInt readonly = PropertyDAOReadOnly::CheckPropertyReadFlag(
99 if (!readonly.IsNull() && *readonly == 1) {
100 LogError("'" << key <<
101 "' key is readonly. Cannot remove property !");
102 ThrowMsg(PropertyDAOReadOnly::Exception::ReadOnlyProperty,
103 "Property is readonly");
106 if (readonly.IsNull()) {
107 WidgetPreference::Row row;
108 row.Set_tizen_appid(tzAppid);
109 row.Set_key_name(key);
110 row.Set_key_value(value);
111 row.Set_readonly(readOnly ? 1 : 0);
113 WRT_DB_INSERT(insert, WidgetPreference, &WrtDatabase::interface())
117 WidgetPreference::Row row;
118 row.Set_key_value(value);
120 WRT_DB_UPDATE(update, WidgetPreference, &WrtDatabase::interface())
122 Equals<WidgetPreference::tizen_appid>(tzAppid),
123 Equals<WidgetPreference::key_name>(key)));
128 transaction.Commit();
130 Catch(DPL::DB::SqlConnection::Exception::Base){
131 ReThrowMsg(PropertyDAOReadOnly::Exception::DatabaseError,
132 "Failure during setting/updating property");
136 void RegisterProperties(TizenAppId tzAppid,
137 const WidgetRegisterInfo ®Info)
139 LogDebug("Registering proferences for widget. appid: " << tzAppid);
141 // Try-Catch in WidgetDAO
143 using namespace DPL::DB::ORM;
144 using namespace DPL::DB::ORM::wrt;
145 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
147 FOREACH(it, widgetConfigurationInfo.preferencesList)
149 { // Insert into table Widget Preferences
150 WidgetPreference::Row row;
151 row.Set_tizen_appid(tzAppid);
152 row.Set_key_name(it->name);
153 row.Set_key_value(it->value);
154 int readonly = true == it->readonly ? 1 : 0;
155 row.Set_readonly(readonly);
157 WRT_DB_INSERT(insert, WidgetPreference, &WrtDatabase::interface())
163 } // namespace PropertyDAO