Commit c76d1cff authored by Steven Murray's avatar Steven Murray
Browse files

Added files missing from previous commit

parent 8307191c
/*
* 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/ArchiveFileItorImpl.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
ArchiveFileItorImpl::~ArchiveFileItorImpl() {
}
} // 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 "common/dataStructures/ArchiveFile.hpp"
namespace cta {
namespace catalogue {
/**
* Abstract class defining the interface to an iterator over a list of archive
* files.
*/
class ArchiveFileItorImpl {
public:
/**
* Destructor.
*/
virtual ~ArchiveFileItorImpl() = 0;
/**
* Returns true if a call to next would return another archive file.
*/
virtual bool hasMore() const = 0;
/**
* Returns the next archive or throws an exception if there isn't one.
*/
virtual common::dataStructures::ArchiveFile next() = 0;
}; // class ArchiveFileItorImpl
} // 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/>.
*/
#include "catalogue/RdbmsArchiveFileItorImpl.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
RdbmsArchiveFileItorImpl::RdbmsArchiveFileItorImpl(
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
//------------------------------------------------------------------------------
RdbmsArchiveFileItorImpl::~RdbmsArchiveFileItorImpl() {
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool RdbmsArchiveFileItorImpl::hasMore() const {
return !m_prefechedArchiveFiles.empty();
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFile RdbmsArchiveFileItorImpl::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/ArchiveFileItorImpl.hpp"
#include "catalogue/RdbmsCatalogue.hpp"
namespace cta {
namespace catalogue {
/**
* Rdbms implementation of ArchiveFileItorImpl.
*/
class RdbmsArchiveFileItorImpl: public ArchiveFileItorImpl {
public:
/**
* Constructor.
*
* @param catalogue The RdbmsCatalogue.
* @param nbArchiveFilesToPrefetch The number of archive files to prefetch.
* @param searchCriteria The search criteria.
*/
RdbmsArchiveFileItorImpl(
const RdbmsCatalogue &catalogue,
const uint64_t nbArchiveFilesToPrefetch,
const TapeFileSearchCriteria &searchCriteria);
/**
* Destructor.
*/
~RdbmsArchiveFileItorImpl() 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 RdbmsArchiveFileItorImpl
} // namespace catalogue
} // namespace cta
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