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() );
144 groups.push_back(std::get<0>(row));
146 return q.retrievedRows();
155 groups.push_back(std::get<0>(row));
157 return q.retrievedRows();
161 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
168 size_t initialSize = iovs.
size();
171 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
172 iovs.push_back( row );
174 return iovs.size()-initialSize;
178 const boost::posix_time::ptime& snapshotTime,
179 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
187 size_t initialSize = iovs.
size();
188 for (
auto row : q ) {
190 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
191 iovs.push_back( row );
193 return iovs.size()-initialSize;
197 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
202 size_t initialSize = iovs.
size();
203 for (
auto row : q ) {
205 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
206 iovs.push_back( row );
208 return iovs.size()-initialSize;
216 for (
auto row : q ) {
217 since = std::get<0>(row);
218 hash = std::get<1>(row);
227 for (
auto row : q ) {
228 size = std::get<0>(row);
238 for (
auto row : q ) {
239 size = std::get<0>(row);
248 const boost::posix_time::ptime& insertTimeStamp ){
250 insertInTable( m_schema,
tname, dataToInsert.
get() );
254 const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
256 for(
auto row : iovs ) inserter.
insert( std::tuple_cat( std::tie(tag),row ) );
264 deleteFromTable( m_schema,
tname, buffer );
272 return existsTable( m_schema,
tname );
278 "PAYLOAD::Schema::create");
283 createTable( m_schema, descr.
get() );
289 for (
auto row : q ) {}
291 return q.retrievedRows();
297 for (
auto row : q ) {
298 objectType = std::get<0>(row);
301 return q.retrievedRows();
310 for (
auto row : q ) {
311 std::tie( payloadData, streamerInfoData, objectType ) = row;
313 return q.retrievedRows();
320 const boost::posix_time::ptime& insertionTime ){
324 RowBuffer< HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME > dataToInsert( std::tie( payloadHash, objectType, payloadData, sinfoData, version, insertionTime ) );
325 bool failOnDuplicate =
false;
326 return insertInTable( m_schema,
tname, dataToInsert.
get(), failOnDuplicate );
332 const boost::posix_time::ptime& insertionTime ){
335 if( !
select( payloadHash ) ){
336 insert( payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime );
346 return existsTable( m_schema,
tname );
351 throwException(
"TAG_MIGRATIONtable already exists in this schema.",
357 createTable( m_schema, descr.
get() );
364 for (
auto row : q ) {
365 std::tie( tagName, statusCode ) = row;
368 return q.retrievedRows();
373 int statusCode,
const boost::posix_time::ptime& insertionTime ){
375 dataToInsert( std::tie( sourceAccount, sourceTag, tagName, statusCode, insertionTime ) );
376 insertInTable( m_schema,
tname, dataToInsert.
get() );
384 updateTable( m_schema,
tname, buffer );
388 m_tagTable( schema ),
389 m_iovTable( schema ),
390 m_payloadTable( schema ),
391 m_tagMigrationTable( schema ){
402 bool created =
false;
Table(coral::ISchema &schema)
void updateValidationCode(const std::string &sourceAccount, const std::string &sourceTag, int statusCode)
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
static char const * tname
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)
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
bool select(const std::string &sourceAccount, const std::string &sourceTag, std::string &tagName, int &statusCode)
const coral::AttributeList & get() const
void addOrderClause(bool ascending=true)
TAG_MIGRATION::Table m_tagMigrationTable
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)
ITagMigrationTable & tagMigrationTable()
bool getType(const cond::Hash &payloadHash, std::string &objectType)
const void * data() const
void setColumnData(const Params ¶ms)
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)
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)
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
void insert(const std::string &sourceAccount, const std::string &sourceTag, const std::string &tagName, int statusCode, const boost::posix_time::ptime &insertionTime)
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="=")