OSDN Git Service

Allow customizing of notebook icons.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NotebookTable.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 \r
21 package cx.fbn.nevernote.sql;\r
22 \r
23 import java.text.DateFormat;\r
24 import java.text.ParseException;\r
25 import java.text.SimpleDateFormat;\r
26 import java.util.ArrayList;\r
27 import java.util.HashMap;\r
28 import java.util.List;\r
29 \r
30 import com.evernote.edam.type.Notebook;\r
31 import com.trolltech.qt.core.QBuffer;\r
32 import com.trolltech.qt.core.QByteArray;\r
33 import com.trolltech.qt.core.QIODevice;\r
34 import com.trolltech.qt.gui.QIcon;\r
35 import com.trolltech.qt.gui.QImage;\r
36 import com.trolltech.qt.gui.QPixmap;\r
37 \r
38 import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
39 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
40 import cx.fbn.nevernote.utilities.Pair;\r
41 \r
42 public class NotebookTable {\r
43         \r
44         private final ApplicationLogger                 logger;\r
45         DatabaseConnection                                                      db;\r
46         \r
47         // Constructor\r
48         public NotebookTable(ApplicationLogger l, DatabaseConnection d) {\r
49                 logger = l;\r
50                 db = d;\r
51         }\r
52         // Create the table\r
53         public void createTable() {\r
54                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
55         logger.log(logger.HIGH, "Creating table Notebook...");\r
56         if (!query.exec("Create table Notebook (guid varchar primary key, " +\r
57                         "sequence integer, " +\r
58                         "name varchar, "+\r
59                         "defaultNotebook varchar, "+\r
60                         "serviceCreated timestamp, " +\r
61                         "serviceUpdated timestamp, "+\r
62                         "published boolean, "+\r
63                         "isDirty boolean, "+\r
64                         "autoEncrypt boolean, "+\r
65                         "local boolean, "+\r
66                         "archived boolean)"))                           \r
67                 logger.log(logger.HIGH, "Table Notebook creation FAILED!!!");   \r
68         Notebook newnote = new Notebook();\r
69         newnote.setDefaultNotebook(true);\r
70         newnote.setName("My Notebook");\r
71         newnote.setPublished(false);\r
72         newnote.setGuid("1");\r
73         addNotebook(newnote, true, false);\r
74                 \r
75         }\r
76         // Drop the table\r
77         public void dropTable() {\r
78                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
79                 query.exec("Drop table Notebook");\r
80         }\r
81         // Save an individual notebook\r
82         public void addNotebook(Notebook tempNotebook, boolean isDirty, boolean local) {\r
83                 boolean check;\r
84                 \r
85                 SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
86         NSqlQuery query = new NSqlQuery(db.getConnection());\r
87                 check = query.prepare("Insert Into Notebook (guid, sequence, name, defaultNotebook, "\r
88                                 +"serviceCreated, serviceUpdated, published, "   \r
89                                 + "isDirty, autoEncrypt," \r
90                                 + "local, archived) Values("\r
91                                 +":guid, :sequence, :name, :defaultNotebook,  "\r
92                                 +":serviceCreated, :serviceUpdated, :published, "\r
93                                 +":isDirty, :autoEncrypt, "\r
94                                 +":local, false)");\r
95                 query.bindValue(":guid", tempNotebook.getGuid());\r
96                 query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());\r
97                 query.bindValue(":name", tempNotebook.getName());\r
98                 query.bindValue(":defaultNotebook", tempNotebook.isDefaultNotebook());\r
99                 \r
100                 StringBuilder serviceCreated = new StringBuilder(simple.format(tempNotebook.getServiceCreated()));                      \r
101                 StringBuilder serviceUpdated = new StringBuilder(simple.format(tempNotebook.getServiceUpdated()));\r
102                 if (serviceUpdated.toString() == null)\r
103                         serviceUpdated = serviceCreated;\r
104                 query.bindValue(":serviceCreated", serviceCreated.toString());\r
105                 query.bindValue(":serviceUpdated", serviceCreated.toString());\r
106                 query.bindValue(":published",tempNotebook.isPublished());\r
107                 \r
108                 if (isDirty)\r
109                         query.bindValue(":isDirty", true);\r
110                 else\r
111                         query.bindValue(":isDirty", false);\r
112                 query.bindValue(":autoEncrypt", false);\r
113                 query.bindValue(":local", local);\r
114 \r
115                 check = query.exec();\r
116                 if (!check) {\r
117                         logger.log(logger.MEDIUM, "Notebook Table insert failed.");\r
118                         logger.log(logger.MEDIUM, query.lastError().toString());\r
119                 }\r
120         }\r
121         // Delete the notebook based on a guid\r
122         public void expungeNotebook(String guid, boolean needsSync) {\r
123                 boolean check;\r
124         NSqlQuery query = new NSqlQuery(db.getConnection());\r
125 \r
126         check = query.prepare("delete from Notebook "\r
127                                 +"where guid=:guid");\r
128                 if (!check) {\r
129                         logger.log(logger.EXTREME, "Notebook SQL delete prepare has failed.");\r
130                         logger.log(logger.EXTREME, query.lastError().toString());\r
131                 }\r
132                 query.bindValue(":guid", guid);\r
133                 check = query.exec();\r
134                 if (!check) \r
135                         logger.log(logger.MEDIUM, "Notebook delete failed.");\r
136                 \r
137                 // Signal the parent that work needs to be done\r
138                 if  (needsSync) {\r
139                         DeletedTable deletedTable = new DeletedTable(logger, db);\r
140                         deletedTable.addDeletedItem(guid, "Notebook");\r
141                 }\r
142         }\r
143         // Update a notebook\r
144         public void updateNotebook(Notebook tempNotebook, boolean isDirty) {\r
145                 boolean check;\r
146                 \r
147                 SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
148                 \r
149         NSqlQuery query = new NSqlQuery(db.getConnection());\r
150         check = query.prepare("Update Notebook set sequence=:sequence, name=:name, defaultNotebook=:defaultNotebook, " +\r
151                         "serviceCreated=:serviceCreated, serviceUpdated=:serviceUpdated, "+\r
152                                 "published=:published, isDirty=:isDirty where guid=:guid ");\r
153                 query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());\r
154                 query.bindValue(":name", tempNotebook.getName());\r
155                 query.bindValue(":defaultNotebook", tempNotebook.isDefaultNotebook());\r
156 \r
157                 StringBuilder serviceCreated = new StringBuilder(simple.format(tempNotebook.getServiceCreated()));                      \r
158                 StringBuilder serviceUpdated = new StringBuilder(simple.format(tempNotebook.getServiceUpdated()));                      \r
159                 query.bindValue(":serviceCreated", serviceCreated.toString());\r
160                 query.bindValue(":serviceUpdated", serviceUpdated.toString());\r
161                 \r
162                 query.bindValue(":published", tempNotebook.isPublished());\r
163                 query.bindValue(":isDirty", isDirty);\r
164                 query.bindValue(":guid", tempNotebook.getGuid());\r
165                 \r
166                 check = query.exec();\r
167                 if (!check) {\r
168                         logger.log(logger.MEDIUM, "Notebook Table update failed.");\r
169                         logger.log(logger.MEDIUM, query.lastError().toString());\r
170                 }\r
171         }\r
172         // Load notebooks from the database\r
173         public List<Notebook> getAll() {\r
174                 Notebook tempNotebook;\r
175                 List<Notebook> index = new ArrayList<Notebook>();\r
176                 boolean check;\r
177                                         \r
178         NSqlQuery query = new NSqlQuery(db.getConnection());\r
179                                         \r
180                 check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
181                                 "serviceCreated, "+\r
182                                 "serviceUpdated, "+\r
183                                 "published, defaultNotebook from Notebook order by name");\r
184                 if (!check)\r
185                         logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
186                 while (query.next()) {\r
187                         tempNotebook = new Notebook();\r
188                         tempNotebook.setGuid(query.valueString(0));\r
189                         int sequence = new Integer(query.valueString(1)).intValue();\r
190                         tempNotebook.setUpdateSequenceNum(sequence);\r
191                         tempNotebook.setName(query.valueString(2));\r
192                         DateFormat indfm = null;\r
193                         try {\r
194                                 indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
195 //                              indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");\r
196                         } catch (Exception e) { }\r
197                         try {\r
198                                 tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());\r
199                                 tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());\r
200                         } catch (ParseException e) {\r
201                                 e.printStackTrace();\r
202                         }\r
203                         tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
204                         tempNotebook.setDefaultNotebook(new Boolean(query.valueString(7)));\r
205                         index.add(tempNotebook); \r
206                 }       \r
207                 return index;\r
208         }       \r
209         public List<Notebook> getAllLocal() {\r
210                 Notebook tempNotebook;\r
211                 List<Notebook> index = new ArrayList<Notebook>();\r
212                 boolean check;\r
213 \r
214         NSqlQuery query = new NSqlQuery(db.getConnection());\r
215                                         \r
216                 check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
217                                 "serviceCreated, serviceUpdated, published from Notebook where local=true order by name");\r
218                 if (!check)\r
219                         logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
220                 while (query.next()) {\r
221                         tempNotebook = new Notebook();\r
222                         tempNotebook.setGuid(query.valueString(0));\r
223                         int sequence = new Integer(query.valueString(1)).intValue();\r
224                         tempNotebook.setUpdateSequenceNum(sequence);\r
225                         tempNotebook.setName(query.valueString(2));\r
226                         \r
227                         DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
228 //                      indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");\r
229                         try {\r
230                                 tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());\r
231                                 tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());\r
232                         } catch (ParseException e) {\r
233                                 e.printStackTrace();\r
234                         }\r
235                         index.add(tempNotebook); \r
236                 }       \r
237                 return index;\r
238         }\r
239         // Archive or un-archive a notebook\r
240         public void setArchived(String guid, boolean val) {\r
241                 boolean check;                  \r
242         NSqlQuery query = new NSqlQuery(db.getConnection());                                    \r
243                 check = query.prepare("Update notebook set archived=:archived where guid=:guid");\r
244                 if (!check)\r
245                         logger.log(logger.EXTREME, "Notebook SQL archive update has failed.");\r
246                 query.bindValue(":guid", guid);\r
247                 query.bindValue(":archived", val);\r
248                 query.exec();\r
249         }\r
250         // Load non-archived notebooks from the database\r
251         public List<Notebook> getAllArchived() {\r
252                 Notebook tempNotebook;\r
253                 List<Notebook> index = new ArrayList<Notebook>();\r
254                 boolean check;\r
255                                                 \r
256         NSqlQuery query = new NSqlQuery(db.getConnection());\r
257                                         \r
258                 check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
259                                 "serviceCreated, serviceUpdated, published from Notebook where archived=true order by name");\r
260                 if (!check)\r
261                         logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
262                 while (query.next()) {\r
263                         tempNotebook = new Notebook();\r
264                         tempNotebook.setGuid(query.valueString(0));\r
265                         int sequence = new Integer(query.valueString(1)).intValue();\r
266                         tempNotebook.setUpdateSequenceNum(sequence);\r
267                         tempNotebook.setName(query.valueString(2));\r
268                         \r
269                         DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
270 //                      indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");\r
271                         try {\r
272                                 tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());\r
273                                 tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());\r
274                         } catch (ParseException e) {\r
275                                 e.printStackTrace();\r
276                         }\r
277                         tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
278                         index.add(tempNotebook); \r
279                 }       \r
280                 return index;\r
281         }       \r
282         // Check for a local/remote notebook\r
283         public boolean isNotebookLocal(String guid) {\r
284         NSqlQuery query = new NSqlQuery(db.getConnection());\r
285                 \r
286                 query.prepare("Select local from Notebook where guid=:guid");\r
287                 query.bindValue(":guid", guid);\r
288                 query.exec();\r
289                 if (!query.next()) {\r
290                         return false;\r
291                 }\r
292                 boolean returnValue = query.valueBoolean(0, false);\r
293                 return returnValue;\r
294         }\r
295         // Update a notebook sequence number\r
296         public void updateNotebookSequence(String guid, int sequence) {\r
297                 boolean check;\r
298         NSqlQuery query = new NSqlQuery(db.getConnection());\r
299                 check = query.prepare("Update Notebook set sequence=:sequence where guid=:guid");\r
300                 query.bindValue(":guid", guid);\r
301                 query.bindValue(":sequence", sequence);\r
302                 query.exec();\r
303                 if (!check) {\r
304                         logger.log(logger.MEDIUM, "Notebook sequence update failed.");\r
305                         logger.log(logger.MEDIUM, query.lastError());\r
306                 } \r
307         }\r
308         // Update a notebook GUID number\r
309         public void updateNotebookGuid(String oldGuid, String newGuid) {\r
310         NSqlQuery query = new NSqlQuery(db.getConnection());\r
311                 query.prepare("Update Notebook set guid=:newGuid where guid=:oldGuid");\r
312                 query.bindValue(":oldGuid", oldGuid);\r
313                 query.bindValue(":newGuid", newGuid);\r
314                 if (!query.exec()) {\r
315                         logger.log(logger.MEDIUM, "Notebook guid update failed.");\r
316                         logger.log(logger.MEDIUM, query.lastError());\r
317                 } \r
318                 \r
319                 // Update any notes containing the notebook guid\r
320                 query.prepare("Update Note set notebookGuid=:newGuid where notebookGuid=:oldGuid");\r
321                 query.bindValue(":oldGuid", oldGuid);\r
322                 query.bindValue(":newGuid", newGuid);\r
323                 if (!query.exec()) {\r
324                         logger.log(logger.MEDIUM, "Notebook guid update for note failed.");\r
325                         logger.log(logger.MEDIUM, query.lastError());\r
326                 } \r
327                 \r
328                 // Update any watch folders with the new guid\r
329                 query = new NSqlQuery(db.getConnection());\r
330                 query.prepare("Update WatchFolders set notebook=:newGuid where notebook=:oldGuid");\r
331                 query.bindValue(":oldGuid", oldGuid);\r
332                 query.bindValue(":newGuid", newGuid);\r
333                 if (!query.exec()) {\r
334                         logger.log(logger.MEDIUM, "Update WatchFolder notebook failed.");\r
335                         logger.log(logger.MEDIUM, query.lastError().toString());\r
336                 }               \r
337         }\r
338         // Get a list of notes that need to be updated\r
339         public List <Notebook> getDirty() {\r
340                 Notebook tempNotebook;\r
341                 List<Notebook> index = new ArrayList<Notebook>();\r
342                 boolean check;\r
343                                                 \r
344                 \r
345         NSqlQuery query = new NSqlQuery(db.getConnection());\r
346                                         \r
347                 check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
348                                 "serviceCreated, serviceUpdated, published from Notebook where isDirty = true and local=false");\r
349                 if (!check) \r
350                         logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
351                 while (query.next()) {\r
352                         tempNotebook = new Notebook();\r
353                         tempNotebook.setGuid(query.valueString(0));\r
354                         int sequence = new Integer(query.valueString(1)).intValue();\r
355                         tempNotebook.setUpdateSequenceNum(sequence);\r
356                         tempNotebook.setName(query.valueString(2));\r
357                         \r
358                         DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");\r
359 //                      indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");\r
360                         try {\r
361                                 tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());\r
362                                 tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());\r
363                         } catch (ParseException e) {\r
364                                 e.printStackTrace();\r
365                         }\r
366                         tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
367                         index.add(tempNotebook); \r
368                 }       \r
369                 return index;   \r
370         }\r
371         // This is a convience method to check if a tag exists & update/create based upon it\r
372         public void syncNotebook(Notebook notebook, boolean isDirty) {\r
373                 if (!exists(notebook.getGuid())) {\r
374                         addNotebook(notebook, isDirty, isDirty);\r
375                         return;\r
376                 }\r
377                 updateNotebook(notebook, isDirty);\r
378         }\r
379         // does a record exist?\r
380         private boolean exists(String guid) {\r
381                 \r
382                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
383                 \r
384                 query.prepare("Select guid from notebook where guid=:guid");\r
385                 query.bindValue(":guid", guid);\r
386                 if (!query.exec())\r
387                         logger.log(logger.EXTREME, "notebook SQL retrieve has failed.");\r
388                 boolean retval = query.next();\r
389                 return retval;\r
390         }\r
391         // Reset the dirty flag.  Typically done after a sync.\r
392         public void  resetDirtyFlag(String guid) {\r
393                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
394                 \r
395                 query.prepare("Update notebook set isdirty='false' where guid=:guid");\r
396                 query.bindValue(":guid", guid);\r
397                 if (!query.exec())\r
398                         logger.log(logger.EXTREME, "Error resetting notebook dirty field.");\r
399         }\r
400         // Set the default notebook\r
401         public void setDefaultNotebook(String guid) {\r
402                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
403                 \r
404                 query.prepare("Update notebook set defaultNotebook=false");\r
405                 if (!query.exec())\r
406                         logger.log(logger.EXTREME, "Error removing default notebook.");\r
407                 query.prepare("Update notebook set defaultNotebook=true where guid = :guid");\r
408                 query.bindValue(":guid", guid);\r
409                 if (!query.exec())\r
410                         logger.log(logger.EXTREME, "Error setting default notebook.");\r
411         }\r
412         \r
413         // Get a list of all icons\r
414         public HashMap<String, QIcon> getAllIcons() {\r
415                 HashMap<String, QIcon> values = new HashMap<String, QIcon>();\r
416                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
417         \r
418                 if (!query.exec("SELECT guid, icon from notebook where ARCHIVED  != true"))\r
419                         logger.log(logger.EXTREME, "Error executing notebook getAllIcons select.");\r
420                 while (query.next()) {\r
421                         if (query.getBlob(1) != null) {\r
422                                 String guid = query.valueString(0);\r
423                                 QByteArray blob = new QByteArray(query.getBlob(1));\r
424                                 QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
425                                 values.put(guid, icon);\r
426                         }\r
427                 }\r
428                 return values;\r
429         }\r
430         \r
431         // Get the notebooks custom icon\r
432         public QIcon getIcon(String guid) {\r
433                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
434                 \r
435                 if (!query.prepare("Select icon from notebook where guid=:guid"))\r
436                         logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
437                 query.bindValue(":guid", guid);\r
438                 if (!query.exec())\r
439                         logger.log(logger.EXTREME, "Error finding notebook icon.");\r
440                 if (!query.next() || query.getBlob(0) == null)\r
441                         return null;\r
442                 \r
443                 QByteArray blob = new QByteArray(query.getBlob(0));\r
444                 QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
445                 return icon;\r
446         }\r
447         // Set the notebooks custom icon\r
448         public void setIcon(String guid, QIcon icon, String type) {\r
449                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
450                 if (icon == null) {\r
451                         if (!query.prepare("update notebook set icon=null where guid=:guid"))\r
452                                 logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
453                 } else {\r
454                         if (!query.prepare("update notebook set icon=:icon where guid=:guid"))\r
455                                 logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
456                         QBuffer buffer = new QBuffer();\r
457                 if (!buffer.open(QIODevice.OpenModeFlag.ReadWrite)) {\r
458                         logger.log(logger.EXTREME, "Failure to open buffer.  Aborting.");\r
459                         return;\r
460                 }\r
461                 QPixmap p = icon.pixmap(32, 32);\r
462                 QImage i = p.toImage();\r
463                 i.save(buffer, type.toUpperCase());\r
464                 buffer.close();\r
465                 QByteArray b = new QByteArray(buffer.buffer());\r
466                 if (!b.isNull() && !b.isEmpty())\r
467                         query.bindValue(":icon", b.toByteArray());\r
468                 else\r
469                         return;\r
470                 }\r
471                 query.bindValue(":guid", guid);\r
472                 if (!query.exec()) \r
473                         logger.log(logger.LOW, "Error setting notebook icon. " +query.lastError());\r
474         }\r
475 \r
476         // does a record exist?\r
477         public String findNotebookByName(String newname) {\r
478                 \r
479                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
480                 \r
481                 query.prepare("Select guid from notebook where name=:newname");\r
482                 query.bindValue(":newname", newname);\r
483                 if (!query.exec())\r
484                         logger.log(logger.EXTREME, "notebook SQL retrieve has failed.");\r
485                 String val = null;\r
486                 if (query.next())\r
487                         val = query.valueString(0);\r
488                 return val;\r
489         }\r
490         // Get a note tag counts\r
491         public List<Pair<String,Integer>> getNotebookCounts() {\r
492                 List<Pair<String,Integer>> counts = new ArrayList<Pair<String,Integer>>();              \r
493                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
494                 if (!query.exec("select notebookGuid, count(guid) from note where active=1 group by notebookguid;")) {\r
495                         logger.log(logger.EXTREME, "NoteTags SQL getTagCounts has failed.");\r
496                         logger.log(logger.MEDIUM, query.lastError());\r
497                         return null;\r
498                 }\r
499                 while (query.next()) {\r
500                         Pair<String,Integer> newCount = new Pair<String,Integer>();\r
501                         newCount.setFirst(query.valueString(0));\r
502                         newCount.setSecond(query.valueInteger(1));\r
503                         counts.add(newCount);\r
504                 }       \r
505                 return counts;\r
506         }\r
507 \r
508 }\r
509 \r