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(){
40 return existsTable( m_schema,
tname );
46 "TAG::Table::create");
50 createTable( m_schema, descr.
get() );
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 ) );
95 insertInTable( m_schema,
tname, dataToInsert.
get() );
102 const boost::posix_time::ptime& updateTime ){
106 updateTable( m_schema,
tname, buffer );
111 const boost::posix_time::ptime& updateTime ){
115 updateTable( m_schema,
tname, buffer );
123 return existsTable( m_schema,
tname );
129 "IOV::Schema::create");
136 createTable( m_schema, descr.
get() );
145 groups.push_back(std::get<0>(row));
147 return q.retrievedRows();
157 groups.push_back(std::get<0>(row));
159 return q.retrievedRows();
163 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
170 size_t initialSize = iovs.
size();
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;
180 const boost::posix_time::ptime& snapshotTime,
181 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
189 size_t initialSize = iovs.
size();
190 for (
auto row : q ) {
192 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
193 iovs.push_back( row );
195 return iovs.size()-initialSize;
199 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
204 size_t initialSize = iovs.
size();
205 for (
auto row : q ) {
207 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
208 iovs.push_back( row );
210 return iovs.size()-initialSize;
214 const boost::posix_time::ptime& snapshotTime,
215 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
221 size_t initialSize = iovs.
size();
222 for (
auto row : q ) {
224 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
225 iovs.push_back( row );
227 return iovs.size()-initialSize;
235 for (
auto row : q ) {
236 since = std::get<0>(row);
237 hash = std::get<1>(row);
249 for (
auto row : q ) {
250 since = std::get<0>(row);
251 hash = std::get<1>(row);
260 for (
auto row : q ) {
261 size = std::get<0>(row);
271 for (
auto row : q ) {
272 size = std::get<0>(row);
281 const boost::posix_time::ptime& insertTimeStamp ){
283 insertInTable( m_schema,
tname, dataToInsert.
get() );
287 const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
289 for(
auto row : iovs ) inserter.
insert( std::tuple_cat( std::tie(tag),row ) );
297 deleteFromTable( m_schema,
tname, buffer );
305 return existsTable( m_schema,
tname );
316 createTable( m_schema, descr.
get() );
320 const boost::posix_time::ptime& eventTime,
327 dataToInsert( std::tie( tag, eventTime, userName, hostName, command, action, userText ) );
328 insertInTable( m_schema,
tname, dataToInsert.
get() );
336 return existsTable( m_schema,
tname );
342 "PAYLOAD::Schema::create");
347 createTable( m_schema, descr.
get() );
353 for (
auto row : q ) {}
355 return q.retrievedRows();
361 for (
auto row : q ) {
362 objectType = std::get<0>(row);
365 return q.retrievedRows();
374 for (
auto row : q ) {
375 std::tie( payloadData, streamerInfoData, objectType ) = row;
377 return q.retrievedRows();
384 const boost::posix_time::ptime& insertionTime ){
388 RowBuffer< HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME > dataToInsert( std::tie( payloadHash, objectType, payloadData, sinfoData, version, insertionTime ) );
389 bool failOnDuplicate =
false;
390 return insertInTable( m_schema,
tname, dataToInsert.
get(), failOnDuplicate );
396 const boost::posix_time::ptime& insertionTime ){
399 if( !
select( payloadHash ) ){
400 insert( payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime );
406 m_tagTable( schema ),
407 m_iovTable( schema ),
408 m_tagLogTable( schema ),
409 m_payloadTable( schema ){
420 bool created =
false;
bool getSnapshotLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash)
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
static char const * tname
static std::string group()
ITagLogTable & tagLogTable()
bool getSize(const std::string &tag, size_t &size)
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)
Table(coral::ISchema &schema)
size_t selectLatest(const std::string &tag, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
bool getLastIov(const std::string &tag, cond::Time_t &since, cond::Hash &hash)
PAYLOAD::Table m_payloadTable
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs)
size_t selectGroups(const std::string &tag, std::vector< cond::Time_t > &groups)
static char const * tname
void setForeignKey(const std::string &name)
bool select(const cond::Hash &payloadHash)
unsigned long long Time_t
void addCondition(const T &value, const std::string condition="=")
static char const * tname
const coral::AttributeList & get() const
void addOrderClause(bool ascending=true)
void erase(const std::string &tag)
void copy(const std::string &source)
void update(const std::string &name, cond::Time_t &endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
IPayloadTable & payloadTable()
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
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)
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
size_t selectSnapshot(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
std::vector< std::vector< double > > tmp
void groupBy(const std::string &expression)
cond::Hash makeHash(const std::string &objectType, const cond::Binary &data)
Table(coral::ISchema &schema)
size_t selectSnapshotByGroup(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)
bool insert(const cond::Hash &payloadHash, const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
volatile std::atomic< bool > shutdown_flag false
Table(coral::ISchema &schema)
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)
tuple size
Write out results.
void throwException(const std::string &message, const std::string &methodName)
size_t selectSnapshotGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< cond::Time_t > &groups)
size_t selectLatestByGroup(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
void addWhereCondition(const P ¶m, const std::string condition="=")