diff --git a/include/recarray.cpp b/include/recarray.cpp index 4fbaa6a6b..b3f0f80ea 100755 --- a/include/recarray.cpp +++ b/include/recarray.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -401,20 +403,23 @@ int TRecord_array::remove() const /////////////////////////////////////////////////////////// TFile_cache::TFile_cache(TLocalisamfile *f , int key) - : _file(NULL), _key(key) + : _file(NULL), _key(key), + _test_changes(FALSE), _last_read(0), _limit(0) { _filecode << f->num(); init_file(f); } TFile_cache::TFile_cache(int num, int key) - : _file(NULL), _key(key), _last_firm(-883) + : _file(NULL), _key(key), _last_firm(-883), + _test_changes(FALSE), _last_read(0), _limit(0) { _filecode << num; } TFile_cache::TFile_cache(const char* tab, int key) - : _file(NULL), _key(key), _last_firm(-883) + : _file(NULL), _key(key), _last_firm(-883), + _test_changes(FALSE), _last_read(0), _limit(0) { _filecode = tab; } @@ -455,6 +460,7 @@ void TFile_cache::init_file(TLocalisamfile* f) dir.get(_file->num(), _nolock, _nordir, _sysdirop); // Se e' un file comune metti a -1, altrimenti alla ditta corrente _last_firm = dir.is_com() ? -1 : prefix().get_codditta(); + _last_read = 0L; } } @@ -462,7 +468,7 @@ void TFile_cache::test_firm() { if (_last_firm < -1) init_file(); - + if (_last_firm >= 0) // Se e' un file di ditta ... { // ... controlla che non sia cambiata const long cur_firm = prefix().get_codditta(); @@ -472,6 +478,30 @@ void TFile_cache::test_firm() _cache.destroy(); } } + + bool flush_needed = FALSE; + + if (_test_changes) + { + if (_file != NULL && _file->is_changed_since(_last_read)) + flush_needed = TRUE; + } + + if (_limit > 0 && items() > _limit) + flush_needed = TRUE; + + if (flush_needed) + { + flush(); + _cache.destroy(); + } + + _last_read = clock(); +} + +void TFile_cache::flush() +{ + // Needed by read/write cache } const TObject& TFile_cache::query(const char* code) diff --git a/include/recarray.h b/include/recarray.h index 5eabdb1dd..c80bd6d71 100755 --- a/include/recarray.h +++ b/include/recarray.h @@ -147,10 +147,11 @@ class TFile_cache : public TObject TToken_string _code; TString16 _filecode; TLocalisamfile* _file; - TString16 _filecode; int _key; long _last_firm; int _error; + long _last_read, _limit; + bool _test_changes; protected: TAssoc_array _cache; @@ -175,6 +176,10 @@ public: long fill(); void destroy(); + virtual void flush(); + + void set_items_limit(long l) { _limit = l; } + void test_file_changes(bool t = TRUE) { _test_changes = t; } TFile_cache(TLocalisamfile *f,int key = 1); TFile_cache(int num, int key = 1);