-rw-r--r-- | libopie/pim/opimaccessbackend.h | 16 | ||||
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 7 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/opimaccessbackend.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 7 |
6 files changed, 44 insertions, 6 deletions
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h index 27d3cb8..0bd2723 100644 --- a/libopie/pim/opimaccessbackend.h +++ b/libopie/pim/opimaccessbackend.h | |||
@@ -62,66 +62,80 @@ public: | |||
62 | * clear the back end | 62 | * clear the back end |
63 | */ | 63 | */ |
64 | virtual void clear() = 0; | 64 | virtual void clear() = 0; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * add T | 67 | * add T |
68 | */ | 68 | */ |
69 | virtual bool add( const T& t ) = 0; | 69 | virtual bool add( const T& t ) = 0; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * remove | 72 | * remove |
73 | */ | 73 | */ |
74 | virtual bool remove( int uid ) = 0; | 74 | virtual bool remove( int uid ) = 0; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * replace a record with T.uid() | 77 | * replace a record with T.uid() |
78 | */ | 78 | */ |
79 | virtual bool replace( const T& t ) = 0; | 79 | virtual bool replace( const T& t ) = 0; |
80 | 80 | ||
81 | /* | 81 | /* |
82 | * setTheFrontEnd!!! | 82 | * setTheFrontEnd!!! |
83 | */ | 83 | */ |
84 | void setFrontend( Frontend* front ); | 84 | void setFrontend( Frontend* front ); |
85 | 85 | ||
86 | /** | ||
87 | * set the read ahead count | ||
88 | */ | ||
89 | void setReadAhead( uint count ); | ||
86 | protected: | 90 | protected: |
87 | void cache( const T& t )const; | 91 | void cache( const T& t )const; |
88 | 92 | ||
89 | /** | 93 | /** |
90 | * use a prime number here! | 94 | * use a prime number here! |
91 | */ | 95 | */ |
92 | void setSaneCacheSize( int ); | 96 | void setSaneCacheSize( int ); |
93 | 97 | ||
98 | uint readAhead()const; | ||
99 | |||
94 | private: | 100 | private: |
95 | Frontend* m_front; | 101 | Frontend* m_front; |
102 | uint m_read; | ||
96 | 103 | ||
97 | }; | 104 | }; |
98 | 105 | ||
99 | template <class T> | 106 | template <class T> |
100 | OPimAccessBackend<T>::OPimAccessBackend() { | 107 | OPimAccessBackend<T>::OPimAccessBackend() { |
101 | m_front = 0l; | 108 | m_front = 0l; |
102 | } | 109 | } |
103 | template <class T> | 110 | template <class T> |
104 | OPimAccessBackend<T>::~OPimAccessBackend() { | 111 | OPimAccessBackend<T>::~OPimAccessBackend() { |
105 | 112 | ||
106 | } | 113 | } |
107 | template <class T> | 114 | template <class T> |
108 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 115 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
109 | m_front = fr; | 116 | m_front = fr; |
110 | } | 117 | } |
111 | template <class T> | 118 | template <class T> |
112 | void OPimAccessBackend<T>::cache( const T& t )const { | 119 | void OPimAccessBackend<T>::cache( const T& t )const { |
113 | if (m_front ) | 120 | if (m_front ) |
114 | m_front->cache( t ); | 121 | m_front->cache( t ); |
115 | } | 122 | } |
116 | template <class T> | 123 | template <class T> |
117 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 124 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
118 | if (m_front ) | 125 | if (m_front ) |
119 | m_front->setSaneCacheSize( size ); | 126 | m_front->setSaneCacheSize( size ); |
120 | } | 127 | } |
121 | template <class T> | 128 | template <class T> |
122 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 129 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
123 | uint, Frontend::CacheDirection )const { | 130 | uint, Frontend::CacheDirection )const { |
124 | return find( uid ); | 131 | return find( uid ); |
125 | } | 132 | } |
126 | 133 | template <class T> | |
134 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | ||
135 | m_read = count; | ||
136 | } | ||
137 | template <class T> | ||
138 | uint OPimAccessBackend<T>::readAhead()const { | ||
139 | return m_read; | ||
140 | } | ||
127 | #endif | 141 | #endif |
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 50cb1e4..c5523a8 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -44,49 +44,49 @@ public: | |||
44 | * rejoin the local changes. Therefore the local database will be set consistent. | 44 | * rejoin the local changes. Therefore the local database will be set consistent. |
45 | */ | 45 | */ |
46 | virtual bool reload(); | 46 | virtual bool reload(); |
47 | 47 | ||
48 | /** Save contacts database. | 48 | /** Save contacts database. |
49 | * Save is more a "commit". After calling this function, all changes are public available. | 49 | * Save is more a "commit". After calling this function, all changes are public available. |
50 | * @return true if successful | 50 | * @return true if successful |
51 | */ | 51 | */ |
52 | virtual bool save(); | 52 | virtual bool save(); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * if the resource was changed externally | 55 | * if the resource was changed externally |
56 | * You should use the signal handling instead of polling possible changes ! | 56 | * You should use the signal handling instead of polling possible changes ! |
57 | * zecke: Do you implement a signal for otodoaccess ? | 57 | * zecke: Do you implement a signal for otodoaccess ? |
58 | */ | 58 | */ |
59 | bool wasChangedExternally()const; | 59 | bool wasChangedExternally()const; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * return a List of records | 62 | * return a List of records |
63 | * you can iterate over them | 63 | * you can iterate over them |
64 | */ | 64 | */ |
65 | virtual List allRecords()const; | 65 | virtual List allRecords()const; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * queryByExample. | 68 | * queryByExample. |
69 | * @see otodoaccess, ocontactaccess | 69 | * @see otodoaccess, ocontactaccess |
70 | */ | 70 | */ |
71 | virtual List queryByExample( const T& t, int querySettings ); | 71 | virtual List queryByExample( const T& t, int querySettings ); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * find the OPimRecord uid | 74 | * find the OPimRecord uid |
75 | */ | 75 | */ |
76 | virtual T find( int uid )const; | 76 | virtual T find( int uid )const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * read ahead cache find method ;) | 79 | * read ahead cache find method ;) |
80 | */ | 80 | */ |
81 | virtual T find( int uid, const QArray<int>&, | 81 | virtual T find( int uid, const QArray<int>&, |
82 | uint current, CacheDirection dir = Forward )const; | 82 | uint current, CacheDirection dir = Forward )const; |
83 | 83 | ||
84 | /* invalidate cache here */ | 84 | /* invalidate cache here */ |
85 | /** | 85 | /** |
86 | * clears the backend and invalidates the backend | 86 | * clears the backend and invalidates the backend |
87 | */ | 87 | */ |
88 | virtual void clear() ; | 88 | virtual void clear() ; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * add T to the backend | 91 | * add T to the backend |
92 | * @param t The item to add. | 92 | * @param t The item to add. |
@@ -95,48 +95,49 @@ public: | |||
95 | virtual bool add( const T& t ) ; | 95 | virtual bool add( const T& t ) ; |
96 | 96 | ||
97 | /* only the uid matters */ | 97 | /* only the uid matters */ |
98 | /** | 98 | /** |
99 | * remove T from the backend | 99 | * remove T from the backend |
100 | * @param t The item to remove | 100 | * @param t The item to remove |
101 | * @return <i>true</i> if successful. | 101 | * @return <i>true</i> if successful. |
102 | */ | 102 | */ |
103 | virtual bool remove( const T& t ); | 103 | virtual bool remove( const T& t ); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * remove the OPimRecord with uid | 106 | * remove the OPimRecord with uid |
107 | * @param uid The ID of the item to remove | 107 | * @param uid The ID of the item to remove |
108 | * @return <i>true</i> if successful. | 108 | * @return <i>true</i> if successful. |
109 | */ | 109 | */ |
110 | virtual bool remove( int uid ); | 110 | virtual bool remove( int uid ); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * replace T from backend | 113 | * replace T from backend |
114 | * @param t The item to replace | 114 | * @param t The item to replace |
115 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
116 | */ | 116 | */ |
117 | virtual bool replace( const T& t) ; | 117 | virtual bool replace( const T& t) ; |
118 | 118 | ||
119 | void setReadAhead( uint count ); | ||
119 | /** | 120 | /** |
120 | * @internal | 121 | * @internal |
121 | */ | 122 | */ |
122 | void cache( const T& )const; | 123 | void cache( const T& )const; |
123 | void setSaneCacheSize( int ); | 124 | void setSaneCacheSize( int ); |
124 | protected: | 125 | protected: |
125 | /** | 126 | /** |
126 | * invalidate the cache | 127 | * invalidate the cache |
127 | */ | 128 | */ |
128 | void invalidateCache(); | 129 | void invalidateCache(); |
129 | 130 | ||
130 | void setBackEnd( BackEnd* end ); | 131 | void setBackEnd( BackEnd* end ); |
131 | /** | 132 | /** |
132 | * returns the backend | 133 | * returns the backend |
133 | */ | 134 | */ |
134 | BackEnd* backEnd(); | 135 | BackEnd* backEnd(); |
135 | BackEnd* m_backEnd; | 136 | BackEnd* m_backEnd; |
136 | Cache m_cache; | 137 | Cache m_cache; |
137 | 138 | ||
138 | }; | 139 | }; |
139 | 140 | ||
140 | template <class T> | 141 | template <class T> |
141 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 142 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
142 | : OTemplateBase<T>(), m_backEnd( end ) | 143 | : OTemplateBase<T>(), m_backEnd( end ) |
@@ -230,25 +231,29 @@ void OPimAccessTemplate<T>::invalidateCache() { | |||
230 | } | 231 | } |
231 | template <class T> | 232 | template <class T> |
232 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 233 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
233 | return m_backEnd; | 234 | return m_backEnd; |
234 | } | 235 | } |
235 | template <class T> | 236 | template <class T> |
236 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 237 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
237 | return false; | 238 | return false; |
238 | } | 239 | } |
239 | template <class T> | 240 | template <class T> |
240 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 241 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
241 | m_backEnd = end; | 242 | m_backEnd = end; |
242 | if (m_backEnd ) | 243 | if (m_backEnd ) |
243 | m_backEnd->setFrontend( this ); | 244 | m_backEnd->setFrontend( this ); |
244 | } | 245 | } |
245 | template <class T> | 246 | template <class T> |
246 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 247 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
247 | /* hacky we need to work around the const*/ | 248 | /* hacky we need to work around the const*/ |
248 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 249 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
249 | } | 250 | } |
250 | template <class T> | 251 | template <class T> |
251 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 252 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
252 | m_cache.setSize( size ); | 253 | m_cache.setSize( size ); |
253 | } | 254 | } |
255 | template <class T> | ||
256 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | ||
257 | m_backEnd->setReadAhead( count ); | ||
258 | } | ||
254 | #endif | 259 | #endif |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 9ef6b7c..8c2ea3a 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -265,51 +265,51 @@ bool OTodoAccessBackendSQL::load(){ | |||
265 | return true; | 265 | return true; |
266 | } | 266 | } |
267 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
268 | return load(); | 268 | return load(); |
269 | } | 269 | } |
270 | 270 | ||
271 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
272 | return m_driver->close(); | 272 | return m_driver->close(); |
273 | } | 273 | } |
274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | 275 | if (m_dirty ) |
276 | update(); | 276 | update(); |
277 | 277 | ||
278 | return m_uids; | 278 | return m_uids; |
279 | } | 279 | } |
280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
281 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
282 | return ints; | 282 | return ints; |
283 | } | 283 | } |
284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
285 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
286 | return todo( m_driver->query(&query) ); | 286 | return todo( m_driver->query(&query) ); |
287 | 287 | ||
288 | } | 288 | } |
289 | #define CACHE 32 | ||
290 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
291 | uint cur, Frontend::CacheDirection dir ) const{ | 290 | uint cur, Frontend::CacheDirection dir ) const{ |
291 | int CACHE = readAhead(); | ||
292 | qWarning("searching for %d", uid ); | 292 | qWarning("searching for %d", uid ); |
293 | QArray<int> search( CACHE ); | 293 | QArray<int> search( CACHE ); |
294 | uint size =0; | 294 | uint size =0; |
295 | OTodo to; | 295 | OTodo to; |
296 | 296 | ||
297 | // we try to cache CACHE items | 297 | // we try to cache CACHE items |
298 | switch( dir ) { | 298 | switch( dir ) { |
299 | /* forward */ | 299 | /* forward */ |
300 | case 0: | 300 | case 0: |
301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
302 | qWarning("size %d %d", size, ints[i] ); | 302 | qWarning("size %d %d", size, ints[i] ); |
303 | search[size] = ints[i]; | 303 | search[size] = ints[i]; |
304 | size++; | 304 | size++; |
305 | } | 305 | } |
306 | break; | 306 | break; |
307 | /* reverse */ | 307 | /* reverse */ |
308 | case 1: | 308 | case 1: |
309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
310 | search[size] = ints[i]; | 310 | search[size] = ints[i]; |
311 | size++; | 311 | size++; |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | } | 314 | } |
315 | search.resize( size ); | 315 | search.resize( size ); |
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index 27d3cb8..0bd2723 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h | |||
@@ -62,66 +62,80 @@ public: | |||
62 | * clear the back end | 62 | * clear the back end |
63 | */ | 63 | */ |
64 | virtual void clear() = 0; | 64 | virtual void clear() = 0; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * add T | 67 | * add T |
68 | */ | 68 | */ |
69 | virtual bool add( const T& t ) = 0; | 69 | virtual bool add( const T& t ) = 0; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * remove | 72 | * remove |
73 | */ | 73 | */ |
74 | virtual bool remove( int uid ) = 0; | 74 | virtual bool remove( int uid ) = 0; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * replace a record with T.uid() | 77 | * replace a record with T.uid() |
78 | */ | 78 | */ |
79 | virtual bool replace( const T& t ) = 0; | 79 | virtual bool replace( const T& t ) = 0; |
80 | 80 | ||
81 | /* | 81 | /* |
82 | * setTheFrontEnd!!! | 82 | * setTheFrontEnd!!! |
83 | */ | 83 | */ |
84 | void setFrontend( Frontend* front ); | 84 | void setFrontend( Frontend* front ); |
85 | 85 | ||
86 | /** | ||
87 | * set the read ahead count | ||
88 | */ | ||
89 | void setReadAhead( uint count ); | ||
86 | protected: | 90 | protected: |
87 | void cache( const T& t )const; | 91 | void cache( const T& t )const; |
88 | 92 | ||
89 | /** | 93 | /** |
90 | * use a prime number here! | 94 | * use a prime number here! |
91 | */ | 95 | */ |
92 | void setSaneCacheSize( int ); | 96 | void setSaneCacheSize( int ); |
93 | 97 | ||
98 | uint readAhead()const; | ||
99 | |||
94 | private: | 100 | private: |
95 | Frontend* m_front; | 101 | Frontend* m_front; |
102 | uint m_read; | ||
96 | 103 | ||
97 | }; | 104 | }; |
98 | 105 | ||
99 | template <class T> | 106 | template <class T> |
100 | OPimAccessBackend<T>::OPimAccessBackend() { | 107 | OPimAccessBackend<T>::OPimAccessBackend() { |
101 | m_front = 0l; | 108 | m_front = 0l; |
102 | } | 109 | } |
103 | template <class T> | 110 | template <class T> |
104 | OPimAccessBackend<T>::~OPimAccessBackend() { | 111 | OPimAccessBackend<T>::~OPimAccessBackend() { |
105 | 112 | ||
106 | } | 113 | } |
107 | template <class T> | 114 | template <class T> |
108 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 115 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
109 | m_front = fr; | 116 | m_front = fr; |
110 | } | 117 | } |
111 | template <class T> | 118 | template <class T> |
112 | void OPimAccessBackend<T>::cache( const T& t )const { | 119 | void OPimAccessBackend<T>::cache( const T& t )const { |
113 | if (m_front ) | 120 | if (m_front ) |
114 | m_front->cache( t ); | 121 | m_front->cache( t ); |
115 | } | 122 | } |
116 | template <class T> | 123 | template <class T> |
117 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 124 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
118 | if (m_front ) | 125 | if (m_front ) |
119 | m_front->setSaneCacheSize( size ); | 126 | m_front->setSaneCacheSize( size ); |
120 | } | 127 | } |
121 | template <class T> | 128 | template <class T> |
122 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 129 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
123 | uint, Frontend::CacheDirection )const { | 130 | uint, Frontend::CacheDirection )const { |
124 | return find( uid ); | 131 | return find( uid ); |
125 | } | 132 | } |
126 | 133 | template <class T> | |
134 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | ||
135 | m_read = count; | ||
136 | } | ||
137 | template <class T> | ||
138 | uint OPimAccessBackend<T>::readAhead()const { | ||
139 | return m_read; | ||
140 | } | ||
127 | #endif | 141 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 9ef6b7c..8c2ea3a 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -265,51 +265,51 @@ bool OTodoAccessBackendSQL::load(){ | |||
265 | return true; | 265 | return true; |
266 | } | 266 | } |
267 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
268 | return load(); | 268 | return load(); |
269 | } | 269 | } |
270 | 270 | ||
271 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
272 | return m_driver->close(); | 272 | return m_driver->close(); |
273 | } | 273 | } |
274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | 275 | if (m_dirty ) |
276 | update(); | 276 | update(); |
277 | 277 | ||
278 | return m_uids; | 278 | return m_uids; |
279 | } | 279 | } |
280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
281 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
282 | return ints; | 282 | return ints; |
283 | } | 283 | } |
284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
285 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
286 | return todo( m_driver->query(&query) ); | 286 | return todo( m_driver->query(&query) ); |
287 | 287 | ||
288 | } | 288 | } |
289 | #define CACHE 32 | ||
290 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
291 | uint cur, Frontend::CacheDirection dir ) const{ | 290 | uint cur, Frontend::CacheDirection dir ) const{ |
291 | int CACHE = readAhead(); | ||
292 | qWarning("searching for %d", uid ); | 292 | qWarning("searching for %d", uid ); |
293 | QArray<int> search( CACHE ); | 293 | QArray<int> search( CACHE ); |
294 | uint size =0; | 294 | uint size =0; |
295 | OTodo to; | 295 | OTodo to; |
296 | 296 | ||
297 | // we try to cache CACHE items | 297 | // we try to cache CACHE items |
298 | switch( dir ) { | 298 | switch( dir ) { |
299 | /* forward */ | 299 | /* forward */ |
300 | case 0: | 300 | case 0: |
301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
302 | qWarning("size %d %d", size, ints[i] ); | 302 | qWarning("size %d %d", size, ints[i] ); |
303 | search[size] = ints[i]; | 303 | search[size] = ints[i]; |
304 | size++; | 304 | size++; |
305 | } | 305 | } |
306 | break; | 306 | break; |
307 | /* reverse */ | 307 | /* reverse */ |
308 | case 1: | 308 | case 1: |
309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
310 | search[size] = ints[i]; | 310 | search[size] = ints[i]; |
311 | size++; | 311 | size++; |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | } | 314 | } |
315 | search.resize( size ); | 315 | search.resize( size ); |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 50cb1e4..c5523a8 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -44,49 +44,49 @@ public: | |||
44 | * rejoin the local changes. Therefore the local database will be set consistent. | 44 | * rejoin the local changes. Therefore the local database will be set consistent. |
45 | */ | 45 | */ |
46 | virtual bool reload(); | 46 | virtual bool reload(); |
47 | 47 | ||
48 | /** Save contacts database. | 48 | /** Save contacts database. |
49 | * Save is more a "commit". After calling this function, all changes are public available. | 49 | * Save is more a "commit". After calling this function, all changes are public available. |
50 | * @return true if successful | 50 | * @return true if successful |
51 | */ | 51 | */ |
52 | virtual bool save(); | 52 | virtual bool save(); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * if the resource was changed externally | 55 | * if the resource was changed externally |
56 | * You should use the signal handling instead of polling possible changes ! | 56 | * You should use the signal handling instead of polling possible changes ! |
57 | * zecke: Do you implement a signal for otodoaccess ? | 57 | * zecke: Do you implement a signal for otodoaccess ? |
58 | */ | 58 | */ |
59 | bool wasChangedExternally()const; | 59 | bool wasChangedExternally()const; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * return a List of records | 62 | * return a List of records |
63 | * you can iterate over them | 63 | * you can iterate over them |
64 | */ | 64 | */ |
65 | virtual List allRecords()const; | 65 | virtual List allRecords()const; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * queryByExample. | 68 | * queryByExample. |
69 | * @see otodoaccess, ocontactaccess | 69 | * @see otodoaccess, ocontactaccess |
70 | */ | 70 | */ |
71 | virtual List queryByExample( const T& t, int querySettings ); | 71 | virtual List queryByExample( const T& t, int querySettings ); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * find the OPimRecord uid | 74 | * find the OPimRecord uid |
75 | */ | 75 | */ |
76 | virtual T find( int uid )const; | 76 | virtual T find( int uid )const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * read ahead cache find method ;) | 79 | * read ahead cache find method ;) |
80 | */ | 80 | */ |
81 | virtual T find( int uid, const QArray<int>&, | 81 | virtual T find( int uid, const QArray<int>&, |
82 | uint current, CacheDirection dir = Forward )const; | 82 | uint current, CacheDirection dir = Forward )const; |
83 | 83 | ||
84 | /* invalidate cache here */ | 84 | /* invalidate cache here */ |
85 | /** | 85 | /** |
86 | * clears the backend and invalidates the backend | 86 | * clears the backend and invalidates the backend |
87 | */ | 87 | */ |
88 | virtual void clear() ; | 88 | virtual void clear() ; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * add T to the backend | 91 | * add T to the backend |
92 | * @param t The item to add. | 92 | * @param t The item to add. |
@@ -95,48 +95,49 @@ public: | |||
95 | virtual bool add( const T& t ) ; | 95 | virtual bool add( const T& t ) ; |
96 | 96 | ||
97 | /* only the uid matters */ | 97 | /* only the uid matters */ |
98 | /** | 98 | /** |
99 | * remove T from the backend | 99 | * remove T from the backend |
100 | * @param t The item to remove | 100 | * @param t The item to remove |
101 | * @return <i>true</i> if successful. | 101 | * @return <i>true</i> if successful. |
102 | */ | 102 | */ |
103 | virtual bool remove( const T& t ); | 103 | virtual bool remove( const T& t ); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * remove the OPimRecord with uid | 106 | * remove the OPimRecord with uid |
107 | * @param uid The ID of the item to remove | 107 | * @param uid The ID of the item to remove |
108 | * @return <i>true</i> if successful. | 108 | * @return <i>true</i> if successful. |
109 | */ | 109 | */ |
110 | virtual bool remove( int uid ); | 110 | virtual bool remove( int uid ); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * replace T from backend | 113 | * replace T from backend |
114 | * @param t The item to replace | 114 | * @param t The item to replace |
115 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
116 | */ | 116 | */ |
117 | virtual bool replace( const T& t) ; | 117 | virtual bool replace( const T& t) ; |
118 | 118 | ||
119 | void setReadAhead( uint count ); | ||
119 | /** | 120 | /** |
120 | * @internal | 121 | * @internal |
121 | */ | 122 | */ |
122 | void cache( const T& )const; | 123 | void cache( const T& )const; |
123 | void setSaneCacheSize( int ); | 124 | void setSaneCacheSize( int ); |
124 | protected: | 125 | protected: |
125 | /** | 126 | /** |
126 | * invalidate the cache | 127 | * invalidate the cache |
127 | */ | 128 | */ |
128 | void invalidateCache(); | 129 | void invalidateCache(); |
129 | 130 | ||
130 | void setBackEnd( BackEnd* end ); | 131 | void setBackEnd( BackEnd* end ); |
131 | /** | 132 | /** |
132 | * returns the backend | 133 | * returns the backend |
133 | */ | 134 | */ |
134 | BackEnd* backEnd(); | 135 | BackEnd* backEnd(); |
135 | BackEnd* m_backEnd; | 136 | BackEnd* m_backEnd; |
136 | Cache m_cache; | 137 | Cache m_cache; |
137 | 138 | ||
138 | }; | 139 | }; |
139 | 140 | ||
140 | template <class T> | 141 | template <class T> |
141 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 142 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
142 | : OTemplateBase<T>(), m_backEnd( end ) | 143 | : OTemplateBase<T>(), m_backEnd( end ) |
@@ -230,25 +231,29 @@ void OPimAccessTemplate<T>::invalidateCache() { | |||
230 | } | 231 | } |
231 | template <class T> | 232 | template <class T> |
232 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 233 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
233 | return m_backEnd; | 234 | return m_backEnd; |
234 | } | 235 | } |
235 | template <class T> | 236 | template <class T> |
236 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 237 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
237 | return false; | 238 | return false; |
238 | } | 239 | } |
239 | template <class T> | 240 | template <class T> |
240 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 241 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
241 | m_backEnd = end; | 242 | m_backEnd = end; |
242 | if (m_backEnd ) | 243 | if (m_backEnd ) |
243 | m_backEnd->setFrontend( this ); | 244 | m_backEnd->setFrontend( this ); |
244 | } | 245 | } |
245 | template <class T> | 246 | template <class T> |
246 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 247 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
247 | /* hacky we need to work around the const*/ | 248 | /* hacky we need to work around the const*/ |
248 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 249 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
249 | } | 250 | } |
250 | template <class T> | 251 | template <class T> |
251 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 252 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
252 | m_cache.setSize( size ); | 253 | m_cache.setSize( size ); |
253 | } | 254 | } |
255 | template <class T> | ||
256 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | ||
257 | m_backEnd->setReadAhead( count ); | ||
258 | } | ||
254 | #endif | 259 | #endif |