summaryrefslogtreecommitdiff
path: root/vcore/src/vcore/Database.h
blob: f4a5d17682c69427785732f16fa7a28ed9822403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
/*
 * @file    webruntime_database.h
 * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
 * @version 1.0
 * @brief   This file contains the declaration of webruntime database
 */
#ifndef VCORE_SRC_VCORE_DATABASE_H
#define VCORE_SRC_VCORE_DATABASE_H

#include <dpl/db/thread_database_support.h>
#include <dpl/db/sql_connection.h>
#include <dpl/thread.h>
#include <mutex>

extern std::mutex g_vcoreDbQueriesMutex;

#define VCORE_DB_INTERNAL(tlsCommand, InternalType, interface)               \
    static VcoreDPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
    {                                                                        \
        std::lock_guard<std::mutex> lock(g_vcoreDbQueriesMutex);             \
        if (!tlsCommand ## Ptr) {                                            \
            static VcoreDPL::ThreadLocalVariable<InternalType> tmp;          \
            tlsCommand ## Ptr = &tmp;                                        \
        }                                                                    \
    }                                                                        \
    VcoreDPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand ## Ptr; \
    if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }

#define VCORE_DB_SELECT(name, type, interface) \
    VCORE_DB_INTERNAL(name, type::Select, interface)

#define VCORE_DB_INSERT(name, type, interface) \
    VCORE_DB_INTERNAL(name, type::Insert, interface)

#define VCORE_DB_UPDATE(name, type, interface) \
    VCORE_DB_INTERNAL(name, type::Update, interface)

#define VCORE_DB_DELETE(name, type, interface) \
    VCORE_DB_INTERNAL(name, type::Delete, interface)

#endif // define VCORE_SRC_VCORE_DATABASE_H