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 template <class T, class C>
51 T
53 {
54  if ((c > std::numeric_limits<T>::max()) ||
59  {
60  JLOG(debugLog().error())
61  << "rangeCheckedCast domain error:"
62  << " value = " << c << " min = " << std::numeric_limits<T>::lowest()
63  << " max: " << std::numeric_limits<T>::max();
64  }
65 
66  return static_cast<T>(c);
67 }
68 
69 class BasicConfig;
70 
77 {
79  soci::backend_factory const& backendFactory_;
81 
82 public:
83  SociConfig(BasicConfig const& config, std::string const& dbName);
85  connectionString() const;
86  void
87  open(soci::session& s) const;
88 };
89 
102 void
103 open(soci::session& s, BasicConfig const& config, std::string const& dbName);
104 
114 void
115 open(
116  soci::session& s,
117  std::string const& beName,
118  std::string const& connectionString);
119 
120 size_t
121 getKBUsedAll(soci::session& s);
122 size_t
123 getKBUsedDB(soci::session& s);
124 
125 void
126 convert(soci::blob& from, std::vector<std::uint8_t>& to);
127 void
128 convert(soci::blob& from, std::string& to);
129 void
130 convert(std::vector<std::uint8_t> const& from, soci::blob& to);
131 void
132 convert(std::string const& from, soci::blob& to);
133 
134 class Checkpointer : public std::enable_shared_from_this<Checkpointer>
135 {
136 public:
137  virtual std::uintptr_t
138  id() const = 0;
139  virtual ~Checkpointer() = default;
140 
141  virtual void
142  schedule() = 0;
143 
144  virtual void
145  checkpoint() = 0;
146 };
147 
156  std::uintptr_t id,
158  JobQueue&,
159  Logs&);
160 
161 } // namespace ripple
162 
163 #if defined(__clang__)
164 #pragma clang diagnostic pop
165 #endif
166 
167 #endif
ripple::SociConfig
SociConfig is used when a client wants to delay opening a soci::session after parsing the config para...
Definition: SociDB.h:76
std::string
STL class.
std::shared_ptr
STL class.
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
ripple::getKBUsedDB
size_t getKBUsedDB(soci::session &s)
Definition: SociDB.cpp:141
ripple::getKBUsedAll
size_t getKBUsedAll(soci::session &s)
Definition: SociDB.cpp:132
sqlite_api
Definition: SociDB.h:44
std::pair
ripple::rangeCheckedCast
T rangeCheckedCast(C c)
Definition: SociDB.h:52
ripple::Checkpointer::checkpoint
virtual void checkpoint()=0
ripple::convert
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
Definition: SociDB.cpp:156
vector
ripple::debugLog
beast::Journal debugLog()
Returns a debug journal.
Definition: Log.cpp:452
std::numeric_limits::lowest
T lowest(T... args)
ripple::Checkpointer
Definition: SociDB.h:134
ripple::Checkpointer::schedule
virtual void schedule()=0
ripple::Checkpointer::~Checkpointer
virtual ~Checkpointer()=default
std::enable_shared_from_this
ripple::Checkpointer::id
virtual std::uintptr_t id() const =0
cstdint
std::uintptr_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::SociConfig::open
void open(soci::session &s) const
Definition: SociDB.cpp:94
ripple::SociConfig::backendFactory_
soci::backend_factory const & backendFactory_
Definition: SociDB.h:79
ripple::SociConfig::connectionString_
std::string connectionString_
Definition: SociDB.h:78
ripple::SociConfig::connectionString
std::string connectionString() const
Definition: SociDB.cpp:88
std::numeric_limits::max
T max(T... args)
ripple::SociConfig::SociConfig
SociConfig(std::pair< std::string, soci::backend_factory const & > init)
Definition: SociDB.cpp:76
std::numeric_limits
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:178
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:335
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:100
string