CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DbSession.h
Go to the documentation of this file.
1 #ifndef COND_DBCommon_DbSession_h
2 #define COND_DBCommon_DbSession_h
3 
6 #include <string>
7 #include <boost/shared_ptr.hpp>
8 
9 //
10 // Package: CondCore/DBCommon
11 // Class: DbSession
12 //
17 namespace coral {
18  class IConnectionService;
19  class ISchema;
20  class ISessionProxy;
21 }
22 
23 namespace cond{
24 
25  class DbTransaction;
26  class DbConnection;
27  class SessionImpl;
28 
29  /*
30  **/
31  class DbSession{
32  public:
33  static const char* COND_SCHEMA_VERSION;
34  static const char* CHANGE_SCHEMA_VERSION;
35 
36  public:
37  DbSession();
38 
39  explicit DbSession( const DbConnection& connection );
40 
41  DbSession( const DbSession& rhs );
42 
43  virtual ~DbSession();
44 
45  DbSession& operator=( const DbSession& rhs );
46 
47  const std::string& connectionString() const;
48 
49  const DbConnection& connection() const;
50 
51  bool isTransactional() const;
52 
53  const std::string& blobStreamingService() const;
54 
55  void open( const std::string& connectionString, bool readOnly=false );
56  void open( const std::string& connectionString, const std::string& role, bool readOnly=false );
57  void openReadOnly( const std::string& connectionString, const std::string& id );
58  void close();
59 
60  bool isOpen() const;
61 
63 
64  bool createDatabase();
65 
66  // TEMPORARY, for the IOV schema changeover.
67  bool isOldSchema();
68 
69  coral::ISchema& schema(const std::string& schemaName);
70 
71  coral::ISchema& nominalSchema();
72 
73  bool deleteMapping( const std::string& mappingVersion );
74 
75  bool importMapping( const std::string& sourceConnectionString,
76  const std::string& contName );
77 
78  ora::Object getObject( const std::string& objectId );
79 
80  template <typename T> boost::shared_ptr<T> getTypedObject( const std::string& objectId );
81 
82  template <typename T> std::string storeObject( const T* object, const std::string& containerName );
83 
84  template <typename T> bool updateObject( const T* object, const std::string& objectId );
85 
86  bool deleteObject( const std::string& objectId );
87 
88  std::string importObject( cond::DbSession& fromDatabase, const std::string& objectId );
89 
90  std::string classNameForItem( const std::string& objectId );
91 
92  void flush();
93 
95 
96  private:
97  std::string storeObject( const ora::Object& objectRef, const std::string& containerName );
98  private:
99 
100  boost::shared_ptr<SessionImpl> m_implementation;
101  };
102 
104  public:
105  explicit PoolTokenParser( ora::Database& db );
107  }
108  ora::OId parse( const std::string& poolToken );
109  std::string className( const std::string& poolToken );
110 
111  private:
113  };
114 
116  public:
117  explicit PoolTokenWriter( ora::Database& db );
119  }
120  std::string write( const ora::OId& oid );
121  private:
123  };
124 
125  template <typename T> inline boost::shared_ptr<T> DbSession::getTypedObject( const std::string& objectId ){
126  ora::OId oid;
127  oid.fromString( objectId );
128  return storage().fetch<T>( oid );
129  }
130 
131  template <typename T> inline std::string DbSession::storeObject( const T* object,
132  const std::string& containerName ){
133  std::string ret("");
134  if( object ){
135  ora::OId oid = storage().insert( containerName, *object );
136  storage().flush();
137  ret = oid.toString();
138  }
139  return ret;
140  }
141 
142  template <typename T> inline bool DbSession::updateObject( const T* object,
143  const std::string& objectId ){
144  bool ret = false;
145  if( object ){
146  ora::OId oid;
147  oid.fromString( objectId );
148  storage().update( oid, *object );
149  storage().flush();
150  ret = true;
151  }
152  return ret;
153  }
154 
155 }
156 
157 #endif
158 // DBSESSION_H
PoolTokenParser(ora::Database &db)
Definition: DbSession.cc:292
boost::shared_ptr< SessionImpl > m_implementation
Definition: DbSession.h:100
const std::string & connectionString() const
Definition: DbSession.cc:169
ora::Database & m_db
Definition: DbSession.h:122
void flush()
Definition: Database.cc:320
std::string write(const ora::OId &oid)
Definition: DbSession.cc:316
bool deleteObject(const std::string &objectId)
Definition: DbSession.cc:259
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:277
OId insert(const std::string &containerName, const T &data)
DbTransaction & transaction()
Definition: DbSession.cc:189
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
const std::string & blobStreamingService() const
Definition: DbSession.cc:184
void openReadOnly(const std::string &connectionString, const std::string &id)
Definition: DbSession.cc:155
tuple db
Definition: EcalCondDB.py:151
Definition: OId.h:8
bool deleteMapping(const std::string &mappingVersion)
Definition: DbSession.cc:233
coral::ISchema & schema(const std::string &schemaName)
Definition: DbSession.cc:223
ora::Database & m_db
Definition: DbSession.h:112
static const char * CHANGE_SCHEMA_VERSION
Definition: DbSession.h:34
static const char * COND_SCHEMA_VERSION
Definition: DbSession.h:33
ora::OId parse(const std::string &poolToken)
Definition: DbSession.cc:296
bool isTransactional() const
Definition: DbSession.cc:180
bool importMapping(const std::string &sourceConnectionString, const std::string &contName)
Definition: DbSession.cc:239
DbSession & operator=(const DbSession &rhs)
Definition: DbSession.cc:139
boost::shared_ptr< T > fetch(const OId &oid)
Definition: Database.h:213
virtual ~DbSession()
Definition: DbSession.cc:136
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
PoolTokenWriter(ora::Database &db)
Definition: DbSession.cc:312
std::string className(const std::string &poolToken)
Definition: DbSession.cc:305
bool isOldSchema()
Definition: DbSession.cc:215
bool createDatabase()
Definition: DbSession.cc:206
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
std::string toString() const
Definition: OId.cc:58
std::string importObject(cond::DbSession &fromDatabase, const std::string &objectId)
Definition: DbSession.cc:267
void update(const OId &oid, const T &data)
Definition: Database.h:237
bool isOpen() const
Definition: DbSession.cc:165
ora::Object getObject(const std::string &objectId)
Definition: DbSession.cc:253
bool fromString(const std::string &s)
Definition: OId.cc:64
bool updateObject(const T *object, const std::string &objectId)
Definition: DbSession.h:142
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
ora::Database & storage()
Definition: DbSession.cc:198
const DbConnection & connection() const
Definition: DbSession.cc:175