CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_store_TransactionalRAMDirectory_ 00008 #define _lucene_store_TransactionalRAMDirectory_ 00009 00010 #include "RAMDirectory.h" 00011 #include "CLucene/util/VoidList.h" 00012 CL_NS_DEF(store) 00013 00014 /*** 00015 This transactional in-memory Directory was created to address a specific 00016 situation, and was deliberately pared down to the simplest viable 00017 implementation. For the sake of simplicity, this implementation imposes 00018 restrictions on what operations can be performed in the directory while a 00019 transaction is in progress (documented in TransactionalRAMDirectory.cpp). 00020 00021 Because the Lucene Directory interface itself is rather simplistic, it 00022 would not be difficult to expand TransactionalRAMDirectory so that it 00023 provided fully general transactionality. However, the developer of this 00024 original implementation was of the opinion that the last thing CLucene 00025 needs is gratuitous features that exceed their required complexity and 00026 haven't been rigorously tested. 00027 */ 00028 class TransactionalRAMDirectory: public RAMDirectory { 00029 private: 00030 typedef CL_NS(util)::CLSet<const char*, void*, CL_NS(util)::Compare::Char> FilenameSet; 00031 FilenameSet filesToRemoveOnAbort; 00032 00033 typedef CL_NS(util)::CLSet<const char*, RAMFile*, CL_NS(util)::Compare::Char,CL_NS(util)::Deletor::acArray,CL_NS(util)::Deletor::Object<RAMFile> > TransFileMap; 00034 TransFileMap filesToRestoreOnAbort; 00035 00036 bool transOpen; 00037 00038 void transResolved(); 00039 bool archiveOrigFileIfNecessary(const char* name); 00040 void unarchiveOrigFile(const char* name); 00041 00042 protected: 00043 bool doDeleteFile(const char* name); 00044 00045 public: 00046 TransactionalRAMDirectory(); 00047 virtual ~TransactionalRAMDirectory(); 00048 00049 bool transIsOpen() const; 00050 void transStart(); 00051 void transCommit(); 00052 void transAbort(); 00053 00054 // Constrained operations: 00055 void renameFile(const char* from, const char* to); 00056 IndexOutput* createOutput(const char* name); 00057 00058 void close(); 00059 }; 00060 00061 CL_NS_END 00062 #endif // ndef _lucene_store_TransactionalRAMDirectory_