File indexing completed on 2025-06-17 01:30:03
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 static constexpr auto minSINCE_ =
0116 condcore_detail::addMin<SINCE::fullyQualifiedName().size()>(SINCE::fullyQualifiedName());
0117 static constexpr std::string_view minSINCE() { return std::string_view(minSINCE_.data()); }
0118 static constexpr auto maxSINCE_ =
0119 condcore_detail::addMax<SINCE::fullyQualifiedName().size()>(SINCE::fullyQualifiedName());
0120 static constexpr std::string_view maxSINCE() { return std::string_view(maxSINCE_.data()); }
0121
0122 struct SINCE_GROUP {
0123 typedef cond::Time_t type;
0124 static constexpr size_t size = 0;
0125 static constexpr std::string_view tableName() { return SINCE::tableName(); }
0126 static constexpr std::string_view fullyQualifiedName() { return minSINCE(); }
0127 static std::string group(unsigned long long groupSize) {
0128 std::string sgroupSize = std::to_string(groupSize);
0129 return "CAST(" + std::string(SINCE::fullyQualifiedName()) + "/" + sgroupSize + " AS INT )*" + sgroupSize;
0130 }
0131 };
0132
0133 struct SEQUENCE_SIZE {
0134 typedef unsigned int type;
0135 static constexpr size_t size = 0;
0136 static constexpr std::string_view tableName() { return SINCE::tableName(); }
0137 static constexpr std::string_view fullyQualifiedName() { return "COUNT(*)"; }
0138 };
0139
0140 struct MIN_SINCE {
0141 typedef cond::Time_t type;
0142 static constexpr size_t size = 0;
0143 static constexpr std::string_view tableName() { return SINCE::tableName(); }
0144 static constexpr std::string_view fullyQualifiedName() { return minSINCE(); }
0145 };
0146
0147 struct MAX_SINCE {
0148 typedef cond::Time_t type;
0149 static constexpr size_t size = 0;
0150 static constexpr std::string_view tableName() { return SINCE::tableName(); }
0151 static constexpr std::string_view fullyQualifiedName() { return maxSINCE(); }
0152 };
0153
0154 class Table : public IIOVTable {
0155 public:
0156 explicit Table(coral::ISchema& schema);
0157 ~Table() override {}
0158 bool exists() override;
0159 void create() override;
0160 size_t getGroups(const std::string& tag,
0161 const boost::posix_time::ptime& snapshotTime,
0162 unsigned long long groupSize,
0163 std::vector<cond::Time_t>& groups) override;
0164 size_t select(const std::string& tag,
0165 cond::Time_t lowerGroup,
0166 cond::Time_t upperGroup,
0167 const boost::posix_time::ptime& snapshotTime,
0168 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0169 bool getLastIov(const std::string& tag,
0170 const boost::posix_time::ptime& snapshotTime,
0171 cond::Time_t& since,
0172 cond::Hash& hash) override;
0173 bool getSize(const std::string& tag, const boost::posix_time::ptime& snapshotTime, size_t& size) override;
0174 bool getRange(const std::string& tag,
0175 cond::Time_t begin,
0176 cond::Time_t end,
0177 const boost::posix_time::ptime& snapshotTime,
0178 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0179 void insertOne(const std::string& tag,
0180 cond::Time_t since,
0181 cond::Hash payloadHash,
0182 const boost::posix_time::ptime& insertTime) override;
0183 void insertMany(
0184 const std::string& tag,
0185 const std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> >& iovs) override;
0186 void eraseOne(const std::string& tag, cond::Time_t since, cond::Hash payloadId) override;
0187 void eraseMany(const std::string& tag, const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override;
0188 void erase(const std::string& tag) override;
0189
0190 private:
0191 coral::ISchema& m_schema;
0192 };
0193 }
0194
0195 conddb_table(TAG_AUTHORIZATION) {
0196 conddb_column(TAG_NAME, std::string);
0197 conddb_column(ACCESS_TYPE, int);
0198 conddb_column(CREDENTIAL, std::string);
0199 conddb_column(CREDENTIAL_TYPE, int);
0200
0201 class Table : public ITagAccessPermissionTable {
0202 public:
0203 explicit Table(coral::ISchema& schema);
0204 ~Table() override {}
0205 bool exists() override;
0206 void create() override;
0207 bool getAccessPermission(const std::string& tagName,
0208 const std::string& credential,
0209 int credentialType,
0210 int accessType) override;
0211 void setAccessPermission(const std::string& tagName,
0212 const std::string& credential,
0213 int credentialType,
0214 int accessType) override;
0215 void removeAccessPermission(const std::string& tagName,
0216 const std::string& credential,
0217 int credentialType) override;
0218 void removeEntriesForCredential(const std::string& credential, int credentialType) override;
0219
0220 private:
0221 coral::ISchema& m_schema;
0222 };
0223 }
0224
0225 conddb_table(TAG_LOG) {
0226 conddb_column(TAG_NAME, std::string);
0227 conddb_column(EVENT_TIME, boost::posix_time::ptime);
0228 conddb_column(USER_NAME, std::string);
0229 conddb_column(HOST_NAME, std::string);
0230 conddb_column(COMMAND, std::string);
0231 conddb_column(ACTION, std::string);
0232 conddb_column(USER_TEXT, std::string);
0233
0234 class Table : public ITagLogTable {
0235 public:
0236 explicit Table(coral::ISchema& schema);
0237 ~Table() override {}
0238 bool exists() override;
0239 void create() override;
0240 void insert(const std::string& tag,
0241 const boost::posix_time::ptime& eventTime,
0242 const std::string& userName,
0243 const std::string& hostName,
0244 const std::string& command,
0245 const std::string& action,
0246 const std::string& userText) override;
0247
0248 private:
0249 coral::ISchema& m_schema;
0250 };
0251 }
0252
0253 class IOVSchema : public IIOVSchema {
0254 public:
0255 explicit IOVSchema(coral::ISchema& schema);
0256 ~IOVSchema() override {}
0257 bool exists() override;
0258 bool create() override;
0259 ITagTable& tagTable() override;
0260 IIOVTable& iovTable() override;
0261 ITagLogTable& tagLogTable() override;
0262 ITagAccessPermissionTable& tagAccessPermissionTable() override;
0263 IPayloadTable& payloadTable() override;
0264
0265 private:
0266 TAG::Table m_tagTable;
0267 IOV::Table m_iovTable;
0268 TAG_LOG::Table m_tagLogTable;
0269 TAG_AUTHORIZATION::Table m_tagAccessPermissionTable;
0270 PAYLOAD::Table m_payloadTable;
0271 };
0272
0273 }
0274 }
0275 #endif