Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / widget_dao / dao / WrtDatabase.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 #include <stddef.h>
17 #include <dpl/wrt-dao-ro/WrtDatabase.h>
18
19 #include <dpl/db/thread_database_support.h>
20 #include <dpl/db/sql_connection.h>
21 #include <dpl/mutex.h>
22 #include <dpl/thread.h>
23 #include <dpl/wrt-dao-ro/global_config.h>
24
25 namespace WrtDB {
26 const char* WrtDatabase::Address()
27 {
28     using namespace WrtDB;
29     return GlobalConfig::GetWrtDatabaseFilePath();
30 }
31
32 DPL::DB::SqlConnection::Flag::Type WrtDatabase::Flags()
33 {
34     return DPL::DB::SqlConnection::Flag::UseLucene;
35 }
36
37 DPL::DB::ThreadDatabaseSupport WrtDatabase::m_interface(
38     WrtDatabase::Address(),
39     WrtDatabase::Flags());
40
41 void WrtDatabase::attachToThreadRO()
42 {
43     m_interface.AttachToThread(DPL::DB::SqlConnection::Flag::RO);
44 }
45
46 void WrtDatabase::attachToThreadRW()
47 {
48     m_interface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
49 }
50
51 void WrtDatabase::detachFromThread()
52 {
53     m_interface.DetachFromThread();
54 }
55
56 DPL::DB::ThreadDatabaseSupport& WrtDatabase::interface()
57 {
58     return m_interface;
59 }
60
61 bool WrtDatabase::CheckTableExist(const char *name)
62 {
63     return m_interface.CheckTableExist(name);
64 }
65 }