OSDN Git Service

- Correct issue with importing when not a premium member.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteResourceTable.java
index 9c612e4..1f24b68 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * This file is part of NeverNote \r
+ * This file is part of NixNote \r
  * Copyright 2009 Randy Baumgarte\r
  * \r
  * This file may be licensed under the terms of of the\r
@@ -37,7 +37,7 @@ public class NoteResourceTable  {
        /**\r
         * \r
         */\r
-       private static final long serialVersionUID = 1L;\r
+//     private static final long serialVersionUID = 1L;\r
        private final ApplicationLogger                 logger;\r
        private final DatabaseConnection                db;     \r
        \r
@@ -82,6 +82,8 @@ public class NoteResourceTable  {
                query.bindValue(":guid", guid);\r
                if (!query.exec())\r
                        logger.log(logger.EXTREME, "Error resetting noteresource dirty field. " +query.lastError());\r
+               else\r
+                       query.exec("commit");\r
        }\r
        // Set if the resource should be indexed\r
        public void  setIndexNeeded(String guid, Boolean indexNeeded) {\r
@@ -91,6 +93,8 @@ public class NoteResourceTable  {
                query.bindValue(":guid", guid);\r
                if (!query.exec())\r
                        logger.log(logger.EXTREME, "Error setting noteresource indexneeded field: " +query.lastError());\r
+               else\r
+                       query.exec("commit");\r
        }\r
        // get any unindexed resource\r
        public List<String> getNextUnindexed(int limit) {\r
@@ -156,8 +160,10 @@ public class NoteResourceTable  {
        }\r
        \r
        public void saveNoteResource(Resource r, boolean isDirty) {\r
-               logger.log(logger.HIGH, "Entering DBRunner.saveNoteResources");\r
+               logger.log(logger.HIGH, "Entering saveNoteResources: isDirty " +isDirty);\r
                boolean check;\r
+               logger.log(logger.HIGH, "Note: " +r.getNoteGuid());\r
+               logger.log(logger.HIGH, "Resource: " +r.getGuid());\r
                NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
                SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
                \r
@@ -184,9 +190,8 @@ public class NoteResourceTable  {
                        query.bindValue(":guid", r.getGuid());\r
                        query.bindValue(":noteGuid", r.getNoteGuid());\r
                        if (r.getData() != null) {\r
-//                             query.bindValue(":dataHash", new QByteArray(r.getData().getBodyHash()).toHex());\r
-//                             query.bindValue(":dataHash", "");\r
                                query.bindValue(":dataHash", byteArrayToHexString(r.getData().getBodyHash()));\r
+//                             query.bindValue(":dataHash", "c0369123fe9871d675ae456fd056ba33");\r
                                query.bindValue(":dataSize", r.getData().getSize());\r
                                query.bindBlob(":dataBody", r.getData().getBody());\r
                        }\r
@@ -228,7 +233,8 @@ public class NoteResourceTable  {
                        if (!check) {\r
                                logger.log(logger.MEDIUM, "*** NoteResource Table insert failed.");             \r
                                logger.log(logger.MEDIUM, query.lastError());\r
-                       }\r
+                       } else\r
+                               query.exec("commit");\r
                        \r
                                                \r
                        logger.log(logger.HIGH, "Leaving DBRunner.saveNoteResources");\r
@@ -239,10 +245,13 @@ public class NoteResourceTable  {
                query.prepare("delete from NoteResources where guid=:guid");\r
                query.bindValue(":guid", guid);\r
                query.exec();\r
-\r
-               query.prepare("delete from InkImages where guid=:guid");\r
-               query.bindValue(":guid", guid);\r
-               query.exec();\r
+               query.exec("commit");\r
+               \r
+               NSqlQuery query2 = new NSqlQuery(db.getConnection());\r
+               query2.prepare("Delete from InkImages where guid=:guid");\r
+               query2.bindValue(":guid", guid);\r
+               query2.exec();\r
+               query2.exec("commit");\r
 \r
        }\r
 \r
@@ -348,7 +357,7 @@ public class NoteResourceTable  {
                                +"recognitionHash, recognitionSize, "\r
                                +"attributeLatitude, attributeLongitude, attributeAltitude, "\r
                                +"attributeCameraMake, attributeCameraModel, attributeClientWillIndex, "\r
-                               +"attributeRecoType, attributeFileName, attributeAttachment, recognitionBinary "\r
+                               +"attributeRecoType, attributeFileName, attributeAttachment, attributeSourceUrl "\r
                                +" from NoteResources where guid=:guid");\r
 \r
                \r
@@ -403,6 +412,7 @@ public class NoteResourceTable  {
                        a.setRecoType(stringValue(query.valueString(18)));                 // Recognition Type\r
                        a.setFileName(stringValue(query.valueString(19)));                  // File Name\r
                        a.setAttachment(booleanValue(query.valueString(20).toString(),false));\r
+                       a.setSourceURL(query.valueString(21));\r
                        r.setAttributes(a);\r
                \r
                        if (withBinary) {\r
@@ -521,12 +531,8 @@ public class NoteResourceTable  {
        // Save Note Resource\r
        public void updateNoteResource(Resource r, boolean isDirty) {\r
                logger.log(logger.HIGH, "Entering ListManager.updateNoteResource");\r
-               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
-               query.prepare("delete from NoteResources where guid=:recGuid");\r
-               query.bindValue(":recGuid", r.getGuid());\r
-               query.exec();\r
+               expungeNoteResource(r.getGuid());\r
                saveNoteResource(r, isDirty);\r
-               query = null;\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResource");\r
        }\r
        // Update note resource GUID\r
@@ -538,6 +544,7 @@ public class NoteResourceTable  {
                query.bindValue(":isDirty", isDirty);\r
                query.bindValue(":oldGuid", oldGuid);\r
                query.exec();\r
+               query.exec("commit");\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");\r
        }\r
        // Update note resource GUID\r
@@ -548,6 +555,7 @@ public class NoteResourceTable  {
                query.bindValue(":isDirty", isDirty);\r
                query.bindValue(":guid", guid);\r
                query.exec();\r
+               query.exec("commit");\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");\r
        }\r
        \r
@@ -555,6 +563,7 @@ public class NoteResourceTable  {
        public void reindexAll() {              \r
                NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
                query.exec("Update NoteResources set indexneeded=true");\r
+               query.exec("commit");\r
        }\r
        // Count attachments\r
        public int getResourceCount() {\r
@@ -625,4 +634,44 @@ public class NoteResourceTable  {
                        return unknown;\r
        }\r
 \r
+       // Update note source url. \r
+       public void updateNoteSourceUrl(String guid, String url, boolean isDirty) {\r
+               logger.log(logger.HIGH, "Entering RNoteResourceTable.updateNoteSourceUrl()");\r
+               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+               query.prepare("update NoteResources set attributesourceurl=:url, isDirty=:isDirty where guid=:guid");\r
+               query.bindValue(":guid", guid);\r
+               query.bindValue(":isDirty", isDirty);\r
+               query.bindValue(":url", url);\r
+               query.exec();\r
+               query.exec("commit");\r
+               logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteSourceUrl()");\r
+       }\r
+       \r
+       // Get note source\r
+       public String getNoteSourceUrl(String guid) {\r
+               logger.log(logger.HIGH, "Entering RNoteResourceTable.getNoteSourceUrl()");\r
+               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+               query.prepare("Select attributesourceurl from noteresources where guid=:guid");\r
+               query.bindValue(":guid", guid);\r
+               query.exec();\r
+               if (query.next()) {\r
+                       logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl()");\r
+                       return query.valueString(0);\r
+               }\r
+               logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl() - no value found");\r
+               return null;\r
+       }\r
+       \r
+       // Get note source\r
+       public List<String> getDistinctNoteGuids() {\r
+               logger.log(logger.HIGH, "Entering NoteResourceTable.getDistinctNoteGuids()");\r
+               List<String> guids = new ArrayList<String>();\r
+               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+               query.exec("select distinct noteguid from noteresources");\r
+               if (query.next()) {\r
+                       guids.add(query.valueString(0));\r
+               }\r
+               logger.log(logger.HIGH, "Leaving NoteResourceTable.getDistinctNoteGuids()");\r
+               return guids;\r
+       }\r
 }\r