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 * property_dao_read_only.cpp
19 * Created on: Nov 16, 2011
20 * Author: Krzysztof Jackiewicz(k.jackiewicz@samsung.com)
23 #include <dpl/wrt-dao-ro/property_dao_read_only.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 PropertyDAOReadOnly {
34 typedef DPL::DB::ORM::wrt::WidgetPreference::key_name::ColumnType
36 typedef DPL::DB::ORM::wrt::WidgetPreference::key_value::ColumnType
37 ORMWidgetPropertyValue;
38 typedef std::list<DPL::DB::ORM::wrt::WidgetPreference::Row>
39 ORMWidgetPreferenceList;
40 typedef std::list<WidgetPropertyKey> ORMWidgetPropertyKeyList;
42 void convertPropertyKey(const ORMWidgetPropertyKey& ormKey,
43 WidgetPropertyKey& key)
48 void convertPropertyValue(const ORMWidgetPropertyValue& ormPropertyVal,
49 WidgetPropertyValue& propertyVal)
51 propertyVal = ormPropertyVal;
54 void convertWidgetPreferenceRow(const ORMWidgetPreferenceList& ormWidgetPrefRow,
55 WidgetPreferenceList& prefRow)
57 FOREACH(it, ormWidgetPrefRow) {
58 WidgetPreferenceRow row;
60 row.tizen_appid = it->Get_tizen_appid();
61 row.key_name = it->Get_key_name();
62 row.key_value = it->Get_key_value();
63 row.readonly = it->Get_readonly();
65 prefRow.push_back(row);
69 void convertWidgetPropertyKeyList(const ORMWidgetPropertyKeyList& propKeyList,
70 WidgetPropertyKeyList& keyList)
72 FOREACH(it, propKeyList) {
73 keyList.push_back(*it);
79 DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle,
80 const WidgetPropertyKey &key)
82 return CheckPropertyReadFlag(WidgetDAOReadOnly::getTzAppId(widgetHandle),
86 DPL::OptionalInt CheckPropertyReadFlag(TizenAppId tzAppid,
87 const WidgetPropertyKey &key)
89 LogDebug("Checking Property flag. appid: " << tzAppid <<
93 using namespace DPL::DB::ORM;
94 using namespace DPL::DB::ORM::wrt;
95 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
96 select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
97 Equals<WidgetPreference::key_name>(key)));
99 return select->GetSingleValue<WidgetPreference::readonly>();
101 Catch(DPL::DB::SqlConnection::Exception::Base){
102 ReThrowMsg(Exception::DatabaseError,
103 "Failure during checking readonly flag for property");
107 WidgetPropertyKeyList GetPropertyKeyList(TizenAppId tzAppid)
109 LogDebug("Get PropertyKey list. appid: " << tzAppid);
111 using namespace DPL::DB::ORM;
112 using namespace DPL::DB::ORM::wrt;
113 ORMWidgetPropertyKeyList keyList;
114 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
115 select->Where(Equals<WidgetPreference::tizen_appid>(tzAppid));
116 keyList = select->GetValueList<WidgetPreference::key_name>();
118 WidgetPropertyKeyList retKeyList;
120 convertWidgetPropertyKeyList(keyList, retKeyList);
123 Catch(DPL::DB::SqlConnection::Exception::Base){
124 ReThrowMsg(Exception::DatabaseError,
125 "Failure during getting propertykey list");
130 WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle)
133 TizenAppId tzAppid = WidgetDAOReadOnly::getTzAppId(widgetHandle);
134 return GetPropertyList(tzAppid);
135 } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){
136 WidgetPreferenceList empty;
141 WidgetPreferenceList GetPropertyList(TizenAppId tzAppId)
143 LogDebug("Get Property list. tizenAppId: " << tzAppId);
145 using namespace DPL::DB::ORM;
146 using namespace DPL::DB::ORM::wrt;
147 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
148 select->Where(Equals<WidgetPreference::tizen_appid>(tzAppId));
150 ORMWidgetPreferenceList ormPrefList = select->GetRowList();
151 WidgetPreferenceList prefList;
152 convertWidgetPreferenceRow(ormPrefList, prefList);
156 Catch(DPL::DB::SqlConnection::Exception::Base){
157 ReThrowMsg(Exception::DatabaseError,
158 "Failure during getting property list");
162 WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid,
163 const WidgetPropertyKey &key)
165 LogDebug("Get Property value. appid: " << tzAppid <<
168 using namespace DPL::DB::ORM;
169 using namespace DPL::DB::ORM::wrt;
170 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
171 select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
172 Equals<WidgetPreference::key_name>(key)));
174 ORMWidgetPropertyValue ormPropValue =
175 select->GetSingleValue<WidgetPreference::key_value>();
177 WidgetPropertyValue propValue;
179 convertPropertyValue(ormPropValue, propValue);
183 Catch(DPL::DB::SqlConnection::Exception::Base){
184 ReThrowMsg(Exception::DatabaseError,
185 "Failure during getting property");
188 } // namespace PropertyDAOReadOnly