Commit 8307191c authored by Steven Murray's avatar Steven Murray
Browse files

catalogue::ArchiveFileItor is no longer abstract

parent 84032229
......@@ -17,15 +17,73 @@
*/
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/ArchiveFileItorImpl.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileItor::ArchiveFileItor():
m_impl(nullptr) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveFileItor::ArchiveFileItor(ArchiveFileItorImpl *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) {
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
......
......@@ -24,26 +24,79 @@ namespace cta {
namespace catalogue {
/**
* Abstract class defining the interface to an iterator over a list of archive
* files.
* Forward declaration.
*/
class ArchiveFileItorImpl;
/**
* Forward declaration.
*/
class Catalogue;
/**
* A wrapper around an object that iterators over a list of archive files.
*
* This wrapper permits the user of the Catalogue API to use different
* iterator implementations whilst only using a single iterator type.
*/
class ArchiveFileItor {
public:
/**
* Constructor.
*/
ArchiveFileItor();
/**
* Constructor.
*
* @param impl The object actually implementing this iterator.
*/
ArchiveFileItor(ArchiveFileItorImpl *const impl);
/**
* Deletion of copy constructor.
*/
ArchiveFileItor(const ArchiveFileItor &) = delete;
/**
* Move constructor.
*
* @param other The other object to be moved.
*/
ArchiveFileItor(ArchiveFileItor &&other);
/**
* Destructor.
*/
virtual ~ArchiveFileItor() = 0;
~ArchiveFileItor();
/**
* Deletion of copy assignment.
*/
ArchiveFileItor &operator=(const ArchiveFileItor &) = delete;
/**
* Move assignment.
*/
ArchiveFileItor &operator=(ArchiveFileItor &&rhs);
/**
* Returns true if a call to next would return another archive file.
*/
virtual bool hasMore() const = 0;
bool hasMore() const;
/**
* Returns the next archive or throws an exception if there isn't one.
*/
virtual common::dataStructures::ArchiveFile next() = 0;
common::dataStructures::ArchiveFile next();
private:
/**
* The object actually implementing this iterator.
*/
ArchiveFileItorImpl *m_impl;
}; // class ArchiveFileItor
......
......@@ -36,12 +36,13 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set (CATALOGUE_LIB_SRC_FILES
ArchiveFileRow.cpp
ArchiveFileItor.cpp
ArchiveFileItorImpl.cpp
Catalogue.cpp
CmdLineTool.cpp
InMemoryCatalogue.cpp
SqliteCatalogueSchema.cpp
TapeFileWritten.cpp
RdbmsArchiveFileItor.cpp
RdbmsArchiveFileItorImpl.cpp
RdbmsCatalogue.cpp
SchemaCreatingSqliteCatalogue.cpp
SqliteCatalogue.cpp
......
......@@ -62,7 +62,6 @@
#include <list>
#include <map>
#include <memory>
#include <set>
#include <stdint.h>
#include <string>
......@@ -463,7 +462,7 @@ public:
* This parameter must be set to a value equal to or greater than 1.
* @return An iterator over the list of archive files.
*/
virtual std::unique_ptr<ArchiveFileItor> getArchiveFileItor(
virtual ArchiveFileItor getArchiveFileItor(
const TapeFileSearchCriteria &searchCriteria = TapeFileSearchCriteria(),
const uint64_t nbArchiveFilesToPrefetch = 1000) const = 0;
......
This diff is collapsed.
/*
* 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/RdbmsArchiveFileItor.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
RdbmsArchiveFileItor::RdbmsArchiveFileItor(
const RdbmsCatalogue &catalogue,
const uint64_t nbArchiveFilesToPrefetch,
const TapeFileSearchCriteria &searchCriteria):
m_catalogue(catalogue),
m_nbArchiveFilesToPrefetch(nbArchiveFilesToPrefetch),
m_searchCriteria(searchCriteria),
m_nextArchiveFileId(1) {
try {
if(1 > m_nbArchiveFilesToPrefetch) {
exception::Exception ex;
ex.getMessage() << "nbArchiveFilesToPrefetch must equal to or greater than 1: actual=" <<
m_nbArchiveFilesToPrefetch;
throw ex;
}
m_prefechedArchiveFiles = m_catalogue.getArchiveFilesForItor(m_nextArchiveFileId, m_nbArchiveFilesToPrefetch,
m_searchCriteria);
if(!m_prefechedArchiveFiles.empty()) {
m_nextArchiveFileId = m_prefechedArchiveFiles.back().archiveFileID + 1;
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " +ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
RdbmsArchiveFileItor::~RdbmsArchiveFileItor() {
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool RdbmsArchiveFileItor::hasMore() const {
return !m_prefechedArchiveFiles.empty();
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFile RdbmsArchiveFileItor::next() {
try {
if(m_prefechedArchiveFiles.empty()) {
throw exception::Exception("No more archive files to iterate over");
}
common::dataStructures::ArchiveFile archiveFile = m_prefechedArchiveFiles.front();
m_prefechedArchiveFiles.pop_front();
if(m_prefechedArchiveFiles.empty()) {
m_prefechedArchiveFiles = m_catalogue.getArchiveFilesForItor(m_nextArchiveFileId, m_nbArchiveFilesToPrefetch,
m_searchCriteria);
if(!m_prefechedArchiveFiles.empty()) {
m_nextArchiveFileId = m_prefechedArchiveFiles.back().archiveFileID + 1;
}
}
return archiveFile;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
} // namespace catalogue
} // 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/>.
*/
#pragma once
#include "catalogue/ArchiveFileItor.hpp"
#include "catalogue/RdbmsCatalogue.hpp"
namespace cta {
namespace catalogue {
/**
* Rdbms implementation of ArchiveFileItor.
*/
class RdbmsArchiveFileItor: public ArchiveFileItor {
public:
/**
* Constructor.
*
* @param catalogue The RdbmsCatalogue.
* @param nbArchiveFilesToPrefetch The number of archive files to prefetch.
* @param searchCriteria The search criteria.
*/
RdbmsArchiveFileItor(
const RdbmsCatalogue &catalogue,
const uint64_t nbArchiveFilesToPrefetch,
const TapeFileSearchCriteria &searchCriteria);
/**
* Destructor.
*/
~RdbmsArchiveFileItor() override;
/**
* Returns true if a call to next would return another archive file.
*/
bool hasMore() const override;
/**
* Returns the next archive or throws an exception if there isn't one.
*/
common::dataStructures::ArchiveFile next() override;
private:
/**
* The RdbmsCatalogue.
*/
const RdbmsCatalogue &m_catalogue;
/**
* The number of archive files to prefetch.
*/
const uint64_t m_nbArchiveFilesToPrefetch;
/**
* The search criteria.
*/
TapeFileSearchCriteria m_searchCriteria;
/**
* The current offset into the list of archive files in the form of an
* archive file ID.
*/
uint64_t m_nextArchiveFileId;
/**
* The current list of prefetched archive files.
*/
std::list<common::dataStructures::ArchiveFile> m_prefechedArchiveFiles;
}; // class RdbmsArchiveFileItor
} // namespace catalogue
} // namespace cta
......@@ -17,7 +17,7 @@
*/
#include "catalogue/ArchiveFileRow.hpp"
#include "catalogue/RdbmsArchiveFileItor.hpp"
#include "catalogue/RdbmsArchiveFileItorImpl.hpp"
#include "catalogue/RdbmsCatalogue.hpp"
#include "catalogue/SqliteCatalogueSchema.hpp"
#include "common/dataStructures/TapeFile.hpp"
......@@ -3466,13 +3466,13 @@ void RdbmsCatalogue::insertArchiveFile(rdbms::PooledConn &conn, const rdbms::Stm
//------------------------------------------------------------------------------
// getArchiveFileItor
//------------------------------------------------------------------------------
std::unique_ptr<ArchiveFileItor> RdbmsCatalogue::getArchiveFileItor(const TapeFileSearchCriteria &searchCriteria,
ArchiveFileItor RdbmsCatalogue::getArchiveFileItor(const TapeFileSearchCriteria &searchCriteria,
const uint64_t nbArchiveFilesToPrefetch) const {
checkTapeFileSearchCriteria(searchCriteria);
try {
return cta::make_unique<RdbmsArchiveFileItor>(*this, nbArchiveFilesToPrefetch, searchCriteria);
return ArchiveFileItor(new RdbmsArchiveFileItorImpl(*this, nbArchiveFilesToPrefetch, searchCriteria));
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
......
......@@ -50,7 +50,7 @@ class ArchiveFileRow;
/**
* Forward declaration.
*/
class RdbmsArchiveFileItor;
class RdbmsArchiveFileItorImpl;
/**
* CTA catalogue implemented using a relational database backend.
......@@ -447,7 +447,7 @@ public:
* This parameter must be set to a value equal to or greater than 1.
* @return An iterator over the list of archive files.
*/
std::unique_ptr<ArchiveFileItor> getArchiveFileItor(const TapeFileSearchCriteria &searchCriteria,
ArchiveFileItor getArchiveFileItor(const TapeFileSearchCriteria &searchCriteria,
const uint64_t nbArchiveFilesToPrefetch) const override;
/**
......@@ -499,7 +499,7 @@ public:
protected:
friend RdbmsArchiveFileItor;
friend RdbmsArchiveFileItorImpl;
/**
* Mutex to be used to a take a global lock on the database.
......
......@@ -135,8 +135,8 @@ void ListArchiveFilesCmd::refreshReadBuffer() {
// Clear the read buffer
m_readBuffer.str(std::string());
while(m_archiveFileItor->hasMore() && nbArchiveFilesToFetch > nbFetchedArchiveFiles) {
const common::dataStructures::ArchiveFile archiveFile = m_archiveFileItor->next();
while(m_archiveFileItor.hasMore() && nbArchiveFilesToFetch > nbFetchedArchiveFiles) {
const common::dataStructures::ArchiveFile archiveFile = m_archiveFileItor.next();
nbFetchedArchiveFiles++;
for(auto copyNbToTapeFile: archiveFile.tapeFiles) {
const auto copyNb = copyNbToTapeFile.first;
......
......@@ -23,7 +23,6 @@
#include "common/log/Logger.hpp"
#include <XrdSfs/XrdSfsInterface.hh>
#include <memory>
#include <sstream>
#include <string>
......@@ -100,7 +99,7 @@ protected:
/**
* Iterator over the archive files in the CTA catalogue that are to be listed.
*/
std::unique_ptr<catalogue::ArchiveFileItor> m_archiveFileItor;
catalogue::ArchiveFileItor m_archiveFileItor;
/**
* The buffer that sits between calls to ListArchiveFilesCmd::read() and calls
......
......@@ -95,10 +95,10 @@ int XrdCtaDir::open(const char *path, const XrdSecEntity *client, const char *op
// nextEntry
//------------------------------------------------------------------------------
const char* XrdCtaDir::nextEntry() {
if(!(m_itor->hasMore())) {
if(!(m_itor.hasMore())) {
return nullptr;
}
return m_itor->next().diskFileId.c_str();
return m_itor.next().diskFileId.c_str();
}
//------------------------------------------------------------------------------
......
......@@ -58,7 +58,7 @@ protected:
/**
* The archive file iterator used loop over catalogue results
*/
std::unique_ptr<cta::catalogue::ArchiveFileItor> m_itor;
catalogue::ArchiveFileItor m_itor;
/**
* The client identity info: username and host
......
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