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 * @file webruntime_database.h
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file contains the declaration of webruntime database
22 #ifndef VCORE_SRC_VCORE_DATABASE_H
23 #define VCORE_SRC_VCORE_DATABASE_H
25 #include <dpl/db/thread_database_support.h>
26 #include <dpl/db/sql_connection.h>
27 #include <dpl/mutex.h>
28 #include <dpl/thread.h>
30 struct VCoreDatabaseConnectionTraits
32 static const char *Address();
34 static DPL::DB::SqlConnection::Flag::Type Flags()
36 return DPL::DB::SqlConnection::Flag::UseLucene;
40 extern DPL::Mutex g_vcoreDbQueriesMutex;
42 #define VCORE_DB_INTERNAL(tlsCommand, InternalType, interface) \
43 static DPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
45 DPL::Mutex::ScopedLock lock(&g_vcoreDbQueriesMutex); \
46 if (!tlsCommand ## Ptr) { \
47 static DPL::ThreadLocalVariable<InternalType> tmp; \
48 tlsCommand ## Ptr = &tmp; \
51 DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand ## Ptr; \
52 if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }
54 #define VCORE_DB_SELECT(name, type, interface) \
55 VCORE_DB_INTERNAL(name, type::Select, interface)
57 #define VCORE_DB_INSERT(name, type, interface) \
58 VCORE_DB_INTERNAL(name, type::Insert, interface)
60 #define VCORE_DB_UPDATE(name, type, interface) \
61 VCORE_DB_INTERNAL(name, type::Update, interface)
63 #define VCORE_DB_DELETE(name, type, interface) \
64 VCORE_DB_INTERNAL(name, type::Delete, interface)
66 #endif // define VCORE_SRC_VCORE_DATABASE_H