Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-04 02:52:39

0001 #include "CondCore/CondDB/interface/Exception.h"
0002 #include "CondCore/CondDB/interface/Auth.h"
0003 #include "Utilities/OpenSSL/interface/openssl_init.h"
0004 #include "IOVSchema.h"
0005 
0006 namespace cond {
0007 
0008   namespace persistency {
0009 
0010     cond::Hash makeHash(const std::string& objectType, const cond::Binary& data) {
0011       cms::openssl_init();
0012       EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
0013       const EVP_MD* md = EVP_get_digestbyname("SHA1");
0014       if (!EVP_DigestInit_ex(mdctx, md, nullptr)) {
0015         throwException("SHA1 initialization error.", "IOVSchema::makeHash");
0016       }
0017       if (!EVP_DigestUpdate(mdctx, objectType.c_str(), objectType.size())) {
0018         throwException("SHA1 processing error (1).", "IOVSchema::makeHash");
0019       }
0020       if (!EVP_DigestUpdate(mdctx, data.data(), data.size())) {
0021         throwException("SHA1 processing error (2).", "IOVSchema::makeHash");
0022       }
0023       unsigned char hash[EVP_MAX_MD_SIZE];
0024       unsigned int md_len = 0;
0025       if (!EVP_DigestFinal_ex(mdctx, hash, &md_len)) {
0026         throwException("SHA1 finalization error.", "IOVSchema::makeHash");
0027       }
0028       EVP_MD_CTX_free(mdctx);
0029       char tmp[EVP_MAX_MD_SIZE * 2 + 1];
0030       // re-write bytes in hex
0031       if (md_len > 20) {
0032         md_len = 20;
0033       }
0034       for (unsigned int i = 0; i < md_len; i++) {
0035         ::sprintf(&tmp[i * 2], "%02x", hash[i]);
0036       }
0037       tmp[md_len * 2] = 0;
0038       return tmp;
0039     }
0040 
0041     TAG::Table::Table(coral::ISchema& schema) : m_schema(schema) {
0042       if (exists()) {
0043         std::set<std::string> columns;
0044         int ncols = m_schema.tableHandle(tname).description().numberOfColumns();
0045         for (int i = 0; i < ncols; i++)
0046           columns.insert(m_schema.tableHandle(tname).description().columnDescription(i).name());
0047         m_isProtectable = columns.count(PROTECTION_CODE::name);
0048       }
0049     }
0050 
0051     bool TAG::Table::Table::exists() { return existsTable(m_schema, tname); }
0052 
0053     void TAG::Table::create() {
0054       if (exists()) {
0055         throwException("TAG table already exists in this schema.", "TAG::Table::create");
0056       }
0057       TableDescription<NAME,
0058                        TIME_TYPE,
0059                        OBJECT_TYPE,
0060                        SYNCHRONIZATION,
0061                        END_OF_VALIDITY,
0062                        DESCRIPTION,
0063                        LAST_VALIDATED_TIME,
0064                        INSERTION_TIME,
0065                        MODIFICATION_TIME,
0066                        PROTECTION_CODE>
0067           descr(tname);
0068       descr.setPrimaryKey<NAME>();
0069       createTable(m_schema, descr.get());
0070       m_isProtectable = true;
0071     }
0072 
0073     bool TAG::Table::select(const std::string& name) {
0074       Query<NAME> q(m_schema);
0075       q.addCondition<NAME>(name);
0076       for (auto row : q) {
0077       }
0078 
0079       return q.retrievedRows();
0080     }
0081 
0082     bool TAG::Table::select(const std::string& name,
0083                             cond::TimeType& timeType,
0084                             std::string& objectType,
0085                             cond::SynchronizationType& synchronizationType,
0086                             cond::Time_t& endOfValidity,
0087                             cond::Time_t& lastValidatedTime,
0088                             int& protectionCode) {
0089       if (isProtectable()) {
0090         Query<TIME_TYPE, OBJECT_TYPE, SYNCHRONIZATION, END_OF_VALIDITY, LAST_VALIDATED_TIME, PROTECTION_CODE> q(
0091             m_schema);
0092         q.addCondition<NAME>(name);
0093         for (const auto& row : q)
0094           std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime, protectionCode) = row;
0095         return q.retrievedRows();
0096       } else {
0097         Query<TIME_TYPE, OBJECT_TYPE, SYNCHRONIZATION, END_OF_VALIDITY, LAST_VALIDATED_TIME> q(m_schema);
0098         q.addCondition<NAME>(name);
0099         for (const auto& row : q)
0100           std::tie(timeType, objectType, synchronizationType, endOfValidity, lastValidatedTime) = row;
0101         protectionCode = 0;
0102 
0103         return q.retrievedRows();
0104       }
0105     }
0106 
0107     bool TAG::Table::getMetadata(const std::string& name,
0108                                  std::string& description,
0109                                  boost::posix_time::ptime& insertionTime,
0110                                  boost::posix_time::ptime& modificationTime) {
0111       Query<DESCRIPTION, INSERTION_TIME, MODIFICATION_TIME> q(m_schema);
0112       q.addCondition<NAME>(name);
0113       for (const auto& row : q)
0114         std::tie(description, insertionTime, modificationTime) = row;
0115       return q.retrievedRows();
0116     }
0117 
0118     void TAG::Table::insert(const std::string& name,
0119                             cond::TimeType timeType,
0120                             const std::string& objectType,
0121                             cond::SynchronizationType synchronizationType,
0122                             cond::Time_t endOfValidity,
0123                             const std::string& description,
0124                             cond::Time_t lastValidatedTime,
0125                             const boost::posix_time::ptime& insertionTime) {
0126       if (isProtectable()) {
0127         RowBuffer<NAME,
0128                   TIME_TYPE,
0129                   OBJECT_TYPE,
0130                   SYNCHRONIZATION,
0131                   END_OF_VALIDITY,
0132                   DESCRIPTION,
0133                   LAST_VALIDATED_TIME,
0134                   INSERTION_TIME,
0135                   MODIFICATION_TIME,
0136                   PROTECTION_CODE>
0137             dataToInsert(std::tie(name,
0138                                   timeType,
0139                                   objectType,
0140                                   synchronizationType,
0141                                   endOfValidity,
0142                                   description,
0143                                   lastValidatedTime,
0144                                   insertionTime,
0145                                   insertionTime,
0146                                   cond::auth::COND_DBTAG_NO_PROTECTION_CODE));
0147         insertInTable(m_schema, tname, dataToInsert.get());
0148       } else {
0149         RowBuffer<NAME,
0150                   TIME_TYPE,
0151                   OBJECT_TYPE,
0152                   SYNCHRONIZATION,
0153                   END_OF_VALIDITY,
0154                   DESCRIPTION,
0155                   LAST_VALIDATED_TIME,
0156                   INSERTION_TIME,
0157                   MODIFICATION_TIME>
0158             dataToInsert(std::tie(name,
0159                                   timeType,
0160                                   objectType,
0161                                   synchronizationType,
0162                                   endOfValidity,
0163                                   description,
0164                                   lastValidatedTime,
0165                                   insertionTime,
0166                                   insertionTime));
0167         insertInTable(m_schema, tname, dataToInsert.get());
0168       }
0169     }
0170 
0171     void TAG::Table::update(const std::string& name,
0172                             cond::SynchronizationType synchronizationType,
0173                             cond::Time_t& endOfValidity,
0174                             cond::Time_t lastValidatedTime,
0175                             const boost::posix_time::ptime& updateTime) {
0176       UpdateBuffer buffer;
0177       buffer.setColumnData<SYNCHRONIZATION, END_OF_VALIDITY, LAST_VALIDATED_TIME, MODIFICATION_TIME>(
0178           std::tie(synchronizationType, endOfValidity, lastValidatedTime, updateTime));
0179       buffer.addWhereCondition<NAME>(name);
0180       updateTable(m_schema, tname, buffer);
0181     }
0182 
0183     void TAG::Table::updateMetadata(const std::string& name,
0184                                     const std::string& description,
0185                                     const boost::posix_time::ptime& updateTime) {
0186       UpdateBuffer buffer;
0187       buffer.setColumnData<DESCRIPTION, MODIFICATION_TIME>(std::tie(description, updateTime));
0188       buffer.addWhereCondition<NAME>(name);
0189       updateTable(m_schema, tname, buffer);
0190     }
0191 
0192     void TAG::Table::updateValidity(const std::string& name,
0193                                     cond::Time_t lastValidatedTime,
0194                                     const boost::posix_time::ptime& updateTime) {
0195       UpdateBuffer buffer;
0196       buffer.setColumnData<LAST_VALIDATED_TIME, MODIFICATION_TIME>(std::tie(lastValidatedTime, updateTime));
0197       buffer.addWhereCondition<NAME>(name);
0198       updateTable(m_schema, tname, buffer);
0199     }
0200 
0201     void TAG::Table::setProtectionCode(const std::string& name, int code) {
0202       if (!isProtectable()) {
0203         throwException("Tag in this schema are not protectable.", "TAG::Table::create");
0204       }
0205       Query<PROTECTION_CODE> q(m_schema);
0206       q.addCondition<NAME>(name);
0207       int newCode = 0;
0208       for (const auto& row : q)
0209         std::tie(newCode) = row;
0210       newCode |= code;
0211       UpdateBuffer buffer;
0212       buffer.setColumnData<PROTECTION_CODE>(std::tie(newCode));
0213       buffer.addWhereCondition<NAME>(name);
0214       updateTable(m_schema, tname, buffer);
0215     }
0216 
0217     void TAG::Table::unsetProtectionCode(const std::string& name, int code) {
0218       if (!isProtectable()) {
0219         throwException("Tag in this schema are not protectable.", "TAG::Table::unsetProtectionCode");
0220       }
0221       Query<PROTECTION_CODE> q(m_schema);
0222       q.addCondition<NAME>(name);
0223       int presentCode = 0;
0224       for (const auto& row : q)
0225         std::tie(presentCode) = row;
0226       int newCode = presentCode & (~code);
0227       UpdateBuffer buffer;
0228       buffer.setColumnData<PROTECTION_CODE>(std::tie(newCode));
0229       buffer.addWhereCondition<NAME>(name);
0230       updateTable(m_schema, tname, buffer);
0231     }
0232 
0233     IOV::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0234 
0235     bool IOV::Table::exists() { return existsTable(m_schema, tname); }
0236 
0237     void IOV::Table::create() {
0238       if (exists()) {
0239         throwException("IOV table already exists in this schema.", "IOV::Schema::create");
0240       }
0241 
0242       TableDescription<TAG_NAME, SINCE, PAYLOAD_HASH, INSERTION_TIME> descr(tname);
0243       descr.setPrimaryKey<TAG_NAME, SINCE, INSERTION_TIME>();
0244       descr.setForeignKey<TAG_NAME, TAG::NAME>("TAG_NAME_FK");
0245       descr.setForeignKey<PAYLOAD_HASH, PAYLOAD::HASH>("PAYLOAD_HASH_FK");
0246       createTable(m_schema, descr.get());
0247     }
0248 
0249     size_t IOV::Table::getGroups(const std::string& tag,
0250                                  const boost::posix_time::ptime& snapshotTime,
0251                                  unsigned long long gSize,
0252                                  std::vector<cond::Time_t>& groups) {
0253       Query<SINCE_GROUP> q(m_schema, true);
0254       q.addCondition<TAG_NAME>(tag);
0255       if (!snapshotTime.is_not_a_date_time()) {
0256         q.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0257       }
0258       q.groupBy(SINCE_GROUP::group(gSize));
0259       q.addOrderClause<SINCE_GROUP>();
0260       for (auto row : q) {
0261         groups.push_back(std::get<0>(row));
0262       }
0263       return q.retrievedRows();
0264     }
0265 
0266     size_t IOV::Table::select(const std::string& tag,
0267                               cond::Time_t lowerSinceGroup,
0268                               cond::Time_t upperSinceGroup,
0269                               const boost::posix_time::ptime& snapshotTime,
0270                               std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
0271       Query<SINCE, PAYLOAD_HASH> q(m_schema);
0272       q.addCondition<TAG_NAME>(tag);
0273       if (lowerSinceGroup > 0)
0274         q.addCondition<SINCE>(lowerSinceGroup, ">=");
0275       if (upperSinceGroup < cond::time::MAX_VAL)
0276         q.addCondition<SINCE>(upperSinceGroup, "<");
0277       if (!snapshotTime.is_not_a_date_time()) {
0278         q.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0279       }
0280       q.addOrderClause<SINCE>();
0281       q.addOrderClause<INSERTION_TIME>(false);
0282       size_t initialSize = iovs.size();
0283       for (auto row : q) {
0284         // starting from the second iov in the array, skip the rows with older timestamp
0285         if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
0286           continue;
0287         iovs.push_back(row);
0288       }
0289       return iovs.size() - initialSize;
0290     }
0291 
0292     bool IOV::Table::getLastIov(const std::string& tag,
0293                                 const boost::posix_time::ptime& snapshotTime,
0294                                 cond::Time_t& since,
0295                                 cond::Hash& hash) {
0296       Query<SINCE, PAYLOAD_HASH> q(m_schema);
0297       q.addCondition<TAG_NAME>(tag);
0298       if (!snapshotTime.is_not_a_date_time()) {
0299         q.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0300       }
0301       q.addOrderClause<SINCE>(false);
0302       q.addOrderClause<INSERTION_TIME>(false);
0303       q.limitReturnedRows(1);
0304       for (auto row : q) {
0305         since = std::get<0>(row);
0306         hash = std::get<1>(row);
0307         return true;
0308       }
0309       return false;
0310     }
0311 
0312     bool IOV::Table::getSize(const std::string& tag, const boost::posix_time::ptime& snapshotTime, size_t& size) {
0313       Query<SEQUENCE_SIZE> q(m_schema);
0314       q.addCondition<TAG_NAME>(tag);
0315       if (!snapshotTime.is_not_a_date_time()) {
0316         q.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0317       }
0318       for (auto row : q) {
0319         size = std::get<0>(row);
0320         return true;
0321       }
0322       return false;
0323     }
0324 
0325     bool IOV::Table::getRange(const std::string& tag,
0326                               cond::Time_t begin,
0327                               cond::Time_t end,
0328                               const boost::posix_time::ptime& snapshotTime,
0329                               std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
0330       Query<MAX_SINCE> q0(m_schema);
0331       q0.addCondition<TAG_NAME>(tag);
0332       q0.addCondition<SINCE>(begin, "<=");
0333       if (!snapshotTime.is_not_a_date_time()) {
0334         q0.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0335       }
0336       cond::Time_t lower_since = 0;
0337       for (auto row : q0) {
0338         lower_since = std::get<0>(row);
0339       }
0340       if (!lower_since)
0341         return false;
0342       Query<SINCE, PAYLOAD_HASH> q1(m_schema);
0343       q1.addCondition<TAG_NAME>(tag);
0344       q1.addCondition<SINCE>(lower_since, ">=");
0345       if (!snapshotTime.is_not_a_date_time()) {
0346         q1.addCondition<INSERTION_TIME>(snapshotTime, "<=");
0347       }
0348       q1.addCondition<SINCE>(end, "<=");
0349       q1.addOrderClause<SINCE>();
0350       q1.addOrderClause<INSERTION_TIME>(false);
0351       size_t initialSize = iovs.size();
0352       for (auto row : q1) {
0353         // starting from the second iov in the array, skip the rows with older timestamp
0354         if (iovs.size() - initialSize && std::get<0>(iovs.back()) == std::get<0>(row))
0355           continue;
0356         iovs.push_back(row);
0357       }
0358       return iovs.size() - initialSize;
0359     }
0360 
0361     void IOV::Table::insertOne(const std::string& tag,
0362                                cond::Time_t since,
0363                                cond::Hash payloadHash,
0364                                const boost::posix_time::ptime& insertTimeStamp) {
0365       RowBuffer<TAG_NAME, SINCE, PAYLOAD_HASH, INSERTION_TIME> dataToInsert(
0366           std::tie(tag, since, payloadHash, insertTimeStamp));
0367       insertInTable(m_schema, tname, dataToInsert.get());
0368     }
0369 
0370     void IOV::Table::insertMany(
0371         const std::string& tag,
0372         const std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> >& iovs) {
0373       BulkInserter<TAG_NAME, SINCE, PAYLOAD_HASH, INSERTION_TIME> inserter(m_schema, tname);
0374       for (auto row : iovs)
0375         inserter.insert(std::tuple_cat(std::tie(tag), row));
0376       inserter.flush();
0377     }
0378 
0379     void IOV::Table::eraseOne(const std::string& tag, cond::Time_t since, cond::Hash payloadId) {
0380       DeleteBuffer buffer;
0381       buffer.addWhereCondition<TAG_NAME>(tag);
0382       buffer.addWhereCondition<SINCE>(since);
0383       buffer.addWhereCondition<PAYLOAD_HASH>(payloadId);
0384       deleteFromTable(m_schema, tname, buffer);
0385     }
0386 
0387     void IOV::Table::eraseMany(const std::string& tag, const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) {
0388       BulkDeleter<TAG_NAME, SINCE, PAYLOAD_HASH> deleter(m_schema, tname);
0389       for (auto iov : iovs)
0390         deleter.erase(std::tuple_cat(std::tie(tag), iov));
0391       deleter.flush();
0392     }
0393 
0394     void IOV::Table::erase(const std::string& tag) {
0395       DeleteBuffer buffer;
0396       buffer.addWhereCondition<TAG_NAME>(tag);
0397       deleteFromTable(m_schema, tname, buffer);
0398     }
0399 
0400     TAG_LOG::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0401 
0402     bool TAG_LOG::Table::exists() { return existsTable(m_schema, tname); }
0403 
0404     void TAG_LOG::Table::create() {
0405       if (exists()) {
0406         throwException("TAG_LOG table already exists in this schema.", "TAG_LOG::create");
0407       }
0408       TableDescription<TAG_NAME, EVENT_TIME, USER_NAME, HOST_NAME, COMMAND, ACTION, USER_TEXT> descr(tname);
0409       descr.setPrimaryKey<TAG_NAME, EVENT_TIME, ACTION>();
0410       descr.setForeignKey<TAG_NAME, TAG::NAME>("TAG_NAME_FK");
0411       createTable(m_schema, descr.get());
0412     }
0413 
0414     void TAG_LOG::Table::insert(const std::string& tag,
0415                                 const boost::posix_time::ptime& eventTime,
0416                                 const std::string& userName,
0417                                 const std::string& hostName,
0418                                 const std::string& command,
0419                                 const std::string& action,
0420                                 const std::string& userText) {
0421       RowBuffer<TAG_NAME, EVENT_TIME, USER_NAME, HOST_NAME, COMMAND, ACTION, USER_TEXT> dataToInsert(
0422           std::tie(tag, eventTime, userName, hostName, command, action, userText));
0423       insertInTable(m_schema, tname, dataToInsert.get());
0424     }
0425 
0426     TAG_AUTHORIZATION::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0427 
0428     bool TAG_AUTHORIZATION::Table::exists() { return existsTable(m_schema, tname); }
0429 
0430     void TAG_AUTHORIZATION::Table::create() {
0431       if (exists()) {
0432         throwException("TAG_AUTHORIZATION table already exists in this schema.", "TAG_AUTHORIZATION::create");
0433       }
0434       TableDescription<TAG_NAME, ACCESS_TYPE, CREDENTIAL, CREDENTIAL_TYPE> descr(tname);
0435       descr.setPrimaryKey<TAG_NAME, CREDENTIAL, CREDENTIAL_TYPE>();
0436       descr.setForeignKey<TAG_NAME, TAG::NAME>("TAG_NAME_FK");
0437       createTable(m_schema, descr.get());
0438     }
0439 
0440     bool TAG_AUTHORIZATION::Table::getAccessPermission(const std::string& tagName,
0441                                                        const std::string& credential,
0442                                                        int credentialType,
0443                                                        int accessType) {
0444       Query<ACCESS_TYPE> q(m_schema);
0445       q.addCondition<TAG_NAME>(tagName);
0446       q.addCondition<CREDENTIAL>(credential);
0447       q.addCondition<CREDENTIAL_TYPE>(credentialType);
0448       int allowedAccess = 0;
0449       for (auto row : q) {
0450         allowedAccess = std::get<0>(row);
0451       }
0452       return allowedAccess & accessType;
0453     }
0454 
0455     void TAG_AUTHORIZATION::Table::setAccessPermission(const std::string& tagName,
0456                                                        const std::string& credential,
0457                                                        int credentialType,
0458                                                        int accessType) {
0459       RowBuffer<TAG_NAME, ACCESS_TYPE, CREDENTIAL, CREDENTIAL_TYPE> dataToInsert(
0460           std::tie(tagName, accessType, credential, credentialType));
0461       insertInTable(m_schema, tname, dataToInsert.get());
0462     }
0463 
0464     void TAG_AUTHORIZATION::Table::removeAccessPermission(const std::string& tagName,
0465                                                           const std::string& credential,
0466                                                           int credentialType) {
0467       DeleteBuffer buffer;
0468       buffer.addWhereCondition<TAG_NAME>(tagName);
0469       buffer.addWhereCondition<CREDENTIAL>(credential);
0470       buffer.addWhereCondition<CREDENTIAL_TYPE>(credentialType);
0471       deleteFromTable(m_schema, tname, buffer);
0472     }
0473 
0474     void TAG_AUTHORIZATION::Table::removeEntriesForCredential(const std::string& credential, int credentialType) {
0475       DeleteBuffer buffer;
0476       buffer.addWhereCondition<CREDENTIAL>(credential);
0477       buffer.addWhereCondition<CREDENTIAL_TYPE>(credentialType);
0478       deleteFromTable(m_schema, tname, buffer);
0479     }
0480 
0481     PAYLOAD::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0482 
0483     bool PAYLOAD::Table::exists() { return existsTable(m_schema, tname); }
0484 
0485     void PAYLOAD::Table::create() {
0486       if (exists()) {
0487         throwException("Payload table already exists in this schema.", "PAYLOAD::Schema::create");
0488       }
0489 
0490       TableDescription<HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME> descr(tname);
0491       descr.setPrimaryKey<HASH>();
0492       createTable(m_schema, descr.get());
0493     }
0494 
0495     bool PAYLOAD::Table::select(const cond::Hash& payloadHash) {
0496       Query<HASH> q(m_schema);
0497       q.addCondition<HASH>(payloadHash);
0498       for (auto row : q) {
0499       }
0500 
0501       return q.retrievedRows();
0502     }
0503 
0504     bool PAYLOAD::Table::getType(const cond::Hash& payloadHash, std::string& objectType) {
0505       Query<OBJECT_TYPE> q(m_schema);
0506       q.addCondition<HASH>(payloadHash);
0507       for (auto row : q) {
0508         objectType = std::get<0>(row);
0509       }
0510 
0511       return q.retrievedRows();
0512     }
0513 
0514     bool PAYLOAD::Table::select(const cond::Hash& payloadHash,
0515                                 std::string& objectType,
0516                                 cond::Binary& payloadData,
0517                                 cond::Binary& streamerInfoData) {
0518       Query<DATA, STREAMER_INFO, OBJECT_TYPE> q(m_schema);
0519       q.addCondition<HASH>(payloadHash);
0520       for (const auto& row : q) {
0521         std::tie(payloadData, streamerInfoData, objectType) = row;
0522       }
0523       return q.retrievedRows();
0524     }
0525 
0526     bool PAYLOAD::Table::insert(const cond::Hash& payloadHash,
0527                                 const std::string& objectType,
0528                                 const cond::Binary& payloadData,
0529                                 const cond::Binary& streamerInfoData,
0530                                 const boost::posix_time::ptime& insertionTime) {
0531       std::string version("dummy");
0532       cond::Binary sinfoData(streamerInfoData);
0533       if (!sinfoData.size())
0534         sinfoData.copy(std::string("0"));
0535       RowBuffer<HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME> dataToInsert(
0536           std::tie(payloadHash, objectType, payloadData, sinfoData, version, insertionTime));
0537       bool failOnDuplicate = false;
0538       return insertInTable(m_schema, tname, dataToInsert.get(), failOnDuplicate);
0539     }
0540 
0541     cond::Hash PAYLOAD::Table::insertIfNew(const std::string& payloadObjectType,
0542                                            const cond::Binary& payloadData,
0543                                            const cond::Binary& streamerInfoData,
0544                                            const boost::posix_time::ptime& insertionTime) {
0545       cond::Hash payloadHash = makeHash(payloadObjectType, payloadData);
0546       // the check on the hash existance is only required to avoid the error message printing in SQLite! once this is removed, this check is useless...
0547       if (!select(payloadHash)) {
0548         insert(payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime);
0549       }
0550       return payloadHash;
0551     }
0552 
0553     IOVSchema::IOVSchema(coral::ISchema& schema)
0554         : m_tagTable(schema),
0555           m_iovTable(schema),
0556           m_tagLogTable(schema),
0557           m_tagAccessPermissionTable(schema),
0558           m_payloadTable(schema) {}
0559 
0560     bool IOVSchema::exists() {
0561       if (!m_tagTable.exists())
0562         return false;
0563       if (!m_payloadTable.exists())
0564         return false;
0565       if (!m_iovTable.exists())
0566         return false;
0567       return true;
0568     }
0569 
0570     bool IOVSchema::create() {
0571       bool created = false;
0572       if (!exists()) {
0573         m_tagTable.create();
0574         m_payloadTable.create();
0575         m_iovTable.create();
0576         m_tagLogTable.create();
0577         m_tagAccessPermissionTable.create();
0578         created = true;
0579       }
0580       return created;
0581     }
0582 
0583     ITagTable& IOVSchema::tagTable() { return m_tagTable; }
0584 
0585     IIOVTable& IOVSchema::iovTable() { return m_iovTable; }
0586 
0587     ITagLogTable& IOVSchema::tagLogTable() { return m_tagLogTable; }
0588 
0589     ITagAccessPermissionTable& IOVSchema::tagAccessPermissionTable() {
0590       if (!m_tagTable.isProtectable()) {
0591         throwException("Tag in this schema are not protectable.", "IOVSchema::tagAccessPermissionTable");
0592       }
0593       return m_tagAccessPermissionTable;
0594     }
0595 
0596     IPayloadTable& IOVSchema::payloadTable() { return m_payloadTable; }
0597 
0598   }  // namespace persistency
0599 }  // namespace cond