2 * This file is part of NeverNote
\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
23 import java.util.List;
\r
25 import cx.fbn.nevernote.Global;
\r
26 import cx.fbn.nevernote.sql.requests.NoteTagsRequest;
\r
27 import cx.fbn.nevernote.sql.runners.NoteTagsRecord;
\r
28 import cx.fbn.nevernote.utilities.Pair;
\r
30 public class NoteTagsTable {
\r
31 private final int id;
\r
34 public NoteTagsTable(int i) {
\r
38 public void createTable() {
\r
39 NoteTagsRequest request = new NoteTagsRequest();
\r
40 request.requestor_id = id;
\r
41 request.type = NoteTagsRequest.Create_Table;
\r
42 Global.dbRunner.addWork(request);
\r
45 public void dropTable() {
\r
46 NoteTagsRequest request = new NoteTagsRequest();
\r
47 request.requestor_id = id;
\r
48 request.type = NoteTagsRequest.Drop_Table;
\r
49 Global.dbRunner.addWork(request); }
\r
50 // Get a note tags by the note's Guid
\r
51 public List<String> getNoteTags(String noteGuid) {
\r
52 NoteTagsRequest request = new NoteTagsRequest();
\r
53 request.requestor_id = id;
\r
54 request.type = NoteTagsRequest.Get_Note_Tags;
\r
55 request.string1 = new String(noteGuid);
\r
56 Global.dbRunner.addWork(request);
\r
57 Global.dbClientWait(id);
\r
58 NoteTagsRequest req = Global.dbRunner.noteTagsResponse.get(id).copy();
\r
59 return req.responseStrings;
\r
61 // Get a note tags by the note's Guid
\r
62 public List<NoteTagsRecord> getAllNoteTags() {
\r
63 NoteTagsRequest request = new NoteTagsRequest();
\r
64 request.requestor_id = id;
\r
65 request.type = NoteTagsRequest.Get_All_Note_Tags;
\r
66 Global.dbRunner.addWork(request);
\r
67 Global.dbClientWait(id);
\r
68 NoteTagsRequest req = Global.dbRunner.noteTagsResponse.get(id).copy();
\r
69 return req.responseNoteTagsRecord;
\r
71 // Check if a note has a specific tag already
\r
72 public boolean checkNoteNoteTags(String noteGuid, String tagGuid) {
\r
73 NoteTagsRequest request = new NoteTagsRequest();
\r
74 request.requestor_id = id;
\r
75 request.type = NoteTagsRequest.Check_Note_Note_Tags;
\r
76 request.string1 = new String(noteGuid);
\r
77 request.string2 = new String(tagGuid);
\r
78 Global.dbRunner.addWork(request);
\r
79 Global.dbClientWait(id);
\r
80 NoteTagsRequest req = Global.dbRunner.noteTagsResponse.get(id).copy();
\r
81 return req.responseBoolean;
\r
84 public void saveNoteTag(String noteGuid, String tagGuid) {
\r
85 NoteTagsRequest request = new NoteTagsRequest();
\r
86 request.requestor_id = id;
\r
87 request.type = NoteTagsRequest.Save_Note_Tag;
\r
88 request.string1 = new String(noteGuid);
\r
89 request.string2 = new String(tagGuid);
\r
90 Global.dbRunner.addWork(request);
\r
92 // Delete a note's tags
\r
93 public void deleteNoteTag(String noteGuid) {
\r
94 NoteTagsRequest request = new NoteTagsRequest();
\r
95 request.requestor_id = id;
\r
96 request.type = NoteTagsRequest.Delete_Note_Tag;
\r
97 request.string1 = new String(noteGuid);
\r
98 Global.dbRunner.addWork(request);
\r
101 public List<Pair<String,Integer>> getTagCounts() {
\r
102 NoteTagsRequest request = new NoteTagsRequest();
\r
103 request.requestor_id = id;
\r
104 request.type = NoteTagsRequest.Tag_Counts;
\r
105 Global.dbRunner.addWork(request);
\r
106 Global.dbClientWait(id);
\r
107 NoteTagsRequest req = Global.dbRunner.noteTagsResponse.get(id).copy();
\r
108 return req.responseCounts;
\r