diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java | 137 | ||||
-rw-r--r-- | client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java | 6 |
2 files changed, 111 insertions, 32 deletions
diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java index 3423e97..86b22d8 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java | |||
@@ -7,6 +7,7 @@ package com.fourisland.instadisc.Database; | |||
7 | import com.sleepycat.je.DatabaseException; | 7 | import com.sleepycat.je.DatabaseException; |
8 | import com.sleepycat.je.Environment; | 8 | import com.sleepycat.je.Environment; |
9 | import com.sleepycat.je.EnvironmentConfig; | 9 | import com.sleepycat.je.EnvironmentConfig; |
10 | import com.sleepycat.je.Transaction; | ||
10 | import com.sleepycat.persist.EntityCursor; | 11 | import com.sleepycat.persist.EntityCursor; |
11 | import com.sleepycat.persist.EntityStore; | 12 | import com.sleepycat.persist.EntityStore; |
12 | import com.sleepycat.persist.PrimaryIndex; | 13 | import com.sleepycat.persist.PrimaryIndex; |
@@ -38,6 +39,8 @@ public class Wrapper { | |||
38 | StoreConfig esConfig = new StoreConfig(); | 39 | StoreConfig esConfig = new StoreConfig(); |
39 | envConfig.setAllowCreate(true); | 40 | envConfig.setAllowCreate(true); |
40 | esConfig.setAllowCreate(true); | 41 | esConfig.setAllowCreate(true); |
42 | envConfig.setTransactional(true); | ||
43 | esConfig.setTransactional(true); | ||
41 | try { | 44 | try { |
42 | e = new Environment(new File(loc), envConfig); | 45 | e = new Environment(new File(loc), envConfig); |
43 | es = new EntityStore(e, "EntityStore", esConfig); | 46 | es = new EntityStore(e, "EntityStore", esConfig); |
@@ -73,15 +76,23 @@ public class Wrapper { | |||
73 | public static void setConfig(String key, String value) { | 76 | public static void setConfig(String key, String value) { |
74 | synchronized (idConfig) { | 77 | synchronized (idConfig) { |
75 | try { | 78 | try { |
76 | if (idConfig.contains(key)) { | 79 | Transaction t = e.beginTransaction(null, null); |
77 | IDConfig temp = idConfig.get(key); | 80 | |
78 | temp.setValue(value); | 81 | try { |
79 | idConfig.put(temp); | 82 | if (idConfig.contains(key)) { |
80 | } else { | 83 | IDConfig temp = idConfig.get(key); |
81 | IDConfig temp = new IDConfig(); | 84 | temp.setValue(value); |
82 | temp.setKey(key); | 85 | idConfig.put(t, temp); |
83 | temp.setValue(value); | 86 | } else { |
84 | idConfig.put(temp); | 87 | IDConfig temp = new IDConfig(); |
88 | temp.setKey(key); | ||
89 | temp.setValue(value); | ||
90 | idConfig.put(t, temp); | ||
91 | } | ||
92 | |||
93 | t.commit(); | ||
94 | } catch (Exception ex) { | ||
95 | t.abort(); | ||
85 | } | 96 | } |
86 | } catch (DatabaseException ex) { | 97 | } catch (DatabaseException ex) { |
87 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 98 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
@@ -112,14 +123,22 @@ public class Wrapper { | |||
112 | public static void emptyOldVerID() { | 123 | public static void emptyOldVerID() { |
113 | synchronized (oldVerID) { | 124 | synchronized (oldVerID) { |
114 | try { | 125 | try { |
115 | EntityCursor<OldVerID> ec = oldVerID.entities(); | 126 | Transaction t = e.beginTransaction(null, null); |
127 | |||
116 | try { | 128 | try { |
117 | Iterator<OldVerID> i = ec.iterator(); | 129 | EntityCursor<OldVerID> ec = oldVerID.entities(); |
118 | while (i.hasNext()) { | 130 | try { |
119 | i.remove(); | 131 | Iterator<OldVerID> i = ec.iterator(); |
132 | while (i.hasNext()) { | ||
133 | oldVerID.delete(t, i.next().getID()); | ||
134 | } | ||
135 | } finally { | ||
136 | ec.close(); | ||
120 | } | 137 | } |
121 | } finally { | 138 | |
122 | ec.close(); | 139 | t.commit(); |
140 | } catch (Exception ex) { | ||
141 | t.abort(); | ||
123 | } | 142 | } |
124 | } catch (DatabaseException ex) { | 143 | } catch (DatabaseException ex) { |
125 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 144 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
@@ -130,9 +149,17 @@ public class Wrapper { | |||
130 | public static void addOldVerID(Integer id) { | 149 | public static void addOldVerID(Integer id) { |
131 | synchronized (oldVerID) { | 150 | synchronized (oldVerID) { |
132 | try { | 151 | try { |
133 | OldVerID temp = new OldVerID(); | 152 | Transaction t = e.beginTransaction(null, null); |
134 | temp.setID(id); | 153 | |
135 | oldVerID.put(temp); | 154 | try { |
155 | OldVerID temp = new OldVerID(); | ||
156 | temp.setID(id); | ||
157 | oldVerID.put(t, temp); | ||
158 | |||
159 | t.commit(); | ||
160 | } catch (Exception ex) { | ||
161 | t.abort(); | ||
162 | } | ||
136 | } catch (DatabaseException ex) { | 163 | } catch (DatabaseException ex) { |
137 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 164 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
138 | } | 165 | } |
@@ -164,7 +191,15 @@ public class Wrapper { | |||
164 | public static void addSubscription(Subscription s) { | 191 | public static void addSubscription(Subscription s) { |
165 | synchronized (subscription) { | 192 | synchronized (subscription) { |
166 | try { | 193 | try { |
167 | subscription.put(s); | 194 | Transaction t = e.beginTransaction(null, null); |
195 | |||
196 | try { | ||
197 | subscription.put(t, s); | ||
198 | |||
199 | t.commit(); | ||
200 | } catch (Exception ex) { | ||
201 | t.abort(); | ||
202 | } | ||
168 | } catch (DatabaseException ex) { | 203 | } catch (DatabaseException ex) { |
169 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 204 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
170 | } | 205 | } |
@@ -175,10 +210,10 @@ public class Wrapper { | |||
175 | synchronized (subscription) { | 210 | synchronized (subscription) { |
176 | Collection vals = subscription.map().values(); | 211 | Collection vals = subscription.map().values(); |
177 | Subscription subs[] = new Subscription[vals.size()]; | 212 | Subscription subs[] = new Subscription[vals.size()]; |
178 | Iterator<Subscription> i = vals.iterator(); | 213 | Iterator i = vals.iterator(); |
179 | int j = 0; | 214 | int j = 0; |
180 | while (i.hasNext()) { | 215 | while (i.hasNext()) { |
181 | subs[j] = i.next(); | 216 | subs[j] = (Subscription) i.next(); |
182 | j++; | 217 | j++; |
183 | } | 218 | } |
184 | return subs; | 219 | return subs; |
@@ -188,7 +223,15 @@ public class Wrapper { | |||
188 | public static void deleteSubscription(String url) { | 223 | public static void deleteSubscription(String url) { |
189 | synchronized (subscription) { | 224 | synchronized (subscription) { |
190 | try { | 225 | try { |
191 | subscription.delete(url); | 226 | Transaction t = e.beginTransaction(null, null); |
227 | |||
228 | try { | ||
229 | subscription.delete(t, url); | ||
230 | |||
231 | t.commit(); | ||
232 | } catch (Exception ex) { | ||
233 | t.abort(); | ||
234 | } | ||
192 | } catch (DatabaseException ex) { | 235 | } catch (DatabaseException ex) { |
193 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 236 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
194 | } | 237 | } |
@@ -203,7 +246,15 @@ public class Wrapper { | |||
203 | 246 | ||
204 | synchronized (filter) { | 247 | synchronized (filter) { |
205 | try { | 248 | try { |
206 | filter.put(f); | 249 | Transaction t = e.beginTransaction(null, null); |
250 | |||
251 | try { | ||
252 | filter.put(t, f); | ||
253 | |||
254 | t.commit(); | ||
255 | } catch (Exception ex) { | ||
256 | t.abort(); | ||
257 | } | ||
207 | } catch (DatabaseException ex) { | 258 | } catch (DatabaseException ex) { |
208 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 259 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
209 | } | 260 | } |
@@ -224,7 +275,15 @@ public class Wrapper { | |||
224 | public static void deleteFilter(Integer id) { | 275 | public static void deleteFilter(Integer id) { |
225 | synchronized (filter) { | 276 | synchronized (filter) { |
226 | try { | 277 | try { |
227 | filter.delete(id); | 278 | Transaction t = e.beginTransaction(null, null); |
279 | |||
280 | try { | ||
281 | filter.delete(t, id); | ||
282 | |||
283 | t.commit(); | ||
284 | } catch (Exception ex) { | ||
285 | t.abort(); | ||
286 | } | ||
228 | } catch (DatabaseException ex) { | 287 | } catch (DatabaseException ex) { |
229 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 288 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
230 | } | 289 | } |
@@ -235,10 +294,10 @@ public class Wrapper { | |||
235 | synchronized (filter) { | 294 | synchronized (filter) { |
236 | Collection vals = filter.map().values(); | 295 | Collection vals = filter.map().values(); |
237 | Filter fils[] = new Filter[vals.size()]; | 296 | Filter fils[] = new Filter[vals.size()]; |
238 | Iterator<Filter> i = vals.iterator(); | 297 | Iterator i = vals.iterator(); |
239 | int j = 0; | 298 | int j = 0; |
240 | while (i.hasNext()) { | 299 | while (i.hasNext()) { |
241 | fils[j] = i.next(); | 300 | fils[j] = (Filter) i.next(); |
242 | j++; | 301 | j++; |
243 | } | 302 | } |
244 | return fils; | 303 | return fils; |
@@ -254,8 +313,16 @@ public class Wrapper { | |||
254 | public static void dropFromTopItem() { | 313 | public static void dropFromTopItem() { |
255 | synchronized (item) { | 314 | synchronized (item) { |
256 | try { | 315 | try { |
257 | Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator(); | 316 | Transaction t = e.beginTransaction(null, null); |
258 | item.delete(i.next().getKey()); | 317 | |
318 | try { | ||
319 | Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator(); | ||
320 | item.delete(t, i.next().getKey()); | ||
321 | |||
322 | t.commit(); | ||
323 | } catch (Exception ex) { | ||
324 | t.abort(); | ||
325 | } | ||
259 | } catch (DatabaseException ex) { | 326 | } catch (DatabaseException ex) { |
260 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 327 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
261 | } | 328 | } |
@@ -266,10 +333,10 @@ public class Wrapper { | |||
266 | synchronized (item) { | 333 | synchronized (item) { |
267 | Collection vals = item.map().values(); | 334 | Collection vals = item.map().values(); |
268 | Item items[] = new Item[vals.size()]; | 335 | Item items[] = new Item[vals.size()]; |
269 | Iterator<Item> i = vals.iterator(); | 336 | Iterator i = vals.iterator(); |
270 | int j = 0; | 337 | int j = 0; |
271 | while (i.hasNext()) { | 338 | while (i.hasNext()) { |
272 | items[j] = i.next(); | 339 | items[j] = (Item) i.next(); |
273 | j++; | 340 | j++; |
274 | } | 341 | } |
275 | return items; | 342 | return items; |
@@ -279,7 +346,15 @@ public class Wrapper { | |||
279 | public static void addItem(Item i) { | 346 | public static void addItem(Item i) { |
280 | synchronized (item) { | 347 | synchronized (item) { |
281 | try { | 348 | try { |
282 | item.put(i); | 349 | Transaction t = e.beginTransaction(null, null); |
350 | |||
351 | try { | ||
352 | item.put(t, i); | ||
353 | |||
354 | t.commit(); | ||
355 | } catch (Exception ex) { | ||
356 | t.abort(); | ||
357 | } | ||
283 | } catch (DatabaseException ex) { | 358 | } catch (DatabaseException ex) { |
284 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 359 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
285 | } | 360 | } |
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java index 91d95aa..7ba5f3b 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java | |||
@@ -5,6 +5,7 @@ | |||
5 | package com.fourisland.instadisc.Item; | 5 | package com.fourisland.instadisc.Item; |
6 | 6 | ||
7 | import com.fourisland.instadisc.Database.Filter; | 7 | import com.fourisland.instadisc.Database.Filter; |
8 | import com.fourisland.instadisc.Database.Subscription; | ||
8 | import com.fourisland.instadisc.Database.Wrapper; | 9 | import com.fourisland.instadisc.Database.Wrapper; |
9 | import com.fourisland.instadisc.Item.Categories.Category; | 10 | import com.fourisland.instadisc.Item.Categories.Category; |
10 | import com.fourisland.instadisc.XmlRpc; | 11 | import com.fourisland.instadisc.XmlRpc; |
@@ -162,7 +163,10 @@ public class WellFormedItem { | |||
162 | private boolean checkForSubscription() { | 163 | private boolean checkForSubscription() { |
163 | boolean good = Wrapper.existsSubscription(aThis.headerMap.get("Subscription")); | 164 | boolean good = Wrapper.existsSubscription(aThis.headerMap.get("Subscription")); |
164 | if (!good) { | 165 | if (!good) { |
165 | SubscriptionFile.deleteSubscription(Wrapper.getSubscription(aThis.headerMap.get("Subscription")), false); | 166 | Subscription s = new Subscription(); |
167 | s.setURL(aThis.headerMap.get("Subscription")); | ||
168 | |||
169 | SubscriptionFile.deleteSubscription(s, false); | ||
166 | } | 170 | } |
167 | return good; | 171 | return good; |
168 | } | 172 | } |