summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimaccesstemplate.h
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h40
1 files changed, 30 insertions, 10 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 );