OSDN Git Service

Add logic to display stacks in notebook tree
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / DeletedTable.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.ArrayList;\r
24 import java.util.List;\r
25 \r
26 import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
27 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
28 import cx.fbn.nevernote.utilities.ListManager;\r
29 \r
30 public class DeletedTable {\r
31         ListManager parent;\r
32         private final ApplicationLogger                 logger;\r
33         private final DatabaseConnection                db;\r
34 \r
35         \r
36         // Constructor\r
37         public DeletedTable(ApplicationLogger l,DatabaseConnection d) {\r
38                 logger = l;\r
39                 db = d;\r
40         }\r
41         // Create the table\r
42         public void createTable() {\r
43                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
44                 logger.log(logger.HIGH, "Creating table DeletedItems...");\r
45         if (!query.exec("Create table DeletedItems (guid varchar primary key, type varchar)"))\r
46                 logger.log(logger.HIGH, "Table DeletedItems creation FAILED!!!"); \r
47         }\r
48         // Drop the table\r
49         public void dropTable() {\r
50                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
51                 query.exec("Drop table DeletedItems");\r
52         }\r
53         // Add an item to the deleted table\r
54         public void addDeletedItem(String guid, String type) {\r
55         NSqlQuery query = new NSqlQuery(db.getConnection());\r
56                 query.prepare("Insert Into DeletedItems (guid, type) Values(:guid, :type)");\r
57                 query.bindValue(":guid", guid);\r
58                 query.bindValue(":type", type);\r
59                 if (!query.exec()) {\r
60                         logger.log(logger.MEDIUM, "Insert into deleted items failed.");\r
61                         logger.log(logger.MEDIUM, query.lastError());\r
62                 }\r
63         }\r
64         // Add an item to the deleted table\r
65         public void expungeDeletedItem(String guid, String type) {\r
66         NSqlQuery query = new NSqlQuery(db.getConnection());\r
67                 query.prepare("delete from DeletedItems where guid=:guid and type=:type");\r
68                 query.bindValue(":guid", guid);\r
69                 query.bindValue(":type", type);\r
70                 if (!query.exec()) {\r
71                         logger.log(logger.MEDIUM, "Expunge deleted items failed.");\r
72                         logger.log(logger.MEDIUM, query.lastError());\r
73                 }\r
74         }\r
75         public List<DeletedItemRecord> getAllDeleted() {\r
76                 logger.log(logger.HIGH, "Entering DeletedTable.getAllDeleted");\r
77                 List<DeletedItemRecord> list = new ArrayList<DeletedItemRecord>();\r
78                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
79                 query.exec("Select guid, type from DeletedItems");\r
80                 while (query.next()) {\r
81                         DeletedItemRecord record = new DeletedItemRecord();\r
82                         record.guid = query.valueString(0);\r
83                         record.type = query.valueString(1);\r
84                         list.add(record);\r
85                 }\r
86                 logger.log(logger.HIGH, "Leaving DeletedTable.getAllDeleted");\r
87                 return list;\r
88 \r
89         }\r
90         public void expungeAllDeletedRecords() {\r
91                 NSqlQuery query = new NSqlQuery(db.getConnection());\r
92                 query.exec("delete from DeletedItems");\r
93         }\r
94 \r
95 }\r