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");
147 if( !snapshotTime.is_not_a_date_time() ){
153 groups.push_back(std::get<0>(row));
155 return q.retrievedRows();
160 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
165 if( !snapshotTime.is_not_a_date_time() ){
170 size_t initialSize = iovs.
size();
171 for (
auto row : q ) {
173 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
174 iovs.push_back( row );
176 return iovs.size()-initialSize;
182 if( !snapshotTime.is_not_a_date_time() ){
187 for (
auto row : q ) {
188 since = std::get<0>(row);
189 hash = std::get<1>(row);
198 if( !snapshotTime.is_not_a_date_time() ){
201 for (
auto row : q ) {
202 size = std::get<0>(row);
210 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
214 if( !snapshotTime.is_not_a_date_time() ){
219 lower_since = std::get<0>( row );
221 if ( !lower_since )
return false;
225 if( !snapshotTime.is_not_a_date_time() ){
231 size_t initialSize = iovs.
size();
234 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
235 iovs.push_back( row );
237 return iovs.size()-initialSize;
243 const boost::posix_time::ptime& insertTimeStamp ){
249 const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
251 for(
auto row : iovs ) inserter.
insert( std::tuple_cat( std::tie(tag),row ) );
282 const boost::posix_time::ptime& eventTime,
289 dataToInsert( std::tie( tag, eventTime, userName, hostName, command, action, userText ) );
304 "PAYLOAD::Schema::create");
315 for (
auto row : q ) {}
317 return q.retrievedRows();
323 for (
auto row : q ) {
324 objectType = std::get<0>(row);
327 return q.retrievedRows();
336 for (
auto row : q ) {
337 std::tie( payloadData, streamerInfoData, objectType ) = row;
339 return q.retrievedRows();
346 const boost::posix_time::ptime& insertionTime ){
350 RowBuffer< HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME > dataToInsert( std::tie( payloadHash, objectType, payloadData, sinfoData, version, insertionTime ) );
351 bool failOnDuplicate =
false;
352 return insertInTable(
m_schema,
tname, dataToInsert.
get(), failOnDuplicate );
358 const boost::posix_time::ptime& insertionTime ){
361 if( !
select( payloadHash ) ){
362 insert( payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime );
368 m_tagTable( schema ),
369 m_iovTable( schema ),
370 m_tagLogTable( schema ),
371 m_payloadTable( schema ){
382 bool created =
false;
static char const * tname
static std::string group()
ITagLogTable & tagLogTable()
const coral::TableDescription & get()
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
void insert(const P ¶ms)
coral::ISchema & m_schema
Table(coral::ISchema &schema)
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)
bool getLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash)
size_t getGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< cond::Time_t > &groups)
PAYLOAD::Table m_payloadTable
coral::ISchema & m_schema
bool getSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs)
static char const * tname
coral::ISchema & m_schema
void setForeignKey(const std::string &name)
bool select(const cond::Hash &payloadHash)
unsigned long long Time_t
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)
static char const * tname
Query & groupBy(const std::string &expression)
const coral::AttributeList & get() const
Query & addCondition(const T &value, const std::string condition="=")
void erase(const std::string &tag)
void copy(const std::string &source)
IPayloadTable & payloadTable()
Query & addOrderClause(bool ascending=true)
bool select(const std::string &name)
bool getType(const cond::Hash &payloadHash, std::string &objectType)
const void * data() const
TAG_LOG::Table m_tagLogTable
void setColumnData(const Params ¶ms)
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)
Table(coral::ISchema &schema)
IOVSchema(coral::ISchema &schema)
coral::ISchema & m_schema
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
std::vector< std::vector< double > > tmp
char data[epos_bytes_allocation]
cond::Hash makeHash(const std::string &objectType, const cond::Binary &data)
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)
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)
static char const * tname
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)
void addWhereCondition(const P ¶m, const std::string condition="=")
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
void throwException(const std::string &message, const std::string &methodName)
void addWhereCondition(const P ¶m, const std::string condition="=")