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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
*
* 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.
*
*
*/
#ifndef SQLSTORAGE_H
#define SQLSTORAGE_H
#include <boost/date_time.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <string>
#include <core/Config/Config.h>
#include "StorageService.h"
#include "Session.h"
namespace tizen_browser
{
namespace Session
{
class SqlStorage
{
/**
* Singleton, protect against being created in wrong place.
*/
SqlStorage();
/**
* Initialise SqlStorage.
*
* Checks if all needed tables are created and if not creates them.
*
* Returns true if there is no error.
*/
bool init();
public:
~SqlStorage();
static SqlStorage* getInstance();
Session createSession(const std::string& name = "");
/**
* Return newes session in storage.
*/
Session getLastSession();
///\todo implement getSession(name); if needed.
//Session getSession(const std::string& name);
SessionsVector getAllSessions();
/**
* Get title of a tab.
*/
std::string getUrlTitle(const std::string& url);
/**
* Store/update all items in storage
*/
void updateSession(tizen_browser::Session::Session& session);
/**
* Update ony one item form session.
*/
void updateSession(tizen_browser::Session::Session& session, const std::string& itemId);
/**
* Updates session last update time.
*/
void updateSessionTimeStamp(tizen_browser::Session::Session& session, boost::posix_time::ptime accessTime = boost::posix_time::second_clock::local_time());
/**
* Change session name.
*/
void updateSessionName(tizen_browser::Session::Session& session, const std::string& newName);
/**
* Deletes item form session, and stores changes.
*/
void removeItem(tizen_browser::Session::Session& sessionToDelFrom, const std::string& itemId);
/**
* \brief Delete session form storage.
*/
void deleteSession(Session& session);
/**
* Delete all sessions in storage.
*/
void deleteAllSessions();
private:
bool initSessionDatabase();
void updateSessionTimeStamp(tizen_browser::Session::Session& session,
const boost::posix_time::ptime& accessTime,
std::shared_ptr<storage::SQLDatabase> connection);
void clearSession(const Session& session, std::shared_ptr<storage::SQLDatabase> connection);
void updateSession(tizen_browser::Session::Session& session,
const std::string& itemId,
std::shared_ptr<storage::SQLDatabase> connection);
void readSession(Session& session, std::shared_ptr<storage::SQLDatabase> connection);
bool m_isInitialized;
config::DefaultConfig config;
std::string m_dbString;
};
}//end namespace Session
}//end namespace tizen_browser
#endif // SQLSTORAGE_H
|