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 open( boost::shared_ptr<coral::ISessionProxy>& coralSession, const std::string& connectionString, const std::string& schemaName="" );
59  void close();
60 
61  bool isOpen() const;
62 
64 
65  bool createDatabase();
66 
67  // TEMPORARY, for the IOV schema changeover.
68  bool isOldSchema();
69 
70  coral::ISchema& schema(const std::string& schemaName);
71 
72  coral::ISchema& nominalSchema();
73 
74  bool deleteMapping( const std::string& mappingVersion );
75 
76  bool importMapping( const std::string& sourceConnectionString,
77  const std::string& contName );
78 
79  ora::Object getObject( const std::string& objectId );
80 
81  template <typename T> boost::shared_ptr<T> getTypedObject( const std::string& objectId );
82 
83  template <typename T> std::string storeObject( const T* object, const std::string& containerName );
84 
85  std::string storeObject( const ora::Object& objectRef, const std::string& containerName );
86 
87  template <typename T> bool updateObject( const T* object, const std::string& objectId );
88 
89  bool deleteObject( const std::string& objectId );
90 
91  std::string importObject( cond::DbSession& fromDatabase, const std::string& objectId );
92 
93  std::string classNameForItem( const std::string& objectId );
94 
95  void flush();
96 
98 
99  private:
100 
101  boost::shared_ptr<SessionImpl> m_implementation;
102  };
103 
105  public:
106  explicit PoolTokenParser( ora::Database& db );
108  }
109  ora::OId parse( const std::string& poolToken );
110  std::string className( const std::string& poolToken );
111 
112  private:
114  };
115 
117  public:
118  explicit PoolTokenWriter( ora::Database& db );
120  }
121  std::string write( const ora::OId& oid );
122  private:
124  };
125 
126  template <typename T> inline boost::shared_ptr<T> DbSession::getTypedObject( const std::string& objectId ){
127  ora::OId oid;
128  oid.fromString( objectId );
129  return storage().fetch<T>( oid );
130  }
131 
132  template <typename T> inline std::string DbSession::storeObject( const T* object,
133  const std::string& containerName ){
134  std::string ret("");
135  if( object ){
136  ora::OId oid = storage().insert( containerName, *object );
137  storage().flush();
138  ret = oid.toString();
139  }
140  return ret;
141  }
142 
143  template <typename T> inline bool DbSession::updateObject( const T* object,
144  const std::string& objectId ){
145  bool ret = false;
146  if( object ){
147  ora::OId oid;
148  oid.fromString( objectId );
149  storage().update( oid, *object );
150  storage().flush();
151  ret = true;
152  }
153  return ret;
154  }
155 
156 }
157 
158 #endif
159 // DBSESSION_H
PoolTokenParser(ora::Database &db)
Definition: DbSession.cc:307
boost::shared_ptr< SessionImpl > m_implementation
Definition: DbSession.h:101
const std::string & connectionString() const
Definition: DbSession.cc:188
ora::Database & m_db
Definition: DbSession.h:123
void flush()
Definition: Database.cc:323
std::string write(const ora::OId &oid)
Definition: DbSession.cc:331
bool deleteObject(const std::string &objectId)
Definition: DbSession.cc:274
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:292
OId insert(const std::string &containerName, const T &data)
DbTransaction & transaction()
Definition: DbSession.cc:208
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
const std::string & blobStreamingService() const
Definition: DbSession.cc:203
void openReadOnly(const std::string &connectionString, const std::string &id)
Definition: DbSession.cc:170
tuple db
Definition: EcalCondDB.py:151
Definition: OId.h:8
bool deleteMapping(const std::string &mappingVersion)
Definition: DbSession.cc:248
coral::ISchema & schema(const std::string &schemaName)
Definition: DbSession.cc:238
ora::Database & m_db
Definition: DbSession.h:113
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:311
bool isTransactional() const
Definition: DbSession.cc:199
bool importMapping(const std::string &sourceConnectionString, const std::string &contName)
Definition: DbSession.cc:254
DbSession & operator=(const DbSession &rhs)
Definition: DbSession.cc:154
boost::shared_ptr< T > fetch(const OId &oid)
Definition: Database.h:220
virtual ~DbSession()
Definition: DbSession.cc:151
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:132
PoolTokenWriter(ora::Database &db)
Definition: DbSession.cc:327
std::string className(const std::string &poolToken)
Definition: DbSession.cc:320
bool isOldSchema()
Definition: DbSession.cc:230
bool createDatabase()
Definition: DbSession.cc:221
coral::ISchema & nominalSchema()
Definition: DbSession.cc:243
std::string toString() const
Definition: OId.cc:58
std::string importObject(cond::DbSession &fromDatabase, const std::string &objectId)
Definition: DbSession.cc:282
void update(const OId &oid, const T &data)
Definition: Database.h:244
bool isOpen() const
Definition: DbSession.cc:184
ora::Object getObject(const std::string &objectId)
Definition: DbSession.cc:268
bool fromString(const std::string &s)
Definition: OId.cc:64
bool updateObject(const T *object, const std::string &objectId)
Definition: DbSession.h:143
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:126
ora::Database & storage()
Definition: DbSession.cc:215
const DbConnection & connection() const
Definition: DbSession.cc:194