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
00053 void disconnect();
00054
00055 bool isConnected();
00056
00057 const std::string& connectionString();
00058
00059 void startTransaction( bool readOnly );
00060
00061 void commitTransaction();
00062
00063 void rollbackTransaction();
00064
00065 bool isTransactionActive( bool checkIfReadOnly=false );
00066
00067 bool exists();
00068
00069 void create( const std::string& userSchemaVersion = std::string("") );
00070
00071 void drop();
00072
00073 void setAccessPermission( const std::string& principal, bool forWrite );
00074
00075 bool testDropPermission();
00076
00077 void open();
00078
00079 std::string schemaVersion( bool userSchema );
00080
00081 Handle<DatabaseContainer> createContainer( const std::string& containerName, const Reflex::Type& type );
00082
00083 Handle<ora::DatabaseContainer> addContainer( const std::string& containerName, const std::string& className );
00084
00085 void dropContainer( const std::string& name );
00086
00087 Handle<DatabaseContainer> containerHandle( const std::string& name );
00088
00089 Handle<DatabaseContainer> containerHandle( int contId );
00090
00091 const std::map<int, Handle<DatabaseContainer> >& containers();
00092
00093 void setObjectName( const std::string& name, int containerId, int itemId );
00094
00095 bool eraseObjectName( const std::string& name );
00096
00097 bool eraseAllNames();
00098
00099 bool getItemId( const std::string& name, OId& destination );
00100
00101 Object fetchObjectByName( const std::string& name );
00102
00103 boost::shared_ptr<void> fetchTypedObjectByName( const std::string& name, const Reflex::Type& asType );
00104
00105 bool getNamesForContainer( int containerId, std::vector<std::string>& destination );
00106
00107 bool getNamesForObject( int containerId, int itemId, std::vector<std::string>& destination );
00108
00109 bool listObjectNames( std::vector<std::string>& destination );
00110
00111 Handle<DatabaseUtilitySession> utility();
00112
00113 public:
00114 IDatabaseSchema& schema();
00115
00116 NamedSequence& containerIdSequence();
00117
00118 MappingDatabase& mappingDatabase();
00119
00120 ContainerUpdateTable& containerUpdateTable();
00121
00122 Configuration& configuration();
00123
00124 public:
00125 SharedSession& storageAccessSession();
00126 boost::shared_ptr<ConnectionPool>& connectionPool();
00127
00128 private:
00129 void clearTransaction();
00130
00131 private:
00132 boost::shared_ptr<ConnectionPool> m_connectionPool;
00133 SharedSession m_dbSession;
00134 std::string m_connectionString;
00135 std::auto_ptr<IDatabaseSchema> m_schema;
00136 std::auto_ptr<NamedSequence> m_contIdSequence;
00137 std::auto_ptr<MappingDatabase> m_mappingDb;
00138 std::auto_ptr<TransactionCache> m_transactionCache;
00139 ContainerUpdateTable m_containerUpdateTable;
00140 Configuration m_configuration;
00141 SessionMonitoringData* m_monitoring;
00142 };
00143
00144
00145 }
00146
00147 #endif