OSDN Git Service

NeverNote 0.88.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NotebookTable.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 \r
21 package cx.fbn.nevernote.sql;\r
22 \r
23 import java.util.List;\r
24 \r
25 import com.evernote.edam.type.Notebook;\r
26 \r
27 import cx.fbn.nevernote.Global;\r
28 import cx.fbn.nevernote.sql.requests.NotebookRequest;\r
29 import cx.fbn.nevernote.utilities.Pair;\r
30 \r
31 public class NotebookTable {\r
32         int id;\r
33         \r
34         public NotebookTable(int i) {\r
35                 id = i;\r
36         }\r
37         \r
38         // Create the table\r
39         public void createTable() {\r
40                 NotebookRequest request = new NotebookRequest();\r
41                 request.requestor_id = id;\r
42                 request.type = NotebookRequest.Create_Table;\r
43                 Global.dbRunner.addWork(request);\r
44         }\r
45         // Drop the table\r
46         public void dropTable() {\r
47                 NotebookRequest request = new NotebookRequest();\r
48                 request.requestor_id = id;\r
49                 request.type = NotebookRequest.Drop_Table;\r
50                 Global.dbRunner.addWork(request);\r
51         }\r
52         // Save an individual notebook\r
53         public void addNotebook(Notebook tempNotebook, boolean isDirty, boolean local) {\r
54                 NotebookRequest request = new NotebookRequest();\r
55                 request.requestor_id = id;\r
56                 request.type = NotebookRequest.Add_Notebook;\r
57                 request.notebook = tempNotebook;\r
58                 request.bool1 = isDirty;\r
59                 request.bool2 = local;\r
60                 Global.dbRunner.addWork(request);\r
61         }\r
62         // Delete the notebook based on a guid\r
63         public void expungeNotebook(String guid, boolean needsSync) {\r
64                 NotebookRequest request = new NotebookRequest();\r
65                 request.requestor_id = id;\r
66                 request.type = NotebookRequest.Expunge_Notebook;\r
67                 request.string1 = guid;\r
68                 Global.dbRunner.addWork(request);\r
69         }\r
70         // Update a notebook\r
71         public void updateNotebook(Notebook tempNotebook, boolean isDirty) {\r
72                 NotebookRequest request = new NotebookRequest();\r
73                 request.requestor_id = id;\r
74                 request.type = NotebookRequest.Update_Notebook;\r
75                 request.notebook = tempNotebook;\r
76                 request.bool1 = isDirty;\r
77                 Global.dbRunner.addWork(request);\r
78         }\r
79         // Load notebooks from the database\r
80         public List<Notebook> getAll() {\r
81                 NotebookRequest request = new NotebookRequest();\r
82                 request.requestor_id = id;\r
83                 request.type = NotebookRequest.Get_All;\r
84                 Global.dbRunner.addWork(request);\r
85                 Global.dbClientWait(id);\r
86                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
87                 return req.responseNotebooks;\r
88                 \r
89         }       \r
90         public List<Notebook> getAllLocal() {\r
91                 NotebookRequest request = new NotebookRequest();\r
92                 request.requestor_id = id;\r
93                 request.type = NotebookRequest.Get_All_Local;\r
94                 Global.dbRunner.addWork(request);\r
95                 Global.dbClientWait(id);\r
96                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
97                 return req.responseNotebooks;\r
98         }\r
99         // Archive or un-archive a notebook\r
100         public void setArchived(String guid, boolean isDirty) {\r
101                 NotebookRequest request = new NotebookRequest();\r
102                 request.requestor_id = id;\r
103                 request.type = NotebookRequest.Set_Archived;\r
104                 request.string1 = guid;\r
105                 request.bool1 = isDirty;\r
106                 Global.dbRunner.addWork(request);\r
107         }\r
108         // Load non-archived notebooks from the database\r
109         public List<Notebook> getAllArchived() {\r
110                 NotebookRequest request = new NotebookRequest();\r
111                 request.requestor_id = id;\r
112                 request.type = NotebookRequest.Get_All_Archived;\r
113                 Global.dbRunner.addWork(request);\r
114                 Global.dbClientWait(id);\r
115                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
116                 return req.responseNotebooks;\r
117         }       \r
118         // Check for a local/remote notebook\r
119         public boolean isNotebookLocal(String guid) {\r
120                 NotebookRequest request = new NotebookRequest();\r
121                 request.requestor_id = id;\r
122                 request.type = NotebookRequest.Is_Notebook_Local;\r
123                 request.string1 = guid;\r
124                 Global.dbRunner.addWork(request);\r
125                 Global.dbClientWait(id);\r
126                 NotebookRequest req =(Global.dbRunner.notebookResponse.get(id)).copy();\r
127                 return req.responseBoolean;\r
128         }\r
129         // Update a notebook sequence number\r
130         public void updateNotebookSequence(String guid, int sequence) {\r
131                 NotebookRequest request = new NotebookRequest();\r
132                 request.requestor_id = id;\r
133                 request.type = NotebookRequest.Update_Notebook_Sequence;\r
134                 request.int1 = sequence;\r
135                 Global.dbRunner.addWork(request);\r
136         }\r
137         // Update a notebook GUID number\r
138         public void updateNotebookGuid(String oldGuid, String newGuid) {\r
139                 NotebookRequest request = new NotebookRequest();\r
140                 request.requestor_id = id;\r
141                 request.type = NotebookRequest.Update_Notebook_Guid;\r
142                 request.string1 = oldGuid;\r
143                 request.string2 = newGuid;\r
144                 Global.dbRunner.addWork(request);\r
145         }\r
146         // Get a list of notes that need to be updated\r
147         public List <Notebook> getDirty() {\r
148                 NotebookRequest request = new NotebookRequest();\r
149                 request.requestor_id = id;\r
150                 request.type = NotebookRequest.Get_Dirty;\r
151                 Global.dbRunner.addWork(request);\r
152                 Global.dbClientWait(id);\r
153                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
154                 return req.responseNotebooks;\r
155         }\r
156 \r
157         // This is a convience method to check if a tag exists & update/create based upon it\r
158         public void syncNotebook(Notebook notebook, boolean isDirty) {\r
159                 NotebookRequest request = new NotebookRequest();\r
160                 request.requestor_id = id;\r
161                 request.type = NotebookRequest.Sync_Notebook;\r
162                 request.notebook = notebook;\r
163                 request.bool1 = isDirty;\r
164                 Global.dbRunner.addWork(request);\r
165         }\r
166         // Reset the dirty flag.  Typically done after a sync.\r
167         public void  resetDirtyFlag(String guid) {\r
168                 NotebookRequest request = new NotebookRequest();\r
169                 request.requestor_id = id;\r
170                 request.type = NotebookRequest.Reset_Dirty;\r
171                 request.string1 = guid;\r
172                 Global.dbRunner.addWork(request);\r
173         }\r
174         // does a record exist?\r
175         public String findNotebookByName(String newname) {\r
176                 NotebookRequest request = new NotebookRequest();\r
177                 request.requestor_id = id;\r
178                 request.type = NotebookRequest.Find_Note_By_Name;\r
179                 request.string1 = newname;\r
180                 Global.dbRunner.addWork(request);\r
181                 Global.dbClientWait(id);\r
182                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
183                 return req.responseString;\r
184         }\r
185         // Get Notebook counts\r
186         public List<Pair<String,Integer>> getNotebookCounts() {\r
187                 NotebookRequest request = new NotebookRequest();\r
188                 request.requestor_id = id;\r
189                 request.type = NotebookRequest.Notebook_Counts;\r
190                 Global.dbRunner.addWork(request);\r
191                 Global.dbClientWait(id);\r
192                 NotebookRequest req = Global.dbRunner.notebookResponse.get(id).copy();\r
193                 return req.responseCounts;\r
194                 \r
195         }\r
196 }\r
197 \r