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 {
36 typedef DPL::DB::ORM::wrt::WidgetPreference::key_name::ColumnType
38 typedef DPL::DB::ORM::wrt::WidgetPreference::key_value::ColumnType
39 ORMWidgetPropertyValue;
40 typedef std::list<DPL::DB::ORM::wrt::WidgetPreference::Row> ORMWidgetPreferenceList;
41 typedef std::list<WidgetPropertyKey> ORMWidgetPropertyKeyList;
44 void convertPropertyKey(const ORMWidgetPropertyKey& ormKey,
45 WidgetPropertyKey& key)
50 void convertPropertyValue(const ORMWidgetPropertyValue& ormPropertyVal,
51 WidgetPropertyValue& propertyVal)
53 propertyVal = ormPropertyVal;
56 void convertWidgetPreferenceRow(const ORMWidgetPreferenceList& ormWidgetPrefRow,
57 WidgetPreferenceList& prefRow)
59 FOREACH(it, ormWidgetPrefRow) {
60 WidgetPreferenceRow row;
62 row.tizen_appid = it->Get_tizen_appid();
63 row.key_name = it->Get_key_name();
64 row.key_value = it->Get_key_value();
65 row.readonly = it->Get_readonly();
67 prefRow.push_back(row);
71 void convertWidgetPropertyKeyList(const ORMWidgetPropertyKeyList& propKeyList,
72 WidgetPropertyKeyList& keyList)
74 FOREACH(it, propKeyList) {
75 keyList.push_back(*it);
83 DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle,
84 const WidgetPropertyKey &key)
86 return CheckPropertyReadFlag(WidgetDAOReadOnly::getTzAppId(widgetHandle),
90 DPL::OptionalInt CheckPropertyReadFlag(TizenAppId tzAppid,
91 const WidgetPropertyKey &key)
93 LogDebug("Checking Property flag. appid: " << tzAppid <<
97 using namespace DPL::DB::ORM;
98 using namespace DPL::DB::ORM::wrt;
99 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
100 select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
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;
117 ORMWidgetPropertyKeyList keyList;
118 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
119 select->Where(Equals<WidgetPreference::tizen_appid>(tzAppid));
120 keyList = select->GetValueList<WidgetPreference::key_name>();
122 WidgetPropertyKeyList retKeyList;
124 convertWidgetPropertyKeyList(keyList, retKeyList);
127 Catch(DPL::DB::SqlConnection::Exception::Base){
128 ReThrowMsg(Exception::DatabaseError,
129 "Failure during getting propertykey list");
134 WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle)
137 TizenAppId tzAppid = WidgetDAOReadOnly::getTzAppId(widgetHandle);
138 return GetPropertyList(tzAppid);
139 }Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){
140 WidgetPreferenceList empty;
145 WidgetPreferenceList GetPropertyList(TizenAppId tzAppId)
147 LogDebug("Get Property list. tizenAppId: " << tzAppId);
149 using namespace DPL::DB::ORM;
150 using namespace DPL::DB::ORM::wrt;
151 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
152 select->Where(Equals<WidgetPreference::tizen_appid>(tzAppId));
154 ORMWidgetPreferenceList ormPrefList = select->GetRowList();
155 WidgetPreferenceList prefList;
156 convertWidgetPreferenceRow(ormPrefList, prefList);
160 Catch(DPL::DB::SqlConnection::Exception::Base){
161 ReThrowMsg(Exception::DatabaseError,
162 "Failure during getting property list");
166 WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid,
167 const WidgetPropertyKey &key)
169 LogDebug("Get Property value. appid: " << tzAppid <<
172 using namespace DPL::DB::ORM;
173 using namespace DPL::DB::ORM::wrt;
174 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
175 select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
176 Equals<WidgetPreference::key_name>(key)));
178 ORMWidgetPropertyValue ormPropValue =
179 select->GetSingleValue<WidgetPreference::key_value>();
181 WidgetPropertyValue propValue;
183 convertPropertyValue(ormPropValue, propValue);
187 Catch(DPL::DB::SqlConnection::Exception::Base){
188 ReThrowMsg(Exception::DatabaseError,
189 "Failure during getting property");
193 } // namespace PropertyDAOReadOnly