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
00029 class ContainerUpdateTable {
00030 public:
00031 ContainerUpdateTable();
00032 ~ContainerUpdateTable();
00033 void takeNote( int contId, unsigned int size );
00034 const std::map<int, unsigned int>& table();
00035 void clear();
00036 private:
00037 std::map<int, unsigned int> m_table;
00038 };
00039
00040 class DatabaseSession {
00041
00042 public:
00043 DatabaseSession();
00044
00045 explicit DatabaseSession( boost::shared_ptr<ConnectionPool>& connectionPool );
00046
00047 virtual ~DatabaseSession();
00048
00049 bool connect( const std::string& connectionString, bool readOnly );
00050
00051 void disconnect();
00052
00053 bool isConnected();
00054
00055 const std::string& connectionString();
00056
00057 void startTransaction( bool readOnly );
00058
00059 void commitTransaction();
00060
00061 void rollbackTransaction();
00062
00063 bool isTransactionActive( bool checkIfReadOnly=false );
00064
00065 bool exists();
00066
00067 void create();
00068
00069 void drop();
00070
00071 void open();
00072
00073 Handle<DatabaseContainer> createContainer( const std::string& containerName, const Reflex::Type& type );
00074
00075 Handle<ora::DatabaseContainer> addContainer( const std::string& containerName, const std::string& className );
00076
00077 void dropContainer( const std::string& name );
00078
00079 Handle<DatabaseContainer> containerHandle( const std::string& name );
00080
00081 Handle<DatabaseContainer> containerHandle( int contId );
00082
00083 const std::map<int, Handle<DatabaseContainer> >& containers();
00084
00085 void setObjectName( const std::string& name, int containerId, int itemId );
00086
00087 bool eraseObjectName( const std::string& name );
00088
00089 bool eraseAllNames();
00090
00091 bool getItemId( const std::string& name, OId& destination );
00092
00093 Object fetchObjectByName( const std::string& name );
00094
00095 boost::shared_ptr<void> fetchTypedObjectByName( const std::string& name, const Reflex::Type& asType );
00096
00097 bool getNamesForContainer( int containerId, std::vector<std::string>& destination );
00098
00099 bool getNamesForObject( int containerId, int itemId, std::vector<std::string>& destination );
00100
00101 bool listObjectNames( std::vector<std::string>& destination );
00102
00103 Handle<DatabaseUtilitySession> utility();
00104
00105 public:
00106 IDatabaseSchema& schema();
00107
00108 NamedSequence& containerIdSequence();
00109
00110 MappingDatabase& mappingDatabase();
00111
00112 ContainerUpdateTable& containerUpdateTable();
00113
00114 Configuration& configuration();
00115
00116 public:
00117 SharedSession& storageAccessSession();
00118 boost::shared_ptr<ConnectionPool>& connectionPool();
00119
00120 private:
00121 void clearTransaction();
00122
00123 private:
00124 boost::shared_ptr<ConnectionPool> m_connectionPool;
00125 SharedSession m_dbSession;
00126 std::string m_connectionString;
00127 std::auto_ptr<IDatabaseSchema> m_schema;
00128 std::auto_ptr<NamedSequence> m_contIdSequence;
00129 std::auto_ptr<MappingDatabase> m_mappingDb;
00130 std::auto_ptr<TransactionCache> m_transactionCache;
00131 ContainerUpdateTable m_containerUpdateTable;
00132 Configuration m_configuration;
00133 };
00134
00135
00136 }
00137
00138 #endif