-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathSessionBase.h
More file actions
103 lines (82 loc) · 3.23 KB
/
SessionBase.h
File metadata and controls
103 lines (82 loc) · 3.23 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/************************************************************************
* Copyright(c) 2010, One Unified. All rights reserved. *
* email: info@oneunified.net *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
// inherited by ISqlite3 and IPostgresql for specialization
#pragma once
#include <string>
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
#include "Constants.h"
namespace ou {
namespace db {
template<class S, class T> // S Session variable (ou::db::CSession), T class for CRTP operations
class SessionBase {
public:
SessionBase();
virtual ~SessionBase();
void Open( const std::string& sDbFileName, enumOpenFlags = EOpenFlagsZero );
void Close();
bool IsOpen() const { return m_bOpened; }
protected:
bool m_bOpened;
std::string m_sDbFileName;
void InitializeManagers() {}; // null placeholder
void RegisterRowDefinitions() {}; // null placeholder
void RegisterTablesForCreation() {}; // null placeholder
void PopulateTables() {}; // null placeholder
void DenitializeManagers() {}; // null placeholder
private:
};
template<class S, class T>
SessionBase<S,T>::SessionBase()
: m_bOpened( false )
{
// static_cast<T*>( this )->Initialize();
}
template<class S, class T>
SessionBase<S,T>::~SessionBase() {
Close();
// static_cast<T*>( this )->Denitialize();
}
template<class S, class T>
void SessionBase<S,T>::Open( const std::string& sDbFileName, enumOpenFlags flags ) {
if ( !m_bOpened ) {
if ( boost::filesystem::exists( sDbFileName ) ) {
// open already created and loaded database
dynamic_cast<S*>( this )->ImplOpen( sDbFileName, flags );
static_cast<T*>( this )->InitializeManagers();
static_cast<T*>( this )->RegisterRowDefinitions();
static_cast<T*>( this )->LoadTables();
}
else {
// create and build new database
dynamic_cast<S*>( this )->ImplOpen( sDbFileName, EOpenFlagsAutoCreate );
static_cast<T*>( this )->InitializeManagers();
static_cast<T*>( this )->RegisterTablesForCreation();
dynamic_cast<S*>( this )->CreateTables();
static_cast<T*>( this )->RegisterRowDefinitions();
static_cast<T*>( this )->PopulateTables();
}
m_bOpened = true;
}
}
template<class S, class T>
void SessionBase<S,T>::Close() {
if ( m_bOpened ) {
m_bOpened = false;
static_cast<T*>( this )->DenitializeManagers();
dynamic_cast<S*>( this )->ImplClose();
}
}
} // db
} // ou