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++) {
30 ::sprintf(&tmp[
i * 2],
"%02x", hash[i]);
39 int ncols =
m_schema.tableHandle(
tname).description().numberOfColumns();
40 for (
int i = 0;
i < ncols;
i++)
41 columns.insert(
m_schema.tableHandle(
tname).description().columnDescription(
i).name());
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));
175 updateTable(m_schema,
tname, buffer);
180 const boost::posix_time::ptime& updateTime) {
184 updateTable(m_schema,
tname, buffer);
189 const boost::posix_time::ptime& updateTime) {
193 updateTable(m_schema,
tname, buffer);
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;
209 updateTable(m_schema,
tname, buffer);
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);
224 buffer.addWhereCondition<
NAME>(
name);
225 updateTable(m_schema,
tname, buffer);
234 throwException(
"IOV table already exists in this schema.",
"IOV::Schema::create");
241 createTable(m_schema, descr.
get());
245 const boost::posix_time::ptime& snapshotTime,
246 unsigned long long gSize,
247 std::vector<cond::Time_t>& groups) {
250 if (!snapshotTime.is_not_a_date_time()) {
256 groups.push_back(std::get<0>(row));
258 return q.retrievedRows();
264 const boost::posix_time::ptime& snapshotTime,
268 if (lowerSinceGroup > 0)
272 if (!snapshotTime.is_not_a_date_time()) {
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;
288 const boost::posix_time::ptime& snapshotTime,
293 if (!snapshotTime.is_not_a_date_time()) {
300 since = std::get<0>(row);
301 hash = std::get<1>(row);
310 if (!snapshotTime.is_not_a_date_time()) {
314 size = std::get<0>(row);
323 const boost::posix_time::ptime& snapshotTime,
328 if (!snapshotTime.is_not_a_date_time()) {
332 for (
auto row : q0) {
333 lower_since = std::get<0>(row);
340 if (!snapshotTime.is_not_a_date_time()) {
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));
379 deleteFromTable(m_schema,
tname, buffer);
384 for (
auto iov :
iovs)
385 deleter.
erase(std::tuple_cat(std::tie(tag), iov));
392 deleteFromTable(m_schema,
tname, buffer);
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,
417 std::tie(tag, eventTime, userName, hostName, command, action, userText));
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) {
466 deleteFromTable(m_schema,
tname, buffer);
473 deleteFromTable(m_schema,
tname, buffer);
482 throwException(
"Payload table already exists in this schema.",
"PAYLOAD::Schema::create");
487 createTable(m_schema, descr.
get());
496 return q.retrievedRows();
503 objectType = std::get<0>(row);
506 return q.retrievedRows();
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");
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
Query & groupBy(const std::string &expression)
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime) override
const coral::AttributeList & get() const
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
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)
const void * data() const
TAG_LOG::Table m_tagLogTable
void setColumnData(const Params ¶ms)
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]
void erase(const P ¶ms)
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
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
void addWhereCondition(const P ¶m, const std::string condition="=")
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
ITagTable & tagTable() override
tuple size
Write out results.
void throwException(const std::string &message, const std::string &methodName)
Query & limitReturnedRows(size_t nrows)
void eraseMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
void addWhereCondition(const P ¶m, const std::string condition="=")