NCBI C++ ToolKit
sqlite_cache_factory.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sqlite_cache_factory.cpp 45986 2021-01-20 17:06:24Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Mike DiCuccio
27  *
28  * File Description: Class factory for SQLITE3 based ICache interface
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistr.hpp>
37 
38 
39 #define NCBI_USE_ERRCODE_X SQLITE3_Cache
40 
42 
43 const string kSQLITE3_BlobCacheDriverName("sqlite3");
44 
45 
46 /// Class factory for SQLITE3 BLOB cache
47 ///
48 /// @internal
49 ///
50 
52  public CSimpleClassFactoryImpl<ICache, CSQLITE3_Cache>
53 {
54 public:
56 
57 public:
61  {
62  }
63 
64  /// Create instance of TDriver
65  virtual
66  ICache* CreateInstance(const string& driver = kEmptyStr,
68  const TPluginManagerParamTree* params = 0) const;
69 };
70 
71 
72 
73 // List of parameters accepted by the CF
74 
75 static const char* kCFParam_database = "database";
76 static const char* kCFParam_cache_age = "cache_age";
77 
78 
79 ////////////////////////////////////////////////////////////////////////////
80 //
81 // CSQLITE3_BlobCacheCF
82 
83 
86  const TPluginManagerParamTree* params) const
87 {
88  unique_ptr<CSQLITE3_Cache> drv(new CSQLITE3_Cache());
89 
90  if ( !params ) {
91  LOG_POST(Warning << "created sqlite3 cache driver, but no params provided");
92  return drv.release();
93  }
94 
95  const string& tree_id = params->GetKey();
98  << "ICache class factory: Top level Id does not match driver name."
99  << " Id = " << tree_id << " driver=" << kSQLITE3_BlobCacheDriverName
100  << " parameters ignored." );
101 
102  return drv.release();
103  }
104 
105  // cache configuration
106  string database = GetParam(params, kCFParam_database, true);
107  // hack: tweak path for 64-bit version to use alternative directory
108  if (sizeof(void*) == 8) {
109  string dir, base, ext;
110  CDirEntry::SplitPath(database, &dir, &base, &ext);
112  string::value_type ch = dir[dir.length()-1];
113  if (ch != '4') {
114  dir.append("64");
115  }
116  database = CDirEntry::MakePath(dir, base, ext);
117  }
118  else { // for the 32-bit version switch from 64-bit cache
119  NStr::ReplaceInPlace(database, "cache64", "cache");
120  }
121 
122  drv->Open(database);
123 
124  const string& cache_age_str =
125  GetParam(params, kCFParam_cache_age, false, "0");
126  unsigned cache_age = 0;
127 
128  try {
129  cache_age = NStr::StringToUInt(cache_age_str);
130  } catch(const CStringException&) {
131  // ignore
132  }
133  if ( !cache_age ) {
134  cache_age = 5 * (24*60*60);
135  }
136  if (cache_age) {
137  drv->SetTimeStampPolicy(0 /* default policy */, cache_age);
138  }
139 
140  return drv.release();
141 }
142 
143 
146 
147 
148 extern "C" {
149 
154 {
156  info_list,
157  method);
158 }
159 
164 {
165  NCBI_EntryPoint_SQLITE3_BlobCache(info_list, method);
166 }
167 
169 {
170  RegisterEntryPoint<ICache>(NCBI_EntryPoint_SQLITE3_BlobCache);
171 }
172 
173 }
Class factory for SQLITE3 BLOB cache.
CSimpleClassFactoryImpl< ICache, CSQLITE3_Cache > TParent
virtual ICache * CreateInstance(const string &driver=kEmptyStr, CVersionInfo version=NCBI_INTERFACE_VERSION(ICache), const TPluginManagerParamTree *params=0) const
Create instance of TDriver.
SQLITE3 cache implementation.
Template class helps to implement one driver class factory.
CStringException –.
Definition: ncbistr.hpp:4505
definition of a Culling tree
Definition: ncbi_tree.hpp:100
CVersionInfo –.
BLOB cache read/write/maintenance interface.
Definition: icache.hpp:64
The NCBI C++ standard methods for dealing with std::string.
void SQLITE3_Register_Cache(void)
Register NCBI_EntryPoint_SQLITE3_BlobCache.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
static string DeleteTrailingPathSeparator(const string &path)
Delete trailing path separator, if any.
Definition: ncbifile.cpp:465
static string MakePath(const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
Assemble a path from basic components.
Definition: ncbifile.cpp:413
static void SplitPath(const string &path, string *dir=0, string *base=0, string *ext=0)
Split a path string into its basic components.
Definition: ncbifile.cpp:358
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
string GetParam(const TPluginManagerParamTree *params, const string &param_name, bool mandatory, const string &default_value) const
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3401
const TKeyType & GetKey(void) const
Definition: ncbi_tree.hpp:197
use only n Cassandra database for the lookups</td > n</tr > n< tr > n< td > yes</td > n< td > do not use tables BIOSEQ_INFO and BLOB_PROP in the Cassandra database
static int version
Definition: mdb_load.c:29
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
Magic spell ;-) needed for some weird compilers... very empiric.
Helper classes and templates to implement plugins.
#define NCBI_SQLITE3_CACHE_EXPORT
void NCBI_EntryPoint_SQLITE3_BlobCache(CPluginManager< ICache >::TDriverInfoList &info_list, CPluginManager< ICache >::EEntryPointRequest method)
static const char * kCFParam_cache_age
USING_SCOPE(ncbi)
const string kSQLITE3_BlobCacheDriverName("sqlite3")
void NCBI_EntryPoint_xcache_sqlite3(CPluginManager< ICache >::TDriverInfoList &info_list, CPluginManager< ICache >::EEntryPointRequest method)
static const char * kCFParam_database
Modified on Thu Nov 30 04:56:30 2023 by modify_doxy.py rev. 669887