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 * This file contains the declaration of custom handler dao class.
19 * @file custom_handler_dao_read_only.cpp
20 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 * @brief This file contains the declaration of custom handler dao
25 #include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
26 #include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
28 #include <orm_generator_custom_handler.h>
30 using namespace DPL::DB::ORM;
31 using namespace DPL::DB::ORM::custom_handler;
33 namespace CustomHandlerDB {
36 CustomHandlerPtr getSingleHandler(std::list<T> row)
38 CustomHandlerPtr handler;
40 // There should be only one
42 ThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
43 "More than one handler registered");
46 handler.reset(new CustomHandler());
47 handler->target = row.front().Get_target();
48 handler->base_url = row.front().Get_base_url();
49 handler->url = row.front().Get_url();
50 handler->title = row.front().Get_title();
51 handler->user_decision =
52 static_cast<HandlerState>(row.front().Get_user_allowed());
58 CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName)
63 CustomHandlerDAOReadOnly::~CustomHandlerDAOReadOnly()
66 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
67 const DPL::String& protocol,
68 const DPL::String& url)
70 WrtLogD("Getting protocol handler");
72 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
74 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
75 And(Equals<ProtocolHandlers::target>(protocol),
76 Equals<ProtocolHandlers::url>(url))));
78 std::list<ProtocolHandlers::Row> list = select->GetRowList();
79 return getSingleHandler(list);
80 } Catch(DPL::DB::SqlConnection::Exception::Base) {
81 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
82 "Failed to get protocol handler");
86 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
87 const DPL::String& content,
88 const DPL::String& url)
90 WrtLogD("Getting content handler");
92 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
94 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
95 And(Equals<ContentHandlers::target>(content),
96 Equals<ContentHandlers::url>(url))));
98 std::list<ContentHandlers::Row> list = select->GetRowList();
99 return getSingleHandler(list);
100 } Catch(DPL::DB::SqlConnection::Exception::Base) {
101 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
102 "Failed to get content handler");
106 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivProtocolHandler(
107 const DPL::String& protocol)
109 WrtLogD("Getting active protocol handler");
111 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
113 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
114 Equals<ProtocolHandlers::target>(protocol)));
116 std::list<ProtocolHandlers::Row> list = select->GetRowList();
117 CustomHandlerPtr handler;
120 if (it->Get_user_allowed() & Agreed) {
121 handler.reset(new CustomHandler());
122 handler->base_url = it->Get_base_url();
123 handler->target = it->Get_target();
124 handler->title = it->Get_title();
125 handler->url = it->Get_url();
126 handler->user_decision =
127 static_cast<HandlerState>(it->Get_user_allowed());
131 } Catch(DPL::DB::SqlConnection::Exception::Base) {
132 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
133 "Failed to get protocol handler");
137 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
138 const DPL::String& protocol,
139 const DPL::String& url,
140 const DPL::String& baseURL)
142 WrtLogD("Check if protocol is registered");
144 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
146 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
147 And(Equals<ProtocolHandlers::target>(protocol),
148 And(Equals<ProtocolHandlers::url>(url),
149 Equals<ProtocolHandlers::base_url>(baseURL)
155 std::list<ProtocolHandlers::Row> list = select->GetRowList();
156 return getSingleHandler(list);
157 } Catch(DPL::DB::SqlConnection::Exception::Base) {
158 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
159 "Failed to get content handler");
163 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivContentHandler(
164 const DPL::String& content)
166 WrtLogD("Getting active content handler");
168 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
170 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
171 Equals<ContentHandlers::target>(content)));
173 std::list<ContentHandlers::Row> list = select->GetRowList();
174 CustomHandlerPtr handler;
177 if (it->Get_user_allowed() & Agreed) {
178 handler.reset(new CustomHandler());
179 handler->base_url = it->Get_base_url();
180 handler->target = it->Get_target();
181 handler->title = it->Get_title();
182 handler->url = it->Get_url();
183 handler->user_decision =
184 static_cast<HandlerState>(it->Get_user_allowed());
188 } Catch(DPL::DB::SqlConnection::Exception::Base) {
189 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
190 "Failed to get protocol handler");
194 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
195 const DPL::String& content,
196 const DPL::String& url,
197 const DPL::String& baseURL)
199 WrtLogD("Check if content is registered");
201 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
203 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
204 And(Equals<ContentHandlers::target>(content),
205 And(Equals<ContentHandlers::url>(url),
206 Equals<ContentHandlers::base_url>(baseURL)))));
208 std::list<ContentHandlers::Row> list = select->GetRowList();
209 return getSingleHandler(list);
210 } Catch(DPL::DB::SqlConnection::Exception::Base) {
211 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
212 "Failed to get content handler");
215 } // namespace CustomHandlerDB