2 * Copyright (c) 2012 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 * @file custom_handler_dao.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
20 * @brief This file contains the definition of custom handler dao class.
23 #include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
24 #include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
25 #include <orm_generator_custom_handler.h>
27 using namespace DPL::DB::ORM;
28 using namespace DPL::DB::ORM::custom_handler;
30 namespace CustomHandlerDB {
35 void fillRow(T& row, const CustomHandler& handler, const DPL::String& pkgName)
37 row.Set_app_id(pkgName);
38 row.Set_target(handler.target);
39 row.Set_base_url(handler.base_url);
40 row.Set_url(handler.url);
41 row.Set_title(handler.title);
42 row.Set_user_allowed(handler.user_allowed);
47 CustomHandlerDAO::CustomHandlerDAO(const DPL::String& pkgName) :
48 CustomHandlerDAOReadOnly(pkgName)
52 CustomHandlerDAO::~CustomHandlerDAO()
56 void CustomHandlerDAO::registerContentHandler(const CustomHandler& handler)
58 LogDebug("Registering content handler " << handler.target << " " <<
61 ContentHandlers::Row row;
62 fillRow(row, handler, m_pkgName);
64 // TODO remove previous if necessary
65 CUSTOM_HANDLER_DB_INSERT(insert, ContentHandlers);
69 Catch(DPL::DB::SqlConnection::Exception::Base){
70 ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
71 "Failed to register custom handler");
75 void CustomHandlerDAO::registerProtocolHandler(const CustomHandler& handler)
77 LogDebug("Registering protocol handler " << handler.target << " " <<
80 ProtocolHandlers::Row row;
81 fillRow(row, handler, m_pkgName);
83 // TODO remove previous if necessary
84 CUSTOM_HANDLER_DB_INSERT(insert, ProtocolHandlers);
88 Catch(DPL::DB::SqlConnection::Exception::Base){
89 ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
90 "Failed to register custom handler");
94 void CustomHandlerDAO::unregisterContentHandler(const DPL::String& target,
95 const DPL::String& url)
97 LogDebug("Removing content handler " << target << " " << url);
99 CUSTOM_HANDLER_DB_DELETE(deleteFrom, ContentHandlers);
100 deleteFrom->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
101 And(Equals<ContentHandlers::target>(target),
102 Equals<ContentHandlers::url>(url))));
103 deleteFrom->Execute();
105 Catch(DPL::DB::SqlConnection::Exception::Base) {
106 ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
107 "Failed to remove content handler");
111 void CustomHandlerDAO::unregisterProtocolHandler(const DPL::String& target,
112 const DPL::String& url)
114 LogDebug("Removing protocol handler " << target << " " << url);
116 CUSTOM_HANDLER_DB_DELETE(deleteFrom, ProtocolHandlers);
117 deleteFrom->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
118 And(Equals<ProtocolHandlers::target>(target),
119 Equals<ProtocolHandlers::url>(url))));
120 deleteFrom->Execute();
122 Catch(DPL::DB::SqlConnection::Exception::Base) {
123 ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
124 "Failed to remove content handler");
129 } // namespace CustomHandlerDB