CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Session.h
Go to the documentation of this file.
1 #ifndef CondCore_CondDB_Session_h
2 #define CondCore_CondDB_Session_h
3 //
4 // Package: CondDB
5 // Class : Session
6 //
10 //
11 // Author: Giacomo Govi
12 // Created: Apr 2013
13 //
14 
23 //
24 // temporarely
25 #include <boost/shared_ptr.hpp>
26 
27 // TO BE REMOVED AFTER THE TRANSITION
28 namespace coral {
29  class ISessionProxy;
30  class ISchema;
31 }
32 // END TO BE REMOVED
33 
34 namespace cond {
35 
36  namespace persistency {
37 
38  class SessionConfiguration;
39 
40  // transaction class
41  class Transaction {
42  public:
43  explicit Transaction( SessionImpl& session );
44  Transaction( const Transaction& rhs );
45  Transaction& operator=( const Transaction& rhs );
46 
47  void start( bool readOnly=true );
48 
49  void commit();
50 
51  void rollback();
52 
53  bool isActive();
54  private:
56  };
57 
58  // with full value semantics. destruction will close the DB connection.
59  class Session {
60  public:
61  // default constructor
62  Session();
63 
64  // constructor
65  explicit Session( const std::shared_ptr<SessionImpl>& sessionImpl );
66 
67  // constructor
68  Session( boost::shared_ptr<coral::ISessionProxy>& session, const std::string& connectionString );
69 
70  //
71  Session( const Session& rhs );
72 
73  //
74  virtual ~Session();
75 
76  //
77  Session& operator=( const Session& rhs );
78 
79  //
80  void close();
81 
82  //
84 
85  //
86  bool existsDatabase();
87 
88  //
89  void createDatabase();
90 
91  // read access to the iov sequence.
92  // by default ( full=false ) the iovs are lazy-loaded in groups when required, with repeatable queries ( for FronTier )
93  // full=true will load the entire sequence in memory. Mainly for test/debugging.
94  IOVProxy readIov( const std::string& tag, bool full=false );//,const boost::posix_time::ptime& snapshottime )
95 
96  //
97  bool existsIov( const std::string& tag );
98 
99  // create a non-existing iov sequence with the specified tag.
100  // the type is required for consistency with the referenced payloads.
101  // fixme: add creation time - required for the migration
102  template <typename T>
103  IOVEditor createIov( const std::string& tag, cond::TimeType timeType,
104  cond::SynchronizationType synchronizationType=cond::OFFLINE );
105  IOVEditor createIov( const std::string& payloadType, const std::string& tag, cond::TimeType timeType,
106  cond::SynchronizationType synchronizationType=cond::OFFLINE );
107 
108  IOVEditor createIovForPayload( const Hash& payloadHash, const std::string& tag, cond::TimeType timeType,
109  cond::SynchronizationType synchronizationType=cond::OFFLINE );
110 
111  // update an existing iov sequence with the specified tag.
112  // timeType and payloadType can't be modified.
113  IOVEditor editIov( const std::string& tag );
114 
115  // functions to store a payload in the database. return the identifier of the item in the db.
116  template <typename T> cond::Hash storePayload( const T& payload,
117  const boost::posix_time::ptime& creationTime = boost::posix_time::microsec_clock::universal_time() );
118  template <typename T> boost::shared_ptr<T> fetchPayload( const cond::Hash& payloadHash );
119 
120  // low-level function to access the payload data as a blob. mainly used for the data migration and testing.
121  bool fetchPayloadData( const cond::Hash& payloadHash, std::string& payloadType, cond::Binary& payloadData );
122 
123  // internal functions. creates proxies without loading a specific tag.
124  IOVProxy iovProxy();
125 
127  GTEditor editGlobalTag( const std::string& name );
128 
129  GTProxy readGlobalTag( const std::string& name );
130  // essentially for the bridge. useless where ORA disappears.
131  GTProxy readGlobalTag( const std::string& name, const std::string& preFix, const std::string& postFix );
132  public:
133 
134  bool checkMigrationLog( const std::string& sourceAccount, const std::string& sourceTag, std::string& destinationTag );
135  void addToMigrationLog( const std::string& sourceAccount, const std::string& sourceTag, const std::string& destinationTag );
136 
138 
139  coral::ISessionProxy& coralSession();
140  // TO BE REMOVED in the long term. The new code will use coralSession().
141  coral::ISchema& nominalSchema();
142 
143  bool isOraSession();
144 
145  private:
146  cond::Hash storePayloadData( const std::string& payloadObjectType, const cond::Binary& payloadData, const boost::posix_time::ptime& creationTime );
147  private:
148 
149  std::shared_ptr<SessionImpl> m_session;
151  };
152 
153  template <typename T> inline IOVEditor Session::createIov( const std::string& tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType ){
154  return createIov( cond::demangledName( typeid(T) ), tag, timeType, synchronizationType );
155  }
156 
157  template <typename T> inline cond::Hash Session::storePayload( const T& payload, const boost::posix_time::ptime& creationTime ){
158 
159  std::string payloadObjectType = cond::demangledName(typeid(payload));
160  return storePayloadData( payloadObjectType, serialize( payload, isOraSession() ), creationTime );
161  }
162 
163  template <typename T> inline boost::shared_ptr<T> Session::fetchPayload( const cond::Hash& payloadHash ){
164  cond::Binary payloadData;
165  std::string payloadType;
166  if(! fetchPayloadData( payloadHash, payloadType, payloadData ) )
167  throwException( "Payload with id="+payloadHash+" has not been found in the database.",
168  "Session::fetchPayload" );
169  return deserialize<T>( payloadType, payloadData, isOraSession() );
170  }
171 
173  public:
175 
177 
178  void start( bool readOnly=true );
179 
180  void commit();
181 
182  void close();
183  private:
185  bool m_status;
186 
187  };
188 
189 
190  }
191 }
192 #endif
GTEditor editGlobalTag(const std::string &name)
Definition: Session.cc:140
Transaction(SessionImpl &session)
Definition: Session.cc:9
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData)
Definition: Session.cc:168
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:163
void start(bool readOnly=true)
Definition: Session.cc:22
void addToMigrationLog(const std::string &sourceAccount, const std::string &sourceTag, const std::string &destinationTag)
Definition: Session.cc:185
TransactionScope(Transaction &transaction)
Definition: Session.cc:204
Transaction & transaction()
Definition: Session.cc:71
TimeType
Definition: Time.h:21
std::string demangledName(const std::type_info &typeInfo)
Definition: ClassUtils.cc:82
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:86
Transaction & operator=(const Transaction &rhs)
Definition: Session.cc:17
coral::ISchema & nominalSchema()
Definition: Session.cc:200
Definition: GenABIO.cc:193
void start(bool readOnly=true)
Definition: Session.cc:215
std::string Hash
Definition: Types.h:34
std::string connectionString()
Definition: Session.cc:191
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:125
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::OFFLINE)
Definition: Session.cc:113
bool checkMigrationLog(const std::string &sourceAccount, const std::string &sourceTag, std::string &destinationTag)
Definition: Session.cc:179
bool existsIov(const std::string &tag)
Definition: Session.cc:93
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:157
coral::ISessionProxy & coralSession()
Definition: Session.cc:195
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::OFFLINE)
Definition: Session.h:153
Binary serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:87
SynchronizationType
Definition: Types.h:22
GTEditor createGlobalTag(const std::string &name)
Definition: Session.cc:132
Session & operator=(const Session &rhs)
Definition: Session.cc:61
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:147
long double T
Transaction m_transaction
Definition: Session.h:150
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
std::shared_ptr< SessionImpl > m_session
Definition: Session.h:149
cond::Hash storePayloadData(const std::string &payloadObjectType, const cond::Binary &payloadData, const boost::posix_time::ptime &creationTime)
Definition: Session.cc:161