File indexing completed on 2024-04-06 12:01:28
0001 #ifndef CondCore_CondDB_IOVSchema_h
0002 #define CondCore_CondDB_IOVSchema_h
0003
0004 #include "DbCore.h"
0005 #include "IDbSchema.h"
0006
0007 #include <boost/date_time/posix_time/posix_time.hpp>
0008
0009 namespace cond {
0010
0011 namespace persistency {
0012
0013 conddb_table(TAG) {
0014 conddb_column(NAME, std::string);
0015 conddb_column(TIME_TYPE, cond::TimeType);
0016 conddb_column(OBJECT_TYPE, std::string);
0017 conddb_column(SYNCHRONIZATION, cond::SynchronizationType);
0018 conddb_column(END_OF_VALIDITY, cond::Time_t);
0019 conddb_column(DESCRIPTION, std::string);
0020 conddb_column(LAST_VALIDATED_TIME, cond::Time_t);
0021 conddb_column(INSERTION_TIME, boost::posix_time::ptime);
0022 conddb_column(MODIFICATION_TIME, boost::posix_time::ptime);
0023 conddb_column(PROTECTION_CODE, int);
0024
0025 class Table : public ITagTable {
0026 public:
0027 explicit Table(coral::ISchema& schema);
0028 ~Table() override {}
0029 bool exists() override;
0030 void create() override;
0031 bool select(const std::string& name) override;
0032 bool select(const std::string& name,
0033 cond::TimeType& timeType,
0034 std::string& objectType,
0035 cond::SynchronizationType& synchronizationType,
0036 cond::Time_t& endOfValidity,
0037 cond::Time_t& lastValidatedTime,
0038 int& protectionCode) override;
0039 bool getMetadata(const std::string& name,
0040 std::string& description,
0041 boost::posix_time::ptime& insertionTime,
0042 boost::posix_time::ptime& modificationTime) override;
0043 void insert(const std::string& name,
0044 cond::TimeType timeType,
0045 const std::string& objectType,
0046 cond::SynchronizationType synchronizationType,
0047 cond::Time_t endOfValidity,
0048 const std::string& description,
0049 cond::Time_t lastValidatedTime,
0050 const boost::posix_time::ptime& insertionTime) override;
0051 void update(const std::string& name,
0052 cond::SynchronizationType synchronizationType,
0053 cond::Time_t& endOfValidity,
0054 cond::Time_t lastValidatedTime,
0055 const boost::posix_time::ptime& updateTime) override;
0056 void updateMetadata(const std::string& name,
0057 const std::string& description,
0058 const boost::posix_time::ptime& updateTime) override;
0059 void updateValidity(const std::string& name,
0060 cond::Time_t lastValidatedTime,
0061 const boost::posix_time::ptime& updateTime) override;
0062 void setProtectionCode(const std::string& name, int code) override;
0063 void unsetProtectionCode(const std::string& name, int code) override;
0064
0065 bool isProtectable() { return m_isProtectable; }
0066
0067 private:
0068 coral::ISchema& m_schema;
0069 bool m_isProtectable = false;
0070 };
0071 }
0072
0073 conddb_table(PAYLOAD) {
0074 static constexpr unsigned int PAYLOAD_HASH_SIZE = 40;
0075
0076 conddb_column(HASH, std::string, PAYLOAD_HASH_SIZE);
0077 conddb_column(OBJECT_TYPE, std::string);
0078 conddb_column(DATA, cond::Binary);
0079 conddb_column(STREAMER_INFO, cond::Binary);
0080 conddb_column(VERSION, std::string);
0081 conddb_column(INSERTION_TIME, boost::posix_time::ptime);
0082
0083 class Table : public IPayloadTable {
0084 public:
0085 explicit Table(coral::ISchema& schema);
0086 ~Table() override {}
0087 bool exists() override;
0088 void create() override;
0089 bool select(const cond::Hash& payloadHash);
0090 bool select(const cond::Hash& payloadHash,
0091 std::string& objectType,
0092 cond::Binary& payloadData,
0093 cond::Binary& streamerInfoData) override;
0094 bool getType(const cond::Hash& payloadHash, std::string& objectType) override;
0095 bool insert(const cond::Hash& payloadHash,
0096 const std::string& objectType,
0097 const cond::Binary& payloadData,
0098 const cond::Binary& streamerInfoData,
0099 const boost::posix_time::ptime& insertionTime);
0100 cond::Hash insertIfNew(const std::string& objectType,
0101 const cond::Binary& payloadData,
0102 const cond::Binary& streamerInfoData,
0103 const boost::posix_time::ptime& insertionTime) override;
0104
0105 private:
0106 coral::ISchema& m_schema;
0107 };
0108 }
0109
0110 conddb_table(IOV) {
0111 conddb_column(TAG_NAME, std::string);
0112 conddb_column(SINCE, cond::Time_t);
0113 conddb_column(PAYLOAD_HASH, std::string, PAYLOAD::PAYLOAD_HASH_SIZE);
0114 conddb_column(INSERTION_TIME, boost::posix_time::ptime);
0115
0116 struct SINCE_GROUP {
0117 typedef cond::Time_t type;
0118 static constexpr size_t size = 0;
0119 static std::string tableName() { return SINCE::tableName(); }
0120 static std::string fullyQualifiedName() { return "MIN(" + SINCE::fullyQualifiedName() + ")"; }
0121 static std::string group(unsigned long long groupSize) {
0122 std::string sgroupSize = std::to_string(groupSize);
0123 return "CAST(" + SINCE::fullyQualifiedName() + "/" + sgroupSize + " AS INT )*" + sgroupSize;
0124 }
0125 };
0126
0127 struct SEQUENCE_SIZE {
0128 typedef unsigned int type;
0129 static constexpr size_t size = 0;
0130 static std::string tableName() { return SINCE::tableName(); }
0131 static std::string fullyQualifiedName() { return "COUNT(*)"; }
0132 };
0133
0134 struct MIN_SINCE {
0135 typedef cond::Time_t type;
0136 static constexpr size_t size = 0;
0137 static std::string tableName() { return SINCE::tableName(); }
0138 static std::string fullyQualifiedName() { return "MIN(" + SINCE::fullyQualifiedName() + ")"; }
0139 };
0140
0141 struct MAX_SINCE {
0142 typedef cond::Time_t type;
0143 static constexpr size_t size = 0;
0144 static std::string tableName() { return SINCE::tableName(); }
0145 static std::string fullyQualifiedName() { return "MAX(" + SINCE::fullyQualifiedName() + ")"; }
0146 };
0147
0148 class Table : public IIOVTable {
0149 public:
0150 explicit Table(coral::ISchema& schema);
0151 ~Table() override {}
0152 bool exists() override;
0153 void create() override;
0154 size_t getGroups(const std::string& tag,
0155 const boost::posix_time::ptime& snapshotTime,
0156 unsigned long long groupSize,
0157 std::vector<cond::Time_t>& groups) override;
0158 size_t select(const std::string& tag,
0159 cond::Time_t lowerGroup,
0160 cond::Time_t upperGroup,
0161 const boost::posix_time::ptime& snapshotTime,
0162 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0163 bool getLastIov(const std::string& tag,
0164 const boost::posix_time::ptime& snapshotTime,
0165 cond::Time_t& since,
0166 cond::Hash& hash) override;
0167 bool getSize(const std::string& tag, const boost::posix_time::ptime& snapshotTime, size_t& size) override;
0168 bool getRange(const std::string& tag,
0169 cond::Time_t begin,
0170 cond::Time_t end,
0171 const boost::posix_time::ptime& snapshotTime,
0172 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0173 void insertOne(const std::string& tag,
0174 cond::Time_t since,
0175 cond::Hash payloadHash,
0176 const boost::posix_time::ptime& insertTime) override;
0177 void insertMany(
0178 const std::string& tag,
0179 const std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> >& iovs) override;
0180 void eraseOne(const std::string& tag, cond::Time_t since, cond::Hash payloadId) override;
0181 void eraseMany(const std::string& tag, const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0182 void erase(const std::string& tag) override;
0183
0184 private:
0185 coral::ISchema& m_schema;
0186 };
0187 }
0188
0189 conddb_table(TAG_AUTHORIZATION) {
0190 conddb_column(TAG_NAME, std::string);
0191 conddb_column(ACCESS_TYPE, int);
0192 conddb_column(CREDENTIAL, std::string);
0193 conddb_column(CREDENTIAL_TYPE, int);
0194
0195 class Table : public ITagAccessPermissionTable {
0196 public:
0197 explicit Table(coral::ISchema& schema);
0198 ~Table() override {}
0199 bool exists() override;
0200 void create() override;
0201 bool getAccessPermission(const std::string& tagName,
0202 const std::string& credential,
0203 int credentialType,
0204 int accessType) override;
0205 void setAccessPermission(const std::string& tagName,
0206 const std::string& credential,
0207 int credentialType,
0208 int accessType) override;
0209 void removeAccessPermission(const std::string& tagName,
0210 const std::string& credential,
0211 int credentialType) override;
0212 void removeEntriesForCredential(const std::string& credential, int credentialType) override;
0213
0214 private:
0215 coral::ISchema& m_schema;
0216 };
0217 }
0218
0219 conddb_table(TAG_LOG) {
0220 conddb_column(TAG_NAME, std::string);
0221 conddb_column(EVENT_TIME, boost::posix_time::ptime);
0222 conddb_column(USER_NAME, std::string);
0223 conddb_column(HOST_NAME, std::string);
0224 conddb_column(COMMAND, std::string);
0225 conddb_column(ACTION, std::string);
0226 conddb_column(USER_TEXT, std::string);
0227
0228 class Table : public ITagLogTable {
0229 public:
0230 explicit Table(coral::ISchema& schema);
0231 ~Table() override {}
0232 bool exists() override;
0233 void create() override;
0234 void insert(const std::string& tag,
0235 const boost::posix_time::ptime& eventTime,
0236 const std::string& userName,
0237 const std::string& hostName,
0238 const std::string& command,
0239 const std::string& action,
0240 const std::string& userText) override;
0241
0242 private:
0243 coral::ISchema& m_schema;
0244 };
0245 }
0246
0247 class IOVSchema : public IIOVSchema {
0248 public:
0249 explicit IOVSchema(coral::ISchema& schema);
0250 ~IOVSchema() override {}
0251 bool exists() override;
0252 bool create() override;
0253 ITagTable& tagTable() override;
0254 IIOVTable& iovTable() override;
0255 ITagLogTable& tagLogTable() override;
0256 ITagAccessPermissionTable& tagAccessPermissionTable() override;
0257 IPayloadTable& payloadTable() override;
0258
0259 private:
0260 TAG::Table m_tagTable;
0261 IOV::Table m_iovTable;
0262 TAG_LOG::Table m_tagLogTable;
0263 TAG_AUTHORIZATION::Table m_tagAccessPermissionTable;
0264 PAYLOAD::Table m_payloadTable;
0265 };
0266
0267 }
0268 }
0269 #endif