1 /* =========================================================================== 2 * $Id: bisi_writer.hpp 609535 2020-06-03 16:00:59Z saprykin $ 3 * =========================================================================== 4 * 5 * PUBLIC DOMAIN NOTICE 6 * National Center for Biotechnology Information 7 * 8 * This software/database is a "United States Government Work" under the 9 * terms of the United States Copyright Act. It was written as part of 10 * the author's official duties as a United States Government employee and 11 * thus cannot be copyrighted. This software/database is freely available 12 * to the public for use. The National Library of Medicine and the U.S. 13 * Government have not placed any restriction on its use or reproduction. 14 * 15 * Although all reasonable efforts have been taken to ensure the accuracy 16 * and reliability of the software and data, the NLM and the U.S. 17 * Government do not and cannot warrant the performance or results that 18 * may be obtained by using this software or data. The NLM and the U.S. 19 * Government disclaim all warranties, express or implied, including 20 * warranties of performance, merchantability or fitness for any particular 21 * purpose. 22 * 23 * Please cite the author in any work or product based on this material. 24 * 25 * =========================================================================== 26 * 27 * Authors: Dmitri Dmitrienko 28 * 29 * File Description: 30 * 31 * Class to produce change log write queries 32 * 33 */ 34 35 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_WRITER_HPP 36 #define OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_WRITER_HPP 37 38 #include <string> 39 40 #include <objtools/pubseq_gateway/impl/cassandra/cass_driver.hpp> 41 #include <objtools/pubseq_gateway/impl/diag/AppLog.hpp> 42 43 #include <objtools/pubseq_gateway/impl/cassandra/changelog/bisi_record.hpp> 44 45 BEGIN_IDBLOB_SCOPE 46 USING_NCBI_SCOPE; 47 48 class CBiSiChangelogWriter 49 { 50 public: 51 CBiSiChangelogWriter() = default; WriteSiEvent(CCassQuery & query,string const & keyspace,CSiChangelogRecord const & record,int64_t ttl) const52 void WriteSiEvent(CCassQuery& query, string const & keyspace, CSiChangelogRecord const & record, int64_t ttl) const 53 { 54 query.SetSQL( 55 "INSERT INTO " + keyspace + ".si2csi_change_log (updated_time, seq_id, seq_id_type, op)" 56 " VALUES (?,?,?,?) USING TTL " + NStr::NumericToString(ttl), 4); 57 query.BindInt64(0, record.GetPartition()); 58 query.BindStr(1, record.GetSeqId()); 59 query.BindInt16(2, record.GetSeqIdType()); 60 query.BindInt8(3, record.GetOperationBase()); 61 query.Execute(CASS_CONSISTENCY_LOCAL_QUORUM, true); 62 } 63 WriteSiPartition(CCassQuery & query,string const & keyspace,int64_t partition,int64_t ttl) const64 void WriteSiPartition(CCassQuery& query, string const & keyspace, int64_t partition, int64_t ttl) const 65 { 66 query.SetSQL( 67 "INSERT INTO " + keyspace + ".si2csi_change_log (updated_time, seq_id, seq_id_type, op)" 68 " VALUES (?,'',0,?) USING TTL " + NStr::NumericToString(ttl), 2); 69 query.BindInt64(0, partition); 70 query.BindInt8 (1, static_cast<TBiSiChangelogOperationBase>(TBiSiChangelogOperation::eChangeLogOpBeacon)); 71 query.Execute(CASS_CONSISTENCY_LOCAL_QUORUM, true); 72 } 73 WriteBiEvent(CCassQuery & query,string const & keyspace,CBiChangelogRecord const & record,int64_t ttl) const74 void WriteBiEvent(CCassQuery& query, string const & keyspace, CBiChangelogRecord const & record, int64_t ttl) const 75 { 76 query.SetSQL( 77 "INSERT INTO " + keyspace + ".bioseq_info_change_log" 78 " (updated_time, accession, version, seq_id_type, gi, op)" 79 " VALUES (?,?,?,?,?,?)" 80 " USING TTL " + NStr::NumericToString(ttl), 6); 81 query.BindInt64(0, record.GetPartition()); 82 query.BindStr(1, record.GetAccession()); 83 query.BindInt16(2, record.GetVersion()); 84 query.BindInt16(3, record.GetSeqIdType()); 85 query.BindInt64(4, record.GetGi()); 86 query.BindInt8(5, static_cast<TBiSiChangelogOperationBase>(TBiSiChangelogOperation::eChangeLogOpInsert)); 87 query.Execute(CASS_CONSISTENCY_LOCAL_QUORUM, true); 88 } 89 WriteBiPartition(CCassQuery & query,string const & keyspace,int64_t partition,int64_t ttl) const90 void WriteBiPartition(CCassQuery& query, string const & keyspace, int64_t partition, int64_t ttl) const 91 { 92 query.SetSQL( 93 "INSERT INTO " + keyspace + ".bioseq_info_change_log" 94 " (updated_time, accession, version, seq_id_type, gi, op)" 95 " VALUES (?,'',0,0,0,?)" 96 " USING TTL " + NStr::NumericToString(ttl), 2); 97 query.BindInt64(0, partition); 98 query.BindInt8 (1, static_cast<TBiSiChangelogOperationBase>(TBiSiChangelogOperation::eChangeLogOpBeacon)); 99 query.Execute(CASS_CONSISTENCY_LOCAL_QUORUM, true); 100 } 101 }; 102 103 END_IDBLOB_SCOPE 104 105 #endif // OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_WRITER_HPP 106