Go to the documentation of this file.00001 #include "CondCore/MetaDataService/interface/MetaData.h"
00002 #include "CondCore/ORA/interface/Database.h"
00003 #include "CondCore/ORA/interface/PoolToken.h"
00004 #include "CondCore/DBCommon/interface/Exception.h"
00005 #include "RelationalAccess/SchemaException.h"
00006 #include <memory>
00007
00008
00009
00010 namespace {
00011
00012 std::string mdErrorPrefix(const std::string& source, const std::string& name) {
00013 return source+std::string(": metadata entry \"")+name+std::string("\" ");
00014 }
00015
00016
00017 void mdError(const std::string& source, const std::string& name, const std::string& mess) {
00018 throw cond::Exception(mdErrorPrefix(source,name)+mess);
00019 }
00020
00021 void mdDuplicateEntryError(const std::string& source, const std::string& name) {
00022 mdError(source, name, "Already exists");
00023 }
00024
00025 void mdNoEntry(const std::string& source, const std::string& name) {
00026 mdError(source, name, "does not exists");
00027 }
00028
00029 }
00030
00031
00032 cond::MetaData::MetaData(cond::DbSession& userSession):m_userSession( userSession ){
00033 }
00034 cond::MetaData::~MetaData(){
00035 }
00036 bool
00037 cond::MetaData::addMapping(const std::string& name,
00038 const std::string& iovtoken,
00039 cond::TimeType timetype ){
00040 try{
00041 std::pair<std::string,int> oid = parseToken( iovtoken );
00042 ora::Container cont = m_userSession.storage().containerHandle( oid.first );
00043 cont.setItemName( name, oid.second );
00044 }catch( const coral::DuplicateEntryInUniqueKeyException& er ){
00045 mdDuplicateEntryError("addMapping",name);
00046 }catch(std::exception& er){
00047 mdError("MetaData::addMapping",name,er.what());
00048 }
00049 return true;
00050 }
00051
00052 const std::string
00053 cond::MetaData::getToken( const std::string& name ) const{
00054 bool ok=false;
00055 std::string iovtoken("");
00056 if(!m_userSession.storage().exists())
00057 return iovtoken;
00058 try{
00059 ora::OId oid;
00060 ok = m_userSession.storage().getItemId( name, oid );
00061 if(ok) {
00062 ora::Container cont = m_userSession.storage().containerHandle( oid.containerId() );
00063 iovtoken = writeToken( cont.name(), oid.containerId(), oid.itemId(), cont.className() );
00064 }
00065 }catch(const std::exception& er){
00066 mdError("MetaData::getToken", name,er.what() );
00067 }
00068 if (!ok) mdNoEntry("MetaData::getToken", name);
00069 return iovtoken;
00070 }
00071
00072 bool cond::MetaData::hasTag( const std::string& name ) const{
00073 bool result=false;
00074 if(!m_userSession.storage().exists())
00075 return result;
00076 try{
00077 ora::OId oid;
00078 result = m_userSession.storage().getItemId( name, oid );
00079 }catch(const std::exception& er){
00080 mdError("MetaData::hasTag", name, er.what() );
00081 }
00082 return result;
00083 }
00084
00085 void
00086 cond::MetaData::listAllTags( std::vector<std::string>& result ) const{
00087 try{
00088 m_userSession.storage().listObjectNames( result );
00089 }catch(const std::exception& er){
00090 throw cond::Exception( std::string("MetaData::listAllTags: " )+er.what() );
00091 }
00092 }
00093
00094 void
00095 cond::MetaData::deleteAllEntries(){
00096 try{
00097 m_userSession.storage().eraseAllNames();
00098 }catch(const std::exception& er){
00099 throw cond::Exception( std::string("MetaData::deleteAllEntries: " )+er.what() );
00100 }
00101 }
00102
00103 void cond::MetaData::deleteEntryByTag( const std::string& tag ){
00104 try{
00105 m_userSession.storage().eraseObjectName( tag );
00106 }catch(const std::exception& er){
00107 throw cond::Exception( std::string("MetaData::deleteEntryByTag: " )+er.what() );
00108 }
00109 }