Commit 0f45ca50 authored by Scott Snyder's avatar Scott Snyder Committed by Graeme Stewart
Browse files

Adjust for checkreq in AtlasPolicy-01-08-15 and fix other checkreq warnings....

Adjust for checkreq in AtlasPolicy-01-08-15 and fix other checkreq warnings. (ImplicitCollection-00-02-03)
parent de2c8916
package ImplicitCollection
# imported to ATLAS by:
author Marcin Nowak
use AtlasPolicy AtlasPolicy-*
private
use GaudiInterface GaudiInterface-* External
use AtlasCORAL AtlasCORAL-* External
use AthenaKernel AthenaKernel-* Control
use PersistentDataModel PersistentDataModel-* Database
use CollectionBase CollectionBase-* Database/APR
use POOLCore POOLCore-* Database/APR
use PersistencySvc PersistencySvc-* Database/APR
use StorageSvc StorageSvc-* Database/APR
#======= PLUGIN LIBRARY
apply_pattern pool_plugin_library
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "ImplicitCollection.h"
#include "ImplicitCollectionIterator.h"
#include "ImplicitCollectionMetadata.h"
#include "PersistencySvc/ISession.h"
#include "PersistencySvc/IDatabase.h"
#include "PersistencySvc/IContainer.h"
#include "PersistencySvc/PersistencySvcException.h"
#include "POOLCore/Exception.h"
#include "CoralBase/MessageStream.h"
#include "StorageSvc/DbType.h"
#include <sstream>
#include <memory>
namespace pool {
ImplicitCollection::
ImplicitCollection( ISession* session,
std::string connection,
std::string name,
ICollection::OpenMode mode )
:
m_container( 0 ),
m_description( name,"ImplicitCollection", connection ),
m_metadata( 0 )
{
open( mode, session );
}
ImplicitCollection::
ImplicitCollection( const ICollectionDescription* description,
ICollection::OpenMode mode,
ISession* session )
:
m_container( 0 ),
m_description( *description ),
m_metadata( 0 )
{
open( mode, session );
}
void
ImplicitCollection::
open( ICollection::OpenMode mode,
ISession* session )
{
coral::MessageStream log( "ImplicitCollection");
if ( mode != ICollection::READ ) {
log << coral::Error << "An implicit collection can be opened only in READ mode" << coral::MessageStream::endmsg;
throw Exception( "An implicit collection can be opened only in READ mode",
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
DatabaseSpecification::NameType dbNameType = DatabaseSpecification::UNDEFINED;
// parse the connection string
const std::string& connection = m_description.connection();
std::string::size_type pos = connection.find( ":" );
if ( pos == std::string::npos ) {
log << coral::Error << "Badly formed connection string : \"" << connection << "\"" << coral::MessageStream::endmsg;
throw Exception( "Badly formed connection string",
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
const std::string dbType = connection.substr( 0, pos );
if ( dbType == "PFN" ) dbNameType = DatabaseSpecification::PFN;
else if ( dbType == "LFN" ) dbNameType = DatabaseSpecification::LFN;
else if ( dbType == "FID" ) dbNameType = DatabaseSpecification::FID;
else {
log << coral::Error << "Unrecognizable database name type : \"" << dbType << "\"" << coral::MessageStream::endmsg;
throw Exception( "Unrecognizable database name type : " + dbType,
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
std::string dbName = "";
std::string technologyName = "";
std::istringstream is( connection.substr( pos + 1 ).c_str() );
is >> dbName >> technologyName;
if ( dbName.empty() ) {
log << coral::Error << "Invalid database name " << coral::MessageStream::endmsg;
throw Exception( "Invalid database name",
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
if( !session ) {
throw Exception( "session object not set",
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
IDatabase* database = session->databaseHandle( dbName, dbNameType );
if( !database ) {
throw Exception( "Could not retrieve a database handle",
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
if ( database->openMode() == IDatabase::CLOSED ) {
// The following fix was added to allow the reading of an implicit
// collection in the absence of a POOL file catalog. For now, it assumes
// a ROOT persistency storage type if no other type can be found.
try {
database->connectForRead();
}
catch ( PersistencySvcException& /* exception */ ) {
// use provided tech name or assume ROOT
DbType theDbType = (technologyName != "") ? DbType::getType( technologyName ) : ROOT_StorageType;
// setting tech will make connectForRead work without a catalog
database->setTechnology( theDbType.type() );
database->connectForRead();
}
}
const std::string& name = m_description.name();
std::vector< std::string > containers = database->containers();
for( std::vector< std::string >::const_iterator iContainer = containers.begin();
iContainer != containers.end(); ++iContainer ) {
if( name == *iContainer ) {
m_container = database->containerHandle( name );
break;
}
}
delete database;
if( !m_container ) {
throw Exception( "Could not open the container " + name,
"ImplicitCollection::ImplicitCollection",
"ImplicitCollection" );
}
log << coral::Info << "Opened the implicit collection with connection string \""
<< connection << "\"" << coral::MessageStream::endmsg
<< "and a name \"" << name << "\"" << coral::MessageStream::endmsg;
}
ImplicitCollection::~ImplicitCollection()
{
delete m_container;
delete m_metadata;
}
ICollection::OpenMode
ImplicitCollection::openMode() const{
return ICollection::READ;
}
// old method implemented for backward compatibility
// and maybe also for the ease of use?
ImplicitCollectionIterator*
ImplicitCollection::select( std::string primaryQuery,
std::string,
std::string )
{
// iterator object supporting the collection query interface
std::auto_ptr<ImplicitCollectionIterator>
iterquery( new ImplicitCollectionIterator( *m_container, m_description ) );
iterquery->setCondition( primaryQuery );
iterquery->execute();
return iterquery.release();
}
void
ImplicitCollection::commit(bool)
{
}
void
ImplicitCollection::rollback()
{
}
void
ImplicitCollection::close()
{
// can't be closed
}
void
ImplicitCollection::open()
{
// hmm, no-op at the moment //MN
}
bool
ImplicitCollection::isOpen() const
{
return true;
}
const ICollectionDescription& ImplicitCollection::description() const
{
return m_description;
}
ICollectionQuery* ImplicitCollection::newQuery() const
{
return new ImplicitCollectionIterator( *m_container, m_description );
}
ICollectionSchemaEditor& ImplicitCollection::schemaEditor()
{
std::string errorMsg = "Cannot modify an ImplicitCollection.";
throw Exception( errorMsg,
"ImplicitCollection::schemaEditor",
"ImplicitCollection" );
return *(ICollectionSchemaEditor*)0;
}
ICollectionDataEditor& ImplicitCollection::dataEditor()
{
std::string errorMsg = "Cannot modify an ImplicitCollection.";
throw Exception( errorMsg,
"ImplicitCollection::dataEditor",
"ImplicitCollection" );
return *(ICollectionDataEditor*)0;
}
ICollectionMetadata& ImplicitCollection::metadata()
{
if( !m_metadata ) {
m_metadata = new ImplicitCollectionMetadata();
}
return *m_metadata;
}
void methodNotImplemented(const std::string &method)
{
throw Exception( std::string("method not implemented"),
std::string("ImplicitCollection::") + method,
"ImplicitCollection" );
}
bool
ImplicitCollection::exists( const std::string& /*name*/, bool, bool ) const
{
methodNotImplemented("exists");
return false;
}
bool
ImplicitCollection::drop( const std::string&, bool, bool)
{
methodNotImplemented("drop");
return false;
}
bool
ImplicitCollection::rename( const std::string&, const std::string&)
{
methodNotImplemented("rename");
return false;
}
bool
ImplicitCollection::grantToUser( const std::string&,
ICollection::Privilege,
const std::string&,
bool)
{
methodNotImplemented("grantToUser");
return false;
}
bool
ImplicitCollection::revokeFromUser( const std::string&,
ICollection::Privilege,
const std::string&,
bool)
{
methodNotImplemented("revokeFromUser");
return false;
}
bool
ImplicitCollection::grantToPublic( const std::string&, bool)
{
methodNotImplemented("grantToPublic");
return false;
}
bool
ImplicitCollection::revokeFromPublic( const std::string&, bool )
{
methodNotImplemented("revokeFromPublic");
return false;
}
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef INCLUDE_IMPLICITCOLLECTION_IMPLICITCOLLECTION_H
#define INCLUDE_IMPLICITCOLLECTION_IMPLICITCOLLECTION_H
#include "CollectionBase/ICollection.h"
#include "CollectionBase/CollectionDescription.h"
#ifdef HAVE_GAUDI_PLUGINSVC
#include "Gaudi/PluginService.h"
#endif
namespace pool {
// forward declarations
class ISession;
class IContainer;
class ICollectionSchemaEditor;
class ICollectionDataEditor;
class ICollectionQuery;
class ICollectionIterator;
class ImplicitCollectionIterator;
class ImplicitCollectionMetadata;
/// An implicit collection implementation of the ICollection interface
class ImplicitCollection : virtual public ICollection
{
public:
#ifdef HAVE_GAUDI_PLUGINSVC
typedef Gaudi::PluginService::Factory3<ICollection*, const ICollectionDescription*, ICollection::OpenMode, ISession*> Factory;
#endif
/** Constructor - old style
Throws POOL exception.
@param session the session object
@param connection database connection string. It has the format databaseNameType:databaseName, where databaseNameType can be FID, PFN or LFN.
@param name the container name in the database
@param mode collection's open mode. For the moment only READONLY mode is allowed.
*/
ImplicitCollection( ISession* session,
std::string connection,
std::string name,
ICollection::OpenMode mode );
/// Constructor compying to the new Collections API
/// parameters as above, but name and connection passed in description
ImplicitCollection( const ICollectionDescription* description,
ICollection::OpenMode mode,
ISession* session );
/// Destructor
~ImplicitCollection();
/// Return openMode
virtual ICollection::OpenMode openMode() const;
/** Method that returns collection's iterator
Throws POOL exception.
@param primaryQuery query string passed to the underlying StorageSvc implementation.
@param secondaryQuery parameter currently unused
@param options type currently unused
*/
ImplicitCollectionIterator* select( std::string primaryQuery = "",
std::string secondaryQuery = "",
std::string options = "" );
/// Commits the last changes made to the collection. Will always return true.
void commit(bool reopen=false);
/// Aborts the last changes made to the collection. Will always return true.
void rollback();
/// no-op at the moment
void close();
/// no-op at the moment
void open();
/// Checks if the collection is open.
bool isOpen() const;
virtual bool exists( const std::string& fragmentName,
bool setForUpdate = false,
bool checkChildFragments = false ) const;
virtual bool drop( const std::string& fragmentName,
bool dropChildFragments = false,
bool ignoreExternalDependencies = false );
virtual bool rename( const std::string& oldName,
const std::string& newName );
virtual bool grantToUser( const std::string& userName,
pool::ICollection::Privilege privilege,
const std::string& fragmentName = "",
bool grantForChildFragments = false );
virtual bool revokeFromUser( const std::string& userName,
pool::ICollection::Privilege privilege,
const std::string& fragmentName = "",
bool revokeForChildFragments = false );
virtual bool grantToPublic( const std::string& fragmentName = "",
bool grantForChildFragments = false );
virtual bool revokeFromPublic( const std::string& fragmentName = "",
bool revokeForChildFragments = false );
/// Returns an object used to describe the collection properties.
virtual const ICollectionDescription& description() const;
/// Returns an object used to modify the collection schema.
/// will throw exception if called
virtual ICollectionSchemaEditor& schemaEditor();
/// Returns an object used to add, update or delete rows of the collection.
/// will throw exception if called
virtual ICollectionDataEditor& dataEditor();
/// Returns an object used to query the collection.
virtual ICollectionQuery* newQuery() const;
/// Returns an object used to access collection metadata
virtual ICollectionMetadata& metadata();
protected:
void open( ICollection::OpenMode mode, ISession* session );
private:
/// The underlying container handle
IContainer *m_container;
CollectionDescription m_description;
ImplicitCollectionMetadata* m_metadata;
};
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "ImplicitCollectionIterator.h"
#include "CollectionBase/CollectionDescription.h"
#include "PersistencySvc/IContainer.h"
#include "PersistencySvc/ITokenIterator.h"
#include "PersistentDataModel/Token.h"
pool::ImplicitCollectionIterator::
ImplicitCollectionIterator( pool::IContainer& container,
const pool::ICollectionDescription& description )
:
m_container( container ),
m_tokenIterator( 0 ),
m_token( 0 )
{
TokenList tokenList;
tokenList.extend( description.eventReferenceColumnName() );
m_rowBuffer.setTokenList( tokenList );
}
pool::ImplicitCollectionIterator::~ImplicitCollectionIterator()
{
if ( m_token ) m_token->release();
delete m_tokenIterator;
}
void
pool::ImplicitCollectionIterator::
setCondition( const std::string& whereClause,
coral::AttributeList*,
TokenList* )
{
m_whereClause += whereClause;
}
pool::ICollectionCursor&
pool::ImplicitCollectionIterator::execute()
{
m_tokenIterator = m_container.tokens( m_whereClause );
return *this;
}
const std::string&
pool::ImplicitCollectionIterator::whereClause() const
{
return m_whereClause;
}
bool
pool::ImplicitCollectionIterator::next()
{
if( m_token ) {
m_token->release();
m_token = 0;
}
if( m_tokenIterator )
m_token = m_tokenIterator->next();
return (m_token!=0);
}
Token*
pool::ImplicitCollectionIterator::token() const
{
return m_token;
}
const pool::CollectionRowBuffer&
pool::ImplicitCollectionIterator::currentRow() const
{
m_token->setData( &*m_rowBuffer.tokenList().begin() );
return m_rowBuffer;
}
bool
pool::ImplicitCollectionIterator::seek (long long int position)
{
IPositionSeek* ies = dynamic_cast<IPositionSeek*> (m_tokenIterator);
if (!ies)
return false;
// We'll have to do a next() to read the event.
// So subtract one here to compensate for that.
return ies->seek (position - 1);
}
int
pool::ImplicitCollectionIterator::size ()
{
ICollectionSize* ics = dynamic_cast<ICollectionSize*> (m_tokenIterator);
if (!ics)
return 0;
return ics->size();
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/