Commit ab78c127 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[catalogue] TAPE_FILE.SUPERSEDED_BY_VID and TAPE_FILE.SUPERSEDED_BY_FSEQ are...

[catalogue] TAPE_FILE.SUPERSEDED_BY_VID and TAPE_FILE.SUPERSEDED_BY_FSEQ are not used in any query anymore
parent 594f9a4c
......@@ -51,7 +51,6 @@ set (CATALOGUE_LIB_SRC_FILES
RdbmsCatalogue.cpp
RdbmsCatalogueGetArchiveFilesForRepackItor.cpp
RdbmsCatalogueGetArchiveFilesItor.cpp
RdbmsCatalogueGetDeletedArchiveFilesItor.cpp
RdbmsCatalogueTapeContentsItor.cpp
RdbmsCatalogueGetFileRecycleLogItor.cpp
SchemaCreatingSqliteCatalogue.cpp
......
......@@ -863,13 +863,6 @@ public:
typedef CatalogueItor<common::dataStructures::DeletedArchiveFile> DeletedArchiveFileItor;
/**
* Returns all the currently deleted archive files. Please note that the list
* of archive files is ordered by archive file ID.
*
* @return The deleted archive files ordered by archive file ID.
*/
virtual DeletedArchiveFileItor getDeletedArchiveFilesItor() const = 0;
typedef CatalogueItor<common::dataStructures::FileRecycleLog> FileRecycleLogItor;
......
......@@ -520,10 +520,6 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getArchiveFilesItor(searchCriteria);}, m_maxTriesToConnect);
}
DeletedArchiveFileItor getDeletedArchiveFilesItor() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getDeletedArchiveFilesItor();}, m_maxTriesToConnect);
}
FileRecycleLogItor getFileRecycleLogItor() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getFileRecycleLogItor();}, m_maxTriesToConnect);
}
......
......@@ -217,18 +217,7 @@ void cta_catalogue_CatalogueTest::SetUp() {
m_catalogue->DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(archiveFile.diskInstance, archiveFile.archiveFileID, dummyLc);
}
}
{
//Delete all the entries from the recycle bin
auto itor = m_catalogue->getDeletedArchiveFilesItor();
std::list<common::dataStructures::DeletedArchiveFile> deletedArchiveFiles;
while(itor.hasMore()){
deletedArchiveFiles.push_back(itor.next());
}
for(const auto &deletedArchiveFile: deletedArchiveFiles){
m_catalogue->deleteFileFromRecycleBin(deletedArchiveFile.archiveFileID,dummyLc);
}
}
{
//Delete all the entries from the recycle log table
auto itor = m_catalogue->getFileRecycleLogItor();
......@@ -297,9 +286,9 @@ void cta_catalogue_CatalogueTest::SetUp() {
if(!m_catalogue->getArchiveRoutes().empty()) {
throw exception::Exception("Found one of more archive routes after emptying the database");
}
if(m_catalogue->getDeletedArchiveFilesItor().hasMore()) {
throw exception::Exception("Found one of more deleted archive files after emptying the database");
if(m_catalogue->getFileRecycleLogItor().hasMore()){
throw exception::Exception("Found one or more files in the file recycle log after emptying the database");
}
 
if(!m_catalogue->getAllDiskSystems().empty()) {
......@@ -9739,7 +9728,6 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.vid = tape1.vid;
searchCriteria.showSuperseded = true;
auto archiveFileItor = m_catalogue->getArchiveFilesItor(searchCriteria);
std::map<uint64_t, common::dataStructures::ArchiveFile> m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
......
......@@ -82,7 +82,6 @@ public:
std::list<common::dataStructures::AdminUser> getAdminUsers() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
DeletedArchiveFileItor getDeletedArchiveFilesItor() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
FileRecycleLogItor getFileRecycleLogItor() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void deleteFileFromRecycleBin(const uint64_t archiveFileId, log::LogContext &lc) {throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");}
void deleteFilesFromRecycleLog(const std::string & vid, log::LogContext & lc) {throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");}
......
......@@ -43,7 +43,7 @@ namespace cta { namespace catalogue {
}
static std::string getDeletionReasonLog(const std::string & deleterName, const std::string & diskInstanceName){
return "File deleted by " + deleterName + "from the " + diskInstanceName + "instance";
return "File deleted by " + deleterName + " from the " + diskInstanceName + " instance";
}
};
......
......@@ -21,7 +21,6 @@
#include "catalogue/RdbmsCatalogue.hpp"
#include "catalogue/RdbmsCatalogueGetArchiveFilesItor.hpp"
#include "catalogue/RdbmsCatalogueGetArchiveFilesForRepackItor.hpp"
#include "catalogue/RdbmsCatalogueGetDeletedArchiveFilesItor.hpp"
#include "catalogue/RdbmsCatalogueTapeContentsItor.hpp"
#include "catalogue/SchemaVersion.hpp"
#include "catalogue/SqliteCatalogueSchema.hpp"
......@@ -3952,9 +3951,7 @@ uint64_t RdbmsCatalogue::getNbFilesOnTape(rdbms::Conn& conn, const std::string&
void RdbmsCatalogue::deleteTapeFiles(rdbms::Conn& conn, const std::string& vid) const {
try {
const char * const sql =
"DELETE FROM TAPE_FILE WHERE VID = :VID "
"AND SUPERSEDED_BY_VID IS NOT NULL "
"AND SUPERSEDED_BY_FSEQ IS NOT NULL";
"DELETE FROM TAPE_FILE WHERE VID = :VID";
auto stmt = conn.createStmt(sql);
stmt.bindString(":VID", vid);
stmt.executeNonQuery();
......@@ -6726,8 +6723,7 @@ Catalogue::ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSea
// If this is the listing of the contents of a tape
if (!searchCriteria.archiveFileId && !searchCriteria.diskInstance && !searchCriteria.diskFileIds &&
searchCriteria.vid) {
const bool showSuperseded = searchCriteria.showSuperseded ? searchCriteria.showSuperseded.value() : false;
return getTapeContentsItor(searchCriteria.vid.value(), showSuperseded);
return getTapeContentsItor(searchCriteria.vid.value());
}
try {
......@@ -6748,11 +6744,11 @@ Catalogue::ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSea
//------------------------------------------------------------------------------
// getTapeContentsItor
//------------------------------------------------------------------------------
Catalogue::ArchiveFileItor RdbmsCatalogue::getTapeContentsItor(const std::string &vid, const bool showSuperseded)
Catalogue::ArchiveFileItor RdbmsCatalogue::getTapeContentsItor(const std::string &vid)
const {
try {
// Create a connection to populate the temporary table (specialised by database type)
auto impl = new RdbmsCatalogueTapeContentsItor(m_log, m_connPool, vid, showSuperseded);
auto impl = new RdbmsCatalogueTapeContentsItor(m_log, m_connPool, vid);
return ArchiveFileItor(impl);
} catch(exception::UserError &) {
throw;
......@@ -6762,22 +6758,6 @@ Catalogue::ArchiveFileItor RdbmsCatalogue::getTapeContentsItor(const std::string
}
}
//------------------------------------------------------------------------------
// getDeletedArchiveFilesItor
//------------------------------------------------------------------------------
Catalogue::DeletedArchiveFileItor RdbmsCatalogue::getDeletedArchiveFilesItor() const {
try {
auto impl = new RdbmsCatalogueGetDeletedArchiveFilesItor(m_log, m_archiveFileListingConnPool);
return DeletedArchiveFileItor(impl);
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
Catalogue::FileRecycleLogItor RdbmsCatalogue::getFileRecycleLogItor() const {
try {
auto impl = new RdbmsCatalogueGetFileRecycleLogItor(m_log, m_archiveFileListingConnPool);
......@@ -6830,8 +6810,7 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getFilesForRepack
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
"WHERE "
"TAPE_FILE.VID = :VID AND "
"TAPE_FILE.FSEQ >= :START_FSEQ AND "
"TAPE_FILE.SUPERSEDED_BY_VID IS NULL "
"TAPE_FILE.FSEQ >= :START_FSEQ "
"ORDER BY FSEQ";
auto conn = m_connPool.getConn();
......@@ -6922,13 +6901,11 @@ common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary(
"INNER JOIN TAPE_POOL ON "
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID";
const bool hideSuperseded = searchCriteria.showSuperseded ? !*searchCriteria.showSuperseded : false;
const bool thereIsAtLeastOneSearchCriteria =
searchCriteria.archiveFileId ||
searchCriteria.diskInstance ||
searchCriteria.vid ||
searchCriteria.diskFileIds ||
hideSuperseded;
searchCriteria.diskFileIds;
if(thereIsAtLeastOneSearchCriteria) {
sql += " WHERE ";
......@@ -6957,11 +6934,6 @@ common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary(
sql += "ARCHIVE_FILE.DISK_FILE_ID IN (SELECT DISK_FILE_ID FROM " + tempDiskFxidsTableName + ")";
addedAWhereConstraint = true;
}
if(hideSuperseded) {
if(addedAWhereConstraint) sql += " AND ";
sql += "TAPE_FILE.SUPERSEDED_BY_VID IS NULL";
addedAWhereConstraint = true;
}
auto stmt = conn.createStmt(sql);
if(searchCriteria.archiveFileId) {
......
......@@ -838,13 +838,10 @@ public:
ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const override;
/**
* Returns all the currently deleted archive files. Please note that the list
* of archive files is ordered by archive file ID.
* Returns all the currently deleted files by looking at the FILE_RECYCLE_LOG table
*
* @return The deleted archive files ordered by archive file ID.
*/
DeletedArchiveFileItor getDeletedArchiveFilesItor() const override;
FileRecycleLogItor getFileRecycleLogItor() const override;
/**
......@@ -2018,10 +2015,9 @@ protected:
* FSEQ.
*
* @param vid The volume identifier of the tape.
* @param showSuperseded Include superseded files in the output?
* @return The iterator.
*/
ArchiveFileItor getTapeContentsItor(const std::string &vid, const bool showSuperseded) const;
ArchiveFileItor getTapeContentsItor(const std::string &vid) const;
/**
* Cached versions of tape copy to tape tape pool mappings for specific
......
......@@ -95,8 +95,6 @@ RdbmsCatalogueGetArchiveFilesForRepackItor::RdbmsCatalogueGetArchiveFilesForRepa
"TAPE_COPY.LOGICAL_SIZE_IN_BYTES AS LOGICAL_SIZE_IN_BYTES,"
"TAPE_COPY.COPY_NB AS COPY_NB,"
"TAPE_COPY.CREATION_TIME AS TAPE_FILE_CREATION_TIME, "
"TAPE_COPY.SUPERSEDED_BY_VID AS SUPERSEDED_BY_VID, "
"TAPE_COPY.SUPERSEDED_BY_FSEQ AS SUPERSEDED_BY_FSEQ, "
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME "
"FROM "
"TAPE_FILE REPACK_TAPE "
......@@ -114,10 +112,6 @@ RdbmsCatalogueGetArchiveFilesForRepackItor::RdbmsCatalogueGetArchiveFilesForRepa
"REPACK_TAPE.VID = :VID "
"AND "
"REPACK_TAPE.FSEQ >= :START_FSEQ "
"AND "
"REPACK_TAPE.SUPERSEDED_BY_VID IS NULL "
"AND "
"REPACK_TAPE.SUPERSEDED_BY_FSEQ IS NULL "
"ORDER BY REPACK_TAPE.FSEQ";
m_conn = connPool.getConn();
......
......@@ -99,8 +99,6 @@ RdbmsCatalogueGetArchiveFilesItor::RdbmsCatalogueGetArchiveFilesItor(
"TAPE_FILE.LOGICAL_SIZE_IN_BYTES AS LOGICAL_SIZE_IN_BYTES,"
"TAPE_FILE.COPY_NB AS COPY_NB,"
"TAPE_FILE.CREATION_TIME AS TAPE_FILE_CREATION_TIME, "
"TAPE_FILE.SUPERSEDED_BY_VID AS SUPERSEDED_BY_VID, "
"TAPE_FILE.SUPERSEDED_BY_FSEQ AS SUPERSEDED_BY_FSEQ, "
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME "
"FROM "
"ARCHIVE_FILE "
......@@ -113,13 +111,11 @@ RdbmsCatalogueGetArchiveFilesItor::RdbmsCatalogueGetArchiveFilesItor(
"INNER JOIN TAPE_POOL ON "
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID";
const bool hideSuperseded = searchCriteria.showSuperseded ? !*searchCriteria.showSuperseded : false;
const bool thereIsAtLeastOneSearchCriteria =
searchCriteria.archiveFileId ||
searchCriteria.diskInstance ||
searchCriteria.vid ||
searchCriteria.diskFileIds ||
hideSuperseded;
searchCriteria.diskFileIds;
if(thereIsAtLeastOneSearchCriteria) {
sql += " WHERE ";
......@@ -146,11 +142,6 @@ RdbmsCatalogueGetArchiveFilesItor::RdbmsCatalogueGetArchiveFilesItor(
sql += "ARCHIVE_FILE.DISK_FILE_ID IN (SELECT DISK_FILE_ID FROM " + tempDiskFxidsTableName + ")";
addedAWhereConstraint = true;
}
if(hideSuperseded) {
if(addedAWhereConstraint) sql += " AND ";
sql += "TAPE_FILE.SUPERSEDED_BY_VID IS NULL";
addedAWhereConstraint = true;
}
// Order by FSEQ if we are listing the contents of a tape, else order by archive file ID
if(searchCriteria.vid) {
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2019 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 "RdbmsCatalogueGetDeletedArchiveFilesItor.hpp"
#include "common/log/LogContext.hpp"
#include "common/exception/UserError.hpp"
namespace cta {
namespace catalogue {
namespace {
/**
* Populates an ArchiveFile object with the current column values of the
* specified result set.
*
* @param rset The result set to be used to populate the ArchiveFile object.
* @return The populated ArchiveFile object.
*/
static common::dataStructures::DeletedArchiveFile populateDeletedArchiveFile(const rdbms::Rset &rset) {
rset.columnUint64("ARCHIVE_FILE_ID");
if(!rset.columnIsNull("VID")) {
rset.columnUint64("COPY_NB");
}
common::dataStructures::DeletedArchiveFile deletedArchiveFile;
deletedArchiveFile.archiveFileID = rset.columnUint64("ARCHIVE_FILE_ID");
deletedArchiveFile.diskInstance = rset.columnString("DISK_INSTANCE_NAME");
deletedArchiveFile.diskFileId = rset.columnString("DISK_FILE_ID");
deletedArchiveFile.diskFileInfo.owner_uid = rset.columnUint64("DISK_FILE_UID");
deletedArchiveFile.diskFileInfo.gid = rset.columnUint64("DISK_FILE_GID");
deletedArchiveFile.fileSize = rset.columnUint64("SIZE_IN_BYTES");
deletedArchiveFile.checksumBlob.deserializeOrSetAdler32(rset.columnBlob("CHECKSUM_BLOB"), rset.columnUint64("CHECKSUM_ADLER32"));
deletedArchiveFile.storageClass = rset.columnString("STORAGE_CLASS_NAME");
deletedArchiveFile.creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME");
deletedArchiveFile.reconciliationTime = rset.columnUint64("RECONCILIATION_TIME");
deletedArchiveFile.diskFileIdWhenDeleted = rset.columnString("DISK_FILE_ID_WHEN_DELETED");
deletedArchiveFile.diskFilePath = rset.columnString("DISK_FILE_PATH");
deletedArchiveFile.deletionTime = rset.columnUint64("DELETION_TIME");
// If there is a tape file
if (!rset.columnIsNull("VID")) {
common::dataStructures::TapeFile tapeFile;
tapeFile.vid = rset.columnString("VID");
tapeFile.fSeq = rset.columnUint64("FSEQ");
tapeFile.blockId = rset.columnUint64("BLOCK_ID");
tapeFile.fileSize = rset.columnUint64("LOGICAL_SIZE_IN_BYTES");
tapeFile.copyNb = rset.columnUint64("COPY_NB");
tapeFile.creationTime = rset.columnUint64("TAPE_FILE_CREATION_TIME");
tapeFile.checksumBlob = deletedArchiveFile.checksumBlob; // Duplicated for convenience
deletedArchiveFile.tapeFiles.push_back(tapeFile);
}
return deletedArchiveFile;
}
} // anonymous namespace
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
RdbmsCatalogueGetDeletedArchiveFilesItor::RdbmsCatalogueGetDeletedArchiveFilesItor(
log::Logger &log,
rdbms::ConnPool &connPool):
m_log(log),
m_connPool(connPool),
m_rsetIsEmpty(true),
m_hasMoreHasBeenCalled(false),
m_archiveFileBuilder(log) {
try {
std::string sql =
"SELECT "
"ARCHIVE_FILE_RECYCLE_BIN.ARCHIVE_FILE_ID AS ARCHIVE_FILE_ID,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_INSTANCE_NAME AS DISK_INSTANCE_NAME,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_FILE_ID AS DISK_FILE_ID,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_FILE_UID AS DISK_FILE_UID,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_FILE_GID AS DISK_FILE_GID,"
"ARCHIVE_FILE_RECYCLE_BIN.SIZE_IN_BYTES AS SIZE_IN_BYTES,"
"ARCHIVE_FILE_RECYCLE_BIN.CHECKSUM_BLOB AS CHECKSUM_BLOB,"
"ARCHIVE_FILE_RECYCLE_BIN.CHECKSUM_ADLER32 AS CHECKSUM_ADLER32,"
"STORAGE_CLASS.STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME,"
"ARCHIVE_FILE_RECYCLE_BIN.CREATION_TIME AS ARCHIVE_FILE_CREATION_TIME,"
"ARCHIVE_FILE_RECYCLE_BIN.RECONCILIATION_TIME AS RECONCILIATION_TIME,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_FILE_ID_WHEN_DELETED AS DISK_FILE_ID_WHEN_DELETED,"
"ARCHIVE_FILE_RECYCLE_BIN.DISK_FILE_PATH AS DISK_FILE_PATH,"
"ARCHIVE_FILE_RECYCLE_BIN.DELETION_TIME AS DELETION_TIME,"
"TAPE_FILE_RECYCLE_BIN.VID AS VID,"
"TAPE_FILE_RECYCLE_BIN.FSEQ AS FSEQ,"
"TAPE_FILE_RECYCLE_BIN.BLOCK_ID AS BLOCK_ID,"
"TAPE_FILE_RECYCLE_BIN.LOGICAL_SIZE_IN_BYTES AS LOGICAL_SIZE_IN_BYTES,"
"TAPE_FILE_RECYCLE_BIN.COPY_NB AS COPY_NB,"
"TAPE_FILE_RECYCLE_BIN.CREATION_TIME AS TAPE_FILE_CREATION_TIME, "
"TAPE_FILE_RECYCLE_BIN.SUPERSEDED_BY_VID AS SUPERSEDED_BY_VID, "
"TAPE_FILE_RECYCLE_BIN.SUPERSEDED_BY_FSEQ AS SUPERSEDED_BY_FSEQ, "
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME "
"FROM "
"ARCHIVE_FILE_RECYCLE_BIN "
"INNER JOIN STORAGE_CLASS ON "
"ARCHIVE_FILE_RECYCLE_BIN.STORAGE_CLASS_ID = STORAGE_CLASS.STORAGE_CLASS_ID "
"INNER JOIN TAPE_FILE_RECYCLE_BIN ON "
"ARCHIVE_FILE_RECYCLE_BIN.ARCHIVE_FILE_ID = TAPE_FILE_RECYCLE_BIN.ARCHIVE_FILE_ID "
"INNER JOIN TAPE ON "
"TAPE_FILE_RECYCLE_BIN.VID = TAPE.VID "
"INNER JOIN TAPE_POOL ON "
"TAPE.TAPE_POOL_ID = TAPE_POOL.TAPE_POOL_ID "
// The following ORDER BY CLAUSE is required by the ArchiveFileBuilder
// which needs tape files with a common archive file to be adjacent to
// each other in the result set
"ORDER BY ARCHIVE_FILE_ID, COPY_NB";
m_conn = connPool.getConn();
m_stmt = m_conn.createStmt(sql);
m_rset = m_stmt.executeQuery();
{
log::LogContext lc(m_log);
lc.log(log::INFO, "RdbmsCatalogueGetDeletedArchiveFilesItor - immediately after m_stmt.executeQuery()");
}
m_rsetIsEmpty = !m_rset.next();
if(m_rsetIsEmpty) releaseDbResources();
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
RdbmsCatalogueGetDeletedArchiveFilesItor::~RdbmsCatalogueGetDeletedArchiveFilesItor() {
releaseDbResources();
}
//------------------------------------------------------------------------------
// releaseDbResources
//------------------------------------------------------------------------------
void RdbmsCatalogueGetDeletedArchiveFilesItor::releaseDbResources() noexcept {
m_rset.reset();
m_stmt.reset();
m_conn.reset();
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool RdbmsCatalogueGetDeletedArchiveFilesItor::hasMore() {
m_hasMoreHasBeenCalled = true;
if(m_rsetIsEmpty) {
// If there is an ArchiveFile object under construction
if(nullptr != m_archiveFileBuilder.getArchiveFile()) {
return true;
} else {
return false;
}
} else {
return true;
}
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
common::dataStructures::DeletedArchiveFile RdbmsCatalogueGetDeletedArchiveFilesItor::next() {
try {
if(!m_hasMoreHasBeenCalled) {
throw exception::Exception("hasMore() must be called before next()");
}
m_hasMoreHasBeenCalled = false;
// If there are no more rows in the result set
if(m_rsetIsEmpty) {
// There must be an ArchiveFile object currently under construction
if(nullptr == m_archiveFileBuilder.getArchiveFile()) {
throw exception::Exception("next() was called with no more rows in the result set and no ArchiveFile object"
" under construction");
}
// Return the ArchiveFile object that must now be complete and clear the
// ArchiveFile builder
common::dataStructures::DeletedArchiveFile tmp = *m_archiveFileBuilder.getArchiveFile();
m_archiveFileBuilder.clear();
return tmp;
}
while(true) {
auto archiveFile = populateDeletedArchiveFile(m_rset);
auto completeArchiveFile = m_archiveFileBuilder.append(archiveFile);
m_rsetIsEmpty = !m_rset.next();
if(m_rsetIsEmpty) releaseDbResources();
// If the ArchiveFile object under construction is complete
if (nullptr != completeArchiveFile.get()) {
return *completeArchiveFile;
// The ArchiveFile object under construction is not complete
} else {
if(m_rsetIsEmpty) {
// There must be an ArchiveFile object currently under construction
if (nullptr == m_archiveFileBuilder.getArchiveFile()) {
throw exception::Exception("next() was called with no more rows in the result set and no ArchiveFile object"
" under construction");
}
// Return the ArchiveFile object that must now be complete and clear the
// ArchiveFile builder
common::dataStructures::DeletedArchiveFile * tmp = m_archiveFileBuilder.getArchiveFile();
m_archiveFileBuilder.clear();
return *tmp;
}
}
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
}}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2019 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 "catalogue/ArchiveFileBuilder.hpp"
#include "catalogue/Catalogue.hpp"
#include "common/dataStructures/DeletedArchiveFile.hpp"
#include "common/log/Logger.hpp"
#include "rdbms/ConnPool.hpp"
#include "rdbms/Stmt.hpp"
#include "rdbms/Rset.hpp"
namespace cta {
namespace catalogue {
class RdbmsCatalogueGetDeletedArchiveFilesItor: public Catalogue::DeletedArchiveFileItor::Impl {
public:
/**
* Constructor.
*
* @param log Object representing the API to the CTA logging system.
* @param connPool The database connection pool.
*/
RdbmsCatalogueGetDeletedArchiveFilesItor(log::Logger &log, rdbms::ConnPool &connPool);
/**
* Destructor.
*/
~RdbmsCatalogueGetDeletedArchiveFilesItor() override;
/**
* Returns true if a call to next would return another archive file.
*/
bool hasMore() override;
/**
* Returns the next archive or throws an exception if there isn't one.
*/
common::dataStructures::DeletedArchiveFile next() override;
private:
/**
* Object representing the API to the CTA logging system.
*/
log::Logger &m_log;
/**
* The database connection pool.
*/
rdbms::ConnPool &m_connPool;
/**
* The search criteria to be used when listing archive files.
*/
TapeFileSearchCriteria m_searchCriteria;
/**
* True if the result set is empty.
*/
bool m_rsetIsEmpty;
/**
* True if hasMore() has been called and the corresponding call to next() has
* not.
*
* This member-variable is used to prevent next() being called before
* hasMore().
*/
bool m_hasMoreHasBeenCalled;
/**
* The database connection.
*/