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.appId = it->Get_app_id();
61 row.tizen_appid = it->Get_tizen_appid();
62 row.key_name = it->Get_key_name();
63 row.key_value = it->Get_key_value();
64 row.readonly = it->Get_readonly();
66 prefRow.push_back(row);
70 void convertWidgetPropertyKeyList(const ORMWidgetPropertyKeyList& propKeyList,
71 WidgetPropertyKeyList& keyList)
73 FOREACH(it, propKeyList) {
74 keyList.push_back(*it);
80 DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle,
81 const WidgetPropertyKey &key)
83 return CheckPropertyReadFlag(WidgetDAOReadOnly::getTzAppId(widgetHandle),
87 DPL::OptionalInt CheckPropertyReadFlag(TizenAppId tzAppid,
88 const WidgetPropertyKey &key)
90 LogDebug("Checking Property flag. appid: " << tzAppid <<
94 using namespace DPL::DB::ORM;
95 using namespace DPL::DB::ORM::wrt;
97 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
99 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
100 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
101 Equals<WidgetPreference::key_name>(key)));
103 return select->GetSingleValue<WidgetPreference::readonly>();
105 Catch(DPL::DB::SqlConnection::Exception::Base){
106 ReThrowMsg(Exception::DatabaseError,
107 "Failure during checking readonly flag for property");
111 WidgetPropertyKeyList GetPropertyKeyList(TizenAppId tzAppid)
113 LogDebug("Get PropertyKey list. appid: " << tzAppid);
115 using namespace DPL::DB::ORM;
116 using namespace DPL::DB::ORM::wrt;
118 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
120 ORMWidgetPropertyKeyList keyList;
121 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
122 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
123 keyList = select->GetValueList<WidgetPreference::key_name>();
125 WidgetPropertyKeyList retKeyList;
127 convertWidgetPropertyKeyList(keyList, retKeyList);
130 Catch(DPL::DB::SqlConnection::Exception::Base){
131 ReThrowMsg(Exception::DatabaseError,
132 "Failure during getting propertykey list");
137 WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle)
140 TizenAppId tzAppid = WidgetDAOReadOnly::getTzAppId(widgetHandle);
141 return GetPropertyList(tzAppid);
142 } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){
143 WidgetPreferenceList empty;
148 WidgetPreferenceList GetPropertyList(TizenAppId tzAppId)
150 LogDebug("Get Property list. tizenAppId: " << tzAppId);
152 using namespace DPL::DB::ORM;
153 using namespace DPL::DB::ORM::wrt;
155 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppId));
157 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
158 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
160 ORMWidgetPreferenceList ormPrefList = select->GetRowList();
161 WidgetPreferenceList prefList;
162 convertWidgetPreferenceRow(ormPrefList, prefList);
166 Catch(DPL::DB::SqlConnection::Exception::Base){
167 ReThrowMsg(Exception::DatabaseError,
168 "Failure during getting property list");
172 WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid,
173 const WidgetPropertyKey &key)
175 LogDebug("Get Property value. appid: " << tzAppid <<
178 using namespace DPL::DB::ORM;
179 using namespace DPL::DB::ORM::wrt;
181 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
183 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
184 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
185 Equals<WidgetPreference::key_name>(key)));
187 ORMWidgetPropertyValue ormPropValue =
188 select->GetSingleValue<WidgetPreference::key_value>();
190 WidgetPropertyValue propValue;
192 convertPropertyValue(ormPropValue, propValue);
196 Catch(DPL::DB::SqlConnection::Exception::Base){
197 ReThrowMsg(Exception::DatabaseError,
198 "Failure during getting property");
201 } // namespace PropertyDAOReadOnly