8 namespace persistency {
13 const EVP_MD* md = EVP_get_digestbyname(
"SHA1");
14 if (!EVP_DigestInit_ex(mdctx, md,
nullptr)) {
15 throwException(
"SHA1 initialization error.",
"IOVSchema::makeHash");
17 if (!EVP_DigestUpdate(mdctx, objectType.c_str(), objectType.size())) {
18 throwException(
"SHA1 processing error (1).",
"IOVSchema::makeHash");
20 if (!EVP_DigestUpdate(mdctx,
data.data(),
data.size())) {
21 throwException(
"SHA1 processing error (2).",
"IOVSchema::makeHash");
23 unsigned char hash[EVP_MAX_MD_SIZE];
24 unsigned int md_len = 0;
25 if (!EVP_DigestFinal_ex(mdctx,
hash, &md_len)) {
29 char tmp[EVP_MAX_MD_SIZE * 2 + 1];
34 for (
unsigned int i = 0;
i < md_len;
i++) {
51 bool TAG::Table::Table::exists() {
return existsTable(m_schema,
tname); }
55 throwException(
"TAG table already exists in this schema.",
"TAG::Table::create");
68 descr.setPrimaryKey<
NAME>();
69 createTable(m_schema, descr.get());
70 m_isProtectable =
true;
79 return q.retrievedRows();
88 int& protectionCode) {
89 if (isProtectable()) {
93 for (
const auto& row :
q)
94 std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime, protectionCode) = row;
95 return q.retrievedRows();
99 for (
const auto& row :
q)
100 std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime) = row;
103 return q.retrievedRows();
109 boost::posix_time::ptime& insertionTime,
110 boost::posix_time::ptime& modificationTime) {
113 for (
const auto& row :
q)
114 std::tie(
description, insertionTime, modificationTime) = row;
115 return q.retrievedRows();
125 const boost::posix_time::ptime& insertionTime) {
126 if (isProtectable()) {
137 dataToInsert(std::tie(
name,
147 insertInTable(m_schema,
tname, dataToInsert.get());
158 dataToInsert(std::tie(
name,
167 insertInTable(m_schema,
tname, dataToInsert.get());
175 const boost::posix_time::ptime& updateTime) {
178 std::tie(synchronizationType, endOfValidity, lastValidatedTime, updateTime));
185 const boost::posix_time::ptime& updateTime) {
194 const boost::posix_time::ptime& updateTime) {
202 if (!isProtectable()) {
203 throwException(
"Tag in this schema are not protectable.",
"TAG::Table::create");
208 for (
const auto& row :
q)
209 std::tie(newCode) = row;
218 if (!isProtectable()) {
219 throwException(
"Tag in this schema are not protectable.",
"TAG::Table::unsetProtectionCode");
224 for (
const auto& row :
q)
225 std::tie(presentCode) = row;
226 int newCode = presentCode & (~code);
239 throwException(
"IOV table already exists in this schema.",
"IOV::Schema::create");
246 createTable(m_schema, descr.
get());
251 unsigned long long gSize,
252 std::vector<cond::Time_t>& groups) {
261 groups.push_back(std::get<0>(row));
263 return q.retrievedRows();
270 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
273 if (lowerSinceGroup > 0)
274 q.addCondition<
SINCE>(lowerSinceGroup,
">=");
276 q.addCondition<
SINCE>(upperSinceGroup,
"<");
280 q.addOrderClause<
SINCE>();
282 size_t initialSize = iovs.
size();
285 if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
289 return iovs.size() - initialSize;
301 q.addOrderClause<
SINCE>(
false);
303 q.limitReturnedRows(1);
305 since = std::get<0>(row);
306 hash = std::get<1>(row);
319 size = std::get<0>(row);
329 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
332 q0.addCondition<
SINCE>(begin,
"<=");
337 for (
auto row :
q0) {
338 lower_since = std::get<0>(row);
351 size_t initialSize = iovs.
size();
352 for (
auto row : q1) {
354 if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
358 return iovs.size() - initialSize;
364 const boost::posix_time::ptime& insertTimeStamp) {
366 std::tie(
tag,
since, payloadHash, insertTimeStamp));
367 insertInTable(m_schema,
tname, dataToInsert.
get());
372 const std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> >& iovs) {
374 for (
auto row : iovs)
375 inserter.
insert(std::tuple_cat(std::tie(
tag), row));
389 for (
auto iov : iovs)
390 deleter.erase(std::tuple_cat(std::tie(
tag), iov));
406 throwException(
"TAG_LOG table already exists in this schema.",
"TAG_LOG::create");
411 createTable(m_schema, descr.
get());
415 const boost::posix_time::ptime& eventTime,
423 insertInTable(m_schema,
tname, dataToInsert.
get());
432 throwException(
"TAG_AUTHORIZATION table already exists in this schema.",
"TAG_AUTHORIZATION::create");
437 createTable(m_schema, descr.
get());
448 int allowedAccess = 0;
450 allowedAccess = std::get<0>(row);
452 return allowedAccess & accessType;
460 std::tie(
tagName, accessType, credential, credentialType));
461 insertInTable(m_schema,
tname, dataToInsert.
get());
466 int credentialType) {
487 throwException(
"Payload table already exists in this schema.",
"PAYLOAD::Schema::create");
492 createTable(m_schema, descr.
get());
497 q.addCondition<
HASH>(payloadHash);
501 return q.retrievedRows();
506 q.addCondition<
HASH>(payloadHash);
508 objectType = std::get<0>(row);
511 return q.retrievedRows();
519 q.addCondition<
HASH>(payloadHash);
520 for (
const auto& row :
q) {
521 std::tie(payloadData, streamerInfoData, objectType) = row;
523 return q.retrievedRows();
530 const boost::posix_time::ptime& insertionTime) {
533 if (!sinfoData.
size())
536 std::tie(payloadHash, objectType, payloadData, sinfoData,
version, insertionTime));
537 bool failOnDuplicate =
false;
538 return insertInTable(m_schema,
tname, dataToInsert.
get(), failOnDuplicate);
544 const boost::posix_time::ptime& insertionTime) {
547 if (!
select(payloadHash)) {
548 insert(payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime);
554 : m_tagTable(schema),
556 m_tagLogTable(schema),
557 m_tagAccessPermissionTable(schema),
558 m_payloadTable(schema) {}
571 bool created =
false;
591 throwException(
"Tag in this schema are not protectable.",
"IOVSchema::tagAccessPermissionTable");
bool getLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash) override
bool select(const cond::Hash &payloadHash)
void update(const std::string &name, cond::SynchronizationType synchronizationType, cond::Time_t &endOfValidity, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime) override
Table(coral::ISchema &schema)
void insert(const std::string &tag, const boost::posix_time::ptime &eventTime, const std::string &userName, const std::string &hostName, const std::string &command, const std::string &action, const std::string &userText) override
const coral::TableDescription & get()
static constexpr char const * name
void insert(const P ¶ms)
void insert(const std::string &name, cond::TimeType timeType, const std::string &objectType, cond::SynchronizationType synchronizationType, cond::Time_t endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &insertionTime) override
void setAccessPermission(const std::string &tagName, const std::string &credential, int credentialType, int accessType) override
PAYLOAD::Table m_payloadTable
coral::ISchema & m_schema
Table(coral::ISchema &schema)
void eraseOne(const std::string &tag, cond::Time_t since, cond::Hash payloadId) override
static constexpr char const * tname
static std::string group(unsigned long long groupSize)
IPayloadTable & payloadTable() override
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime) override
void setForeignKey(const std::string &name)
static constexpr char const * tname
TAG_AUTHORIZATION::Table m_tagAccessPermissionTable
unsigned long long Time_t
static constexpr char const * tname
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime) override
bool select(const std::string &name) override
void unsetProtectionCode(const std::string &name, int code) override
Query & addCondition(const T &value, const std::string condition="=")
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime) override
void erase(const std::string &tag) override
void removeEntriesForCredential(const std::string &credential, int credentialType) override
void copy(const std::string &source)
void removeAccessPermission(const std::string &tagName, const std::string &credential, int credentialType) override
static constexpr int COND_DBTAG_NO_PROTECTION_CODE
const coral::AttributeList & get() const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Table(coral::ISchema &schema)
bool getRange(const std::string &tag, cond::Time_t begin, cond::Time_t end, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
ITagLogTable & tagLogTable() override
size_t select(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
Query & addOrderClause(bool ascending=true)
void updateMetadata(const std::string &name, const std::string &description, const boost::posix_time::ptime &updateTime) override
Table(coral::ISchema &schema)
TAG_LOG::Table m_tagLogTable
Table(coral::ISchema &schema)
IOVSchema(coral::ISchema &schema)
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime) override
void setProtectionCode(const std::string &name, int code) override
bool getSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size) override
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs) override
static constexpr char const * tname
char data[epos_bytes_allocation]
bool getType(const cond::Hash &payloadHash, std::string &objectType) override
cond::Hash makeHash(const std::string &objectType, const cond::Binary &data)
size_t getGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, unsigned long long groupSize, std::vector< cond::Time_t > &groups) override
static constexpr size_t size
bool insert(const cond::Hash &payloadHash, const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
IIOVTable & iovTable() override
static constexpr char const * tname
bool getAccessPermission(const std::string &tagName, const std::string &credential, int credentialType, int accessType) override
ITagAccessPermissionTable & tagAccessPermissionTable() override
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
ITagTable & tagTable() override
void throwException(const std::string &message, const std::string &methodName)
void eraseMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override