rippled
SociDB.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2015 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_SOCIDB_H_INCLUDED
21 #define RIPPLE_SOCIDB_H_INCLUDED
22 
31 #if defined(__clang__)
32 #pragma clang diagnostic push
33 #pragma clang diagnostic ignored "-Wdeprecated"
34 #endif
35 
36 #include <ripple/basics/Log.h>
37 #include <ripple/core/JobQueue.h>
38 #define SOCI_USE_BOOST
39 #include <cstdint>
40 #include <soci/soci.h>
41 #include <string>
42 #include <vector>
43 
44 namespace sqlite_api {
45 struct sqlite3;
46 }
47 
48 namespace ripple {
49 
50 class BasicConfig;
51 
57 class DBConfig
58 {
60  explicit DBConfig(std::string const& dbPath);
61 
62 public:
63  DBConfig(BasicConfig const& config, std::string const& dbName);
65  connectionString() const;
66  void
67  open(soci::session& s) const;
68 };
69 
82 void
83 open(soci::session& s, BasicConfig const& config, std::string const& dbName);
84 
94 void
95 open(
96  soci::session& s,
97  std::string const& beName,
98  std::string const& connectionString);
99 
101 getKBUsedAll(soci::session& s);
103 getKBUsedDB(soci::session& s);
104 
105 void
106 convert(soci::blob& from, std::vector<std::uint8_t>& to);
107 void
108 convert(soci::blob& from, std::string& to);
109 void
110 convert(std::vector<std::uint8_t> const& from, soci::blob& to);
111 void
112 convert(std::string const& from, soci::blob& to);
113 
114 class Checkpointer : public std::enable_shared_from_this<Checkpointer>
115 {
116 public:
117  virtual std::uintptr_t
118  id() const = 0;
119  virtual ~Checkpointer() = default;
120 
121  virtual void
122  schedule() = 0;
123 
124  virtual void
125  checkpoint() = 0;
126 };
127 
136  std::uintptr_t id,
138  JobQueue&,
139  Logs&);
140 
141 } // namespace ripple
142 
143 #if defined(__clang__)
144 #pragma clang diagnostic pop
145 #endif
146 
147 #endif
std::string
STL class.
std::shared_ptr
STL class.
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
sqlite_api
Definition: SociDB.h:44
ripple::DBConfig::connectionString
std::string connectionString() const
Definition: SociDB.cpp:86
ripple::Checkpointer::checkpoint
virtual void checkpoint()=0
ripple::convert
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
Definition: SociDB.cpp:154
ripple::DBConfig::open
void open(soci::session &s) const
Definition: SociDB.cpp:92
vector
ripple::getKBUsedDB
std::uint32_t getKBUsedDB(soci::session &s)
Definition: SociDB.cpp:139
ripple::DBConfig
DBConfig is used when a client wants to delay opening a soci::session after parsing the config parame...
Definition: SociDB.h:57
ripple::Checkpointer
Definition: SociDB.h:114
ripple::Checkpointer::schedule
virtual void schedule()=0
ripple::Checkpointer::~Checkpointer
virtual ~Checkpointer()=default
ripple::getKBUsedAll
std::uint32_t getKBUsedAll(soci::session &s)
Definition: SociDB.cpp:130
std::enable_shared_from_this
ripple::Checkpointer::id
virtual std::uintptr_t id() const =0
cstdint
ripple::DBConfig::DBConfig
DBConfig(std::string const &dbPath)
Definition: SociDB.cpp:76
std::uint32_t
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
std::weak_ptr
STL class.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:215
ripple::makeCheckpointer
std::shared_ptr< Checkpointer > makeCheckpointer(std::uintptr_t id, std::weak_ptr< soci::session > session, JobQueue &queue, Logs &logs)
Returns a new checkpointer which makes checkpoints of a soci database every checkpointPageCount pages...
Definition: SociDB.cpp:333
ripple::DBConfig::connectionString_
std::string connectionString_
Definition: SociDB.h:59
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:98
string