|
|
Go to the documentation of this file.
5 #include <openssl/sha.h>
9 namespace persistency {
13 if (!SHA1_Init(&ctx)) {
14 throwException(
"SHA1 initialization error.",
"IOVSchema::makeHash");
16 if (!SHA1_Update(&ctx, objectType.c_str(), objectType.size())) {
17 throwException(
"SHA1 processing error (1).",
"IOVSchema::makeHash");
19 if (!SHA1_Update(&ctx,
data.data(),
data.size())) {
20 throwException(
"SHA1 processing error (2).",
"IOVSchema::makeHash");
22 unsigned char hash[SHA_DIGEST_LENGTH];
23 if (!SHA1_Final(
hash, &ctx)) {
27 char tmp[SHA_DIGEST_LENGTH * 2 + 1];
29 for (
unsigned int i = 0;
i < 20;
i++) {
46 bool TAG::Table::Table::exists() {
return existsTable(m_schema,
tname); }
50 throwException(
"TAG table already exists in this schema.",
"TAG::Table::create");
63 descr.setPrimaryKey<
NAME>();
64 createTable(m_schema, descr.get());
65 m_isProtectable =
true;
74 return q.retrievedRows();
83 int& protectionCode) {
84 if (isProtectable()) {
88 for (
const auto& row :
q)
89 std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime, protectionCode) = row;
90 return q.retrievedRows();
94 for (
const auto& row :
q)
95 std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime) = row;
98 return q.retrievedRows();
104 boost::posix_time::ptime& insertionTime,
105 boost::posix_time::ptime& modificationTime) {
108 for (
const auto& row :
q)
109 std::tie(
description, insertionTime, modificationTime) = row;
110 return q.retrievedRows();
120 const boost::posix_time::ptime& insertionTime) {
121 if (isProtectable()) {
132 dataToInsert(std::tie(
name,
142 insertInTable(m_schema,
tname, dataToInsert.get());
153 dataToInsert(std::tie(
name,
162 insertInTable(m_schema,
tname, dataToInsert.get());
170 const boost::posix_time::ptime& updateTime) {
173 std::tie(synchronizationType, endOfValidity, lastValidatedTime, updateTime));
180 const boost::posix_time::ptime& updateTime) {
189 const boost::posix_time::ptime& updateTime) {
197 if (!isProtectable()) {
198 throwException(
"Tag in this schema are not protectable.",
"TAG::Table::create");
203 for (
const auto& row :
q)
204 std::tie(newCode) = row;
213 if (!isProtectable()) {
214 throwException(
"Tag in this schema are not protectable.",
"TAG::Table::unsetProtectionCode");
219 for (
const auto& row :
q)
220 std::tie(presentCode) = row;
221 int newCode = presentCode & (~code);
234 throwException(
"IOV table already exists in this schema.",
"IOV::Schema::create");
241 createTable(m_schema, descr.
get());
246 unsigned long long gSize,
247 std::vector<cond::Time_t>& groups) {
256 groups.push_back(std::get<0>(row));
258 return q.retrievedRows();
265 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
268 if (lowerSinceGroup > 0)
269 q.addCondition<
SINCE>(lowerSinceGroup,
">=");
271 q.addCondition<
SINCE>(upperSinceGroup,
"<");
275 q.addOrderClause<
SINCE>();
277 size_t initialSize = iovs.
size();
280 if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
284 return iovs.size() - initialSize;
296 q.addOrderClause<
SINCE>(
false);
298 q.limitReturnedRows(1);
300 since = std::get<0>(row);
301 hash = std::get<1>(row);
314 size = std::get<0>(row);
324 std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
327 q0.addCondition<
SINCE>(begin,
"<=");
332 for (
auto row :
q0) {
333 lower_since = std::get<0>(row);
339 q1.addCondition<
SINCE>(lower_since,
">=");
346 size_t initialSize = iovs.
size();
347 for (
auto row :
q1) {
349 if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
353 return iovs.size() - initialSize;
359 const boost::posix_time::ptime& insertTimeStamp) {
361 std::tie(
tag,
since, payloadHash, insertTimeStamp));
362 insertInTable(m_schema,
tname, dataToInsert.
get());
367 const std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> >& iovs) {
369 for (
auto row : iovs)
370 inserter.
insert(std::tuple_cat(std::tie(
tag), row));
384 for (
auto iov : iovs)
385 deleter.erase(std::tuple_cat(std::tie(
tag), iov));
401 throwException(
"TAG_LOG table already exists in this schema.",
"TAG_LOG::create");
406 createTable(m_schema, descr.
get());
410 const boost::posix_time::ptime& eventTime,
418 insertInTable(m_schema,
tname, dataToInsert.
get());
427 throwException(
"TAG_AUTHORIZATION table already exists in this schema.",
"TAG_AUTHORIZATION::create");
432 createTable(m_schema, descr.
get());
443 int allowedAccess = 0;
445 allowedAccess = std::get<0>(row);
447 return allowedAccess & accessType;
455 std::tie(
tagName, accessType, credential, credentialType));
456 insertInTable(m_schema,
tname, dataToInsert.
get());
461 int credentialType) {
482 throwException(
"Payload table already exists in this schema.",
"PAYLOAD::Schema::create");
487 createTable(m_schema, descr.
get());
492 q.addCondition<
HASH>(payloadHash);
496 return q.retrievedRows();
501 q.addCondition<
HASH>(payloadHash);
503 objectType = std::get<0>(row);
506 return q.retrievedRows();
514 q.addCondition<
HASH>(payloadHash);
515 for (
const auto& row :
q) {
516 std::tie(payloadData, streamerInfoData, objectType) = row;
518 return q.retrievedRows();
525 const boost::posix_time::ptime& insertionTime) {
528 if (!sinfoData.
size())
531 std::tie(payloadHash, objectType, payloadData, sinfoData,
version, insertionTime));
532 bool failOnDuplicate =
false;
533 return insertInTable(m_schema,
tname, dataToInsert.
get(), failOnDuplicate);
539 const boost::posix_time::ptime& insertionTime) {
542 if (!
select(payloadHash)) {
543 insert(payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime);
549 : m_tagTable(schema),
551 m_tagLogTable(schema),
552 m_tagAccessPermissionTable(schema),
553 m_payloadTable(schema) {}
566 bool created =
false;
586 throwException(
"Tag in this schema are not protectable.",
"IOVSchema::tagAccessPermissionTable");
Table(coral::ISchema &schema)
bool insert(const cond::Hash &payloadHash, const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
void updateMetadata(const std::string &name, const std::string &description, const boost::posix_time::ptime &updateTime) override
void eraseMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
void erase(const std::string &tag) override
void eraseOne(const std::string &tag, cond::Time_t since, cond::Hash payloadId) override
static constexpr char const * name
Table(coral::ISchema &schema)
void setAccessPermission(const std::string &tagName, const std::string &credential, int credentialType, int accessType) override
void update(const std::string &name, cond::SynchronizationType synchronizationType, cond::Time_t &endOfValidity, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime) override
PAYLOAD::Table m_payloadTable
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
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
TAG_LOG::Table m_tagLogTable
ITagLogTable & tagLogTable() override
cond::Hash makeHash(const std::string &objectType, const cond::Binary &data)
void copy(const std::string &source)
ITagAccessPermissionTable & tagAccessPermissionTable() override
static constexpr char const * tname
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
Table(coral::ISchema &schema)
const coral::TableDescription & get()
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime) override
static constexpr char const * tname
void setProtectionCode(const std::string &name, int code) override
IPayloadTable & payloadTable() override
bool select(const std::string &name) override
static constexpr char const * tname
static std::string group(unsigned long long groupSize)
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs) override
bool getLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash) override
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime) override
static constexpr char const * tname
void insert(const P ¶ms)
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime) override
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime) override
bool getSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size) override
coral::ISchema & m_schema
unsigned long long Time_t
Table(coral::ISchema &schema)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
size_t getGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, unsigned long long groupSize, std::vector< cond::Time_t > &groups) override
bool getAccessPermission(const std::string &tagName, const std::string &credential, int credentialType, int accessType) override
IOVSchema(coral::ISchema &schema)
bool select(const cond::Hash &payloadHash)
const coral::AttributeList & get() const
static constexpr size_t size
IIOVTable & iovTable() override
void removeEntriesForCredential(const std::string &credential, int credentialType) override
void unsetProtectionCode(const std::string &name, int code) override
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
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
void removeAccessPermission(const std::string &tagName, const std::string &credential, int credentialType) override
void throwException(const std::string &message, const std::string &methodName)
char data[epos_bytes_allocation]
ITagTable & tagTable() override
static constexpr char const * tname
TAG_AUTHORIZATION::Table m_tagAccessPermissionTable
void setForeignKey(const std::string &name)
bool getType(const cond::Hash &payloadHash, std::string &objectType) override
static constexpr int COND_DBTAG_NO_PROTECTION_CODE
Table(coral::ISchema &schema)