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/log/log.h>
25 #include <dpl/foreach.h>
26 #include <dpl/wrt-dao-ro/webruntime_database.h>
27 #include <dpl/wrt-dao-ro/WrtDatabase.h>
28 #include <orm_generator_wrt.h>
31 namespace PropertyDAOReadOnly {
35 typedef DPL::DB::ORM::wrt::WidgetPreference::key_name::ColumnType
37 typedef DPL::DB::ORM::wrt::WidgetPreference::key_value::ColumnType
38 ORMWidgetPropertyValue;
39 typedef std::list<DPL::DB::ORM::wrt::WidgetPreference::Row> ORMWidgetPreferenceList;
40 typedef std::list<WidgetPropertyKey> ORMWidgetPropertyKeyList;
43 void convertPropertyKey(const ORMWidgetPropertyKey& ormKey,
44 WidgetPropertyKey& key)
49 void convertPropertyValue(const ORMWidgetPropertyValue& ormPropertyVal,
50 WidgetPropertyValue& propertyVal)
52 propertyVal = ormPropertyVal;
55 void convertWidgetPreferenceRow(const ORMWidgetPreferenceList& ormWidgetPrefRow,
56 WidgetPreferenceList& prefRow)
58 FOREACH(it, ormWidgetPrefRow) {
59 WidgetPreferenceRow row;
61 row.app_id = it->Get_app_id();
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);
81 WidgetPropertyKeyList GetPropertyKeyList(DbWidgetHandle widgetHandle)
83 LogDebug("Get PropertyKey list. Handle: " << widgetHandle);
85 using namespace DPL::DB::ORM;
86 using namespace DPL::DB::ORM::wrt;
87 ORMWidgetPropertyKeyList keyList;
88 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
89 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
90 keyList = select->GetValueList<WidgetPreference::key_name>();
92 WidgetPropertyKeyList retKeyList;
94 convertWidgetPropertyKeyList(keyList, retKeyList);
97 Catch(DPL::DB::SqlConnection::Exception::Base){
98 ReThrowMsg(Exception::DatabaseError,
99 "Failure during getting propertykey list");
103 WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle)
105 LogDebug("Get Property list. Handle: " << widgetHandle);
107 using namespace DPL::DB::ORM;
108 using namespace DPL::DB::ORM::wrt;
109 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
110 select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
112 ORMWidgetPreferenceList ormPrefList = select->GetRowList();
113 WidgetPreferenceList prefList;
114 convertWidgetPreferenceRow(ormPrefList, prefList);
118 Catch(DPL::DB::SqlConnection::Exception::Base){
119 ReThrowMsg(Exception::DatabaseError,
120 "Failure during getting property list");
124 WidgetPropertyValue GetPropertyValue(DbWidgetHandle widgetHandle,
125 const WidgetPropertyKey &key)
127 LogDebug("Get Property value. Handle: " << widgetHandle <<
130 using namespace DPL::DB::ORM;
131 using namespace DPL::DB::ORM::wrt;
132 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
133 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
134 Equals<WidgetPreference::key_name>(key)));
136 ORMWidgetPropertyValue ormPropValue =
137 select->GetSingleValue<WidgetPreference::key_value>();
139 WidgetPropertyValue propValue;
141 convertPropertyValue(ormPropValue, propValue);
145 Catch(DPL::DB::SqlConnection::Exception::Base){
146 ReThrowMsg(Exception::DatabaseError,
147 "Failure during getting property");
151 DPL::OptionalInt CheckPropertyReadFlag(DbWidgetHandle widgetHandle,
152 const WidgetPropertyKey &key)
154 LogDebug("Checking Property flag. Handle: " << widgetHandle <<
157 using namespace DPL::DB::ORM;
158 using namespace DPL::DB::ORM::wrt;
159 WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
160 select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
161 Equals<WidgetPreference::key_name>(key)));
163 return select->GetSingleValue<WidgetPreference::readonly>();
165 Catch(DPL::DB::SqlConnection::Exception::Base){
166 ReThrowMsg(Exception::DatabaseError,
167 "Failure during checking readonly flag for property");
171 } // namespace PropertyDAOReadOnly