4 #include <openssl/sha.h> 8 namespace persistency {
12 if( !SHA1_Init( &ctx ) ){
13 throwException(
"SHA1 initialization error.",
"IOVSchema::makeHash");
15 if( !SHA1_Update( &ctx, objectType.c_str(), objectType.size() ) ){
16 throwException(
"SHA1 processing error (1).",
"IOVSchema::makeHash");
18 if( !SHA1_Update( &ctx, data.
data(), data.
size() ) ){
19 throwException(
"SHA1 processing error (2).",
"IOVSchema::makeHash");
21 unsigned char hash[SHA_DIGEST_LENGTH];
22 if( !SHA1_Final(hash, &ctx) ){
26 char tmp[SHA_DIGEST_LENGTH*2+1];
28 for (
unsigned int i = 0;
i < 20;
i++) {
29 ::sprintf(&tmp[
i * 2],
"%02x", hash[i]);
39 bool TAG::Table::Table::exists(){
46 "TAG::Table::create");
56 for (
auto row : q ) {}
58 return q.retrievedRows();
70 for (
auto row : q ) std::tie( timeType, objectType, synchronizationType, endOfValidity, description, lastValidatedTime ) = row;
72 return q.retrievedRows();
77 boost::posix_time::ptime& insertionTime,
78 boost::posix_time::ptime& modificationTime ){
81 for (
auto row : q ) std::tie( description, insertionTime, modificationTime ) = row;
82 return q.retrievedRows();
92 const boost::posix_time::ptime& insertionTime ){
94 dataToInsert( std::tie( name, timeType, objectType, synchronizationType, endOfValidity, description, lastValidatedTime, insertionTime, insertionTime ) );
103 const boost::posix_time::ptime& updateTime ){
116 const boost::posix_time::ptime& updateTime ){
134 "IOV::Schema::create");
146 unsigned long long gSize,
147 std::vector<cond::Time_t>& groups ){
150 if( !snapshotTime.is_not_a_date_time() ){
156 groups.push_back(std::get<0>(row));
158 return q.retrievedRows();
163 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
168 if( !snapshotTime.is_not_a_date_time() ){
173 size_t initialSize = iovs.
size();
174 for (
auto row : q ) {
176 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
177 iovs.push_back( row );
179 return iovs.size()-initialSize;
185 if( !snapshotTime.is_not_a_date_time() ){
190 for (
auto row : q ) {
191 since = std::get<0>(row);
192 hash = std::get<1>(row);
201 if( !snapshotTime.is_not_a_date_time() ){
204 for (
auto row : q ) {
205 size = std::get<0>(row);
213 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
217 if( !snapshotTime.is_not_a_date_time() ){
222 lower_since = std::get<0>( row );
224 if ( !lower_since )
return false;
228 if( !snapshotTime.is_not_a_date_time() ){
234 size_t initialSize = iovs.
size();
237 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
238 iovs.push_back( row );
240 return iovs.size()-initialSize;
246 const boost::posix_time::ptime& insertTimeStamp ){
252 const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
254 for(
auto row : iovs ) inserter.
insert( std::tuple_cat( std::tie(tag),row ) );
285 const boost::posix_time::ptime& eventTime,
292 dataToInsert( std::tie( tag, eventTime, userName, hostName, command, action, userText ) );
307 "PAYLOAD::Schema::create");
318 for (
auto row : q ) {}
320 return q.retrievedRows();
326 for (
auto row : q ) {
327 objectType = std::get<0>(row);
330 return q.retrievedRows();
339 for (
auto row : q ) {
340 std::tie( payloadData, streamerInfoData, objectType ) = row;
342 return q.retrievedRows();
349 const boost::posix_time::ptime& insertionTime ){
353 RowBuffer< HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME > dataToInsert( std::tie( payloadHash, objectType, payloadData, sinfoData, version, insertionTime ) );
354 bool failOnDuplicate =
false;
355 return insertInTable(
m_schema,
tname, dataToInsert.
get(), failOnDuplicate );
361 const boost::posix_time::ptime& insertionTime ){
364 if( !
select( payloadHash ) ){
365 insert( payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime );
371 m_tagTable( schema ),
372 m_iovTable( schema ),
373 m_tagLogTable( schema ),
374 m_payloadTable( schema ){
385 bool created =
false;
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)
static char const * tname
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()
void insert(const P ¶ms)
coral::ISchema & m_schema
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
PAYLOAD::Table m_payloadTable
coral::ISchema & m_schema
Table(coral::ISchema &schema)
static std::string group(unsigned long long groupSize)
static char const * tname
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
coral::ISchema & m_schema
void setForeignKey(const std::string &name)
void update(const std::string &name, cond::SynchronizationType synchronizationType, cond::Time_t &endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime) override
unsigned long long Time_t
static 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
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 copy(const std::string &source)
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)
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
coral::ISchema & m_schema
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
std::vector< std::vector< double > > tmp
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
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 char const * tname
void addWhereCondition(const P ¶m, const std::string condition="=")
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 addWhereCondition(const P ¶m, const std::string condition="=")