diff --git a/catalogue/CMakeLists.txt b/catalogue/CMakeLists.txt index 8fea9bb5552a94734f8fd5610b1cff8875a93873..a00d7dd531eba0851feab4b2570a6a4064d6568f 100644 --- a/catalogue/CMakeLists.txt +++ b/catalogue/CMakeLists.txt @@ -26,16 +26,22 @@ set (CATALOGUE_LIB_SRC_FILES DbLogin.cpp DummyCatalogue.cpp OcciConn.cpp + OcciEnv.cpp OcciStmt.cpp Sqlite.cpp SqliteCatalogue.cpp SqliteConn.cpp SqliteStmt.cpp) -add_library (ctacatalogue +add_library (ctacatalogue SHARED ${CATALOGUE_LIB_SRC_FILES}) +target_link_libraries (ctacatalogue + ${ORACLE-INSTANTCLIENT_LIBRARIES} + ${SQLITE_LIBRARIES}) + set (CATALOGUE_UNIT_TESTS_LIB_SRC_FILES + OcciEnvTest.cpp SqliteCatalogueTest.cpp SqliteStmtTest.cpp) @@ -43,7 +49,6 @@ add_library (ctacatalogueunittests SHARED ${CATALOGUE_UNIT_TESTS_LIB_SRC_FILES}) target_link_libraries (ctacatalogueunittests - ctacatalogue - ${SQLITE_LIBRARIES}) + ctacatalogue) install(TARGETS ctacatalogueunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) diff --git a/catalogue/OcciConn.hpp b/catalogue/OcciConn.hpp index 3b6e6fe077b412c7197d1d76c78250ec718dc649..7cd0cc0f09f6ecc6812083e11f54b4255fe9eb34 100644 --- a/catalogue/OcciConn.hpp +++ b/catalogue/OcciConn.hpp @@ -34,7 +34,7 @@ namespace catalogue { class OcciStmt; /** - * A C++ wrapper around a connection to an OCCI database. + * A convenience wrapper around a connection to an OCCI database. */ class OcciConn { public: diff --git a/catalogue/OcciConnTest.cpp b/catalogue/OcciConnTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27be268ed02e1a77cc0003a38a94bbad09f02976 --- /dev/null +++ b/catalogue/OcciConnTest.cpp @@ -0,0 +1,48 @@ +/* + * 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/>. + */ + +#include "catalogue/OcciConn.hpp" +#include "common/exception/Exception.hpp" + +#include <gtest/gtest.h> +#include <memory> + +namespace unitTests { + +class cta_catalogue_OcciConnTest : public ::testing::Test { +protected: + + virtual void SetUp() { + } + + virtual void TearDown() { + } +}; + +TEST_F(cta_catalogue_OcciConnTest, constructor) { + using namespace cta::catalogue; + + // WARNING - The database whose connection details are specified in the + // following database configuration file will be destroyed + const std::string testDbConfigFile = "cta_catalogue_test_db.conf"; + const DbLogin dbLogin = DbLogin::readFromFile(testDbConfigFile); + + +} + +} // namespace unitTests diff --git a/catalogue/OcciEnv.cpp b/catalogue/OcciEnv.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dad8cbdbb420771e104638332b7bf6a5fbba1092 --- /dev/null +++ b/catalogue/OcciEnv.cpp @@ -0,0 +1,57 @@ +/* + * 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/>. + */ + +#include "catalogue/OcciEnv.hpp" +#include "common/exception/Exception.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::catalogue::OcciEnv::OcciEnv() { + using namespace oracle::occi; + m_env = Environment::createEnvironment(Environment::THREADED_MUTEXED); + if(NULL == m_env) { + exception::Exception ex; + ex.getMessage() << __FUNCTION__ << " failed" + ": createEnvironment() returned a NULL pointer"; + throw ex; + } +} + +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +cta::catalogue::OcciEnv::~OcciEnv() throw() { + using namespace oracle::occi; + + Environment::terminateEnvironment(m_env); +} + +//------------------------------------------------------------------------------ +// get +//------------------------------------------------------------------------------ +oracle::occi::Environment *cta::catalogue::OcciEnv::get() const { + return m_env; +} + +//------------------------------------------------------------------------------ +// operator-> +//------------------------------------------------------------------------------ +oracle::occi::Environment *cta::catalogue::OcciEnv::operator->() const { + return get(); +} diff --git a/catalogue/OcciEnv.hpp b/catalogue/OcciEnv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..88566f8a1a574973f889b38d5e8f9cd09a0e4d58 --- /dev/null +++ b/catalogue/OcciEnv.hpp @@ -0,0 +1,70 @@ +/* + * 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/>. + */ + +#pragma once + +#include <occi.h> + +namespace cta { +namespace catalogue { + +/** + * A convenience wrapper around an OCCI environment. + */ +class OcciEnv { +public: + + /** + * Constructor. + * + * Creates an OCCI environment with a THREADED_MUTEXED mode. + */ + OcciEnv(); + + /** + * Destructor. + * + * Terminates the underlying OCCI environment. + */ + ~OcciEnv() throw(); + + /** + * Returns the underlying OCCI environment. + * + * @return The underlying OCCI environment. + */ + oracle::occi::Environment *get() const; + + /** + * An alias for the get() method. + * + * @return The underlying OCCI environment. + */ + oracle::occi::Environment *operator->() const; + +private: + + /** + * The OCCI environment. + */ + oracle::occi::Environment *m_env; + +}; // class OcciEnv + +} // namespace catalogue +} // namespace cta diff --git a/catalogue/OcciEnvTest.cpp b/catalogue/OcciEnvTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..171f2debff0382f419338181e25ec928cc97cd66 --- /dev/null +++ b/catalogue/OcciEnvTest.cpp @@ -0,0 +1,42 @@ +/* + * 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/>. + */ + +#include "catalogue/OcciEnv.hpp" + +#include <gtest/gtest.h> +#include <memory> + +namespace unitTests { + +class cta_catalogue_OcciEnvTest : public ::testing::Test { +protected: + + virtual void SetUp() { + } + + virtual void TearDown() { + } +}; + +TEST_F(cta_catalogue_OcciEnvTest, constructor) { + using namespace cta::catalogue; + + OcciEnv env; +} + +} // namespace unitTests diff --git a/catalogue/OcciStmt.hpp b/catalogue/OcciStmt.hpp index f65f3fc0cf8aa67b4b191a5c414a2778f7b1d848..abf85a69eeb528017442c3ebeea819c7585f4aca 100644 --- a/catalogue/OcciStmt.hpp +++ b/catalogue/OcciStmt.hpp @@ -35,7 +35,7 @@ namespace catalogue { class OcciConn; /** - * A C++ wrapper around an OCCI prepared statement. + * A convenience wrapper around an OCCI prepared statement. */ class OcciStmt { public: diff --git a/catalogue/SqliteConn.hpp b/catalogue/SqliteConn.hpp index 5c9edd556b3fd93145773bcbbac42d33614cd758..0535c40ea68891aecf8c0eb7799ee77bf52c4108 100644 --- a/catalogue/SqliteConn.hpp +++ b/catalogue/SqliteConn.hpp @@ -32,7 +32,7 @@ namespace catalogue { class SqliteStmt; /** - * A C++ wrapper around a connection to an SQLite database. + * A convenience wrapper around a connection to an SQLite database. */ class SqliteConn { public: diff --git a/catalogue/SqliteStmt.hpp b/catalogue/SqliteStmt.hpp index 06b33de6f1e2a672f1671280093e30d289badc42..c15c77f9e31729382092e877c8e536c0c5bb040a 100644 --- a/catalogue/SqliteStmt.hpp +++ b/catalogue/SqliteStmt.hpp @@ -35,7 +35,7 @@ namespace catalogue { class SqliteConn; /** - * A C++ wrapper around an SQLite prepared statement. + * A convenience wrapper around an SQLite prepared statement. */ class SqliteStmt { public: diff --git a/cmake/Findoracle-instantclient.cmake b/cmake/Findoracle-instantclient.cmake index 48b2908a01c2ef15e7151f037f35f8413f6d41c2..d739c50b246409f61efdf6c245eaf2435d0f4e1f 100644 --- a/cmake/Findoracle-instantclient.cmake +++ b/cmake/Findoracle-instantclient.cmake @@ -24,11 +24,20 @@ find_path(ORACLE-INSTANTCLIENT_INCLUDE_DIRS PATHS /usr/include/oracle/12.1/client64 NO_DEFAULT_PATH) -find_library(ORACLE-INSTANTCLIENT_LIBRARIES +find_library(ORACLE-INSTANTCLIENT_OCCI_LIBRARY NAME occi PATHS /usr/lib/oracle/12.1/client64/lib NO_DEFAULT_PATH) +find_library(ORACLE-INSTANTCLIENT_CLNTSH_LIBRARY + NAME clntsh + PATHS /usr/lib/oracle/12.1/client64/lib + NO_DEFAULT_PATH) + +set(ORACLE-INSTANTCLIENT_LIBRARIES + ${ORACLE-INSTANTCLIENT_OCCI_LIBRARY} + ${ORACLE-INSTANTCLIENT_CLNTSH_LIBRARY}) + include(FindPackageHandleStandardArgs) find_package_handle_standard_args(oracle-instantclient DEFAULT_MSG ORACLE-INSTANTCLIENT_INCLUDE_DIRS ORACLE-INSTANTCLIENT_LIBRARIES) diff --git a/tests/valgrind.suppr b/tests/valgrind.suppr index ad88261f79f60644fbcfc468bd604d3fda7139cd..bafd3a2492f56485bfb71149052da19a0d54e87e 100644 --- a/tests/valgrind.suppr +++ b/tests/valgrind.suppr @@ -316,4 +316,120 @@ fun:_ZN6castor6server6Thread14pthread_runnerEPv fun:start_thread fun:clone -} \ No newline at end of file +} +{ + OCIEnvCreate_1 + Memcheck:Cond + fun:__intel_sse2_strcpy + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr + fun:OCIEnvCreate + fun:_ZN6oracle4occi11Environment17createEnvironmentENS1_4ModeEPvPFS3_S3_mEPFS3_S3_S3_mEPFvS3_S3_E + fun:_ZN3cta9catalogue7OcciEnvC1Ev + fun:_ZN9unitTests42cta_catalogue_OcciEnvTest_constructor_Test8TestBodyEv + fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc + fun:_ZN7testing4Test3RunEv + fun:_ZN7testing8TestInfo3RunEv +} +{ + OCIEnvCreate_2 + Memcheck:Cond + fun:__intel_sse2_strcpy + fun:slpmadp + fun:lpmapd + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr + fun:OCIEnvCreate + fun:_ZN6oracle4occi11Environment17createEnvironmentENS1_4ModeEPvPFS3_S3_mEPFS3_S3_S3_mEPFvS3_S3_E + fun:_ZN3cta9catalogue7OcciEnvC1Ev + fun:_ZN9unitTests42cta_catalogue_OcciEnvTest_constructor_Test8TestBodyEv + fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc +} +{ + OCIEnvCreate_3 + Memcheck:Cond + fun:__intel_sse2_strcpy + fun:slpmadp + fun:lpmapd + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr + fun:OCIEnvCreate + fun:_ZN6oracle4occi11Environment17createEnvironmentENS1_4ModeEPvPFS3_S3_mEPFS3_S3_S3_mEPFvS3_S3_E + fun:_ZN3cta9catalogue7OcciEnvC1Ev + fun:_ZN9unitTests42cta_catalogue_OcciEnvTest_constructor_Test8TestBodyEv + fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc +} +{ + OCIEnvCreate_4 + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:slzsetevar + fun:lfvSetOHome + fun:slpmloclfv + fun:slpmloc + fun:lpmloadpkg + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr + fun:OCIEnvCreate + fun:_ZN6oracle4occi11Environment17createEnvironmentENS1_4ModeEPvPFS3_S3_mEPFS3_S3_S3_mEPFvS3_S3_E +} +{ + oracle_misc_1 + Memcheck:Leak + match-leak-kinds: possible + fun:malloc + fun:ssMemMalloc + fun:sltsmxi + fun:lmmhpinit + fun:lmmcis + fun:lpmpali + fun:lpminitm + fun:lpminit + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr +} +{ + OCIEnvCreate_5 + Memcheck:Leak + match-leak-kinds: possible + fun:malloc + fun:ssMemMalloc + fun:sltsmxi + fun:lmmhpinit + fun:lmmcis + fun:lpmpali + fun:lpmloadpkg + fun:lfvini1 + fun:lfvinit + fun:kpummpin + fun:kpuenvcr + fun:OCIEnvCreate +} +{ + oracle_misc_2 + Memcheck:Leak + match-leak-kinds: possible + fun:calloc + fun:ssMemCalloc + fun:slwmmgetmem + fun:lmmstvrt + fun:lmmstchnk + fun:lmmstsml + fun:lmmstmalloc + fun:lmmmalloc + fun:lmmcis + fun:lpmpali + fun:lpminitm + fun:lpminit +}