Skip to content

Commit

Permalink
Merge branch 'tickets/DM-40506'
Browse files Browse the repository at this point in the history
  • Loading branch information
iagaponenko committed Aug 28, 2023
2 parents 4971fc5 + b3d4bcc commit 9aaf64f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
15 changes: 3 additions & 12 deletions src/qmeta/QMetaSelect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
// Class header
#include "qmeta/QMetaSelect.h"

// System headers

// Third-party headers

// LSST headers
#include "lsst/log/Log.h"

Expand All @@ -43,23 +39,18 @@ LOG_LOGGER _log = LOG_GET("lsst.qserv.qmeta.QMetaSelect");

namespace lsst::qserv::qmeta {

// Constructors
QMetaSelect::QMetaSelect(mysql::MySqlConfig const& mysqlConf)
: _conn(sql::SqlConnectionFactory::make(mysqlConf)) {}

// Destructor
QMetaSelect::~QMetaSelect() {}

std::unique_ptr<sql::SqlResults> QMetaSelect::select(std::string const& query) {
// run query
sql::SqlErrorObject errObj;
std::unique_ptr<sql::SqlResults> results(new sql::SqlResults);
LOGS(_log, LOG_LVL_DEBUG, "Executing query: " << query);
if (not _conn->runQuery(query, *results, errObj)) {
std::lock_guard<std::mutex> const lock(_connMtx);
if (!_conn->runQuery(query, *results, errObj)) {
LOGS(_log, LOG_LVL_ERROR, "SQL query failed: " << query);
throw SqlError(ERR_LOC, errObj);
throw qmeta::SqlError(ERR_LOC, errObj);
}

return results;
}

Expand Down
17 changes: 8 additions & 9 deletions src/qmeta/QMetaSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define LSST_QSERV_QMETA_QMETASELECT_H

// System headers
#include <memory>
#include <mutex>
#include <string>
#include <vector>

Expand All @@ -38,7 +40,6 @@ namespace lsst::qserv::qmeta {

/**
* @ingroup qmeta
*
* @brief Select interface for QMeta database.
*
* This is somewhat special class to used for selecting data from
Expand All @@ -48,17 +49,14 @@ namespace lsst::qserv::qmeta {

class QMetaSelect {
public:
/**
* @param mysqlConf: Configuration object for mysql connection
*/
QMetaSelect(mysql::MySqlConfig const& mysqlConf);
/// @param mysqlConf: Configuration object for mysql connection
explicit QMetaSelect(mysql::MySqlConfig const& mysqlConf);

// Instances cannot be copied
QMetaSelect() = delete;
QMetaSelect(QMetaSelect const&) = delete;
QMetaSelect& operator=(QMetaSelect const&) = delete;

// Destructor
virtual ~QMetaSelect();
~QMetaSelect() = default;

/**
* @brief Run arbitrary select on a table or view.
Expand All @@ -71,9 +69,10 @@ class QMetaSelect {
* @returns SqlResults instance
* @throws SqlError
*/
virtual std::unique_ptr<sql::SqlResults> select(std::string const& query);
std::unique_ptr<sql::SqlResults> select(std::string const& query);

protected:
std::mutex _connMtx; ///< The mutex guarding the database connector
std::shared_ptr<sql::SqlConnection> _conn;
};

Expand Down

0 comments on commit 9aaf64f

Please sign in to comment.