-rw-r--r-- | libopie/pim/opimcache.h | 4 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 81 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 81 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcache.h | 4 |
6 files changed, 162 insertions, 14 deletions
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h index 067f6e7..839550c 100644 --- a/libopie/pim/opimcache.h +++ b/libopie/pim/opimcache.h @@ -62,5 +62,7 @@ void OPimCacheItem<T>::setRecord( const T& t ) { // Cache template <class T> -OPimCache<T>::OPimCache() { +OPimCache<T>::OPimCache() + : m_cache(100, 53 ) +{ m_cache.setAutoDelete( TRUE ); } diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -82,7 +82,11 @@ namespace { public: FindQuery(int uid); + FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: + QString single()const; + QString multi()const; + QArray<int> m_uids; int m_uid; }; @@ -139,4 +143,5 @@ namespace { */ QString InsertQuery::query()const{ + int year, month, day; year = month = day = 0; @@ -176,11 +181,29 @@ namespace { : OSQLQuery(), m_uid(uid ) { } + FindQuery::FindQuery(const QArray<int>& ints) + : OSQLQuery(), m_uids(ints){ + } FindQuery::~FindQuery() { } QString FindQuery::query()const{ + if (m_uids.count() == 0 ) + return single(); + else + return multi(); + } + QString FindQuery::single()const{ QString qu = "select uid, categories, completed, progress, summary, "; qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); return qu; } + QString FindQuery::multi()const { + QString qu = "select uid, categories, completed, progress, summary, "; + qu += "DueDate, priority, description from todolist where "; + for (uint i = 0; i < m_uids.count(); i++ ) { + qu += " UID = " + QString::number( m_uids[i] ) + " OR"; + } + qu.remove( qu.length()-2, 2 ); + return qu; + } OverDueQuery::OverDueQuery(): OSQLQuery() {} @@ -262,4 +285,37 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{ } +OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, + uint cur, Frontend::CacheDirection dir ) const{ + qWarning("searching for %d", uid ); + QArray<int> search( 8 ); + uint size =0; + OTodo to; + + // we try to cache 8 items + switch( dir ) { + /* forward */ + case 0: + for (uint i = cur; i < ints.count() && size < 8; i++ ) { + qWarning("size %d %d", size, ints[i] ); + search[size] = ints[i]; + size++; + } + break; + /* reverse */ + case 1: + for (uint i = cur; i >= 0 && size < 8; i-- ) { + 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; + + return todo( res ); +} void OTodoAccessBackendSQL::clear() { ClearQuery cle; @@ -394,12 +450,25 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); - + qWarning("todo1"); + OTodo to = todo( (*it) ); + cache( to ); + ++it; + + for ( ; it != list.end(); ++it ) { + qWarning("caching"); + cache( todo( (*it) ) ); + } + return to; +} +OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { + qWarning("todo"); bool has = false; QDate da = QDate::currentDate(); - has = date( da, (*it).data("DueDate") ); - QStringList cats = QStringList::split(";", (*it).data("categories") ); + has = date( da, item.data("DueDate") ); + QStringList cats = QStringList::split(";", item.data("categories") ); - OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), - cats, (*it).data("summary"), (*it).data("description"), - (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); + OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), + cats, item.data("summary"), item.data("description"), + item.data("progress").toUShort(), has, da, + item.data("uid").toInt() ); return to; } diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index 6c5f50a..c1aa2ed 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h @@ -8,4 +8,5 @@ class OSQLDriver; class OSQLResult; +class OSQLResultItem; class OTodoAccessBackendSQL : public OTodoAccessBackend { public: @@ -20,4 +21,5 @@ public: QArray<int> queryByExample( const OTodo& t, int sort ); OTodo find(int uid)const; + OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; void clear(); bool add( const OTodo& t ); @@ -35,4 +37,5 @@ private: inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; + inline OTodo todo( OSQLResultItem& )const; inline QArray<int> uids( const OSQLResult& )const; OTodo todo( int uid )const; diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -82,7 +82,11 @@ namespace { public: FindQuery(int uid); + FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: + QString single()const; + QString multi()const; + QArray<int> m_uids; int m_uid; }; @@ -139,4 +143,5 @@ namespace { */ QString InsertQuery::query()const{ + int year, month, day; year = month = day = 0; @@ -176,11 +181,29 @@ namespace { : OSQLQuery(), m_uid(uid ) { } + FindQuery::FindQuery(const QArray<int>& ints) + : OSQLQuery(), m_uids(ints){ + } FindQuery::~FindQuery() { } QString FindQuery::query()const{ + if (m_uids.count() == 0 ) + return single(); + else + return multi(); + } + QString FindQuery::single()const{ QString qu = "select uid, categories, completed, progress, summary, "; qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); return qu; } + QString FindQuery::multi()const { + QString qu = "select uid, categories, completed, progress, summary, "; + qu += "DueDate, priority, description from todolist where "; + for (uint i = 0; i < m_uids.count(); i++ ) { + qu += " UID = " + QString::number( m_uids[i] ) + " OR"; + } + qu.remove( qu.length()-2, 2 ); + return qu; + } OverDueQuery::OverDueQuery(): OSQLQuery() {} @@ -262,4 +285,37 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{ } +OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, + uint cur, Frontend::CacheDirection dir ) const{ + qWarning("searching for %d", uid ); + QArray<int> search( 8 ); + uint size =0; + OTodo to; + + // we try to cache 8 items + switch( dir ) { + /* forward */ + case 0: + for (uint i = cur; i < ints.count() && size < 8; i++ ) { + qWarning("size %d %d", size, ints[i] ); + search[size] = ints[i]; + size++; + } + break; + /* reverse */ + case 1: + for (uint i = cur; i >= 0 && size < 8; i-- ) { + 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; + + return todo( res ); +} void OTodoAccessBackendSQL::clear() { ClearQuery cle; @@ -394,12 +450,25 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); - + qWarning("todo1"); + OTodo to = todo( (*it) ); + cache( to ); + ++it; + + for ( ; it != list.end(); ++it ) { + qWarning("caching"); + cache( todo( (*it) ) ); + } + return to; +} +OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { + qWarning("todo"); bool has = false; QDate da = QDate::currentDate(); - has = date( da, (*it).data("DueDate") ); - QStringList cats = QStringList::split(";", (*it).data("categories") ); + has = date( da, item.data("DueDate") ); + QStringList cats = QStringList::split(";", item.data("categories") ); - OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), - cats, (*it).data("summary"), (*it).data("description"), - (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); + OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), + cats, item.data("summary"), item.data("description"), + item.data("progress").toUShort(), has, da, + item.data("uid").toInt() ); return to; } diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 6c5f50a..c1aa2ed 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h @@ -8,4 +8,5 @@ class OSQLDriver; class OSQLResult; +class OSQLResultItem; class OTodoAccessBackendSQL : public OTodoAccessBackend { public: @@ -20,4 +21,5 @@ public: QArray<int> queryByExample( const OTodo& t, int sort ); OTodo find(int uid)const; + OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; void clear(); bool add( const OTodo& t ); @@ -35,4 +37,5 @@ private: inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; + inline OTodo todo( OSQLResultItem& )const; inline QArray<int> uids( const OSQLResult& )const; OTodo todo( int uid )const; diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index 067f6e7..839550c 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h @@ -62,5 +62,7 @@ void OPimCacheItem<T>::setRecord( const T& t ) { // Cache template <class T> -OPimCache<T>::OPimCache() { +OPimCache<T>::OPimCache() + : m_cache(100, 53 ) +{ m_cache.setAutoDelete( TRUE ); } |