Commit 5acc3454 authored by Steven Murray's avatar Steven Murray
Browse files

Split cta::catalogue into cta::catalogue and cta::rdbms

parent 51c159dc
......@@ -114,6 +114,7 @@ ELSE(DEFINED PackageOnly)
add_subdirectory(cmdline)
add_subdirectory(common)
add_subdirectory(objectstore)
add_subdirectory(rdbms)
add_subdirectory(remotens)
add_subdirectory(scheduler)
add_subdirectory(tapeserver)
......
......@@ -23,32 +23,14 @@ include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set (CATALOGUE_LIB_SRC_FILES
ArchiveFileRow.cpp
ArchiveFileItor.cpp
AutoRollback.cpp
Catalogue.cpp
CatalogueFactory.cpp
ColumnNameToIdx.cpp
ColumnNameToIdxAndType.cpp
DbConn.cpp
DbLogin.cpp
DbRset.cpp
DbStmt.cpp
InMemoryCatalogue.cpp
InMemoryCatalogueSchema.cpp
TapeFileWritten.cpp
NullDbValue.cpp
OcciConn.cpp
OcciEnv.cpp
OcciEnvSingleton.cpp
OcciRset.cpp
OcciStmt.cpp
OracleCatalogue.cpp
ParamNameToIdx.cpp
RdbmsCatalogue.cpp
Sqlite.cpp
SqliteCatalogue.cpp
SqliteConn.cpp
SqliteRset.cpp
SqliteStmt.cpp
TapeForWriting.cpp
UserError.cpp)
......@@ -59,6 +41,7 @@ install (TARGETS ctacatalogue DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
target_link_libraries (ctacatalogue
ctacommon
ctardbms
${ORACLE-INSTANTCLIENT_LIBRARIES}
${SQLITE_LIBRARIES})
......@@ -91,11 +74,11 @@ add_custom_command(OUTPUT InMemoryCatalogueSchema.cpp
set(IN_MEMORY_CATALOGUE_UNIT_TESTS_LIB_SRC_FILES
CatalogueTest.cpp
CatalogueFactoryTest.cpp
DbLoginFactory.cpp
DbLoginTest.cpp
ParamNameToIdxTest.cpp
../rdbms/DbLoginFactory.cpp
../rdbms/DbLoginTest.cpp
../rdbms/ParamNameToIdxTest.cpp
InMemoryCatalogueTest.cpp
SqliteStmtTest.cpp)
../rdbms/SqliteStmtTest.cpp)
add_library (ctainmemorycatalogueunittests SHARED
${IN_MEMORY_CATALOGUE_UNIT_TESTS_LIB_SRC_FILES})
......@@ -108,7 +91,7 @@ install(TARGETS ctainmemorycatalogueunittests DESTINATION usr/${CMAKE_INSTALL_LI
set (CATALOGUE_UNIT_TESTS_LIB_SRC_FILES
CatalogueTest.cpp
DbConfigCatalogueTest.cpp
DbLoginFactory.cpp)
../rdbms/DbLoginFactory.cpp)
add_library (ctacatalogueunittests SHARED
${CATALOGUE_UNIT_TESTS_LIB_SRC_FILES})
......
......@@ -28,16 +28,16 @@ namespace catalogue {
//------------------------------------------------------------------------------
// create
//------------------------------------------------------------------------------
Catalogue *CatalogueFactory::create(const DbLogin &dbLogin) {
Catalogue *CatalogueFactory::create(const rdbms::DbLogin &dbLogin) {
try {
switch(dbLogin.dbType) {
case DbLogin::DBTYPE_IN_MEMORY:
case rdbms::DbLogin::DBTYPE_IN_MEMORY:
return new InMemoryCatalogue();
case DbLogin::DBTYPE_ORACLE:
case rdbms::DbLogin::DBTYPE_ORACLE:
return new OracleCatalogue(dbLogin.username, dbLogin.password, dbLogin.database);
case DbLogin::DBTYPE_SQLITE:
case rdbms::DbLogin::DBTYPE_SQLITE:
return new SqliteCatalogue(dbLogin.database);
case DbLogin::DBTYPE_NONE:
case rdbms::DbLogin::DBTYPE_NONE:
throw exception::Exception("Cannot create a catalogue without a database type");
default:
{
......
......@@ -19,7 +19,7 @@
#pragma once
#include "catalogue/Catalogue.hpp"
#include "catalogue/DbLogin.hpp"
#include "rdbms/DbLogin.hpp"
#include <memory>
#include <mutex>
......@@ -46,7 +46,7 @@ public:
* @return The newly created CTA catalogue object. Please note that it is the
* responsibility of the caller to delete the returned CTA catalogue object.
*/
static Catalogue *create(const DbLogin &dbLogin);
static Catalogue *create(const rdbms::DbLogin &dbLogin);
}; // class CatalogueFactory
......
......@@ -58,7 +58,7 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) {
using namespace cta;
using namespace cta::catalogue;
DbLogin dbLogin(DbLogin::DBTYPE_IN_MEMORY, "", "", "");
rdbms::DbLogin dbLogin(rdbms::DbLogin::DBTYPE_IN_MEMORY, "", "", "");
std::unique_ptr<Catalogue> catalogue(CatalogueFactory::create(dbLogin));
ASSERT_TRUE(NULL != catalogue.get());
......
......@@ -20,9 +20,9 @@
#include "catalogue/ArchiveFileRow.hpp"
#include "catalogue/CatalogueFactory.hpp"
#include "catalogue/DbLoginFactory.hpp"
#include "catalogue/UserError.hpp"
#include "common/exception/Exception.hpp"
#include "rdbms/DbLoginFactory.hpp"
#include <gtest/gtest.h>
#include <map>
......@@ -31,7 +31,7 @@
namespace unitTests {
class cta_catalogue_CatalogueTest : public ::testing::TestWithParam<cta::catalogue::DbLoginFactory*> {
class cta_catalogue_CatalogueTest : public ::testing::TestWithParam<cta::rdbms::DbLoginFactory*> {
public:
/**
......
......@@ -26,7 +26,7 @@ namespace {
* details are specified in a database configuration file passed on the
* command-line to the catalogue unit-tests program.
*/
class DbConfigFileLoginFactory: public cta::catalogue::DbLoginFactory {
class DbConfigFileLoginFactory: public cta::rdbms::DbLoginFactory {
public:
/**
......@@ -40,9 +40,9 @@ public:
*
* @return A newly created DbLogin object.
*/
virtual cta::catalogue::DbLogin create() {
virtual cta::rdbms::DbLogin create() {
using namespace cta::catalogue;
return DbLogin::parseFile(g_cmdLineArgs.dbConfigPath);
return cta::rdbms::DbLogin::parseFile(g_cmdLineArgs.dbConfigPath);
}
}; // class OracleDbLoginFactory
......@@ -53,6 +53,6 @@ DbConfigFileLoginFactory g_dbConfigLoginFactory;
namespace unitTests {
INSTANTIATE_TEST_CASE_P(DbConfigFile, cta_catalogue_CatalogueTest,
::testing::Values(dynamic_cast<cta::catalogue::DbLoginFactory*>(&g_dbConfigLoginFactory)));
::testing::Values(dynamic_cast<cta::rdbms::DbLoginFactory*>(&g_dbConfigLoginFactory)));
} // namespace unitTests
......@@ -18,7 +18,7 @@
#include "catalogue/InMemoryCatalogue.hpp"
#include "catalogue/RdbmsCatalogueSchema.hpp"
#include "catalogue/SqliteConn.hpp"
#include "rdbms/SqliteConn.hpp"
namespace cta {
namespace catalogue {
......@@ -27,7 +27,7 @@ namespace catalogue {
// constructor
//------------------------------------------------------------------------------
InMemoryCatalogue::InMemoryCatalogue() {
std::unique_ptr<SqliteConn> sqliteConn(new SqliteConn(":memory:"));
std::unique_ptr<rdbms::SqliteConn> sqliteConn(new rdbms::SqliteConn(":memory:"));
m_conn.reset(sqliteConn.release());
createCatalogueSchema();
}
......@@ -51,7 +51,7 @@ void InMemoryCatalogue::executeNonQueryMultiStmt(const std::string &multiStmt) {
const std::string::size_type length = findResult - searchPos + 1;
const std::string sql = multiStmt.substr(searchPos, length);
searchPos = findResult + 1;
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->executeNonQuery();
}
}
......
......@@ -25,7 +25,7 @@ namespace {
/**
* Creates DbLogin objects for in-memory catalogue databases.
*/
class InMemoryDbLoginFactory: public cta::catalogue::DbLoginFactory {
class InMemoryDbLoginFactory: public cta::rdbms::DbLoginFactory {
public:
/**
......@@ -39,9 +39,9 @@ public:
*
* @return A newly created DbLogin object.
*/
virtual cta::catalogue::DbLogin create() {
virtual cta::rdbms::DbLogin create() {
using namespace cta::catalogue;
return DbLogin(DbLogin::DBTYPE_IN_MEMORY, "", "", "");
return cta::rdbms::DbLogin(cta::rdbms::DbLogin::DBTYPE_IN_MEMORY, "", "", "");
}
}; // class InMemoryDbLoginFactory
......@@ -50,6 +50,6 @@ InMemoryDbLoginFactory g_inMemoryDbLoginFactory;
} // anonymous namespace
INSTANTIATE_TEST_CASE_P(InMemory, cta_catalogue_CatalogueTest,
::testing::Values(dynamic_cast<cta::catalogue::DbLoginFactory*>(&g_inMemoryDbLoginFactory)));
::testing::Values(dynamic_cast<cta::rdbms::DbLoginFactory*>(&g_inMemoryDbLoginFactory)));
} // namespace unitTests
......@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/OcciConn.hpp"
#include "catalogue/OcciEnvSingleton.hpp"
#include "rdbms/OcciConn.hpp"
#include "rdbms/OcciEnvSingleton.hpp"
#include "catalogue/OracleCatalogue.hpp"
#include "catalogue/UserError.hpp"
#include "common/exception/Exception.hpp"
......@@ -33,7 +33,7 @@ OracleCatalogue::OracleCatalogue(
const std::string &username,
const std::string &password,
const std::string &database) {
m_conn.reset(OcciEnvSingleton::instance().createConn(username, password, database));
m_conn.reset(rdbms::OcciEnvSingleton::instance().createConn(username, password, database));
}
//------------------------------------------------------------------------------
......@@ -77,9 +77,9 @@ common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile(const uin
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID "
"FOR UPDATE";
std::unique_ptr<DbStmt> selectStmt(m_conn->createStmt(selectSql));
std::unique_ptr<rdbms::DbStmt> selectStmt(m_conn->createStmt(selectSql));
selectStmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
std::unique_ptr<DbRset> selectRset(selectStmt->executeQuery());
std::unique_ptr<rdbms::DbRset> selectRset(selectStmt->executeQuery());
while(selectRset->next()) {
if(NULL == archiveFile.get()) {
archiveFile.reset(new common::dataStructures::ArchiveFile);
......@@ -121,14 +121,14 @@ common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile(const uin
{
const char *const sql = "DELETE FROM TAPE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
}
{
const char *const sql = "DELETE FROM ARCHIVE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
}
......@@ -154,8 +154,8 @@ uint64_t OracleCatalogue::getNextArchiveFileId() {
"FROM "
"DUAL";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<DbRset> rset(stmt->executeQuery());
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbRset> rset(stmt->executeQuery());
if (!rset->next()) {
throw exception::Exception(std::string("Result set is unexpectedly empty"));
}
......@@ -208,9 +208,9 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(const std::str
"VID = :VID "
"FOR UPDATE";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindString(":VID", vid);
std::unique_ptr<DbRset> rset(stmt->executeQuery());
std::unique_ptr<rdbms::DbRset> rset(stmt->executeQuery());
if (!rset->next()) {
throw exception::Exception(std::string("The tape with VID " + vid + " does not exist"));
}
......
This diff is collapsed.
......@@ -19,7 +19,7 @@
#pragma once
#include "catalogue/Catalogue.hpp"
#include "catalogue/DbConn.hpp"
#include "rdbms/DbConn.hpp"
#include "catalogue/RequesterAndGroupMountPolicies.hpp"
#include <memory>
......@@ -460,7 +460,7 @@ protected:
* @param timeColNAme The name of the database column that contains the time
* stamp.
*/
optional<common::dataStructures::TapeLog> getTapeLogFromRset(const DbRset &rset,
optional<common::dataStructures::TapeLog> getTapeLogFromRset(const rdbms::DbRset &rset,
const std::string &driveColName, const std::string &timeColName) const;
/**
......@@ -479,7 +479,7 @@ protected:
/**
* The connection to the underlying relational database.
*/
std::unique_ptr<DbConn> m_conn;
std::unique_ptr<rdbms::DbConn> m_conn;
/**
* Creates the database schema.
......
......@@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/AutoRollback.hpp"
#include "rdbms/AutoRollback.hpp"
#include "catalogue/RdbmsCatalogueSchema.hpp"
#include "catalogue/SqliteCatalogue.hpp"
#include "catalogue/SqliteConn.hpp"
#include "rdbms/SqliteConn.hpp"
#include "catalogue/UserError.hpp"
#include "common/exception/Exception.hpp"
#include "common/utils/utils.hpp"
......@@ -31,7 +31,7 @@ namespace catalogue {
// constructor
//------------------------------------------------------------------------------
SqliteCatalogue::SqliteCatalogue(const std::string &filename) {
std::unique_ptr<SqliteConn> sqliteConn(new SqliteConn(filename));
std::unique_ptr<rdbms::SqliteConn> sqliteConn(new rdbms::SqliteConn(filename));
m_conn.reset(sqliteConn.release());
}
......@@ -82,9 +82,9 @@ common::dataStructures::ArchiveFile SqliteCatalogue::deleteArchiveFile(const uin
"ARCHIVE_FILE.ARCHIVE_FILE_ID = TAPE_FILE.ARCHIVE_FILE_ID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
std::unique_ptr<DbStmt> selectStmt(m_conn->createStmt(selectSql));
std::unique_ptr<rdbms::DbStmt> selectStmt(m_conn->createStmt(selectSql));
selectStmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
std::unique_ptr<DbRset> selectRset(selectStmt->executeQuery());
std::unique_ptr<rdbms::DbRset> selectRset(selectStmt->executeQuery());
while(selectRset->next()) {
if(NULL == archiveFile.get()) {
archiveFile.reset(new common::dataStructures::ArchiveFile);
......@@ -126,14 +126,14 @@ common::dataStructures::ArchiveFile SqliteCatalogue::deleteArchiveFile(const uin
{
const char *const sql = "DELETE FROM TAPE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID;";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
}
{
const char *const sql = "DELETE FROM ARCHIVE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID;";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
}
......@@ -154,7 +154,7 @@ common::dataStructures::ArchiveFile SqliteCatalogue::deleteArchiveFile(const uin
uint64_t SqliteCatalogue::getNextArchiveFileId() {
try {
m_conn->executeNonQuery("BEGIN EXCLUSIVE;");
AutoRollback autoRollback(m_conn.get());
rdbms::AutoRollback autoRollback(m_conn.get());
m_conn->executeNonQuery("UPDATE ARCHIVE_FILE_ID SET ID = ID + 1;");
uint64_t archiveFileId = 0;
......@@ -164,8 +164,8 @@ uint64_t SqliteCatalogue::getNextArchiveFileId() {
"ID AS ID "
"FROM "
"ARCHIVE_FILE_ID";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<DbRset> rset(stmt->executeQuery());
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbRset> rset(stmt->executeQuery());
if(!rset->next()) {
throw exception::Exception("ARCHIVE_FILE_ID table is empty");
}
......@@ -227,9 +227,9 @@ common::dataStructures::Tape SqliteCatalogue::selectTapeForUpdate(const std::str
"WHERE "
"VID = :VID;";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
std::unique_ptr<rdbms::DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindString(":VID", vid);
std::unique_ptr<DbRset> rset(stmt->executeQuery());
std::unique_ptr<rdbms::DbRset> rset(stmt->executeQuery());
if (!rset->next()) {
throw exception::Exception(std::string("The tape with VID " + vid + " does not exist"));
}
......
......@@ -129,6 +129,7 @@ The shared libraries
%attr(0755,root,root) %{_libdir}/libctamediachangerutils.so
%attr(0755,root,root) %{_libdir}/libctamessages.so
%attr(0755,root,root) %{_libdir}/libctamessagesutils.so
%attr(0755,root,root) %{_libdir}/libctardbms.so
%attr(0755,root,root) %{_libdir}/libctatapereactorutils.so
%attr(0755,root,root) %{_libdir}/libctatapeserverdaemonutils.so
%attr(0644,root,root) %{_sysconfdir}/cta/cta_catalogue_db.conf.example
......
......@@ -16,12 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/AutoRollback.hpp"
#include "catalogue/DbConn.hpp"
#include "AutoRollback.hpp"
#include "DbConn.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
namespace rdbms {
//------------------------------------------------------------------------------
// constructor
......@@ -49,5 +49,5 @@ void AutoRollback::cancel() {
m_dbConn = NULL;
}
} // namespace catalogue
} // namespace rdbms
} // namespace cta
......@@ -19,7 +19,7 @@
#pragma once
namespace cta {
namespace catalogue {
namespace rdbms {
/**
* Forward declaration.
......@@ -72,5 +72,5 @@ private:
}; // class DbLogin
} // namespace catalogue
} // namespace rdbms
} // namespace cta
# The CERN Tape Archive (CTA) project
# Copyright (C) 2015 CERN
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required (VERSION 2.6)
find_package (oracle-instantclient REQUIRED)
find_package (sqlite REQUIRED)
include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set (RDBMS_LIB_SRC_FILES
AutoRollback.cpp
ColumnNameToIdx.cpp
ColumnNameToIdxAndType.cpp
DbConn.cpp
DbLogin.cpp
DbRset.cpp
DbStmt.cpp
NullDbValue.cpp
OcciConn.cpp
OcciEnv.cpp
OcciEnvSingleton.cpp
OcciRset.cpp
OcciStmt.cpp
ParamNameToIdx.cpp
Sqlite.cpp
SqliteConn.cpp
SqliteRset.cpp
SqliteStmt.cpp)
add_library (ctardbms SHARED
${RDBMS_LIB_SRC_FILES})
target_link_libraries (ctardbms
ctacommon
${ORACLE-INSTANTCLIENT_LIBRARIES}
${SQLITE_LIBRARIES})
install (TARGETS ctardbms DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
......@@ -16,11 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/ColumnNameToIdx.hpp"
#include "ColumnNameToIdx.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
namespace rdbms {
//------------------------------------------------------------------------------
// add
......@@ -50,5 +50,5 @@ bool ColumnNameToIdx::empty() const {
return m_nameToIdx.empty();
}
} // namespace catalogue
} // namespace rdbms
} // namespace cta
......@@ -22,7 +22,7 @@
#include <string>
namespace cta {
namespace catalogue {
namespace rdbms {
/**
* A map from column name to column index.
......@@ -67,5 +67,5 @@ private:
}; // class ColumnNameToIdx
} // namespace catalogue
} // namespace rdbms
} // namespace cta
......@@ -16,11 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/ColumnNameToIdxAndType.hpp"
#include "ColumnNameToIdxAndType.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
namespace rdbms {
//------------------------------------------------------------------------------
// add
......@@ -50,5 +50,5 @@ bool ColumnNameToIdxAndType::empty() const {
return m_nameToIdxAndType.empty();
}
} // namespace catalogue
} // namespace rdbms
} // namespace cta
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment