Commit 7f426708 authored by Steven Murray's avatar Steven Murray
Browse files

Removed ArchiveFileItor.?pp and DeletedArchiveFileItor.?pp

parent 26b3dc2b
/*
* 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/ArchiveFileItor.hpp"
#include "catalogue/CatalogueItorImpl.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileItor::ArchiveFileItor():
m_impl(nullptr) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileItor::ArchiveFileItor(ArchiveFileItor::Impl *const impl):
m_impl(impl) {
if(nullptr == impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Pointer to implementation object is null");
}
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileItor::ArchiveFileItor(ArchiveFileItor &&other):
m_impl(other.m_impl) {
other.m_impl = nullptr;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
ArchiveFileItor::~ArchiveFileItor() {
delete m_impl;
}
//------------------------------------------------------------------------------
// operator=
//------------------------------------------------------------------------------
ArchiveFileItor &ArchiveFileItor::operator=(ArchiveFileItor &&rhs) {
// Protect against self assignment
if(this != &rhs) {
// Avoid memory leak
delete m_impl;
m_impl = rhs.m_impl;
rhs.m_impl = nullptr;
}
return *this;
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool ArchiveFileItor::hasMore() const {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: "
"This iterator is invalid");
}
return m_impl->hasMore();
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFile ArchiveFileItor::next() {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: "
"This iterator is invalid");
}
return m_impl->next();
}
} // namespace catalogue
} // namespace cta
......@@ -29,13 +29,11 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set (CATALOGUE_LIB_SRC_FILES
ArchiveFileBuilder.cpp
ArchiveFileRow.cpp
ArchiveFileItor.cpp
Catalogue.cpp
CatalogueFactory.cpp
CatalogueFactoryFactory.cpp
CatalogueSchema.cpp
CmdLineTool.cpp
DeletedArchiveFileItor.cpp
InMemoryCatalogue.cpp
InMemoryCatalogueFactory.cpp
MysqlCatalogue.cpp
......
......@@ -18,10 +18,11 @@
#pragma once
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/CatalogueItor.hpp"
#include "catalogue/CreateTapeAttributes.hpp"
#include "catalogue/MediaType.hpp"
#include "catalogue/MediaTypeWithLogs.hpp"
#include "catalogue/SchemaVersion.hpp"
#include "catalogue/TapeFileSearchCriteria.hpp"
#include "catalogue/TapeItemWrittenPointer.hpp"
#include "catalogue/TapeFileWritten.hpp"
......@@ -37,6 +38,7 @@
#include "common/dataStructures/ArchiveRoute.hpp"
#include "common/dataStructures/CancelRetrieveRequest.hpp"
#include "common/dataStructures/DeleteArchiveRequest.hpp"
#include "common/dataStructures/DeletedArchiveFile.hpp"
#include "common/dataStructures/DiskFileInfo.hpp"
#include "common/dataStructures/DriveState.hpp"
#include "common/dataStructures/EntryLog.hpp"
......@@ -60,22 +62,20 @@
#include "common/dataStructures/VirtualOrganization.hpp"
#include "common/dataStructures/VidToTapeMap.hpp"
#include "common/dataStructures/WriteTestResult.hpp"
#include "disk/DiskSystem.hpp"
#include "common/exception/FileSizeMismatch.hpp"
#include "common/exception/TapeFseqMismatch.hpp"
#include "common/exception/UserError.hpp"
#include "common/log/LogContext.hpp"
#include "common/log/Logger.hpp"
#include "common/optional.hpp"
#include "SchemaVersion.hpp"
#include "DeletedArchiveFileItor.hpp"
#include "disk/DiskSystem.hpp"
#include <list>
#include <map>
#include <memory>
#include <set>
#include <stdint.h>
#include <string>
#include <memory>
namespace cta {
......@@ -818,6 +818,8 @@ public:
const std::string &name, const uint64_t sleepTime) = 0;
virtual void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin,
const std::string &name, const std::string &comment) = 0;
typedef CatalogueItor<common::dataStructures::ArchiveFile> ArchiveFileItor;
/**
* Returns the specified archive files. Please note that the list of files
......@@ -829,6 +831,8 @@ public:
virtual ArchiveFileItor getArchiveFilesItor(
const TapeFileSearchCriteria &searchCriteria = TapeFileSearchCriteria()) const = 0;
typedef CatalogueItor<common::dataStructures::DeletedArchiveFile> DeletedArchiveFileItor;
/**
* Returns the specified deleted archive files. Please note that the list of files
* is ordered by archive file ID.
......
......@@ -19,70 +19,104 @@
#pragma once
#include "catalogue/CatalogueItorImpl.hpp"
#include "common/dataStructures/ArchiveFile.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
/**
* A wrapper around an object that iterators over a list of archive files.
* A wrapper around an object that iterators over a list of items retrieved
* from the CTA catalogue.
*
* This wrapper permits the user of the Catalogue API to use different
* iterator implementations whilst only using a single iterator type.
*/
class ArchiveFileItor {
template <typename Item>
class CatalogueItor {
public:
typedef CatalogueItorImpl<common::dataStructures::ArchiveFile> Impl;
typedef CatalogueItorImpl<Item> Impl;
/**
* Constructor.
*/
ArchiveFileItor();
CatalogueItor():
m_impl(nullptr) {
}
/**
* Constructor.
*
* @param impl The object actually implementing this iterator.
*/
ArchiveFileItor(Impl *const impl);
CatalogueItor(Impl *const impl):
m_impl(impl) {
if(nullptr == impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Pointer to implementation object is null");
}
}
/**
* Deletion of copy constructor.
*/
ArchiveFileItor(const ArchiveFileItor &) = delete;
CatalogueItor(const CatalogueItor &) = delete;
/**
* Move constructor.
*
* @param other The other object to be moved.
*/
ArchiveFileItor(ArchiveFileItor &&other);
CatalogueItor(CatalogueItor &&other):
m_impl(other.m_impl) {
other.m_impl = nullptr;
}
/**
* Destructor.
*/
~ArchiveFileItor();
~CatalogueItor() {
delete m_impl;
}
/**
* Deletion of copy assignment.
*/
ArchiveFileItor &operator=(const ArchiveFileItor &) = delete;
CatalogueItor &operator=(const CatalogueItor &) = delete;
/**
* Move assignment.
*/
ArchiveFileItor &operator=(ArchiveFileItor &&rhs);
CatalogueItor &operator=(CatalogueItor &&rhs) {
// Protect against self assignment
if(this != &rhs) {
// Avoid memory leak
delete m_impl;
m_impl = rhs.m_impl;
rhs.m_impl = nullptr;
}
return *this;
}
/**
* Returns true if a call to next would return another archive file.
* Returns true if a call to next would return another item.
*/
bool hasMore() const;
bool hasMore() const {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: This iterator is invalid");
}
return m_impl->hasMore();
}
/**
* Returns the next archive or throws an exception if there isn't one.
* Returns the next item or throws an exception if there isn't one.
*/
common::dataStructures::ArchiveFile next();
Item next() {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: This iterator is invalid");
}
return m_impl->next();
}
private:
......@@ -91,7 +125,7 @@ private:
*/
Impl *m_impl;
}; // class ArchiveFileItor
}; // class CatalogueItor
} // namespace catalogue
} // namespace cta
......@@ -28,7 +28,6 @@
#include "common/threading/Thread.hpp"
#include "common/threading/Mutex.hpp"
#include "common/threading/MutexLocker.hpp"
#include "DeletedArchiveFileItor.hpp"
 
#include <algorithm>
#include <gtest/gtest.h>
......@@ -347,7 +346,7 @@ std::map<std::string, cta::common::dataStructures::Tape> cta_catalogue_Catalogue
// archiveFileItorToMap
//------------------------------------------------------------------------------
std::map<uint64_t, cta::common::dataStructures::ArchiveFile> cta_catalogue_CatalogueTest::archiveFileItorToMap(
cta::catalogue::ArchiveFileItor &itor) {
cta::catalogue::Catalogue::ArchiveFileItor &itor) {
using namespace cta;
 
try {
......@@ -15184,7 +15183,7 @@ TEST_P(cta_catalogue_CatalogueTest, moveFilesToRecycleBin) {
std::vector<common::dataStructures::DeletedArchiveFile> deletedArchiveFiles;
{
cta::catalogue::DeletedArchiveFileItor itor = m_catalogue->getDeletedArchiveFilesItor();
auto itor = m_catalogue->getDeletedArchiveFilesItor();
while(itor.hasMore()){
deletedArchiveFiles.push_back(itor.next());
}
......@@ -15316,7 +15315,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTapeRemovesFilesFromRecycleBin) {
std::vector<common::dataStructures::DeletedArchiveFile> deletedArchiveFiles;
{
cta::catalogue::DeletedArchiveFileItor itor = m_catalogue->getDeletedArchiveFilesItor();
auto itor = m_catalogue->getDeletedArchiveFilesItor();
while(itor.hasMore()){
deletedArchiveFiles.push_back(itor.next());
}
......
......@@ -70,7 +70,7 @@ protected:
* @return Map from archive file ID to archive file.
*/
std::map<uint64_t, cta::common::dataStructures::ArchiveFile> archiveFileItorToMap(
cta::catalogue::ArchiveFileItor &itor);
cta::catalogue::Catalogue::ArchiveFileItor &itor);
/**
* Creates a map from archive file ID to archive file from the specified
......
/*
* 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 "DeletedArchiveFileItor.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
DeletedArchiveFileItor::DeletedArchiveFileItor():
m_impl(nullptr) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
DeletedArchiveFileItor::DeletedArchiveFileItor(DeletedArchiveFileItor::Impl *const impl):
m_impl(impl) {
if(nullptr == impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Pointer to implementation object is null");
}
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
DeletedArchiveFileItor::DeletedArchiveFileItor(DeletedArchiveFileItor &&other):
m_impl(other.m_impl) {
other.m_impl = nullptr;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
DeletedArchiveFileItor::~DeletedArchiveFileItor() {
delete m_impl;
}
//------------------------------------------------------------------------------
// operator=
//------------------------------------------------------------------------------
DeletedArchiveFileItor &DeletedArchiveFileItor::operator=(DeletedArchiveFileItor &&rhs) {
// Protect against self assignment
if(this != &rhs) {
// Avoid memory leak
delete m_impl;
m_impl = rhs.m_impl;
rhs.m_impl = nullptr;
}
return *this;
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool DeletedArchiveFileItor::hasMore() const {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: "
"This iterator is invalid");
}
return m_impl->hasMore();
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
common::dataStructures::DeletedArchiveFile DeletedArchiveFileItor::next() {
if(nullptr == m_impl) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: "
"This iterator is invalid");
}
return m_impl->next();
}
}}
/*
* 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 "common/dataStructures/DeletedArchiveFile.hpp"
#include "catalogue/CatalogueItorImpl.hpp"
namespace cta {
namespace catalogue {
class DeletedArchiveFileItor {
public:
typedef CatalogueItorImpl<common::dataStructures::DeletedArchiveFile> Impl;
/**
* Constructor.
*/
DeletedArchiveFileItor();
/**
* Constructor.
*
* @param impl The object actually implementing this iterator.
*/
DeletedArchiveFileItor(Impl *const impl);
/**
* Deletion of copy constructor.
*/
DeletedArchiveFileItor(const DeletedArchiveFileItor &) = delete;
/**
* Move constructor.
*
* @param other The other object to be moved.
*/
DeletedArchiveFileItor(DeletedArchiveFileItor &&other);
/**
* Destructor.
*/
~DeletedArchiveFileItor();
/**
* Deletion of copy assignment.
*/
DeletedArchiveFileItor &operator=(const DeletedArchiveFileItor &) = delete;
/**
* Move assignment.
*/
DeletedArchiveFileItor &operator=(DeletedArchiveFileItor &&rhs);
/**
* Returns true if a call to next would return another archive file.
*/
bool hasMore() const;
/**
* Returns the next archive or throws an exception if there isn't one.
*/
common::dataStructures::DeletedArchiveFile next();
private:
/**
* The object actually implementing this iterator.
*/
Impl *m_impl;
};
}}
......@@ -6544,7 +6544,7 @@ void RdbmsCatalogue::checkTapeFileSearchCriteria(const TapeFileSearchCriteria &s
//------------------------------------------------------------------------------
// getArchiveFilesItor
//------------------------------------------------------------------------------
ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const {
Catalogue::ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const {
checkTapeFileSearchCriteria(searchCriteria);
......@@ -6566,7 +6566,8 @@ ArchiveFileItor RdbmsCatalogue::getArchiveFilesItor(const TapeFileSearchCriteria
//------------------------------------------------------------------------------
// getDeletedArchiveFilesItor
//------------------------------------------------------------------------------
DeletedArchiveFileItor RdbmsCatalogue::getDeletedArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria) const {
Catalogue::DeletedArchiveFileItor RdbmsCatalogue::getDeletedArchiveFilesItor(
const TapeFileSearchCriteria &searchCriteria) const {
checkTapeFileSearchCriteria(searchCriteria);
......@@ -6679,7 +6680,7 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getFilesForRepack
//------------------------------------------------------------------------------
// getArchiveFileItorForRepack
//------------------------------------------------------------------------------
ArchiveFileItor RdbmsCatalogue::getArchiveFilesForRepackItor(const std::string &vid, const uint64_t startFSeq) const {
Catalogue::ArchiveFileItor RdbmsCatalogue::getArchiveFilesForRepackItor(const std::string &vid, const uint64_t startFSeq) const {
try {
auto impl = new RdbmsCatalogueGetArchiveFilesForRepackItor(m_log, m_archiveFileListingConnPool, vid, startFSeq);
return ArchiveFileItor(impl);
......
......@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/RdbmsCatalogueGetArchiveFilesForRepackItor.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/LostDatabaseConnection.hpp"
......
......@@ -19,6 +19,7 @@
#pragma once
#include "catalogue/ArchiveFileBuilder.hpp"
#include "catalogue/Catalogue.hpp"
#include "common/log/Logger.hpp"
#include "rdbms/ConnPool.hpp"
#include "rdbms/Stmt.hpp"
......@@ -32,7 +33,7 @@ namespace catalogue {
* RdbmsCatalogue::getArchiveFilesForRepack() implementation of
* ArchiveFileItorImpl.
*/
class RdbmsCatalogueGetArchiveFilesForRepackItor: public ArchiveFileItor::Impl {
class RdbmsCatalogueGetArchiveFilesForRepackItor: public Catalogue::ArchiveFileItor::Impl {
public:
/**
......
......@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/RdbmsCatalogueGetArchiveFilesItor.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/LostDatabaseConnection.hpp"
......
......@@ -19,6 +19,7 @@
#pragma once
#include "catalogue/ArchiveFileBuilder.hpp"
#include "catalogue/Catalogue.hpp"
#include "catalogue/TapeFileSearchCriteria.hpp"
#include "common/dataStructures/ArchiveFile.hpp"
#include "common/log/Logger.hpp"
......@@ -32,7 +33,7 @@ namespace catalogue {
/**
* RdbmsCatalogue::getArchiveFiles() implementation of ArchiveFileItorImpl.
*/
class RdbmsCatalogueGetArchiveFilesItor: public ArchiveFileItor::Impl {
class RdbmsCatalogueGetArchiveFilesItor: public Catalogue::ArchiveFileItor::Impl {
public:
/**
......
......@@ -19,7 +19,7 @@
#pragma once
#include "catalogue/ArchiveFileBuilder.hpp"
#include "catalogue/DeletedArchiveFileItor.hpp"
#include "catalogue/Catalogue.hpp"
#include "catalogue/TapeFileSearchCriteria.hpp"
#include "common/dataStructures/DeletedArchiveFile.hpp"
#include "common/log/Logger.hpp"
......@@ -31,7 +31,7 @@
namespace cta {
namespace catalogue {
class RdbmsCatalogueGetDeletedArchiveFilesItor: public DeletedArchiveFileItor::Impl {