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>
29 using namespace DPL::DB::ORM;
30 using namespace DPL::DB::ORM::autosave;
31 using namespace AutoSaveDB::Interface;
34 namespace AutoSaveDB {
36 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
38 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
39 Catch(DPL::DB::SqlConnection::Exception::Base) { \
41 ReThrowMsg(AutoSaveDAOReadOnly::Exception::DatabaseError, \
45 AutoSaveDAOReadOnly::AutoSaveDAOReadOnly()
49 AutoSaveDAOReadOnly::~AutoSaveDAOReadOnly()
53 void AutoSaveDAOReadOnly::attachDatabaseRO(void)
55 m_autoSavedbInterface.AttachToThread(
56 DPL::DB::SqlConnection::Flag::RO);
59 void AutoSaveDAOReadOnly::detachDatabase(void)
61 m_autoSavedbInterface.DetachFromThread();
64 DPL::Optional<AutoSaveData>
65 AutoSaveDAOReadOnly::getAutoSaveIdPasswd(const DPL::String &url)
67 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
69 AUTOSAVE_DB_SELECT(select, AutoSaveIdPasswd, &m_autoSavedbInterface);
70 select->Where(Equals<AutoSaveIdPasswd::address>(url));
71 AutoSaveIdPasswd::Select::RowList rows = select->GetRowList();
74 return DPL::Optional<AutoSaveData>::Null;
77 AutoSaveData saveData;
78 saveData.userId = rows.front().Get_userId();
79 saveData.passwd = rows.front().Get_passwd();
82 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get autosave data string")
85 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
86 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
88 } // namespace AutoSaveDB