OSDN Git Service

- Correct issue with importing when not a premium member.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteTable.java
index 2cfeb45..f19deee 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
@@ -255,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
@@ -298,15 +309,20 @@ public class NoteTable {
                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
@@ -371,6 +387,7 @@ public class NoteTable {
        }\r
        // Update a note's title\r
        public void updateNoteTitle(String guid, String title) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteTitle");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set title=:title, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -384,9 +401,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note title has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteTitle");\r
        }\r
        // Update a note's creation date\r
        public void updateNoteCreatedDate(String guid, QDateTime date) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteCreatedDate");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set created=:created, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -402,9 +421,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note creation date has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteCreatedDate");\r
        }\r
        // Update a note's creation date\r
        public void updateNoteAlteredDate(String guid, QDateTime date) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteAlteredDate");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set updated=:altered, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -420,9 +441,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note altered date has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteAlteredDate");\r
        }\r
        // Update a note's creation date\r
        public void updateNoteSubjectDate(String guid, QDateTime date) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteSubjectDate");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set attributeSubjectDate=:altered, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -438,9 +461,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note subject date date has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteSubjectDate");\r
        }\r
        // Update a note's creation date\r
        public void updateNoteAuthor(String guid, String author) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteSubject");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set attributeAuthor=:author, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -456,10 +481,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note author has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
-               \r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteSubject");\r
        }\r
        // Update a note's geo tags\r
        public void updateNoteGeoTags(String guid, Double lon, Double lat, Double alt) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteGeoTags");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set attributeLongitude=:longitude, "+\r
                                "attributeLatitude=:latitude, attributeAltitude=:altitude, isDirty=true where guid=:guid");\r
@@ -478,10 +504,12 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note geo tag has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteGeoTags");\r
                \r
        }\r
        // Update a note's creation date\r
        public void updateNoteSourceUrl(String guid, String url) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteSourceUrl");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set attributeSourceUrl=:url, isDirty=true where guid=:guid");\r
                if (!check) {\r
@@ -497,10 +525,11 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note url has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
-               \r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteSourceUrl");\r
        }\r
        // Update the notebook that a note is assigned to\r
        public void updateNoteNotebook(String guid, String notebookGuid, boolean expungeFromRemote) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteNotebook");\r
                String currentNotebookGuid = new String("");\r
                \r
                \r
@@ -529,10 +558,12 @@ public class NoteTable {
                if (!check) {\r
                        logger.log(logger.EXTREME, "Update note notebook has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
-               };\r
+               }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteNotebook");\r
        }\r
        // Update a note's title\r
        public void updateNoteContent(String guid, String content) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteContent");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                boolean check = query.prepare("Update Note set content=:content, updated=CURRENT_TIMESTAMP(), isDirty=true, indexNeeded=true, " +\r
                                " thumbnailneeded=true where guid=:guid");\r
@@ -552,10 +583,12 @@ public class NoteTable {
                        logger.log(logger.EXTREME, "Update note content has failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteContent");\r
        }\r
 \r
        // Delete a note\r
        public void deleteNote(String guid) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.deleteNote");\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
         query.prepare("Update Note set deleted=CURRENT_TIMESTAMP(), active=false, isDirty=true where guid=:guid");\r
                query.bindValue(":guid", guid);\r
@@ -563,12 +596,14 @@ public class NoteTable {
                        logger.log(logger.MEDIUM, "Note delete failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.deleteNote");\r
        }\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
