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 <soci/soci.h>
40 #include <string>
41 #include <cstdint>
42 #include <vector>
43 
44 namespace sqlite_api {
45  struct sqlite3;
46 }
47 
48 namespace ripple {
49 
50 template <class T, class C>
52 {
53  if ((c > std::numeric_limits<T>::max ()) ||
58  {
59  JLOG (debugLog().error()) << "rangeCheckedCast domain error:"
60  << " value = " << c
61  << " min = " << std::numeric_limits<T>::lowest ()
62  << " max: " << std::numeric_limits<T>::max ();
63  }
64 
65  return static_cast<T>(c);
66 }
67 
68 class BasicConfig;
69 
76 {
78  soci::backend_factory const& backendFactory_;
80 
81 public:
82  SociConfig(BasicConfig const& config,
83  std::string const& dbName);
85  void open (soci::session& s) const;
86 };
87 
100 void open (soci::session& s,
101  BasicConfig const& config,
102  std::string const& dbName);
103 
113 void open (soci::session& s,
114  std::string const& beName,
115  std::string const& connectionString);
116 
117 size_t getKBUsedAll (soci::session& s);
118 size_t getKBUsedDB (soci::session& s);
119 
120 void convert (soci::blob& from, std::vector<std::uint8_t>& to);
121 void convert (soci::blob& from, std::string& to);
122 void convert (std::vector<std::uint8_t> const& from, soci::blob& to);
123 void convert (std::string const& from, soci::blob& to);
124 
126 {
127  public:
128  virtual ~Checkpointer() = default;
129 };
130 
138 
139 } // ripple
140 
141 #if defined(__clang__)
142 #pragma clang diagnostic pop
143 #endif
144 
145 #endif
ripple::SociConfig
SociConfig is used when a client wants to delay opening a soci::session after parsing the config para...
Definition: SociDB.h:75
std::string
STL class.
ripple::Logs
Manages partitions for logging.
Definition: Log.h:49
ripple::getKBUsedDB
size_t getKBUsedDB(soci::session &s)
Definition: SociDB.cpp:136
ripple::getKBUsedAll
size_t getKBUsedAll(soci::session &s)
Definition: SociDB.cpp:129
sqlite_api
Definition: SociDB.h:44
std::pair
ripple::rangeCheckedCast
T rangeCheckedCast(C c)
Definition: SociDB.h:51
ripple::convert
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
Definition: SociDB.cpp:150
vector
ripple::debugLog
beast::Journal debugLog()
Returns a debug journal.
Definition: Log.cpp:417
std::numeric_limits::lowest
T lowest(T... args)
ripple::Checkpointer
Definition: SociDB.h:125
ripple::Checkpointer::~Checkpointer
virtual ~Checkpointer()=default
ripple::makeCheckpointer
std::unique_ptr< Checkpointer > makeCheckpointer(soci::session &session, JobQueue &queue, Logs &logs)
Returns a new checkpointer which makes checkpoints of a soci database every checkpointPageCount pages...
Definition: SociDB.cpp:269
cstdint
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:56
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:93
ripple::SociConfig::backendFactory_
soci::backend_factory const & backendFactory_
Definition: SociDB.h:78
ripple::SociConfig::connectionString_
std::string connectionString_
Definition: SociDB.h:77
ripple::SociConfig::connectionString
std::string connectionString() const
Definition: SociDB.cpp:88
std::numeric_limits::max
T max(T... args)
std::unique_ptr
STL class.
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:177
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:98
string