summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp5
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h4
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h22
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp20
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h2
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h4
6 files changed, 25 insertions, 32 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index abfd944..221e977 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -833,57 +833,60 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
return nonCustomMap;
}
/* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */
OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const
{
// We want to get all contacts with one query.
// We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h).
// All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned
// by using the cache..
QArray<int> cachelist = uidlist;
+ OPimContact retContact;
odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl;
QTime t;
t.start();
int t2needed = 0;
int t3needed = 0;
QTime t2;
t2.start();
FindQuery query( cachelist );
OSQLResult res_noncustom = m_driver->query( &query );
t2needed = t2.elapsed();
QMap<int, QString> nonCustomMap;
QTime t3;
t3.start();
OSQLResultItem resItem = res_noncustom.first();
do {
OPimContact contact( fillNonCustomMap( resItem ) );
contact.setExtraMap( requestCustom( contact.uid() ) );
odebug << "Caching uid: " << contact.uid() << oendl;
cache( contact );
+ if ( contact.uid() == uid )
+ retContact = contact;
resItem = res_noncustom.next();
} while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !!
t3needed = t3.elapsed();
// odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
<< " ms, mapping: " << t3needed << " ms" << oendl;
- return cacheFind( uid );
+ return retContact;
}
QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const
{
QMap<int, QString> nonCustomMap;
// Now loop through all columns
QStringList fieldList = OPimContactFields::untrfields( false );
QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
// Get data for the selected column and store it with the
// corresponding id into the map..
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
index 4f81735..28d9746 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
@@ -63,26 +63,26 @@ class OPimContactAccessBackend_SQL : public OPimContactAccessBackend {
~OPimContactAccessBackend_SQL ();
bool save();
bool load ();
void clear ();
bool wasChangedExternally();
QArray<int> allRecords() const;
- OPimContact find ( int uid ) const;
- OPimContact find( int uid, const QArray<int>&, uint cur, Frontend::CacheDirection ) const;
+ OPimContact find( int uid ) const;
+ OPimContact find( int uid, const QArray<int>& items, uint cur, Frontend::CacheDirection ) const;
QArray<int> queryByExample ( const OPimContact &query, int settings,
const QDateTime& d );
QArray<int> matchRegexp( const QRegExp &r ) const;
const uint querySettings();
bool hasQuerySettings (uint querySettings) const;
// Currently only asc implemented..
QArray<int> sorted( bool asc, int , int , int );
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 15a7b7f..26af762 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -84,27 +84,27 @@ public:
virtual QArray<int> matchRegexp(const QRegExp &r) const = 0;
/**
* queryByExample for T with the given Settings
*
*/
virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
/**
* find the OPimRecord with uid @param uid
* returns T and T.isEmpty() if nothing was found
*/
- virtual T find(int uid )const = 0;
+ virtual T find( int uid )const = 0;
- virtual T find(int uid, const QArray<int>& items,
+ virtual T find( int uid, const QArray<int>& items,
uint current, typename Frontend::CacheDirection ) const;
/**
* clear the back end
*/
virtual void clear() = 0;
/**
* add T
*/
virtual bool add( const T& t ) = 0;
/**
@@ -122,31 +122,24 @@ public:
*/
void setFrontend( Frontend* front );
/**
* set the read ahead count
*/
void setReadAhead( uint count );
protected:
int access()const;
void cache( const T& t )const;
- /**
- * Returns the element with given uid out of the cache.
- * Returns empty element if nothing was found.
- * <b>Attention:</b> This just works if we have a frontend which contains the cache !
- */
- T cacheFind( int uid ) const;
-
/**
* use a prime number here!
*/
void setSaneCacheSize( int );
uint readAhead()const;
private:
OPimAccessBackendPrivate *d;
Frontend* m_front;
uint m_read;
int m_acc;
@@ -164,43 +157,34 @@ OPimAccessBackend<T>::~OPimAccessBackend() {
}
template <class T>
void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
m_front = fr;
}
template <class T>
void OPimAccessBackend<T>::cache( const T& t )const {
if ( m_front )
m_front->cache( t );
}
-template <class T>
-T OPimAccessBackend<T>::cacheFind( int uid )const {
- if ( ! m_front ){
- qWarning ( "No frontend assigned ! Therefore we cannot access the cache to return the right element!" );
- return T();
- }
-
- return m_front->cacheFind( uid );
-}
template <class T>
void OPimAccessBackend<T>::setSaneCacheSize( int size) {
if ( m_front )
m_front->setSaneCacheSize( size );
}
template <class T>
T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
uint, typename Frontend::CacheDirection ) const{
- qDebug( "*** Lookahead feature not supported. Fallback to default find!" );
+ qDebug( "*** Lookahead feature not supported. Fallback to default find!!" );
return find( uid );
}
template <class T>
void OPimAccessBackend<T>::setReadAhead( uint count ) {
m_read = count;
}
template <class T>
uint OPimAccessBackend<T>::readAhead()const {
return m_read;
}
template <class T>
int OPimAccessBackend<T>::access()const {
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 12a8bea..4e3e47b 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -445,25 +445,25 @@ bool OPimTodoAccessBackendSQL::save(){
QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
if (m_dirty )
update();
return m_uids;
}
QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
QArray<int> ints(0);
return ints;
}
OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
- return todo( m_driver->query(&query) );
+ return parseResultAndCache( uid, m_driver->query(&query) );
}
// Remember: uid is already in the list of uids, called ints !
OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
uint cur, Frontend::CacheDirection dir ) const{
uint CACHE = readAhead();
odebug << "searching for " << uid << "" << oendl;
QArray<int> search( CACHE );
uint size =0;
OPimTodo to;
@@ -483,26 +483,25 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
search[size] = ints[i];
size++;
}
break;
}
search.resize( size );
FindQuery query( search );
OSQLResult res = m_driver->query( &query );
if ( res.state() != OSQLResult::Success )
return to;
- todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers)
- return cacheFind( uid );
+ return parseResultAndCache( uid, res );
}
void OPimTodoAccessBackendSQL::clear() {
ClearQuery cle;
OSQLResult res = m_driver->query( &cle );
CreateQuery qu;
res = m_driver->query(&qu);
}
bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
InsertQuery ins( t );
OSQLResult res = m_driver->query( &ins );
@@ -621,42 +620,47 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
if ( str == "0-0-0" )
return false;
else{
int day, year, month;
QStringList list = QStringList::split("-", str );
year = list[0].toInt();
month = list[1].toInt();
day = list[2].toInt();
da.setYMD( year, month, day );
return true;
}
}
-OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
+OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
if ( res.state() == OSQLResult::Failure ) {
OPimTodo to;
return to;
}
+ OPimTodo retTodo;
+
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
odebug << "todo1" << oendl;
OPimTodo to = todo( (*it) );
cache( to );
++it;
for ( ; it != list.end(); ++it ) {
odebug << "caching" << oendl;
- cache( todo( (*it) ) );
+ OPimTodo newTodo = todo( (*it) );
+ cache( newTodo );
+ if ( newTodo.uid() == uid )
+ retTodo = newTodo;
}
- return to;
+ return retTodo;
}
OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
odebug << "todo(ResultItem)" << oendl;
// Request information from addressbook table and create the OPimTodo-object.
bool hasDueDate = false; QDate dueDate = QDate::currentDate();
hasDueDate = date( dueDate, item.data("DueDate") );
QStringList cats = QStringList::split(";", item.data("categories") );
odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
@@ -698,27 +702,29 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
recMap.insert( OPimRecurrence::Created , item.data("Created") );
recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
OPimRecurrence recur;
recur.fromMap( recMap );
to.setRecurrence( recur );
// Finally load the custom-entries for this UID and put it into the created object
to.setExtraMap( requestCustom( to.uid() ) );
return to;
}
+
+// FIXME: Where is the difference to "find" ? (eilers)
OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
FindQuery find( uid );
- return todo( m_driver->query(&find) );
+ return parseResultAndCache( uid, m_driver->query(&find) );
}
/*
* update the dict
*/
void OPimTodoAccessBackendSQL::fillDict() {
#if 0
/* initialize dict */
/*
* UPDATE dict if you change anything!!!
* FIXME: Isn't this dict obsolete ? (eilers)
*/
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0cc7722..415f791 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -66,25 +66,25 @@ public:
const QDate& end, bool includeNoDates );
QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
QBitArray supports()const;
QArray<int> matchRegexp( const QRegExp &r ) const;
void removeAllCompleted();
private:
void update()const;
void fillDict();
inline bool date( QDate& date, const QString& )const;
- inline OPimTodo todo( const Opie::DB::OSQLResult& )const;
+ inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const;
inline OPimTodo todo( Opie::DB::OSQLResultItem& )const;
inline QArray<int> uids( const Opie::DB::OSQLResult& )const;
OPimTodo todo( int uid )const;
QBitArray sup() const;
QMap<QString, QString> requestCustom( int uid ) const;
// QAsciiDict<int> m_dict;
Opie::DB::OSQLDriver* m_driver;
QArray<int> m_uids;
bool m_dirty : 1;
};
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 6f01b46..7ab1ea5 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -110,30 +110,30 @@ public:
*/
virtual List matchRegexp( const QRegExp &r ) const;
/**
* queryByExample.
* @see otodoaccess, ocontactaccess
*/
virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
/**
* find the OPimRecord uid
*/
- virtual T find( int uid )const;
+ T find( int uid )const;
/**
* read ahead cache find method ;)
*/
- virtual T find( int uid, const QArray<int>&,
+ 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.