test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Database.h
Go to the documentation of this file.
1 #ifndef INCLUDE_ORA_DATABASE_H
2 #define INCLUDE_ORA_DATABASE_H
3 
4 #include "Object.h"
5 #include "OId.h"
6 #include "Version.h"
7 #include "Container.h"
8 #include "Configuration.h"
9 #include "DatabaseUtility.h"
10 #include "Exception.h"
11 //
12 #include <set>
13 #include <vector>
14 #include <memory>
15 #include <boost/shared_ptr.hpp>
16 
17 namespace coral {
18  class ISessionProxy;
19 }
20 
21 namespace ora {
22 
23  class ConnectionPool;
24  class Transaction;
25  class DatabaseImpl;
26  class SharedSession;
27 
28  class Database {
29  public:
30 
31  //
32  static std::string nameForContainer( const std::type_info& typeInfo );
33  //
35 
36  public:
37 
38  //
39  Database();
40 
41  //
42  Database( const Database& rhs );
43 
44  //
45  Database(boost::shared_ptr<ConnectionPool>& connectionPool);
46 
48  virtual ~Database();
49 
51  Database& operator=( const Database& rhs );
52 
55 
57  ora::Version schemaVersion( bool userSchema=false );
58 
60  bool connect( const std::string& connectionString, bool readOnly=false );
61 
63  bool connect( const std::string& connectionString, const std::string& asRole, bool readOnly=false );
64 
66  bool connect( boost::shared_ptr<coral::ISessionProxy>& coralSession, const std::string& connectionString, const std::string& schemaName="" );
67 
69  void disconnect();
70 
72  bool isConnected();
73 
76 
79 
81  bool exists();
82 
84  bool create( std::string userSchemaVersion = std::string("") );
85 
87  bool drop();
88 
90  void setAccessPermission( const std::string& principal, bool forWrite );
91 
93  std::set< std::string > containers();
94 
96  template <typename T> Container createContainer( const std::string& name );
97 
99  template <typename T> Container createContainer();
100 
102  Container createContainer( const std::string& className, std::string name="" );
103 
105  bool dropContainer( const std::string& name );
106 
108  bool lockContainer( const std::string& name );
109 
111  Container containerHandle( const std::string& name );
112 
114  Container containerHandle( int contId );
115 
117  Object fetchItem(const OId& oid);
118 
120  template <typename T> boost::shared_ptr<T> fetch( const OId& oid);
121 
123  OId insertItem( const std::string& containerName, const Object& data );
124 
126  template <typename T> OId insert( const std::string& containerName, const T& data);
127 
129  template <typename T> OId insert( const T& data);
130 
132  void updateItem(const OId& oid, const Object& data );
133 
135  template <typename T> void update( const OId& oid, const T& data );
136 
138  void erase(const OId& oid);
139 
141  void flush();
142 
144  void setObjectName( const std::string& name, const OId& oid );
145 
147  bool eraseObjectName( const std::string& name );
148 
150  bool eraseAllNames();
151 
153  bool getItemId( const std::string& name, OId& destination );
154 
156  Object fetchItemByName( const std::string& name );
157 
159  template <typename T> boost::shared_ptr<T> fetchByName( const std::string& name );
160 
162  bool getNamesForObject( const OId& oid, std::vector<std::string>& destination );
163 
165  bool listObjectNames( std::vector<std::string>& destination );
166 
169 
170  public:
171 
174 
175  private:
176 
178  void open( bool writingAccess=false );
179 
181  void checkTransaction();
182 
184  Container createContainer( const std::string& name, const std::type_info& typeInfo );
185 
187  Container createContainer( const std::type_info& typeInfo );
188 
190  Container getContainer( const std::string& name, const std::type_info& typeInfo );
191 
193  Container getContainer( const std::type_info& typeInfo );
194 
196  boost::shared_ptr<void> getTypedObjectByName( const std::string& name, const std::type_info& typeInfo );
197 
198  private:
199 
200  boost::shared_ptr<DatabaseImpl> m_impl;
201 
202  };
203 
204 }
205 
206 template <typename T>
207 inline
209  return createContainer( name, typeid(T) );
210 }
211 
212 template <typename T>
213 inline
215  return createContainer( typeid(T) );
216 }
217 
218 template <typename T>
219 inline
220 boost::shared_ptr<T> ora::Database::fetch( const ora::OId& oid){
221  Container cont = containerHandle( oid.containerId() );
222  return cont.fetch<T>( oid.itemId() );
223 }
224 
225 template <typename T>
226 inline
228  const T& data){
229  Container cont = getContainer( containerName, typeid(data) );
230  int itemId = cont.insert( data );
231  return OId( cont.id(), itemId );
232 }
233 
234 template <typename T>
235 inline
237  Container cont = getContainer( typeid(data) );
238  int itemId = cont.insert( data );
239  return OId( cont.id(), itemId );
240 }
241 
242 template <typename T>
243 inline
245  const T& data ){
246  Container cont = containerHandle( oid.containerId() );
247  cont.update( oid.itemId(), data );
248 }
249 
250 template <typename T>
251 inline
252 boost::shared_ptr<T> ora::Database::fetchByName( const std::string& name ){
253  return boost::static_pointer_cast<T>( getTypedObjectByName( name, typeid(T) ) );
254 }
255 
256 
257 #endif
bool create(std::string userSchemaVersion=std::string(""))
Definition: Database.cc:138
int insert(const T &data)
Definition: Container.h:135
void flush()
Definition: Database.cc:323
Object fetchItemByName(const std::string &name)
Definition: Database.cc:358
OId insert(const std::string &containerName, const T &data)
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
const std::string & connectionString()
Definition: Database.cc:113
void checkTransaction()
Definition: Database.cc:124
bool getItemId(const std::string &name, OId &destination)
Definition: Database.cc:347
Definition: OId.h:8
virtual ~Database()
Definition: Database.cc:78
ora::Version schemaVersion(bool userSchema=false)
Definition: Database.cc:186
void open(bool writingAccess=false)
Definition: Database.cc:174
bool lockContainer(const std::string &name)
Definition: Database.cc:265
Transaction & transaction()
Definition: Database.cc:117
SharedSession & storageAccessSession()
Definition: Database.cc:386
void disconnect()
Definition: Database.cc:105
void erase(const OId &oid)
Definition: Database.cc:317
Object fetchItem(const OId &oid)
Definition: Database.cc:297
Container containerHandle(const std::string &name)
Definition: Database.cc:275
boost::shared_ptr< T > fetchByName(const std::string &name)
Definition: Database.h:252
bool exists()
Definition: Database.cc:133
std::set< std::string > containers()
Definition: Database.cc:194
int containerId() const
Definition: OId.cc:50
void update(int itemId, const T &data)
Definition: Container.h:141
boost::shared_ptr< T > fetch(const OId &oid)
Definition: Database.h:220
bool dropContainer(const std::string &name)
Definition: Database.cc:256
Container createContainer()
boost::shared_ptr< DatabaseImpl > m_impl
Definition: Database.h:200
DatabaseUtility utility()
Definition: Database.cc:380
bool getNamesForObject(const OId &oid, std::vector< std::string > &destination)
Definition: Database.cc:363
OId insertItem(const std::string &containerName, const Object &data)
Definition: Database.cc:302
Database & operator=(const Database &rhs)
Definition: Database.cc:81
bool connect(const std::string &connectionString, bool readOnly=false)
Definition: Database.cc:90
bool eraseObjectName(const std::string &name)
Definition: Database.cc:337
bool drop()
Definition: Database.cc:147
static std::string nameForContainer(const std::type_info &typeInfo)
Definition: Database.cc:57
void update(const OId &oid, const T &data)
Definition: Database.h:244
boost::shared_ptr< T > fetch(int itemId)
Definition: Container.h:129
bool isConnected()
Definition: Database.cc:109
bool eraseAllNames()
Definition: Database.cc:342
bool listObjectNames(std::vector< std::string > &destination)
Definition: Database.cc:372
boost::shared_ptr< void > getTypedObjectByName(const std::string &name, const std::type_info &typeInfo)
Definition: Database.cc:352
Configuration & configuration()
Definition: Database.cc:86
long double T
void updateItem(const OId &oid, const Object &data)
Definition: Database.cc:310
void setObjectName(const std::string &name, const OId &oid)
Definition: Database.cc:332
std::string className(const T &t)
Definition: ClassName.h:30
Container getContainer(const std::string &name, const std::type_info &typeInfo)
Definition: Database.cc:242
void setAccessPermission(const std::string &principal, bool forWrite)
Definition: Database.cc:162
int itemId() const
Definition: OId.cc:54