2 * This file is part of NixNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 package cx.fbn.nevernote.sql;
\r
22 import java.text.SimpleDateFormat;
\r
23 import java.util.ArrayList;
\r
24 import java.util.List;
\r
26 import com.evernote.edam.type.Data;
\r
27 import com.evernote.edam.type.Resource;
\r
28 import com.evernote.edam.type.ResourceAttributes;
\r
29 import com.trolltech.qt.core.QByteArray;
\r
31 import cx.fbn.nevernote.sql.driver.NSqlQuery;
\r
32 import cx.fbn.nevernote.utilities.ApplicationLogger;
\r
36 public class NoteResourceTable {
\r
40 // private static final long serialVersionUID = 1L;
\r
41 private final ApplicationLogger logger;
\r
42 private final DatabaseConnection db;
\r
45 public NoteResourceTable(ApplicationLogger l, DatabaseConnection d) {
\r
50 public void createTable() {
\r
51 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
52 // Create the NoteResource table
\r
53 logger.log(logger.HIGH, "Creating table NoteResource...");
\r
54 if (!query.exec("Create table NoteResources (guid varchar primary key, " +
\r
55 "noteGuid varchar, updateSequenceNumber integer, dataHash varchar, "+
\r
56 "dataSize integer, dataBinary blob, "+
\r
57 "mime varchar, width integer, height integer, duration integer, "+
\r
58 "active integer, recognitionHash varchar, recognitionSize integer, " +
\r
59 "recognitionBinary varchar, attributeSourceUrl varchar, attributeTimestamp timestamp, " +
\r
60 "attributeLatitude double, attributeLongitude double, "+
\r
61 "attributeAltitude double, attributeCameraMake varchar, attributeCameraModel varchar, "
\r
62 +"attributeClientWillIndex varchar, attributeRecoType varchar, attributeFileName varchar,"+
\r
63 "attributeAttachment boolean, isDirty boolean, indexNeeded boolean)"))
\r
64 logger.log(logger.HIGH, "Table NoteResource creation FAILED!!!");
\r
65 if (!query.exec("CREATE INDEX unindexed_resources on noteresources (indexneeded desc, guid);"))
\r
66 logger.log(logger.HIGH, "Noteresources unindexed_resources index creation FAILED!!!");
\r
67 if (!query.exec("CREATE INDEX resources_dataheshhex on noteresources (datahash, guid);"))
\r
68 logger.log(logger.HIGH, "Noteresources resources_datahash index creation FAILED!!!");
\r
69 if (!query.exec("create index RESOURCES_GUID_INDEX on noteresources (noteGuid, guid);"))
\r
70 logger.log(logger.HIGH, "Noteresources resources_datahash index creation FAILED!!!");
\r
73 public void dropTable() {
\r
74 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
75 query.exec("Drop table NoteResources");
\r
77 // Reset the dirty flag
\r
78 public void resetDirtyFlag(String guid) {
\r
79 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
81 query.prepare("Update noteresources set isdirty=false where guid=:guid");
\r
82 query.bindValue(":guid", guid);
\r
84 logger.log(logger.EXTREME, "Error resetting noteresource dirty field. " +query.lastError());
\r
86 query.exec("commit");
\r
88 // Set if the resource should be indexed
\r
89 public void setIndexNeeded(String guid, Boolean indexNeeded) {
\r
90 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
91 query.prepare("Update noteresources set indexNeeded=:needed where guid=:guid");
\r
92 query.bindValue(":needed", indexNeeded);
\r
93 query.bindValue(":guid", guid);
\r
95 logger.log(logger.EXTREME, "Error setting noteresource indexneeded field: " +query.lastError());
\r
97 query.exec("commit");
\r
99 // get any unindexed resource
\r
100 public List<String> getNextUnindexed(int limit) {
\r
101 List<String> guids = new ArrayList<String>();
\r
102 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
104 if (!query.exec("Select guid from NoteResources where indexNeeded = true limit " +limit))
\r
105 logger.log(logger.EXTREME, "NoteResources SQL retrieve has failed on getNextUnindexed(): " +query.lastError());
\r
107 // Get a list of the notes
\r
109 while (query.next()) {
\r
110 guid = new String();
\r
111 guid = query.valueString(0);
\r
116 // get any unindexed resource
\r
117 public List<String> getUnindexed() {
\r
118 List<String> guids = new ArrayList<String>();
\r
119 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
121 if (!query.exec("Select guid from NoteResources where indexNeeded = true"))
\r
122 logger.log(logger.EXTREME, "NoteResources SQL retrieve has failed on getUnindexed(): " +query.lastError());
\r
124 // Get a list of the notes
\r
126 while (query.next()) {
\r
127 guid = new String();
\r
128 guid = query.valueString(0);
\r
134 public List<String> getAll() {
\r
135 List<String> guids = new ArrayList<String>();
\r
136 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
138 query.prepare("Select guid from noteresources;");
\r
140 logger.log(logger.EXTREME, "Error getting all note resource guids. " +query.lastError());
\r
142 while (query.next()) {
\r
143 guids.add(query.valueString(0));
\r
148 public List<String> findInkNotes() {
\r
149 List<String> guids = new ArrayList<String>();
\r
150 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
152 query.prepare("Select guid from noteresources where mime='application/vnd.evernote.ink'");
\r
154 logger.log(logger.EXTREME, "Error searching for ink notes. " +query.lastError());
\r
156 while (query.next()) {
\r
157 guids.add(query.valueString(0));
\r
162 public void saveNoteResource(Resource r, boolean isDirty) {
\r
163 logger.log(logger.HIGH, "Entering DBRunner.saveNoteResources");
\r
165 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
166 SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
\r
168 check = query.prepare("Insert Into NoteResources ("
\r
169 +"guid, noteGuid, dataHash, dataSize, dataBinary, updateSequenceNumber, "
\r
170 +"mime, width, height, duration, active, recognitionHash, "
\r
171 +"recognitionSize, recognitionBinary, attributeSourceUrl, attributeTimestamp, "
\r
172 +"attributeLatitude, attributeLongitude, attributeAltitude, attributeCameraMake, "
\r
173 +"attributeCameraModel, "
\r
174 +"attributeClientWillIndex, attributeRecoType, attributeFileName, attributeAttachment, isDirty, "
\r
175 +"indexNeeded) Values("
\r
176 +":guid, :noteGuid, :dataHash,:dataSize, :dataBody, :updateSequenceNumber, "
\r
177 +":mime, :width, :height, :duration, :active, :recognitionHash, "
\r
178 +":recognitionSize, :recognitionBody, :attributeSourceUrl, :attributeTimestamp, "
\r
179 +":attributeLatitude, :attributeLongitude, :attributeAltitude, :attributeCameraMake, "
\r
180 +":attributeCameraModel, "
\r
181 +":attributeClientWillIndex, :attributeRecoType, :attributeFileName, :attributeAttachment, "
\r
182 +":isDirty, true)");
\r
184 logger.log(logger.EXTREME, "NoteResource SQL insert prepare has failed.");
\r
185 logger.log(logger.MEDIUM, query.lastError());
\r
188 query.bindValue(":guid", r.getGuid());
\r
189 query.bindValue(":noteGuid", r.getNoteGuid());
\r
190 if (r.getData() != null) {
\r
191 query.bindValue(":dataHash", byteArrayToHexString(r.getData().getBodyHash()));
\r
192 // query.bindValue(":dataHash", "c0369123fe9871d675ae456fd056ba33");
\r
193 query.bindValue(":dataSize", r.getData().getSize());
\r
194 query.bindBlob(":dataBody", r.getData().getBody());
\r
196 query.bindValue(":updateSequenceNumber", r.getUpdateSequenceNum());
\r
197 query.bindValue(":mime", r.getMime());
\r
198 query.bindValue(":width", new Integer(r.getWidth()));
\r
199 query.bindValue(":height", new Integer(r.getHeight()));
\r
200 query.bindValue(":duration", new Integer(r.getDuration()));
\r
201 query.bindValue(":active", r.isActive());
\r
202 if (r.getRecognition() != null) {
\r
203 query.bindValue(":recognitionHash", r.getRecognition().getBodyHash());
\r
204 query.bindValue(":recognitionSize", r.getRecognition().getSize());
\r
205 if (r.getRecognition().getBody() != null)
\r
206 query.bindValue(":recognitionBody", new String(r.getRecognition().getBody()));
\r
208 query.bindValue(":recognitionBody", "");
\r
210 query.bindValue(":recognitionHash", "");
\r
211 query.bindValue(":recognitionSize", 0);
\r
212 query.bindValue(":recognitionBody", "");
\r
214 if (r.getAttributes() != null) {
\r
215 query.bindValue(":attributeSourceUrl", r.getAttributes().getSourceURL());
\r
216 StringBuilder ts = new StringBuilder(simple.format(r.getAttributes().getTimestamp()));
\r
217 query.bindValue(":attributeTimestamp", ts.toString());
\r
218 query.bindValue(":attributeLatitude", r.getAttributes().getLatitude());
\r
219 query.bindValue(":attributeLongitude", r.getAttributes().getLongitude());
\r
220 query.bindValue(":attributeAltitude", r.getAttributes().getAltitude());
\r
221 query.bindValue(":attributeCameraMake", r.getAttributes().getCameraMake());
\r
222 query.bindValue(":attributeCameraModel", r.getAttributes().getCameraModel());
\r
223 query.bindValue(":attributeClientWillIndex", r.getAttributes().isClientWillIndex());
\r
224 query.bindValue(":attributeRecoType", r.getAttributes().getRecoType());
\r
225 query.bindValue(":attributeFileName", r.getAttributes().getFileName());
\r
226 query.bindValue(":attributeAttachment", r.getAttributes().isAttachment());
\r
228 query.bindValue(":isDirty", isDirty);
\r
230 check = query.exec();
\r
232 logger.log(logger.MEDIUM, "*** NoteResource Table insert failed.");
\r
233 logger.log(logger.MEDIUM, query.lastError());
\r
235 query.exec("commit");
\r
238 logger.log(logger.HIGH, "Leaving DBRunner.saveNoteResources");
\r
240 // delete an old resource
\r
241 public void expungeNoteResource(String guid) {
\r
242 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
243 query.prepare("delete from NoteResources where guid=:guid");
\r
244 query.bindValue(":guid", guid);
\r
246 query.exec("commit");
\r
248 NSqlQuery query2 = new NSqlQuery(db.getConnection());
\r
249 query2.prepare("Delete from InkImages where guid=:guid");
\r
250 query2.bindValue(":guid", guid);
\r
252 query2.exec("commit");
\r
257 // Get a note resource from the database by it's hash value
\r
258 public String getNoteResourceGuidByHashHex(String noteGuid, String hash) {
\r
259 logger.log(logger.HIGH, "Entering DBRunner.getNoteResourceGuidByHashHex");
\r
262 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
264 check = query.prepare("Select guid from NoteResources " +
\r
265 "where noteGuid=:noteGuid and dataHash=:hash");
\r
267 logger.log(logger.EXTREME, "NoteResource SQL select prepare was successful.");
\r
269 logger.log(logger.EXTREME, "NoteResource SQL select prepare has failed.");
\r
270 logger.log(logger.MEDIUM, query.lastError());
\r
272 query.bindValue(":noteGuid", noteGuid);
\r
273 query.bindValue(":hash", hash);
\r
275 check = query.exec();
\r
277 logger.log(logger.MEDIUM, "dbRunner.getNoteResourceGuidByHashHex Select failed." +
\r
278 "Note Guid:" +noteGuid+
\r
279 "Data Body Hash:" +hash);
\r
280 logger.log(logger.MEDIUM, query.lastError());
\r
282 if (!query.next()) {
\r
283 logger.log(logger.MEDIUM, "Note Resource not found.");
\r
286 return query.valueString(0);
\r
289 // Get a note resource from the database by it's hash value
\r
290 public Resource getNoteResourceDataBodyByHashHex(String noteGuid, String hash) {
\r
291 logger.log(logger.HIGH, "Entering DBRunner.getNoteResourceDataBodyByHash");
\r
294 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
296 check = query.prepare("Select guid, mime, from NoteResources " +
\r
297 "where noteGuid=:noteGuid and dataHash=:hash");
\r
299 logger.log(logger.EXTREME, "NoteResource SQL select prepare has failed.");
\r
300 logger.log(logger.MEDIUM, query.lastError());
\r
302 query.bindValue(":noteGuid", noteGuid);
\r
303 query.bindValue(":hash", hash);
\r
305 if (!query.exec()) {
\r
306 logger.log(logger.MEDIUM, "NoteResource Select failed." +
\r
307 "Note Guid:" +noteGuid+
\r
308 "Data Body Hash:" +hash);
\r
309 logger.log(logger.MEDIUM, query.lastError());
\r
311 if (!query.next()) {
\r
312 logger.log(logger.MEDIUM, "Note Resource not found.");
\r
316 Resource r = new Resource();
\r
317 r.setGuid(query.valueString(0));
\r
318 r.setMime(query.valueString(1));
\r
320 NSqlQuery binary = new NSqlQuery(db.getResourceConnection());
\r
321 if (!binary.prepare("Select databinary from NoteResources " +
\r
322 "where guid=:guid")) {
\r
323 logger.log(logger.MEDIUM, "Prepare for NoteResources Binary failed");
\r
324 logger.log(logger.MEDIUM, binary.lastError());
\r
327 if (!binary.exec()) {
\r
328 logger.log(logger.MEDIUM, "NoteResources Binary Select failed." +
\r
329 "Note Guid:" +noteGuid+
\r
330 "Data Body Hash:" +hash);
\r
331 logger.log(logger.MEDIUM, binary.lastError());
\r
333 if (!binary.next()) {
\r
334 logger.log(logger.MEDIUM, "Note Resource Binary not found.");
\r
338 Data d = new Data();
\r
340 d.setBody(binary.valueString(0).getBytes());
\r
341 logger.log(logger.HIGH, "Leaving DBRunner.getNoteResourceDataBodyByHash");
\r
346 // Get a note's resourcesby Guid
\r
347 public Resource getNoteResource(String guid, boolean withBinary) {
\r
351 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
352 String queryString;
\r
353 queryString = new String("Select guid, noteGuid, mime, width, height, duration, "
\r
354 +"active, updateSequenceNumber, dataHash, dataSize, "
\r
355 +"recognitionHash, recognitionSize, "
\r
356 +"attributeLatitude, attributeLongitude, attributeAltitude, "
\r
357 +"attributeCameraMake, attributeCameraModel, attributeClientWillIndex, "
\r
358 +"attributeRecoType, attributeFileName, attributeAttachment, attributeSourceUrl "
\r
359 +" from NoteResources where guid=:guid");
\r
362 query.prepare(queryString);
\r
364 query.bindValue(":guid", guid);
\r
365 if (!query.exec()) {
\r
366 logger.log(logger.EXTREME, "NoteResources SQL select has failed.");
\r
367 logger.log(logger.MEDIUM, query.lastError());
\r
371 if (query.next()) {
\r
373 r = new Resource();
\r
374 r.setGuid(query.valueString(0)); // Resource Guid
\r
375 r.setNoteGuid(query.valueString(1)); // note Guid
\r
376 r.setMime(query.valueString(2)); // Mime Type
\r
377 r.setWidth(new Short(query.valueString(3))); // Width
\r
378 r.setHeight(new Short(query.valueString(4))); // Height
\r
379 r.setDuration(new Short(query.valueString(5))); // Duration
\r
380 r.setActive(new Boolean(query.valueString(6))); // active
\r
381 r.setUpdateSequenceNum(new Integer(query.valueString(7))); // update sequence number
\r
383 Data d = new Data();
\r
384 byte[] h = query.valueString(8).getBytes(); // data hash
\r
385 QByteArray hData = new QByteArray(h);
\r
386 QByteArray bData = new QByteArray(QByteArray.fromHex(hData));
\r
387 d.setBodyHash(bData.toByteArray());
\r
388 d.setSize(new Integer(query.valueString(9)));
\r
391 Data rec = new Data();
\r
392 if (query.valueObject(10) != null)
\r
393 rec.setBodyHash(query.valueString(10).getBytes()); // Recognition Hash
\r
394 if (query.valueObject(11) != null)
\r
395 rec.setSize(new Integer(query.valueString(11)));
\r
398 r.setRecognition(rec);
\r
400 ResourceAttributes a = new ResourceAttributes();
\r
401 if (!query.valueString(12).equals("")) // Latitude
\r
402 a.setLatitude(new Float(query.valueString(12)));
\r
403 if (!query.valueString(13).equals("")) // Longitude
\r
404 a.setLongitude(new Float(query.valueString(13)));
\r
405 if (!query.valueString(14).equals("")) // Altitude
\r
406 a.setAltitude(new Float(query.valueString(14)));
\r
407 a.setCameraMake(stringValue(query.valueString(15))); // Camera Make
\r
408 a.setCameraModel(stringValue(query.valueString(16)));
\r
409 a.setClientWillIndex(booleanValue(query.valueString(17).toString(),false)); // Camera Model
\r
410 a.setRecoType(stringValue(query.valueString(18))); // Recognition Type
\r
411 a.setFileName(stringValue(query.valueString(19))); // File Name
\r
412 a.setAttachment(booleanValue(query.valueString(20).toString(),false));
\r
413 a.setSourceURL(query.valueString(21));
\r
414 r.setAttributes(a);
\r
418 query.prepare("Select dataBinary from NoteResources where guid=:guid");
\r
419 query.bindValue(":guid", r.getGuid());
\r
421 if (query.next()) {
\r
422 byte[] b = query.getBlob(0);
\r
423 r.getData().setBody(b);
\r
431 // Get a note's resourcesby Guid
\r
432 public List<Resource> getNoteResources(String noteGuid, boolean withBinary) {
\r
433 if (noteGuid == null)
\r
435 List<Resource> res = new ArrayList<Resource>();
\r
437 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
438 query.prepare("Select guid"
\r
439 +" from NoteResources where noteGuid = :noteGuid");
\r
440 query.bindValue(":noteGuid", noteGuid);
\r
441 if (!query.exec()) {
\r
442 logger.log(logger.EXTREME, "NoteResources SQL select has failed.");
\r
443 logger.log(logger.MEDIUM, query.lastError());
\r
446 while (query.next()) {
\r
447 String guid = (query.valueString(0));
\r
448 res.add(getNoteResource(guid, withBinary));
\r
452 // Get all of a note's recognition data by the note guid
\r
453 public List<Resource> getNoteResourcesRecognition(String noteGuid) {
\r
454 if (noteGuid == null)
\r
457 List<Resource> res = new ArrayList<Resource>();
\r
458 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
459 check = query.prepare("Select "
\r
460 +"recognitionHash, recognitionSize, recognitionBinary "
\r
461 +" from NoteResources where noteGuid=:guid");
\r
463 logger.log(logger.EXTREME, "NoteTable.getNoteRecognition SQL prepare has failed.");
\r
464 logger.log(logger.MEDIUM, query.lastError());
\r
467 query.bindValue(":guid", noteGuid);
\r
469 logger.log(logger.EXTREME, "NoteTable.getNoteRecognition exec has failed.");
\r
470 logger.log(logger.MEDIUM, query.lastError());
\r
473 while (query.next()) {
\r
474 Resource r = new Resource();
\r
476 Data rec = new Data();
\r
477 rec.setBodyHash(query.valueString(0).getBytes());
\r
478 String x = new String(query.valueString(1));
\r
479 if (!x.equals("")) {
\r
480 rec.setSize(new Integer(x));
\r
481 rec.setBody(query.valueString(2).getBytes());
\r
484 r.setRecognition(rec);
\r
490 // Get a note's recognition data by it's guid.
\r
491 public Resource getNoteResourceRecognition(String guid) {
\r
495 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
496 check = query.prepare("Select "
\r
497 +"recognitionHash, recognitionSize, recognitionBinary, noteGuid "
\r
498 +" from NoteResources where guid=:guid");
\r
500 logger.log(logger.EXTREME, "NoteTable.getNoteRecognition SQL prepare has failed.");
\r
501 logger.log(logger.MEDIUM, query.lastError());
\r
504 query.bindValue(":guid", guid);
\r
507 logger.log(logger.EXTREME, "NoteTable.getNoteRecognition exec has failed.");
\r
508 logger.log(logger.MEDIUM, query.lastError());
\r
512 while (query.next()) {
\r
514 r = new Resource();
\r
515 Data rec = new Data();
\r
516 rec.setBodyHash(query.valueString(0).getBytes());
\r
517 String x = new String(query.valueString(1));
\r
518 if (!x.equals("")) {
\r
519 rec.setSize(new Integer(x));
\r
520 rec.setBody(query.valueString(2).getBytes());
\r
523 r.setRecognition(rec);
\r
524 r.setNoteGuid(query.valueString(3));
\r
529 // Save Note Resource
\r
530 public void updateNoteResource(Resource r, boolean isDirty) {
\r
531 logger.log(logger.HIGH, "Entering ListManager.updateNoteResource");
\r
532 expungeNoteResource(r.getGuid());
\r
533 saveNoteResource(r, isDirty);
\r
534 logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResource");
\r
536 // Update note resource GUID
\r
537 public void updateNoteResourceGuid(String oldGuid, String newGuid, boolean isDirty) {
\r
538 logger.log(logger.HIGH, "Entering RNoteResourceTable.updateNoteResourceGuid");
\r
539 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
540 query.prepare("update NoteResources set guid=:newGuid, isDirty=:isDirty where guid=:oldGuid");
\r
541 query.bindValue(":newGuid", newGuid);
\r
542 query.bindValue(":isDirty", isDirty);
\r
543 query.bindValue(":oldGuid", oldGuid);
\r
545 query.exec("commit");
\r
546 logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");
\r
548 // Update note resource GUID
\r
549 public void resetUpdateSequenceNumber(String guid, boolean isDirty) {
\r
550 logger.log(logger.HIGH, "Entering RNoteResourceTable.updateNoteResourceGuid");
\r
551 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
552 query.prepare("update NoteResources set updateSequenceNumber=0, isDirty=:isDirty where guid=:guid");
\r
553 query.bindValue(":isDirty", isDirty);
\r
554 query.bindValue(":guid", guid);
\r
556 query.exec("commit");
\r
557 logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");
\r
561 public void reindexAll() {
\r
562 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
563 query.exec("Update NoteResources set indexneeded=true");
\r
564 query.exec("commit");
\r
566 // Count attachments
\r
567 public int getResourceCount() {
\r
568 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
569 query.exec("select count(*) from noteresources");
\r
571 int returnValue = new Integer(query.valueString(0));
\r
572 return returnValue;
\r
575 // Count unindexed notes
\r
576 public int getUnindexedCount() {
\r
577 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
578 query.exec("select count(*) from noteresources where indexneeded=true");
\r
580 int returnValue = new Integer(query.valueString(0));
\r
581 return returnValue;
\r
584 //********************************************
\r
585 //** Utility Functions
\r
586 //********************************************
\r
587 // Convert a byte array to a hex string
\r
588 private static String byteArrayToHexString(byte data[]) {
\r
589 StringBuffer buf = new StringBuffer();
\r
590 for (byte element : data) {
\r
591 int halfbyte = (element >>> 4) & 0x0F;
\r
594 if ((0 <= halfbyte) && (halfbyte <= 9))
\r
595 buf.append((char) ('0' + halfbyte));
\r
597 buf.append((char) ('a' + (halfbyte - 10)));
\r
598 halfbyte = element & 0x0F;
\r
599 } while(two_halfs++ < 1);
\r
601 return buf.toString();
\r
605 private String stringValue(Object value) {
\r
606 if (value != null && value.toString() != null)
\r
607 return value.toString();
\r
612 private boolean booleanValue(Object value, boolean unknown) {
\r
613 if (value != null && value.toString() != null) {
\r
615 if ((Integer)value > 0)
\r
619 } catch (java.lang.ClassCastException e) {
\r
621 String stringValue = (String)value;
\r
622 if (stringValue.equalsIgnoreCase("true"))
\r
626 } catch (java.lang.ClassCastException e1) {
\r
635 // Update note source url.
\r
636 public void updateNoteSourceUrl(String guid, String url, boolean isDirty) {
\r
637 logger.log(logger.HIGH, "Entering RNoteResourceTable.updateNoteSourceUrl()");
\r
638 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
639 query.prepare("update NoteResources set attributesourceurl=:url, isDirty=:isDirty where guid=:guid");
\r
640 query.bindValue(":guid", guid);
\r
641 query.bindValue(":isDirty", isDirty);
\r
642 query.bindValue(":url", url);
\r
644 query.exec("commit");
\r
645 logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteSourceUrl()");
\r
649 public String getNoteSourceUrl(String guid) {
\r
650 logger.log(logger.HIGH, "Entering RNoteResourceTable.getNoteSourceUrl()");
\r
651 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
652 query.prepare("Select attributesourceurl from noteresources where guid=:guid");
\r
653 query.bindValue(":guid", guid);
\r
655 if (query.next()) {
\r
656 logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl()");
\r
657 return query.valueString(0);
\r
659 logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl() - no value found");
\r
664 public List<String> getDistinctNoteGuids() {
\r
665 logger.log(logger.HIGH, "Entering NoteResourceTable.getDistinctNoteGuids()");
\r
666 List<String> guids = new ArrayList<String>();
\r
667 NSqlQuery query = new NSqlQuery(db.getResourceConnection());
\r
668 query.exec("select distinct noteguid from noteresources");
\r
669 if (query.next()) {
\r
670 guids.add(query.valueString(0));
\r
672 logger.log(logger.HIGH, "Leaving NoteResourceTable.getDistinctNoteGuids()");
\r