@@ -576,6 +611,7 @@ public class NoteTable {
        }\r
        // Purge a note (actually delete it instead of just marking it deleted)\r
        public void expungeNote(String guid, boolean permanentExpunge, boolean needsSync) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.expungeNote");\r
                \r
                if (!permanentExpunge) {\r
                        hideExpungedNote(guid, needsSync);\r
@@ -620,7 +656,7 @@ public class NoteTable {
                        DeletedTable deletedTable = new DeletedTable(logger, db);\r
                        deletedTable.addDeletedItem(guid, "Note");\r
                }\r
-\r
+               logger.log(logger.HIGH, "Leaving NoteTable.expungeNote");\r
        }\r
        // Purge a bunch of notes based upon the notebook\r
        public void expungeNotesByNotebook(String notebookGuid, boolean permanentExpunge, boolean needsSync) {\r
@@ -674,6 +710,7 @@ public class NoteTable {
                \r
        // Purge all deleted notes;\r
        public void expungeAllDeletedNotes() {\r
+               logger.log(logger.HIGH, "Entering NoteTable.expungeAllDeletedNotes");\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                query.exec("select guid, updateSequenceNumber from note where active = false");\r
                List<String> guids = new ArrayList<String>();\r
@@ -692,9 +729,11 @@ public class NoteTable {
                        else\r
                                expungeNote(guid, false, true);\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.expungeAllDeletedNotes");\r
        }\r
        // Update the note sequence number\r
        public void updateNoteSequence(String guid, int sequence) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteSequence");\r
                boolean check;\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                check = query.prepare("Update Note set updateSequenceNumber=:sequence where guid=:guid");\r
@@ -707,9 +746,11 @@ public class NoteTable {
                        logger.log(logger.MEDIUM, "Note sequence update failed.");\r
                        logger.log(logger.MEDIUM, query.lastError());\r
                } \r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteSequence");\r
        }\r
        // Update the note Guid\r
        public void updateNoteGuid(String oldGuid, String newGuid) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNoteGuid");\r
                boolean check;\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
         NSqlQuery resQuery = new NSqlQuery(db.getResourceConnection());\r
@@ -751,9 +792,11 @@ public class NoteTable {
                        logger.log(logger.MEDIUM, "Note guid update failed for noteresources.");\r
                        logger.log(logger.MEDIUM, resQuery.lastError());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNoteGuid");\r
        }\r
        // Update a note\r
        public void updateNote(Note n) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.updateNote");\r
                NoteMetadata meta = getNoteMetaInformation(n.getGuid());\r
                String originalGuid = findAlternateGuid(n.getGuid());\r
                expungeNote(n.getGuid(), true, false);\r
@@ -765,6 +808,7 @@ public class NoteTable {
                        updateNoteGuid(n.getGuid(), originalGuid);\r
                        updateNoteGuid(originalGuid, n.getGuid());\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.updateNote");\r
        }\r
        // Does a note exist?\r
        public boolean exists(String guid) {\r
@@ -796,6 +840,7 @@ public class NoteTable {
        }\r
        // This is a convience method to check if a note exists & update/create based upon it\r
        public void syncNote(Note note) {\r
+               logger.log(logger.HIGH, "Entering NoteTable.syncNote");\r
                // If we got the note from Evernote we use its \r
                // metadata instead of the local copy.\r
                NoteMetadata meta = null;\r
@@ -817,6 +862,7 @@ public class NoteTable {
                        meta.setGuid(note.getGuid());\r
                        updateNoteMetadata(meta);\r
                }\r
+               logger.log(logger.HIGH, "Leaving NoteTable.syncNote");\r
        }\r
        // Get a list of notes that need to be updated\r
        public List <Note> getDirty() {\r
@@ -844,6 +890,7 @@ public class NoteTable {
                        tempNote = getNote(index.get(i), true,true,false,true,true);\r
                        notes.add(tempNote);\r
                }\r
+               logger.log(logger.LOW, "Dirty local notes: " +new Integer(notes.size()).toString());\r
                return notes;   \r
        }\r
        // Get a list of notes that need to be updated\r
@@ -872,6 +919,7 @@ public class NoteTable {
                        tempNote = getNote(index.get(i), true,true,false,true,true);\r
                        notes.add(tempNote);\r
                }\r
+               logger.log(logger.LOW, "Dirty linked local notes: " +new Integer(notes.size()).toString());\r
                return notes;   \r
        }\r
        // Get a list of notes that need to be updated\r
@@ -902,6 +950,7 @@ public class NoteTable {
                        tempNote = getNote(index.get(i), true,true,false,true,true);\r
                        notes.add(tempNote);\r
                }\r
+               logger.log(logger.LOW, "Dirty local notes for notebook " +notebookGuid +": " +new Integer(notes.size()).toString());\r
                return notes;   \r
        }\r
        // Get a list of notes that need to be updated\r
@@ -949,6 +998,7 @@ public class NoteTable {
 \r
        // Reset the dirty bit\r
        public void  resetDirtyFlag(String guid) {\r
+               logger.log(logger.LOW, "Resetting dirty flag for " +guid);\r
                NSqlQuery query = new NSqlQuery(db.getConnection());\r
                \r
                query.prepare("Update note set isdirty=false where guid=:guid");\r
@@ -1004,6 +1054,42 @@ public class NoteTable {
                query.exec("select count(guid) from note where isDirty=true and isExpunged = false");\r
                query.next(); \r
                int returnValue = new Integer(query.valueString(0));\r
+               logger.log(logger.LOW, "dirty count: " +returnValue);\r
+               //query.exec("select count(guid) from note where isDirty=true and Active = 0 and isExpunged = false");\r
+               //query.next(); \r
+               //logger.log(logger.LOW, "dirty count (active only): " +query.valueString(0));\r
+               //query.exec("Select count(guid) from Note where isDirty = true and isExpunged = false and notebookGuid not in (select guid from notebook where local = true or linked = true)");\r
+               //query.next(); \r
+               //logger.log(logger.LOW, "dirty count (no l&l notebooks): " +query.valueString(0));\r
+               //logger.log(logger.LOW, "Beginning stack trace");\r
+               //logger.log(logger.LOW, Thread.currentThread().getStackTrace());\r
+\r
+               //logger.log(logger.LOW, "*************************");\r
+               //logger.log(logger.LOW, "*** DIRTY RECORD DUMP ***");\r
+               //logger.log(logger.LOW, "*************************");\r
+               //List<Note> recs = getDirty();\r
+               //for (int i=0; i<recs.size(); i++) {\r
+                       //Note n = getNote(recs.get(i).getGuid(), true, true, true, false, true);\r
+                       //logger.log(logger.LOW, "-- Begin Record ---");\r
+                       //logger.log(logger.LOW, "Guid: " +n.getGuid());\r
+                       //logger.log(logger.LOW, "Title: " +n.getTitle());\r
+                       //logger.log(logger.LOW, "Active: " +n.isActive());\r
+                       //logger.log(logger.LOW, "USN: " +n.getUpdateSequenceNum());\r
+                       //logger.log(logger.LOW, "Date Created: " +n.getCreated());\r
+                       //logger.log(logger.LOW, "Date Updated: " +n.getUpdated());\r
+                       //logger.log(logger.LOW, "Date Deleted: " +n.getDeleted());\r
+                       //logger.log(logger.LOW, "Resource Count: " +n.getResourcesSize());\r
+                       //for (int j=0; j<n.getResourcesSize(); j++) {\r
+                               //Resource r = n.getResources().get(j);\r
+                               //logger.log(logger.LOW, "Resource " +j +": " +r.getGuid());\r
+                               //logger.log(logger.LOW, "Active: " +r.isActive());\r
+                               //logger.log(logger.LOW, "USN: " +r.getUpdateSequenceNum());\r
+                       //}\r
+                       //logger.log(logger.LOW, "-- End Record ---");\r
+               //}\r
+               //logger.log(logger.LOW, "*****************************");\r
+               //logger.log(logger.LOW, "*** End DIRTY RECORD DUMP ***");\r
+               //logger.log(logger.LOW, "*****************************");\r
                return returnValue;\r
        }\r
        // Count notes\r