OSDN Git Service

Add shared notebook editing & syncing logic.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteTable.java
index 59446da..38948cc 100644 (file)
@@ -732,7 +732,7 @@ public class NoteTable {
                boolean check;                  \r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                                        \r
-               check = query.exec("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid not in (select guid from notebook where local = true)");\r
+               check = query.exec("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid not in (select guid from notebook where local = true or linked = true)");\r
                if (!check) \r
                        logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
                \r
@@ -751,6 +751,57 @@ public class NoteTable {
                return notes;   \r
        }\r
        // Get a list of notes that need to be updated\r
+       public List <Note> getDirtyLinked(String notebookGuid) {\r
+               String guid;\r
+               Note tempNote;\r
+               List<Note> notes = new ArrayList<Note>();\r
+               List<String> index = new ArrayList<String>();\r
+               \r
+               boolean check;                  \r
+        NSqlQuery query = new NSqlQuery(db.getConnection());\r
+                                       \r
+               query.prepare("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid=:notebookGuid");\r
+               query.bindValue(":notebookGuid", notebookGuid);\r
+               check = query.exec();\r
+               if (!check) \r
+                       logger.log(logger.EXTREME, "Note SQL retrieve has failed getting dirty linked notes: " +query.lastError().toString());\r
+               \r
+               // Get a list of the notes\r
+               while (query.next()) {\r
+                       guid = new String();\r
+                       guid = query.valueString(0);\r
+                       index.add(guid); \r
+               }       \r
+               \r
+               // Start getting notes\r
+               for (int i=0; i<index.size(); i++) {\r
+                       tempNote = getNote(index.get(i), true,true,false,true,true);\r
+                       notes.add(tempNote);\r
+               }\r
+               return notes;   \r
+       }\r
+       // Get a list of notes that need to be updated\r
+       public List <String> getNotesByNotebook(String notebookGuid) {\r
+               List<String> notes = new ArrayList<String>();\r
+               List<String> index = new ArrayList<String>();\r
+               \r
+               boolean check;                  \r
+        NSqlQuery query = new NSqlQuery(db.getConnection());\r
+                                       \r
+               check = query.prepare("Select guid from Note where notebookguid=:notebookguid");\r
+               if (!check) \r
+                       logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
+               query.bindValue(":notebookguid", notebookGuid);\r
+               query. exec();\r
+               \r
+               // Get a list of the notes\r
+               while (query.next()) {\r
+                       index.add(query.valueString(0)); \r
+               }       \r
+               \r
+               return notes;   \r
+       }\r
+       // Get a list of notes that need to be updated\r
        public boolean isNoteDirty(String guid) {\r
                \r
                boolean check;                  \r
@@ -779,7 +830,7 @@ public class NoteTable {
                boolean check;                  \r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                                        \r
-               check = query.exec("Select guid from Note where isDirty = true");\r
+               check = query.exec("Select guid from Note where isDirty=true");\r
                if (!check) \r
                        logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
                \r
@@ -843,7 +894,7 @@ public class NoteTable {
        // Count unsynchronized notes\r
        public int getDirtyCount() {\r
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
-               query.exec("select count(*) from note where isDirty=true and isExpunged = false");\r
+               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
                return returnValue;\r
@@ -1191,7 +1242,6 @@ public class NoteTable {
        }\r
 \r
        \r
-       \r
        // Update a note content's hash.  This happens if a resource is edited outside of NN\r
        public void updateResourceContentHash(String guid, String oldHash, String newHash) {\r
                Note n = getNote(guid, true, false, false, false,false);\r