OSDN Git Service

- Gui cleanup - Rework count threads to reduce SQL overhead & improve performance.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteTagsTable.java
index 2b71bb4..75585ce 100644 (file)
@@ -30,6 +30,7 @@ import cx.fbn.nevernote.utilities.Pair;
 public class NoteTagsTable {\r
        private final ApplicationLogger                 logger;\r
        DatabaseConnection                                              db;\r
+       NSqlQuery                                                               getNoteTagsQuery;\r
 \r
        \r
        // Constructor\r
@@ -55,22 +56,26 @@ public class NoteTagsTable {
        public List<String> getNoteTags(String noteGuid) {\r
                if (noteGuid == null)\r
                        return null;\r
-               boolean check;\r
                List<String> tags = new ArrayList<String>();\r
                \r
-               NSqlQuery query = new NSqlQuery(db.getConnection());\r
-               check = query.exec("Select "\r
-                               +"TagGuid from NoteTags where noteGuid = '" +noteGuid +"'");\r
-               if (!check) {\r
+               if (getNoteTagsQuery == null)\r
+                       prepareGetNoteTagsQuery();\r
+               \r
+               getNoteTagsQuery.bindValue(":guid", noteGuid);\r
+               if (!getNoteTagsQuery.exec()) {\r
                        logger.log(logger.EXTREME, "NoteTags SQL select has failed.");\r
-                       logger.log(logger.MEDIUM, query.lastError());\r
+                       logger.log(logger.MEDIUM, getNoteTagsQuery.lastError());\r
                        return null;\r
                }\r
-               while (query.next()) {\r
-                       tags.add(query.valueString(0));\r
+               while (getNoteTagsQuery.next()) {\r
+                       tags.add(getNoteTagsQuery.valueString(0));\r
                }       \r
                return tags;\r
        }\r
+       void prepareGetNoteTagsQuery() {\r
+               getNoteTagsQuery = new NSqlQuery(db.getConnection());\r
+               getNoteTagsQuery.prepare("Select TagGuid from NoteTags where noteGuid = :guid");\r
+       }\r
        // Get a note tags by the note's Guid\r
        public List<NoteTagsRecord> getAllNoteTags() {\r
                List<NoteTagsRecord> tags = new ArrayList<NoteTagsRecord>();\r