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 auto save dao class.
19 * @file auto_save_dao_read_only.cpp
20 * @author Jihoon Chung (jihoon.chung@samsung.com)
22 * @brief This file contains the declaration of auto save dao
25 #include <wrt-commons/auto-save-dao-ro/auto_save_dao_read_only.h>
26 #include <wrt-commons/auto-save-dao/AutoSaveDatabase.h>
27 #include <orm_generator_autosave.h>
28 #include <dpl/foreach.h>
30 using namespace DPL::DB::ORM;
31 using namespace DPL::DB::ORM::autosave;
32 using namespace AutoSaveDB::Interface;
35 namespace AutoSaveDB {
37 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
39 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
40 Catch(DPL::DB::SqlConnection::Exception::Base) { \
42 ReThrowMsg(AutoSaveDAOReadOnly::Exception::DatabaseError, \
46 AutoSaveDAOReadOnly::AutoSaveDAOReadOnly()
50 AutoSaveDAOReadOnly::~AutoSaveDAOReadOnly()
54 void AutoSaveDAOReadOnly::attachDatabaseRO(void)
56 m_autoSavedbInterface.AttachToThread(
57 DPL::DB::SqlConnection::Flag::RO);
60 void AutoSaveDAOReadOnly::detachDatabase(void)
62 m_autoSavedbInterface.DetachFromThread();
65 SubmitFormData AutoSaveDAOReadOnly::getAutoSaveSubmitFormData(
66 const DPL::String &url)
68 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
70 AUTOSAVE_DB_SELECT(select, AutoSaveSubmitFormElement, &m_autoSavedbInterface);
71 select->Where(Equals<AutoSaveSubmitFormElement::address>(url));
72 AutoSaveSubmitFormElement::Select::RowList rows = select->GetRowList();
74 SubmitFormData submitFormData;
76 SubmitFormElement element;
77 element.key = it->Get_key();
78 element.value = it->Get_value();
79 submitFormData.push_back(element);
81 return submitFormData;
83 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get autosave data string")
86 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
87 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
89 } // namespace AutoSaveDB