CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondCore/ORA/src/DatabaseSession.h

Go to the documentation of this file.
00001 #ifndef INCLUDE_ORA_DATABASESESSION_H
00002 #define INCLUDE_ORA_DATABASESESSION_H
00003 
00004 #include "CondCore/ORA/interface/Handle.h"
00005 #include "CondCore/ORA/interface/OId.h"
00006 #include "CondCore/ORA/interface/Object.h"
00007 #include "CondCore/ORA/interface/ConnectionPool.h"
00008 #include "CondCore/ORA/interface/Configuration.h"
00009 //
00010 #include <string>
00011 #include <memory>
00012 #include <map>
00013 
00014 namespace Reflex {
00015   class Type;
00016 }
00017 
00018 namespace ora {
00019 
00020   class Configuration;
00021   class ConnectionPool;
00022   class NamedSequence;
00023   class MappingDatabase;
00024   class IDatabaseSchema;
00025   class TransactionCache;
00026   class DatabaseContainer;
00027   class DatabaseUtilitySession;
00028   class SessionMonitoringData;
00029 
00030   class ContainerUpdateTable {
00031     public:
00032     ContainerUpdateTable();
00033     ~ContainerUpdateTable();
00034     void takeNote( int contId, unsigned int size );
00035     void remove( int contId );
00036     const std::map<int, unsigned int>& table();
00037     void clear();
00038     private:
00039     std::map<int, unsigned int> m_table;
00040   };
00041 
00042   class DatabaseSession  {
00043     
00044     public:
00045     DatabaseSession();
00046 
00047     explicit DatabaseSession( boost::shared_ptr<ConnectionPool>& connectionPool );
00048 
00049     virtual ~DatabaseSession();
00050 
00051     bool connect( const std::string& connectionString, bool readOnly );
00052     bool connect( const std::string& connectionString, const std::string& asRole, bool readOnly );
00053 
00054     void disconnect();
00055 
00056     bool isConnected();
00057 
00058     const std::string& connectionString();
00059 
00060     void startTransaction( bool readOnly );
00061 
00062     void commitTransaction();
00063 
00064     void rollbackTransaction();
00065 
00066     bool isTransactionActive( bool checkIfReadOnly=false );
00067     
00068     bool exists();
00069 
00070     void create( const std::string& userSchemaVersion = std::string("") );
00071 
00072     void drop();
00073 
00074     void setAccessPermission( const std::string& principal, bool forWrite );
00075 
00076     bool testDropPermission();
00077 
00078     void open();
00079    
00080     std::string schemaVersion( bool userSchema );
00081 
00082     Handle<DatabaseContainer> createContainer( const std::string& containerName, const Reflex::Type& type );
00083 
00084     Handle<ora::DatabaseContainer> addContainer( const std::string& containerName, const std::string& className );
00085     
00086     void dropContainer( const std::string& name );
00087 
00088     Handle<DatabaseContainer> containerHandle( const std::string& name );
00089 
00090     Handle<DatabaseContainer> containerHandle( int contId );
00091 
00092     const std::map<int, Handle<DatabaseContainer> >& containers();
00093 
00094     void setObjectName( const std::string& name, int containerId, int itemId );
00095 
00096     bool eraseObjectName( const std::string& name );
00097 
00098     bool eraseAllNames();
00099 
00100     bool getItemId( const std::string& name, OId& destination );
00101 
00102     Object fetchObjectByName( const std::string& name );
00103 
00104     boost::shared_ptr<void> fetchTypedObjectByName( const std::string& name, const Reflex::Type& asType );
00105 
00106     bool getNamesForContainer( int containerId, std::vector<std::string>& destination );
00107 
00108     bool getNamesForObject( int containerId, int itemId, std::vector<std::string>& destination );
00109 
00110     bool listObjectNames( std::vector<std::string>& destination );
00111 
00112     Handle<DatabaseUtilitySession> utility();
00113 
00114     public:
00115     IDatabaseSchema& schema();
00116 
00117     NamedSequence& containerIdSequence();
00118 
00119     MappingDatabase& mappingDatabase();
00120 
00121     ContainerUpdateTable& containerUpdateTable();
00122 
00123     Configuration& configuration();
00124     
00125     public:
00126     SharedSession& storageAccessSession();
00127     boost::shared_ptr<ConnectionPool>& connectionPool();
00128     
00129     private:
00130     void clearTransaction();
00131 
00132     private:
00133     boost::shared_ptr<ConnectionPool> m_connectionPool;
00134     SharedSession m_dbSession;
00135     std::string m_connectionString;
00136     std::auto_ptr<IDatabaseSchema> m_schema;
00137     std::auto_ptr<NamedSequence> m_contIdSequence;
00138     std::auto_ptr<MappingDatabase> m_mappingDb;
00139     std::auto_ptr<TransactionCache> m_transactionCache;
00140     ContainerUpdateTable m_containerUpdateTable;
00141     Configuration m_configuration;
00142     SessionMonitoringData* m_monitoring;
00143   };
00144   
00145 
00146 }
00147 
00148 #endif