summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
authoreilers <eilers>2004-08-29 12:50:18 (UTC)
committer eilers <eilers>2004-08-29 12:50:18 (UTC)
commit679d9fef2673eea18fe5d9c85df2b10b09a8a250 (patch) (side-by-side diff)
tree8b3d6dbef45568be6f5daac31094d6e599fdefdf /libopie2/opiepim/core
parent45327ef3c0f093fc227682f79158632afc09e6d1 (diff)
downloadopie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.zip
opie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.tar.gz
opie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.tar.bz2
Added lookahead caching for addressbook (SQL-only) for speed improvement.
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h40
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h16
2 files changed, 45 insertions, 11 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 55d600a..6f01b46 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -26,25 +26,24 @@
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
#define OPIE_PIM_ACCESS_TEMPLATE_H
/* OPIE */
#include <opie2/opimrecord.h>
#include <opie2/opimaccessbackend.h>
#include <opie2/opimrecordlist.h>
-#include <opie2/opimcache.h>
#include <opie2/opimtemplatebase.h>
#include <opie2/odebug.h>
/* QT */
#include <qarray.h>
namespace Opie {
class OPimAccessTemplatePrivate;
/**
* Thats the frontend to our OPIE PIM
* Library. Either you want to use it's
@@ -119,42 +118,45 @@ public:
/**
* find the OPimRecord uid
*/
virtual T find( int uid )const;
/**
* read ahead cache find method ;)
*/
virtual T find( int uid, const QArray<int>&,
uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
+
/* invalidate cache here */
/**
* clears the backend and invalidates the backend
*/
void clear() ;
/**
* add T to the backend
* @param t The item to add.
* @return <i>true</i> if added successfully.
*/
- virtual bool add( const T& t ) ;
+ virtual bool add( const T& t ) ;
+
bool add( const OPimRecord& );
- // Needed for real generic access (eilers)
- // Info: Take this if you are working with OPimRecord, which is a generic base class, and
- // you need to add it into any database, you cannot generate a reference to
- // it and casting may be not approriate, too.
- // But take care that the accessing database is compatible to the real type of OPimRecord !!
+ /**
+ * Add an Opie PimRecord.
+ * Info: Take this if you are working with OPimRecords and you need to add it into any database.
+ * But take care that the accessing database is compatible to the real type of OPimRecord !!
+ * Otherwise this access will be rejected !
+ */
bool add( const OPimRecord* );
/* only the uid matters */
/**
* remove T from the backend
* @param t The item to remove
* @return <i>true</i> if successful.
*/
virtual bool remove( const T& t );
/**
@@ -167,40 +169,42 @@ public:
/**
* replace T from backend
* @param t The item to replace
* @return <i>true</i> if successful.
*/
virtual bool replace( const T& t) ;
void setReadAhead( uint count );
/**
* @internal
*/
+ virtual T cacheFind( int uid )const;
void cache( const T& )const;
void setSaneCacheSize( int );
QArray<int> records()const;
protected:
/**
* invalidate the cache
*/
void invalidateCache();
void setBackEnd( BackEnd* end );
/**
* returns the backend
*/
BackEnd* backEnd();
BackEnd* m_backEnd;
+
Cache m_cache;
private:
OPimAccessTemplatePrivate *d;
};
template <class T>
OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
: OTemplateBase<T>(), m_backEnd( end )
{
if (end )
@@ -209,25 +213,25 @@ OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
template <class T>
OPimAccessTemplate<T>::~OPimAccessTemplate() {
owarn << "~OPimAccessTemplate<T>" << oendl;
delete m_backEnd;
}
template <class T>
bool OPimAccessTemplate<T>::load() {
invalidateCache();
return m_backEnd->load();
}
template <class T>
bool OPimAccessTemplate<T>::reload() {
- invalidateCache(); // zecke: I think this should be added (se)
+ invalidateCache();
return m_backEnd->reload();
}
template <class T>
bool OPimAccessTemplate<T>::save() {
return m_backEnd->save();
}
template <class T>
typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
QArray<int> ints = m_backEnd->allRecords();
List lis(ints, this );
return lis;
}
@@ -242,74 +246,90 @@ QArray<int> OPimAccessTemplate<T>::records()const {
return m_backEnd->allRecords();
}
template <class T>
typename OPimAccessTemplate<T>::List
OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
List lis(ints, this );
return lis;
}
template <class T>
T OPimAccessTemplate<T>::find( int uid ) const{
+ // First search in cache..
+ if ( m_cache.contains( uid ) )
+ return m_cache.find( uid );
+
T t = m_backEnd->find( uid );
cache( t );
+
return t;
}
+
+template <class T>
+T OPimAccessTemplate<T>::cacheFind( int uid ) const
+{
+ return m_cache.find( uid );
+}
+
template <class T>
T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
uint current, typename OTemplateBase<T>::CacheDirection dir )const {
/*
* better do T.isEmpty()
* after a find this way we would
* avoid two finds in QCache...
*/
// owarn << "find it now " << uid << oendl;
- if (m_cache.contains( uid ) ) {
+ if ( m_cache.contains( uid ) ) {
return m_cache.find( uid );
}
T t = m_backEnd->find( uid, ar, current, dir );
cache( t );
return t;
}
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
m_backEnd->clear();
}
template <class T>
bool OPimAccessTemplate<T>::add( const T& t ) {
cache( t );
return m_backEnd->add( t );
}
template <class T>
-bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
+bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
/* same type */
T tempInstance;
if ( rec.rtti() == tempInstance.rtti() ) {
const T& t = static_cast<const T&>(rec);
return add(t);
+ } else {
+ owarn << "Adding not possible: Objecttype mismatch" << oendl;
}
return false;
}
template <class T>
bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
/* same type, but pointer */
T tempInstance;
if ( rec -> rtti() == tempInstance.rtti() ) {
const T* t = static_cast<const T*>(rec);
return add( *t );
+ } else {
+ owarn << "Adding not possible: Objecttype mismatch" << oendl;
}
return false;
}
template <class T>
bool OPimAccessTemplate<T>::remove( const T& t ) {
return remove( t.uid() );
}
template <class T>
bool OPimAccessTemplate<T>::remove( int uid ) {
m_cache.remove( uid );
return m_backEnd->remove( uid );
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index b48dfed..ec9a94e 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -22,24 +22,25 @@
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTEMPLATEBASE_H
#define OTEMPLATEBASE_H
/* OPIE */
#include <opie2/opimrecord.h>
+#include <opie2/opimcache.h>
/* QT */
#include <qarray.h>
namespace Opie {
/**
* Templates do not have a base class, This is why
* we've this class
* this is here to give us the possibility
* to have a common base class
* You may not want to use that interface internaly
* POOR mans interface
@@ -61,48 +62,61 @@ struct OPimBase {
virtual bool save() = 0;
virtual QArray<int> records()const = 0;
/*
* ADD editing here?
* -zecke
*/
private:
OPimBasePrivate* d;
};
/**
* internal template base
- * T needs to implement the copy c'tor!!!
+ * Attention: T needs to implement the copy c'tor!!!
*/
class OTemplateBasePrivate;
template <class T = OPimRecord>
class OTemplateBase : public OPimBase {
public:
+ /** Look ahead direction of cache */
enum CacheDirection { Forward=0, Reverse };
+
OTemplateBase() {
};
virtual ~OTemplateBase() {
}
virtual T find( int uid )const = 0;
/**
* read ahead find
*/
virtual T find( int uid, const QArray<int>& items,
uint current, CacheDirection dir = Forward )const = 0;
+
+ /**
+ * Find in Cache..
+ * Returns empty object if nothing found.
+ */
+ virtual T cacheFind( int uid )const = 0;
+
+ /**
+ * Put element into Cache
+ */
virtual void cache( const T& )const = 0;
virtual void setSaneCacheSize( int ) = 0;
OPimRecord* record()const;
OPimRecord* record(int uid )const;
static T* rec();
+
private:
OTemplateBasePrivate *d;
};
template <class T>
OPimRecord* OTemplateBase<T>::record()const {
T* t = new T;
return t;
}
template <class T>