Commit a759ecbd authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

Schemas are now in the binary of the cta-catalogue-schema-verify tool

parent 7cd83969
This diff is collapsed.
/**
* The CERN Tape Archive (CTA) project
* Copyright © 2018 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 <map>
namespace cta{
namespace catalogue{
class AllCatalogueSchema {
public:
static std::map<std::string,std::map<std::string,std::string>> mapSchema;
};
std::map<std::string,std::map<std::string,std::string>> AllCatalogueSchema::mapSchema = ALL_SCHEMA_MAP
}}
......@@ -189,6 +189,10 @@ add_custom_command(OUTPUT PostgresCatalogueSchema.cpp
COMMAND sed -e '/CTA_SQL_SCHEMA/r postgres_catalogue_schema.cpp' ${CMAKE_CURRENT_SOURCE_DIR}/PostgresCatalogueSchema.before_SQL.cpp > PostgresCatalogueSchema.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/PostgresCatalogueSchema.before_SQL.cpp postgres_catalogue_schema.cpp)
add_custom_target(
CreateAllSchemasMap ALL
${CMAKE_CURRENT_SOURCE_DIR}/CreateAllSchemasCppFile.sh ${CMAKE_CURRENT_SOURCE_DIR}
)
set(IN_MEMORY_CATALOGUE_UNIT_TESTS_LIB_SRC_FILES
CatalogueTest.cpp
......@@ -286,6 +290,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-user-create.1cta D
add_executable(cta-catalogue-schema-verify
SQLiteSchemaInserter.cpp
SchemaSqlStatementsReader.cpp
SchemaComparer.cpp
SQLiteSchemaComparer.cpp
DbToSQLiteStatementTransformer.cpp
......
#!/bin/sh
#
# This script is ran by cmake in order to generate the C++ map that will store all schemas in it.
# Takes as argument the disk emplacement where the .sql files are located
# Example :
# {
# {"1.0",
# {
# {"oracle","oracle sqlStatements 1.0"},
# {"sqlite","sqlite sqlStatements 1.0"},
# }
# },
# {"1.1",
# {
# {"oracle","oracle sqlStatements 1.1"},
# {"sqlite","sqlite sqlStatements 1.1"},
# }
# },
#
# };
#
die() {
echo "$@" 1>&2
test -z $TAILPID || kill ${TAILPID} &> /dev/null
exit 1
}
databaseTypes=('oracle' 'mysql' 'sqlite' 'postgres')
schemaPostfix='_catalogue_schema.sql'
cd $1
schemaVersionsDirectories=`find . -type d -regex '^./[0-9]+\.[0-9]+$'`
mapSchemaCode='
{
'
for schemaVersionDir in $schemaVersionsDirectories
do
#extract schema version
schemaVersion=${schemaVersionDir#"./"}
mapSchemaCode+=" {\"$schemaVersion\",
{
"
for databaseType in ${databaseTypes[@]}
do
schemaSqlFilePath="$schemaVersionDir/$databaseType$schemaPostfix"
notTranslatedSchemaSQL=`cat $schemaSqlFilePath` || die "Unable to open file $schemaSqlFilePath"
schemaSql=`cat $schemaVersionDir/$databaseType$schemaPostfix | sed 's/^/\ \ \"/' | sed 's/$/\"/'`
mapSchemaCode+=" {\"$databaseType\",$schemaSql
},
"
done
mapSchemaCode+=" }\n"
mapSchemaCode+=" },\n"
done
mapSchemaCode+="};"
awk -v r="$mapSchemaCode" '{gsub(/ALL_SCHEMA_MAP/,r)}1' ./AllCatalogueSchema.hpp.in > ./AllCatalogueSchema.hpp || die "Unable to create the map containing all catalogue schemas"
......@@ -51,7 +51,7 @@ CreateGlobalTempTableToSQLiteStatementTransformer::CreateGlobalTempTableToSQLite
std::string CreateGlobalTempTableToSQLiteStatementTransformer::transform(){
utils::searchAndReplace(m_statement,"GLOBAL TEMPORARY ","");
utils::searchAndReplace(m_statement,"\nON COMMIT DELETE ROWS;",";");
utils::searchAndReplace(m_statement,"ON COMMIT DELETE ROWS;",";");
return m_statement;
}
......
......@@ -25,13 +25,12 @@
namespace cta {
namespace catalogue {
SQLiteSchemaComparer::SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn, const std::string & allSchemasVersionPath): SchemaComparer(catalogueDbType,catalogueConn),m_allSchemasVersionPath(allSchemasVersionPath) {
SQLiteSchemaComparer::SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn): SchemaComparer(catalogueDbType,catalogueConn) {
log::DummyLogger dl("dummy","dummy");
auto login = rdbms::Login::parseString("in_memory");
m_sqliteConnPool.reset(new rdbms::ConnPool(login,1));
m_sqliteConn = std::move(m_sqliteConnPool->getConn());
m_sqliteSchemaMetadataGetter.reset(new SQLiteCatalogueMetadataGetter(m_sqliteConn));
insertSchemaInSQLite();
}
SQLiteSchemaComparer::~SQLiteSchemaComparer() {
......@@ -41,6 +40,7 @@ SQLiteSchemaComparer::~SQLiteSchemaComparer() {
}
SchemaComparerResult SQLiteSchemaComparer::compareAll(){
insertSchemaInSQLite();
SchemaComparerResult res;
res += compareTables();
res += compareIndexes();
......@@ -48,6 +48,7 @@ SchemaComparerResult SQLiteSchemaComparer::compareAll(){
}
SchemaComparerResult SQLiteSchemaComparer::compareTables(){
insertSchemaInSQLite();
std::list<std::string> catalogueTables = m_catalogueMetadataGetter->getTableNames();
std::list<std::string> schemaTables = m_sqliteSchemaMetadataGetter->getTableNames();
SchemaComparerResult res = compareTables(catalogueTables,schemaTables);
......@@ -55,11 +56,19 @@ SchemaComparerResult SQLiteSchemaComparer::compareTables(){
}
void SQLiteSchemaComparer::insertSchemaInSQLite() {
cta::catalogue::SQLiteSchemaInserter schemaInserter(m_catalogueSchemaVersion,m_dbType,m_allSchemasVersionPath,m_sqliteConn);
schemaInserter.insert();
if(!m_isSchemaInserted){
if(m_schemaSqlStatementsReader != nullptr){
cta::catalogue::SQLiteSchemaInserter schemaInserter(m_sqliteConn);
schemaInserter.insert(m_schemaSqlStatementsReader->getStatements());
} else {
throw cta::exception::Exception("In SQLiteSchemaComparer::insertSchemaInSQLite(): unable to insert schema in sqlite because no SchemaSqlStatementReader has been set.");
}
}
m_isSchemaInserted = true;
}
SchemaComparerResult SQLiteSchemaComparer::compareIndexes(){
insertSchemaInSQLite();
std::list<std::string> catalogueIndexes = m_catalogueMetadataGetter->getIndexNames();
std::list<std::string> schemaIndexes = m_sqliteSchemaMetadataGetter->getIndexNames();
return compareItems("INDEX", catalogueIndexes, schemaIndexes);
......
......@@ -31,9 +31,8 @@ public:
* Constructs a SQLiteSchemaComparer
* @param catalogueDbType
* @param catalogueConn
* @param allSchemasVersionPath
*/
SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn, const std::string & allSchemasVersionPath);
SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn);
/**
* Compare the catalogue schema against the InMemory SQLite catalogue schema
* @return a SchemaComparerResult object that will contain the differences if there are some
......@@ -53,7 +52,7 @@ private:
rdbms::Conn m_sqliteConn;
std::unique_ptr<rdbms::ConnPool> m_sqliteConnPool;
std::unique_ptr<SQLiteCatalogueMetadataGetter> m_sqliteSchemaMetadataGetter;
const std::string m_allSchemasVersionPath;
bool m_isSchemaInserted = false;
};
}}
\ No newline at end of file
......@@ -27,85 +27,27 @@
namespace cta {
namespace catalogue {
SQLiteSchemaInserter::SQLiteSchemaInserter(const std::string & schemaVersion, const cta::rdbms::Login::DbType &catalogueDbType, const std::string &allSchemasVersionPath,rdbms::Conn &sqliteConn):m_schemaVersion(schemaVersion),m_dbType(catalogueDbType),m_allSchemasVersionPath(allSchemasVersionPath), m_sqliteCatalogueConn(sqliteConn){}
SQLiteSchemaInserter::SQLiteSchemaInserter(rdbms::Conn &sqliteConn): m_sqliteCatalogueConn(sqliteConn){}
SQLiteSchemaInserter::~SQLiteSchemaInserter() {}
void SQLiteSchemaInserter::insert() {
//Get all the statements from the correct .sql files
std::list<std::string> statements = getAllStatementsFromSchema(readSchemaFromFile());
void SQLiteSchemaInserter::insert(const std::list<std::string> &schemaStatements) {
std::list<std::string> sqliteStatements;
for(auto& stmt: statements){
//Transform the statements in order to make them compatible with the SQLite database
std::string sqliteStatement = DbToSQLiteStatementTransformerFactory::create(stmt)->transform();
if(!sqliteStatement.empty())
sqliteStatements.emplace_back(sqliteStatement);
//Transform the statements in order to make them compatible with the SQLite database
for(auto& schemaStatement: schemaStatements){
std::string sqliteTransformedStatement = DbToSQLiteStatementTransformerFactory::create(schemaStatement)->transform();
if(!sqliteTransformedStatement.empty()){
sqliteStatements.emplace_back(sqliteTransformedStatement);
}
}
executeStatements(sqliteStatements);
}
void SQLiteSchemaInserter::executeStatements(const std::list<std::string> & stmts){
for(auto& sqliteStatement: stmts){
void SQLiteSchemaInserter::executeStatements(const std::list<std::string>& sqliteStatements){
for(auto &sqliteStatement: sqliteStatements){
auto stmt = m_sqliteCatalogueConn.createStmt(sqliteStatement);
stmt.executeNonQuery();
}
}
std::list<std::string> SQLiteSchemaInserter::getAllStatementsFromSchema(const std::string &schema){
std::list<std::string> statements;
std::string::size_type searchPos = 0;
std::string::size_type findResult = std::string::npos;
try {
while(std::string::npos != (findResult = schema.find(';', searchPos))) {
// Calculate the length of the current statement without the trailing ';'
const std::string::size_type stmtLen = findResult - searchPos;
const std::string sqlStmt = utils::trimString(schema.substr(searchPos, stmtLen));
searchPos = findResult + 1;
if(0 < sqlStmt.size()) { // Ignore empty statements
statements.push_back(sqlStmt+";");
}
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
return statements;
}
std::string SQLiteSchemaInserter::readSchemaFromFile() {
std::string schemaFilePath = getSchemaFilePath();
std::ifstream schemaFile(schemaFilePath);
if(schemaFile.fail()){
throw cta::exception::Exception("In SQLiteSchemaInserter::readSchemaFromFile, unable to open the file located in "+schemaFilePath);
}
std::string content((std::istreambuf_iterator<char>(schemaFile)),(std::istreambuf_iterator<char>()));
return content;
}
std::string SQLiteSchemaInserter::getSchemaFilePath() {
return m_allSchemasVersionPath+m_schemaVersion+"/"+getDatabaseType()+c_catalogueFileNameTrailer;
}
std::string SQLiteSchemaInserter::getDatabaseType() {
switch(m_dbType){
case rdbms::Login::DBTYPE_IN_MEMORY:
case rdbms::Login::DBTYPE_SQLITE:
return "sqlite";
case rdbms::Login::DBTYPE_POSTGRESQL:
return "postgres";
case rdbms::Login::DBTYPE_MYSQL:
return "mysql";
case rdbms::Login::DBTYPE_ORACLE:
return "oracle";
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("The database type should not be DBTYPE_NONE");
default:
{
exception::Exception ex;
ex.getMessage() << "Unknown database type: value=" << m_dbType;
throw ex;
}
}
}
}}
\ No newline at end of file
......@@ -23,59 +23,26 @@
namespace cta {
namespace catalogue {
/**
* This class is used to create a InMemory SQLiteSchema from .sql files
* located in allSchemasVersionPath (example : /catalogue/1.0/dbtype_catalogue_schema.sql)
* This class is used to create a InMemory SQLiteSchema from sql statements
*
* @param schemaVersion the schema version to insert in order to look in the correct folder within allSchemasVersionPath
* @param catalogueDbType the dbType of the schema to insert in the SQLiteSchema
* @param allSchemasVersionPath the directory containing all the versions of the catalogue schema
* @param sqliteConn the connection of the InMemory SQLite schema
*/
class SQLiteSchemaInserter {
public:
/**
* Constructor
* @param schemaVersion the schema version to insert in order to look in the correct folder within allSchemasVersionPath
* @param catalogueDbType the dbType of the schema to insert in the SQLiteSchema
* @param allSchemasVersionPath the directory containing all the versions of the catalogue schema
* @param sqliteConn the connection of the InMemory SQLite schema
*/
SQLiteSchemaInserter(const std::string & schemaVersion, const cta::rdbms::Login::DbType &catalogueDbType, const std::string &allSchemasVersionPath,rdbms::Conn &sqliteConn);
SQLiteSchemaInserter(rdbms::Conn &sqliteConn);
/**
* Insert the schema corresponding to the version and the database type into the
* InMemory SQLite database accessible via the one given in the constructor
* Transform and insert the schema statements passed in parameter into the
* InMemory SQLite database
*/
void insert();
void insert(const std::list<std::string> &schemaStatements);
virtual ~SQLiteSchemaInserter();
private:
const std::string c_catalogueFileNameTrailer = "_catalogue_schema.sql";
std::string m_schemaVersion;
cta::rdbms::Login::DbType m_dbType;
std::string m_allSchemasVersionPath;
private:
cta::rdbms::Conn & m_sqliteCatalogueConn;
/**
* Put the schema located in SCHEMA_VERSION/dbType_catalogue_schema.sql
* @return the string containing the .sql statements for the creation of the schema
*/
std::string readSchemaFromFile();
/**
* Separates the statements and put them in a std::list<std::string>
* @param schema the sql statements put all together
* @return a list containing separated statements from the schema passed in parameter
*/
std::list<std::string> getAllStatementsFromSchema(const std::string &schema);
/**
* Returns the string corresponding to the database type
* This method is used to determine the correct .sql file to create the InMemory SQLite database
* @return the string corresponding to the database type
*/
std::string getDatabaseType();
/**
* Returns the path of the .sql file that will be executed to create the InMemory SQLite database
* @return
*/
std::string getSchemaFilePath();
/**
* Execute all the statements passed in parameter against the InMemory SQLite database
* @param statements the statements to execute in the InMemory SQLite database
......
......@@ -28,8 +28,15 @@ SchemaChecker::SchemaChecker(rdbms::Login::DbType dbType,cta::rdbms::Conn &conn)
SchemaChecker::~SchemaChecker() {
}
void SchemaChecker::useSQLiteSchemaComparer(const std::string &allSchemasVersionPath){
m_schemaComparer.reset(new SQLiteSchemaComparer(m_dbType,m_catalogueConn,allSchemasVersionPath));
void SchemaChecker::useSQLiteSchemaComparer(const cta::optional<std::string> allSchemasVersionsDirectory){
m_schemaComparer.reset(new SQLiteSchemaComparer(m_dbType,m_catalogueConn));
std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader;
if(allSchemasVersionsDirectory){
schemaSqlStatementsReader.reset(new DirectoryVersionsSqlStatementsReader(m_dbType,m_schemaComparer->getCatalogueVersion(),allSchemasVersionsDirectory.value()));
} else {
schemaSqlStatementsReader.reset(new MapSqlStatementsReader(m_dbType,m_schemaComparer->getCatalogueVersion()));
}
m_schemaComparer->setSchemaSqlStatementsReader(std::move(schemaSqlStatementsReader));
}
SchemaChecker::Status SchemaChecker::compareSchema(){
......
......@@ -61,18 +61,9 @@ public:
* statements defined in the allSchemasDirectoryPath and will compare what is in SQLite with
* what is in the catalogue database.
*
* @param allSchemasDirectoryPath the path where all the schemas sql files are located.
* This directory should contains all the directories containing the schema creation script specific to a schema VERSION
* Example of the content of the directory :
* catalogue
* |-- 1.0
* | |-- oracle_catalogue_schema.sql
* | |-- postgres_catalogue_schema.sql
* | |....
* |-- 1.1
* | |-- ...
* @param allSchemaVersionsDirectoryPath the schema sql statement reader used to get the schema
*/
void useSQLiteSchemaComparer(const std::string &allSchemasDirectoryPath);
void useSQLiteSchemaComparer(cta::optional<std::string> allSchemaVersionsDirectoryPath);
/**
* Compare the schema by using a SchemaComparer
* @throws Exception if no SchemaComparer has been set.
......
......@@ -35,6 +35,10 @@ std::string SchemaComparer::getCatalogueVersion(){
return m_catalogueSchemaVersion;
}
void SchemaComparer::setSchemaSqlStatementsReader(std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader){
m_schemaSqlStatementsReader = std::move(schemaSqlStatementsReader);
}
SchemaComparer::~SchemaComparer() {
}
......
......@@ -27,6 +27,7 @@
#include "rdbms/ConnPool.hpp"
#include "SchemaComparerResult.hpp"
#include "CatalogueMetadataGetter.hpp"
#include "SchemaSqlStatementsReader.hpp"
namespace cta {
namespace catalogue {
......@@ -67,11 +68,19 @@ public:
* @return the catalogue version of the schema located in the database to compare
*/
std::string getCatalogueVersion();
/**
* Sets the way the schema sql statements will be read to do the schemas comparison
* @param schemaSqlStatementsReader the reader used to get the schema sql statements in order to do schema comparison
*/
void setSchemaSqlStatementsReader(std::unique_ptr<SchemaSqlStatementsReader> schemaSqlStatementsReader);
protected:
const cta::rdbms::Login::DbType &m_dbType;
std::string m_catalogueSchemaVersion;
cta::rdbms::Conn &m_catalogueConn;
std::unique_ptr<cta::catalogue::CatalogueMetadataGetter> m_catalogueMetadataGetter;
std::unique_ptr<SchemaSqlStatementsReader> m_schemaSqlStatementsReader;
bool m_compareTableConstraints;
};
......
/**
* The CERN Tape Archive (CTA) project
* Copyright © 2018 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 <memory>
#include <fstream>
#include "SchemaSqlStatementsReader.hpp"
#include "SqliteCatalogueSchema.hpp"
#include "PostgresCatalogueSchema.hpp"
#include "MysqlCatalogueSchema.hpp"
#include "OracleCatalogueSchema.hpp"
#include "common/exception/Exception.hpp"
#include "common/utils/utils.hpp"
#include "AllCatalogueSchema.hpp"
namespace cta{ namespace catalogue{
//////////////////////////////////////////////////////////////////
// SchemaSqlStatementsReader
//////////////////////////////////////////////////////////////////
SchemaSqlStatementsReader::SchemaSqlStatementsReader(const cta::rdbms::Login::DbType dbType):m_dbType(dbType) {
}
SchemaSqlStatementsReader::SchemaSqlStatementsReader(const SchemaSqlStatementsReader& orig) {
m_dbType = orig.m_dbType;
}
SchemaSqlStatementsReader::~SchemaSqlStatementsReader() {
}
std::list<std::string> SchemaSqlStatementsReader::getStatements(){
std::unique_ptr<CatalogueSchema> schema;
switch(m_dbType) {
case rdbms::Login::DBTYPE_IN_MEMORY:
case rdbms::Login::DBTYPE_SQLITE:
schema.reset(new SqliteCatalogueSchema);
break;
case rdbms::Login::DBTYPE_POSTGRESQL:
schema.reset(new PostgresCatalogueSchema);
break;
case rdbms::Login::DBTYPE_MYSQL:
schema.reset(new MysqlCatalogueSchema);
break;
case rdbms::Login::DBTYPE_ORACLE:
schema.reset(new OracleCatalogueSchema);
break;
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("Cannot get statements without a database type");
}
return getAllStatementsFromSchema(schema->sql);
}
std::list<std::string> SchemaSqlStatementsReader::getAllStatementsFromSchema(const std::string& schema){
std::list<std::string> statements;
std::string::size_type searchPos = 0;
std::string::size_type findResult = std::string::npos;
try {
while(std::string::npos != (findResult = schema.find(';', searchPos))) {
// Calculate the length of the current statement without the trailing ';'
const std::string::size_type stmtLen = findResult - searchPos;
const std::string sqlStmt = utils::trimString(schema.substr(searchPos, stmtLen));
searchPos = findResult + 1;
if(0 < sqlStmt.size()) { // Ignore empty statements
statements.push_back(sqlStmt+";");
}
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
return statements;
}
std::string SchemaSqlStatementsReader::getDatabaseType() {
switch(m_dbType){
case rdbms::Login::DBTYPE_IN_MEMORY:
case rdbms::Login::DBTYPE_SQLITE:
return "sqlite";
case rdbms::Login::DBTYPE_POSTGRESQL:
return "postgres";
case rdbms::Login::DBTYPE_MYSQL:
return "mysql";
case rdbms::Login::DBTYPE_ORACLE:
return "oracle";
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("The database type should not be DBTYPE_NONE");
default:
{
exception::Exception ex;
ex.getMessage() << "Unknown database type: value=" << m_dbType;
throw ex;
}
}
}
//////////////////////////////////////////////////////////////////
// DirectoryVersionsSqlStatementsReader
//////////////////////////////////////////////////////////////////
DirectoryVersionsSqlStatementsReader::DirectoryVersionsSqlStatementsReader(const cta::rdbms::Login::DbType dbType,const std::string &catalogueVersion,const std::string &allSchemasVersionPath):SchemaSqlStatementsReader(dbType),m_catalogueVersion(catalogueVersion),m_allSchemasVersionPath(allSchemasVersionPath) {
}
DirectoryVersionsSqlStatementsReader::DirectoryVersionsSqlStatementsReader(const DirectoryVersionsSqlStatementsReader& orig):SchemaSqlStatementsReader(orig) {
m_allSchemasVersionPath = orig.m_allSchemasVersionPath;
m_catalogueVersion = orig.m_catalogueVersion;
}
DirectoryVersionsSqlStatementsReader::~DirectoryVersionsSqlStatementsReader() {
}
std::list<std::string> DirectoryVersionsSqlStatementsReader::getStatements(){
return getAllStatementsFromSchema(readSchemaFromFile());
}
std::string DirectoryVersionsSqlStatementsReader::readSchemaFromFile() {
std::string schemaFilePath = getSchemaFilePath();
std::ifstream schemaFile(schemaFilePath);
if(schemaFile.fail()){
throw cta::exception::Exception("In DirectoryVersionsSqlStatementsReader::readSchemaFromFile(), unable to open the file located in "+schemaFilePath);
}
std::string content((std::istreambuf_iterator<char>(schemaFile)),(std::istreambuf_iterator<char>()));
return content;
}
std::string DirectoryVersionsSqlStatementsReader::getSchemaFilePath() {
return m_allSchemasVersionPath+m_catalogueVersion+"/"+getDatabaseType()+c_catalogueFileNameTrailer;
}
//////////////////////////////////////////////////////////////////
// MapSqlStatementsReader
//////////////////////////////////////////////////////////////////
MapSqlStatementsReader::MapSqlStatementsReader(const cta::rdbms::Login::DbType dbType, const std::string &catalogueVersion):SchemaSqlStatementsReader(dbType),m_catalogueVersion(catalogueVersion){}
MapSqlStatementsReader::MapSqlStatementsReader(const MapSqlStatementsReader& orig):SchemaSqlStatementsReader(orig) {
m_catalogueVersion = orig.m_catalogueVersion;
}
MapSqlStatementsReader::~MapSqlStatementsReader() {
}
std::list<std::string> MapSqlStatementsReader::getStatements(){