Source code formating unification
[framework/web/wrt-commons.git] / modules / auto_save_dao / dao / auto_save_dao_read_only.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * This file contains the declaration of auto save dao class.
18  *
19  * @file    auto_save_dao_read_only.cpp
20  * @author  Jihoon Chung (jihoon.chung@samsung.com)
21  * @version 1.0
22  * @brief   This file contains the declaration of auto save dao
23  */
24 #include <stddef.h>
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>
29
30 using namespace DPL::DB::ORM;
31 using namespace DPL::DB::ORM::autosave;
32 using namespace AutoSaveDB::Interface;
33
34 namespace AutoSaveDB {
35 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN          Try
36
37 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message)   \
38     Catch(DPL::DB::SqlConnection::Exception::Base) {       \
39         LogError(message);                              \
40         ReThrowMsg(AutoSaveDAOReadOnly::Exception::DatabaseError, \
41                    message);                            \
42     }
43
44 AutoSaveDAOReadOnly::AutoSaveDAOReadOnly()
45 {}
46
47 AutoSaveDAOReadOnly::~AutoSaveDAOReadOnly()
48 {}
49
50 void AutoSaveDAOReadOnly::attachDatabaseRO(void)
51 {
52     m_autoSavedbInterface.AttachToThread(
53         DPL::DB::SqlConnection::Flag::RO);
54 }
55
56 void AutoSaveDAOReadOnly::detachDatabase(void)
57 {
58     m_autoSavedbInterface.DetachFromThread();
59 }
60
61 SubmitFormData AutoSaveDAOReadOnly::getAutoSaveSubmitFormData(
62     const DPL::String &url)
63 {
64     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
65     {
66         AUTOSAVE_DB_SELECT(select,
67                            AutoSaveSubmitFormElement,
68                            &m_autoSavedbInterface);
69         select->Where(Equals<AutoSaveSubmitFormElement::address>(url));
70         AutoSaveSubmitFormElement::Select::RowList rows = select->GetRowList();
71
72         SubmitFormData submitFormData;
73         FOREACH(it, rows) {
74             SubmitFormElement element;
75             element.key = it->Get_key();
76             element.value = it->Get_value();
77             submitFormData.push_back(element);
78         }
79         return submitFormData;
80     }
81     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get autosave data string")
82 }
83
84 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
85 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
86 } // namespace AutoSaveDB