Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
cet::sqlite::Connection Class Reference

#include "/cvmfs/nova.opensciencegrid.org/externals/cetlib/v3_06_01/source/cetlib/sqlite/Connection.h"

Public Member Functions

 Connection ()=default
 
 ~Connection () noexcept
 
sqlite3 * get () const
 
 operator sqlite3 * ()
 
template<std::size_t NColumns, typename Row >
int flush_no_throw (std::vector< Row > const &buffer, sqlite3_stmt *&insertStmt)
 
 Connection (Connection const &)=delete
 
Connectionoperator= (Connection const &)=delete
 
 Connection (Connection &&) noexcept
 
Connectionoperator= (Connection &&) noexcept
 

Private Member Functions

template<typename DatabaseOpenPolicy >
 Connection (std::string const &file_name, std::shared_ptr< std::mutex > m, DatabaseOpenPolicy)
 

Private Attributes

sqlite3 * db_ {nullptr}
 
std::shared_ptr< std::mutex > m_
 

Friends

class ConnectionFactory
 

Detailed Description

Definition at line 31 of file Connection.h.

Constructor & Destructor Documentation

cet::sqlite::Connection::Connection ( )
explicitdefault

Referenced by operator sqlite3 *().

cet::sqlite::Connection::~Connection ( )
noexcept
cet::sqlite::Connection::Connection ( Connection const &  )
delete
cet::sqlite::Connection::Connection ( Connection &&  )
noexcept
template<typename DatabaseOpenPolicy >
cet::sqlite::Connection::Connection ( std::string const &  file_name,
std::shared_ptr< std::mutex >  m,
DatabaseOpenPolicy  policy 
)
explicitprivate

Definition at line 74 of file Connection.h.

References db_, and ConvertToSnowGlobesInput::file_name.

77  : m_{m}
78 {
79  // No lock necessary since the c'tor is called in a protected
80  // environment.
81  db_ = policy.open(file_name);
82 }
std::shared_ptr< std::mutex > m_
Definition: Connection.h:66

Member Function Documentation

template<std::size_t NColumns, typename Row >
int cet::sqlite::Connection::flush_no_throw ( std::vector< Row > const &  buffer,
sqlite3_stmt *&  insertStmt 
)

Definition at line 86 of file Connection.h.

References cet::sqlite::detail::bind_parameters< TUP, N >::bind(), db_, m_, r(), submit_cafana::rc, and levelDB2LMDB::txn.

Referenced by cet::sqlite::Ntuple< Args >::flush_no_throw(), and operator sqlite3 *().

88 {
89  // Guard against concurrent updates to the same database.
90  std::lock_guard<decltype((*m_))> hold{*m_};
91  sqlite::Transaction txn{db_};
92  for (auto const& r : buffer) {
94  int const rc{sqlite3_step(insertStmt)};
95  if (rc != SQLITE_DONE) {
96  return rc;
97  }
98  sqlite3_reset(insertStmt);
99  }
100  txn.commit();
101  return SQLITE_DONE;
102 }
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
TRandom3 r(0)
std::shared_ptr< std::mutex > m_
Definition: Connection.h:66
static void bind(sqlite3_stmt *s, TUP const &t)
sqlite3* cet::sqlite::Connection::get ( ) const
inline

Definition at line 41 of file Connection.h.

References db_.

42  {
43  return db_;
44  }
cet::sqlite::Connection::operator sqlite3 * ( )
inline

Definition at line 45 of file Connection.h.

References Connection(), db_, ConvertToSnowGlobesInput::file_name, flush_no_throw(), m, operator=(), and string.

45 { return db_; }
Connection& cet::sqlite::Connection::operator= ( Connection const &  )
delete

Referenced by operator sqlite3 *().

Connection& cet::sqlite::Connection::operator= ( Connection &&  )
noexcept

Friends And Related Function Documentation

friend class ConnectionFactory
friend

Definition at line 63 of file Connection.h.

Member Data Documentation

sqlite3* cet::sqlite::Connection::db_ {nullptr}
private

Definition at line 65 of file Connection.h.

Referenced by Connection(), flush_no_throw(), get(), and operator sqlite3 *().

std::shared_ptr<std::mutex> cet::sqlite::Connection::m_
private
Initial value:
{
nullptr}

Definition at line 66 of file Connection.h.

Referenced by flush_no_throw().


The documentation for this class was generated from the following file: