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/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 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);
78 WidgetPreferenceList GetPropertyListRows(DbWidgetHandle widgetHandle)
81 using namespace DPL::DB::ORM;
82 using namespace DPL::DB::ORM::wrt;
83 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
84 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
85 ORMWidgetPreferenceList ormPrefList = select->GetRowList();
86 WidgetPreferenceList prefList;
87 convertWidgetPreferenceRow(ormPrefList, prefList);
89 }Catch(DPL::DB::SqlConnection::Exception::Base){
90 ReThrowMsg(Exception::DatabaseError,
91 "Failure during getting property list");
97 DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle,
98 const WidgetPropertyKey &key)
100 return CheckPropertyReadFlag(WidgetDAOReadOnly::getTizenAppId(widgetHandle),
104 DPL::OptionalInt CheckPropertyReadFlag(TizenAppId tzAppid,
105 const WidgetPropertyKey &key)
107 WrtLogD("Checking Property flag. appid: %ls, key: %ls",
108 tzAppid.c_str(), key.c_str());
111 using namespace DPL::DB::ORM;
112 using namespace DPL::DB::ORM::wrt;
114 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
116 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
117 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
118 Equals<WidgetPreference::key_name>(key)));
120 return select->GetSingleValue<WidgetPreference::readonly>();
122 Catch(DPL::DB::SqlConnection::Exception::Base){
123 ReThrowMsg(Exception::DatabaseError,
124 "Failure during checking readonly flag for property");
128 WidgetPropertyKeyList GetPropertyKeyList(TizenAppId tzAppid)
130 WrtLogD("Get PropertyKey list. appid: %ls", tzAppid.c_str());
132 using namespace DPL::DB::ORM;
133 using namespace DPL::DB::ORM::wrt;
135 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
137 ORMWidgetPropertyKeyList keyList;
138 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
139 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
140 keyList = select->GetValueList<WidgetPreference::key_name>();
142 WidgetPropertyKeyList retKeyList;
144 convertWidgetPropertyKeyList(keyList, retKeyList);
147 Catch(DPL::DB::SqlConnection::Exception::Base){
148 ReThrowMsg(Exception::DatabaseError,
149 "Failure during getting propertykey list");
153 WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle)
155 if(!(WidgetDAOReadOnly::isWidgetInstalled(widgetHandle)))
156 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
157 "Failed to get widget");
158 return GetPropertyListRows(widgetHandle);
161 WidgetPreferenceList GetPropertyList(TizenAppId tzAppId)
163 WrtLogD("Get Property list. tizenAppId: %ls", tzAppId.c_str());
164 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppId));
165 return GetPropertyListRows(widgetHandle);
169 WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid,
170 const WidgetPropertyKey &key)
172 WrtLogD("Get Property value. appid: %ls, key: %ls",
173 tzAppid.c_str(), key.c_str());
175 using namespace DPL::DB::ORM;
176 using namespace DPL::DB::ORM::wrt;
178 DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
180 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
181 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
182 Equals<WidgetPreference::key_name>(key)));
184 ORMWidgetPropertyValue ormPropValue =
185 select->GetSingleValue<WidgetPreference::key_value>();
187 WidgetPropertyValue propValue;
189 convertPropertyValue(ormPropValue, propValue);
193 Catch(DPL::DB::SqlConnection::Exception::Base){
194 ReThrowMsg(Exception::DatabaseError,
195 "Failure during getting property");
198 } // namespace PropertyDAOReadOnly