OpenTREP Logo  0.07.9
C++ Open Travel Request Parsing Library
FacXapianDB.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Xapian
7 #include <xapian.h>
8 // OpenTrep
13 
14 namespace OPENTREP {
15 
16  FacXapianDB* FacXapianDB::_instance = NULL;
17 
18  // //////////////////////////////////////////////////////////////////////
20  clean ();
21  _instance = NULL;
22  }
23 
24  // //////////////////////////////////////////////////////////////////////
26  for (XapianDBPool_T::iterator itXapianDB = _pool.begin();
27  itXapianDB != _pool.end(); itXapianDB++) {
28  Xapian::WritableDatabase* currentXapianDB_ptr = *itXapianDB;
29  assert (currentXapianDB_ptr != NULL);
30 
31  delete currentXapianDB_ptr; currentXapianDB_ptr = NULL;
32  }
33 
34  // Now that all the objects have been deleted, empty the underlying pool
35  _pool.clear();
36  }
37 
38  // //////////////////////////////////////////////////////////////////////
40  if (_instance == NULL) {
41  _instance = new FacXapianDB();
43  }
44  assert (_instance != NULL);
45  return *_instance;
46  }
47 
48  // //////////////////////////////////////////////////////////////////////
49  Xapian::WritableDatabase* FacXapianDB::
50  create (const TravelDBFilePath_T& iTravelIndexFilePath,
51  const int& iXapianActionFlag) {
52  Xapian::WritableDatabase* oXapianDatabase_ptr = NULL;
53 
54  oXapianDatabase_ptr = new Xapian::WritableDatabase (iTravelIndexFilePath,
55  iXapianActionFlag);
56  if (oXapianDatabase_ptr == NULL) {
57  std::ostringstream errorStr;
58  errorStr << "Error when trying to create the Xapian database/index ('"
59  << iTravelIndexFilePath << "')";
60  OPENTREP_LOG_ERROR (errorStr.str());
61  throw XapianDatabaseFailureException (errorStr.str());
62  }
63 
64 
65  // The new object is added to the Service pool
66  _pool.push_back (oXapianDatabase_ptr);
67 
68  return oXapianDatabase_ptr;
69  }
70 
71 }
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:24
static FacSupervisor & instance()
void registerXapianDBFactory(FacXapianDB *)
Factory for a Xapian WritableDatabase object.
Definition: FacXapianDB.hpp:22
static FacXapianDB & instance()
Definition: FacXapianDB.cpp:39
Xapian::WritableDatabase * create(const TravelDBFilePath_T &, const int &iXapianActionFlag)
Definition: FacXapianDB.cpp:50