OSDN Git Service

Correct problem where altering a tag for a note may not set the note as dirty.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteTable.java
index 0901a8b..54da38b 100644 (file)
@@ -151,6 +151,16 @@ public class NoteTable {
                        query.bindValue(":attributeSource", n.getAttributes().getSource());\r
                        query.bindValue(":attributeSourceUrl", n.getAttributes().getSourceURL());\r
                        query.bindValue(":attributeSourceApplication", n.getAttributes().getSourceApplication());\r
+               } else {\r
+                       created = new StringBuilder(simple.format(n.getCreated()));     \r
+                       query.bindValue(":attributeSubjectDate", created.toString());\r
+                       query.bindValue(":attributeLatitude", 0.0);\r
+                       query.bindValue(":attributeLongitude", 0.0);\r
+                       query.bindValue(":attributeAltitude", 0.0);\r
+                       query.bindValue(":attributeAuthor", "");\r
+                       query.bindValue(":attributeSource", "");\r
+                       query.bindValue(":attributeSourceUrl", "");\r
+                       query.bindValue(":attributeSourceApplication", "");\r
                }\r
                query.bindValue(":indexNeeded", true);\r
                query.bindValue(":isExpunged", false);\r
@@ -176,6 +186,7 @@ public class NoteTable {
                                        +"created, updated, deleted, active, notebookGuid, "\r
                                        +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
                                        +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+                                       +"attributeContentClass, "\r
                                        +"content, contentHash, contentLength"\r
                                        +" from Note where guid=:guid and isExpunged=false")) {\r
                                                logger.log(logger.EXTREME, "Note SQL select prepare with content has failed.");\r
@@ -189,7 +200,8 @@ public class NoteTable {
                                        +"guid, updateSequenceNumber, title, "\r
                                        +"created, updated, deleted, active, notebookGuid, "\r
                                        +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
-                                       +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+                                       +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+                                       +"attributeContentClass"\r
                                        +" from Note where guid=:guid and isExpunged=false")) {\r
                                                logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
                                                logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
@@ -203,7 +215,8 @@ public class NoteTable {
                                +"guid, updateSequenceNumber, title, "\r
                                +"created, updated, deleted, active, notebookGuid, "\r
                                +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
-                               +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+                               +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+                               +"attributeContentClass "\r
                                +" from Note where isExpunged = false")) {\r
                                logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
                                        logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
@@ -252,6 +265,7 @@ public class NoteTable {
                }\r
                Note n = mapNoteFromQuery(query, loadContent, loadResources, loadRecognition, loadBinary, loadTags);\r
                n.setContent(fixCarriageReturn(n.getContent()));\r
+               n.getAttributes().setContentClassIsSet(false);\r
                return n;\r
        }\r
        // Get a note by Guid\r
@@ -292,23 +306,29 @@ public class NoteTable {
                na.setSource(query.valueString(13));\r
                na.setSourceURL(query.valueString(14));\r
                na.setSourceApplication(query.valueString(15));\r
+               na.setContentClass(query.valueString(16));\r
                \r
                if (loadTags) {\r
-                       n.setTagGuids(noteTagsTable.getNoteTags(n.getGuid()));\r
+                       List<String> tagGuids = noteTagsTable.getNoteTags(n.getGuid());\r
                        List<String> tagNames = new ArrayList<String>();\r
                        TagTable tagTable = db.getTagTable();\r
-                       for (int i=0; i<n.getTagGuids().size(); i++) {\r
-                               String currentGuid = n.getTagGuids().get(i);\r
+                       for (int i=0; i<tagGuids.size(); i++) {\r
+                               String currentGuid = tagGuids.get(i);\r
                                Tag tag = tagTable.getTag(currentGuid);\r
-                               tagNames.add(tag.getName());\r
+                               if (tag.getName() != null)\r
+                                       tagNames.add(tag.getName());\r
+                               else\r
+                                       tagNames.add("");\r
                        }\r
+\r
                        n.setTagNames(tagNames);\r
+                       n.setTagGuids(tagGuids);                \r
                }\r
                \r
                if (loadContent) {\r
                        QTextCodec codec = QTextCodec.codecForLocale();\r
                        codec = QTextCodec.codecForName("UTF-8");\r
-               String unicode =  codec.fromUnicode(query.valueString(16)).toString();\r
+               String unicode =  codec.fromUnicode(query.valueString(17)).toString();\r
 \r
                // This is a hack.  Basically I need to convert HTML Entities to "normal" text, but if I\r
                // convert the &lt; character to < it will mess up the XML parsing.  So, to get around this\r
@@ -316,7 +336,7 @@ public class NoteTable {
                // I'm done I convert it back.\r
                StringBuffer buffer = new StringBuffer(unicode);\r
                if (Global.enableHTMLEntitiesFix && unicode.indexOf("&#") > 0) {\r
-                       unicode = query.valueString(16);\r
+                       unicode = query.valueString(17);\r
                        //System.out.println(unicode);\r
                        //unicode = unicode.replace("&lt;", "&_lt;");\r
                        //unicode = codec.fromUnicode(StringEscapeUtils.unescapeHtml(unicode)).toString();\r
@@ -343,10 +363,10 @@ public class NoteTable {
                n.setContent(unicode);\r
 //                     n.setContent(query.valueString(16).toString());\r
                        \r
-                       String contentHash = query.valueString(17);\r
+                       String contentHash = query.valueString(18);\r
                        if (contentHash != null)\r
                                n.setContentHash(contentHash.getBytes());\r
-                       n.setContentLength(new Integer(query.valueString(18)));\r
+                       n.setContentLength(new Integer(query.valueString(19)));\r
                }\r
                if (loadResources)\r
                        n.setResources(noteResourceTable.getNoteResources(n.getGuid(), loadBinary));\r
@@ -562,9 +582,10 @@ public class NoteTable {
        }\r
        public void restoreNote(String guid) {\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
-               query.prepare("Update Note set deleted='1969-12-31 19.00.00', active=true, isDirty=true where guid=:guid");\r
+               query.prepare("Update Note set deleted=:reset, active=true, isDirty=true where guid=:guid");\r
 //             query.prepare("Update Note set deleted=0, active=true, isDirty=true where guid=:guid");\r
                query.bindValue(":guid", guid);\r
+               query.bindValue(":reset", "1969-12-31 19:00:00");\r
                if (!query.exec()) {\r
                        logger.log(logger.MEDIUM, "Note restore failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r