/*\r
- * This file is part of NeverNote \r
+ * This file is part of NixNote/NeighborNote \r
* Copyright 2009 Randy Baumgarte\r
* \r
* This file may be licensed under the terms of of the\r
/**\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
}\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
- check = query.prepare("Insert Into NoteResources ("\r
+ query.prepare("Insert Into NoteResources ("\r
+"guid, noteGuid, dataHash, dataSize, dataBinary, updateSequenceNumber, "\r
+"mime, width, height, duration, active, recognitionHash, " \r
+"recognitionSize, recognitionBinary, attributeSourceUrl, attributeTimestamp, "\r
+":attributeCameraModel, "\r
+":attributeClientWillIndex, :attributeRecoType, :attributeFileName, :attributeAttachment, "\r
+":isDirty, true)");\r
- if (!check) {\r
- logger.log(logger.EXTREME, "NoteResource SQL insert prepare has failed.");\r
- logger.log(logger.MEDIUM, query.lastError());\r
- }\r
\r
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
query.bindValue(":attributeRecoType", r.getAttributes().getRecoType());\r
query.bindValue(":attributeFileName", r.getAttributes().getFileName());\r
query.bindValue(":attributeAttachment", r.getAttributes().isAttachment()); \r
- }\r
+ } \r
query.bindValue(":isDirty", isDirty);\r
\r
check = query.exec();\r
+"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
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
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
+ public void resetAllDirty() {\r
+ NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+ query.exec("update noteresources set isdirty=false");\r
+ }\r
+ \r
+ // リソーステキストを更新\r
+ public void updateResourceText(String guid, String text) {\r
+ logger.log(logger.HIGH, "Entering NoteResourceTable.updateResourceText");\r
+ NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+ boolean check = query.prepare("Update noteResources set resourceText=:resourceText where guid=:guid");\r
+ if (!check) {\r
+ logger.log(logger.EXTREME, "Update resourceText sql prepare has failed.");\r
+ logger.log(logger.MEDIUM, query.lastError());\r
+ }\r
+ \r
+ query.bindValue(":resourceText", text);\r
+ query.bindValue(":guid", guid);\r
+ \r
+ check = query.exec();\r
+ if (!check) {\r
+ logger.log(logger.EXTREME, "Update resourceText has failed.");\r
+ logger.log(logger.MEDIUM, query.lastError());\r
+ }\r
+ logger.log(logger.HIGH, "Leaving NoteResourceTable.updateResourceText");\r
+ query.exec();\r
+ }\r
}\r
+\r