File indexing completed on 2024-04-06 12:01:27
0001 #include "CondCore/CondDB/interface/Exception.h"
0002 #include "GTSchema.h"
0003
0004 namespace cond {
0005
0006 namespace persistency {
0007
0008 GLOBAL_TAG::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0009
0010 bool GLOBAL_TAG::Table::exists() { return existsTable(m_schema, tname); }
0011
0012 void GLOBAL_TAG::Table::create() {
0013 if (exists()) {
0014 throwException("GLOBAL_TAG table already exists in this schema.", "GLOBAL_TAG::Table::create");
0015 }
0016 TableDescription<NAME, VALIDITY, DESCRIPTION, RELEASE, SNAPSHOT_TIME, INSERTION_TIME> descr(tname);
0017 descr.setPrimaryKey<NAME>();
0018 createTable(m_schema, descr.get());
0019 }
0020
0021 bool GLOBAL_TAG::Table::select(const std::string& name) {
0022 Query<NAME> q(m_schema);
0023 q.addCondition<NAME>(name);
0024 for (auto row : q) {
0025 }
0026
0027 return q.retrievedRows();
0028 }
0029
0030 bool GLOBAL_TAG::Table::select(const std::string& name,
0031 cond::Time_t& validity,
0032 boost::posix_time::ptime& snapshotTime) {
0033 Query<VALIDITY, SNAPSHOT_TIME> q(m_schema);
0034 q.addCondition<NAME>(name);
0035 for (auto row : q)
0036 std::tie(validity, snapshotTime) = row;
0037
0038 return q.retrievedRows();
0039 }
0040
0041 bool GLOBAL_TAG::Table::select(const std::string& name,
0042 cond::Time_t& validity,
0043 std::string& description,
0044 std::string& release,
0045 boost::posix_time::ptime& snapshotTime) {
0046 Query<VALIDITY, DESCRIPTION, RELEASE, SNAPSHOT_TIME> q(m_schema);
0047 q.addCondition<NAME>(name);
0048 for (const auto& row : q)
0049 std::tie(validity, description, release, snapshotTime) = row;
0050
0051 return q.retrievedRows();
0052 }
0053
0054 void GLOBAL_TAG::Table::insert(const std::string& name,
0055 cond::Time_t validity,
0056 const std::string& description,
0057 const std::string& release,
0058 const boost::posix_time::ptime& snapshotTime,
0059 const boost::posix_time::ptime& insertionTime) {
0060 RowBuffer<NAME, VALIDITY, DESCRIPTION, RELEASE, SNAPSHOT_TIME, INSERTION_TIME> dataToInsert(
0061 std::tie(name, validity, description, release, snapshotTime, insertionTime));
0062 insertInTable(m_schema, tname, dataToInsert.get());
0063 }
0064
0065 void GLOBAL_TAG::Table::update(const std::string& name,
0066 cond::Time_t validity,
0067 const std::string& description,
0068 const std::string& release,
0069 const boost::posix_time::ptime& snapshotTime,
0070 const boost::posix_time::ptime& insertionTime) {
0071 UpdateBuffer buffer;
0072 buffer.setColumnData<VALIDITY, DESCRIPTION, RELEASE, SNAPSHOT_TIME, INSERTION_TIME>(
0073 std::tie(validity, description, release, snapshotTime, insertionTime));
0074 buffer.addWhereCondition<NAME>(name);
0075 updateTable(m_schema, tname, buffer);
0076 }
0077
0078 GLOBAL_TAG_MAP::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
0079
0080 bool GLOBAL_TAG_MAP::Table::exists() { return existsTable(m_schema, tname); }
0081
0082 void GLOBAL_TAG_MAP::Table::create() {
0083 if (exists()) {
0084 throwException("GLOBAL_TAG_MAP table already exists in this schema.", "GLOBAL_TAG_MAP::Table::create");
0085 }
0086 TableDescription<GLOBAL_TAG_NAME, RECORD, LABEL, TAG_NAME> descr(tname);
0087 descr.setPrimaryKey<GLOBAL_TAG_NAME, RECORD, LABEL>();
0088 createTable(m_schema, descr.get());
0089 }
0090
0091 bool GLOBAL_TAG_MAP::Table::select(const std::string& gtName,
0092 std::vector<std::tuple<std::string, std::string, std::string> >& tags) {
0093 Query<RECORD, LABEL, TAG_NAME> q(m_schema);
0094 q.addCondition<GLOBAL_TAG_NAME>(gtName);
0095 q.addOrderClause<RECORD>();
0096 q.addOrderClause<LABEL>();
0097 for (auto row : q) {
0098 if (std::get<1>(row) == "-") {
0099 std::get<1>(row) = "";
0100 }
0101 tags.push_back(row);
0102 }
0103 return q.retrievedRows();
0104 }
0105
0106 bool GLOBAL_TAG_MAP::Table::select(const std::string& gtName,
0107 const std::string&,
0108 const std::string&,
0109 std::vector<std::tuple<std::string, std::string, std::string> >& tags) {
0110 return select(gtName, tags);
0111 }
0112
0113 void GLOBAL_TAG_MAP::Table::insert(const std::string& gtName,
0114 const std::vector<std::tuple<std::string, std::string, std::string> >& tags) {
0115 BulkInserter<GLOBAL_TAG_NAME, RECORD, LABEL, TAG_NAME> inserter(m_schema, tname);
0116 for (auto row : tags)
0117 inserter.insert(std::tuple_cat(std::tie(gtName), row));
0118 inserter.flush();
0119 }
0120
0121 GTSchema::GTSchema(coral::ISchema& schema) : m_gtTable(schema), m_gtMapTable(schema) {}
0122
0123 bool GTSchema::exists() {
0124 if (!m_gtTable.exists())
0125 return false;
0126 if (!m_gtMapTable.exists())
0127 return false;
0128 return true;
0129 }
0130
0131 void GTSchema::create() {
0132 m_gtTable.create();
0133 m_gtMapTable.create();
0134 }
0135
0136 GLOBAL_TAG::Table& GTSchema::gtTable() { return m_gtTable; }
0137
0138 GLOBAL_TAG_MAP::Table& GTSchema::gtMapTable() { return m_gtMapTable; }
0139
0140 }
0141 }