00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #define DBCNV_DBSESSION_CPP
00018
00019 #include "GaudiDb/DbSession.h"
00020 #include "GaudiDb/DbObject.h"
00021 #include "DbDataBaseObj.h"
00022 #include "DbContainerObj.h"
00023 #include "DbFederationObj.h"
00024 #include "DbSessionObj.h"
00025
00026
00027 void dbHandle<DbSession>::switchPtr(_DataType* obj) const {
00028 if ( obj ) obj->addRef();
00029 if ( m_ptr ) m_ptr->release();
00030 m_ptr = obj;
00031 if ( m_ptr ) {
00032 setType(m_ptr->type());
00033 }
00034 }
00035
00036
00037 dbHandle<DbSession>::dbHandle<DbSession>(unsigned char type) {
00038 m_mode = DbOOMs::READ;
00039 setType(type);
00040 }
00041
00042
00043 dbHandle<DbSession>::dbHandle(const dbHandle<DbSession>& copy)
00044 : dbHandleBase<DbSession>()
00045 {
00046 *this = copy;
00047 }
00048
00049
00050 dbHandle<DbSession>::~dbHandle() {
00051 switchPtr( 0 );
00052 }
00053
00054
00055 dbHandle<DbSession>& dbHandle<DbSession>::operator=(const dbHandle<DbSession>& copy) {
00056 switchPtr( copy.m_ptr );
00057 m_mode = copy.m_mode;
00058 setType(copy.type());
00059 return *this;
00060 }
00061
00062
00063 const char* dbHandle<DbSession>::typeName() const {
00064 return "DbSession";
00065 }
00066
00067
00068 DbAccessMode dbHandle<DbSession>::openMode() const {
00069 return m_mode;
00070 }
00071
00072
00073 DbResult dbHandle<DbSession>::open(IOODataBase* db, IMessageSvc* msg, DbAccessMode mode) {
00074 m_mode = mode;
00075 if ( !m_ptr ) {
00076 switchPtr(new DbSession(db, msg, type()));
00077 }
00078 return (isValid()) ? m_ptr->open(m_mode) : DbOOMs::DbError;
00079 }
00080
00081
00082 DbResult dbHandle<DbSession>::close() const {
00083 if ( m_ptr ) {
00084 m_ptr->clearEntries();
00085 m_ptr->close();
00086 }
00087 switchPtr(0);
00088 m_mode = DbOOMs::NOT_OPEN;
00089 return DbOOMs::DbSuccess;
00090 }
00091
00092
00093 DbResult dbHandle<DbSession>::add(const std::string& name, DbFederation* fed) const {
00094 if ( isValid() && fed ) {
00095 return m_ptr->add(name, fed);
00096 }
00097 return DbOOMs::DbError;
00098 }
00099
00100
00101 DbFederation* dbHandle<DbSession>::find(const std::string& name) const {
00102 if ( isValid() ) {
00103 return m_ptr->find(name);
00104 }
00105 return 0;
00106 }
00107
00108
00109 DbResult dbHandle<DbSession>::remove(DbFederation* fed) {
00110 if ( isValid() ) {
00111 return m_ptr->remove(fed);
00112 }
00113 return DbOOMs::DbError;
00114 }
00115
00116
00117 IDbSession* dbHandle<DbSession>::info() const {
00118 if ( isValid() ) {
00119 return m_ptr->info();
00120 }
00121 return 0;
00122 }
00123
00124
00125 IOODataBase* dbHandle<DbSession>::db() {
00126 if ( isValid() ) {
00127 return m_ptr->db();
00128 }
00129 return 0;
00130 }
00131
00132
00133 IMessageSvc* dbHandle<DbSession>::msgSvc() {
00134 if ( isValid() ) {
00135 return m_ptr->msgSvc();
00136 }
00137 return 0;
00138 }