Panagiotis Triantafyllou

minor db revert

...@@ -35,7 +35,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -35,7 +35,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
35 } 35 }
36 36
37 private static final String DB_NAME = "warply.db"; 37 private static final String DB_NAME = "warply.db";
38 - private static final int DB_VERSION = 6; 38 + private static final int DB_VERSION = 7;
39 private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; 39 private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W";
40 40
41 //------------------------------ Fields -----------------------------// 41 //------------------------------ Fields -----------------------------//
...@@ -222,15 +222,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -222,15 +222,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
222 values.put(KEY_CLIENT_ID, clientId); 222 values.put(KEY_CLIENT_ID, clientId);
223 if (!TextUtils.isEmpty(clientSecret)) 223 if (!TextUtils.isEmpty(clientSecret))
224 values.put(KEY_CLIENT_SECRET, clientSecret); 224 values.put(KEY_CLIENT_SECRET, clientSecret);
225 - if (isTableNotEmpty(TABLE_CLIENT)) { 225 + if (isTableNotEmpty(TABLE_CLIENT))
226 - new Thread(() -> {
227 update(TABLE_CLIENT, values); 226 update(TABLE_CLIENT, values);
228 - }).start(); 227 + else
229 - } else {
230 - new Thread(() -> {
231 insert(TABLE_CLIENT, values); 228 insert(TABLE_CLIENT, values);
232 - }).start();
233 - }
234 } 229 }
235 230
236 public synchronized void saveAuthAccess(String accessToken, String refreshToken) { 231 public synchronized void saveAuthAccess(String accessToken, String refreshToken) {
...@@ -239,15 +234,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -239,15 +234,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
239 values.put(KEY_ACCESS_TOKEN, accessToken); 234 values.put(KEY_ACCESS_TOKEN, accessToken);
240 if (!TextUtils.isEmpty(refreshToken)) 235 if (!TextUtils.isEmpty(refreshToken))
241 values.put(KEY_REFRESH_TOKEN, refreshToken); 236 values.put(KEY_REFRESH_TOKEN, refreshToken);
242 - if (isTableNotEmpty(TABLE_AUTH)) { 237 + if (isTableNotEmpty(TABLE_AUTH))
243 - new Thread(() -> {
244 update(TABLE_AUTH, values); 238 update(TABLE_AUTH, values);
245 - }).start(); 239 + else
246 - } else {
247 - new Thread(() -> {
248 insert(TABLE_AUTH, values); 240 insert(TABLE_AUTH, values);
249 - }).start();
250 - }
251 } 241 }
252 242
253 @Nullable 243 @Nullable
...@@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
275 } 265 }
276 266
277 public synchronized void deleteClient() { 267 public synchronized void deleteClient() {
278 - new Thread(() -> {
279 clearTable(TABLE_CLIENT); 268 clearTable(TABLE_CLIENT);
280 - }).start();
281 } 269 }
282 270
283 public synchronized void deleteAuth() { 271 public synchronized void deleteAuth() {
284 - new Thread(() -> {
285 clearTable(TABLE_AUTH); 272 clearTable(TABLE_AUTH);
286 - }).start();
287 } 273 }
288 274
289 //------------------------------ Api requests -----------------------------// 275 //------------------------------ Api requests -----------------------------//
...@@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
312 } 298 }
313 299
314 public synchronized void deleteAllRequests() { 300 public synchronized void deleteAllRequests() {
315 - new Thread(() -> {
316 clearTable(TABLE_REQUESTS); 301 clearTable(TABLE_REQUESTS);
317 - }).start();
318 } 302 }
319 303
320 public synchronized void deleteAllPushRequests() { 304 public synchronized void deleteAllPushRequests() {
321 - new Thread(() -> {
322 clearTable(TABLE_PUSH_REQUESTS); 305 clearTable(TABLE_PUSH_REQUESTS);
323 - }).start();
324 } 306 }
325 307
326 public synchronized void deleteAllPushAckRequests() { 308 public synchronized void deleteAllPushAckRequests() {
327 - new Thread(() -> {
328 clearTable(TABLE_PUSH_ACK_REQUESTS); 309 clearTable(TABLE_PUSH_ACK_REQUESTS);
329 - }).start();
330 } 310 }
331 311
332 public synchronized long addRequest(String microapp, String entity, boolean force) { 312 public synchronized long addRequest(String microapp, String entity, boolean force) {
333 - new Thread(() -> {
334 ContentValues values = new ContentValues(); 313 ContentValues values = new ContentValues();
335 values.put(KEY_REQUESTS_MICROAPP, microapp); 314 values.put(KEY_REQUESTS_MICROAPP, microapp);
336 values.put(KEY_REQUESTS_ENTITY, entity); 315 values.put(KEY_REQUESTS_ENTITY, entity);
337 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); 316 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
338 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); 317 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
339 insert(TABLE_REQUESTS, values); 318 insert(TABLE_REQUESTS, values);
340 - }).start();
341 return getRequestsInQueueCount(); 319 return getRequestsInQueueCount();
342 } 320 }
343 321
344 public synchronized long addPushRequest(String microapp, String entity, boolean force) { 322 public synchronized long addPushRequest(String microapp, String entity, boolean force) {
345 - new Thread(() -> {
346 ContentValues values = new ContentValues(); 323 ContentValues values = new ContentValues();
347 values.put(KEY_REQUESTS_MICROAPP, microapp); 324 values.put(KEY_REQUESTS_MICROAPP, microapp);
348 values.put(KEY_REQUESTS_ENTITY, entity); 325 values.put(KEY_REQUESTS_ENTITY, entity);
349 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); 326 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
350 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); 327 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
351 insert(TABLE_PUSH_REQUESTS, values); 328 insert(TABLE_PUSH_REQUESTS, values);
352 - }).start();
353 return getPushRequestsInQueueCount(); 329 return getPushRequestsInQueueCount();
354 } 330 }
355 331
356 public synchronized long addPushAckRequest(String microapp, String entity, boolean force) { 332 public synchronized long addPushAckRequest(String microapp, String entity, boolean force) {
357 - new Thread(() -> {
358 ContentValues values = new ContentValues(); 333 ContentValues values = new ContentValues();
359 values.put(KEY_REQUESTS_MICROAPP, microapp); 334 values.put(KEY_REQUESTS_MICROAPP, microapp);
360 values.put(KEY_REQUESTS_ENTITY, entity); 335 values.put(KEY_REQUESTS_ENTITY, entity);
361 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); 336 values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
362 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); 337 values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
363 insert(TABLE_PUSH_ACK_REQUESTS, values); 338 insert(TABLE_PUSH_ACK_REQUESTS, values);
364 - }).start();
365 return getPushAckRequestsInQueueCount(); 339 return getPushAckRequestsInQueueCount();
366 } 340 }
367 341
...@@ -388,9 +362,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -388,9 +362,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
388 strFilter.append("="); 362 strFilter.append("=");
389 strFilter.append(ids[i]); 363 strFilter.append(ids[i]);
390 } 364 }
391 - new Thread(() -> {
392 getDb().delete(TABLE_REQUESTS, strFilter.toString(), null); 365 getDb().delete(TABLE_REQUESTS, strFilter.toString(), null);
393 - }).start();
394 } 366 }
395 367
396 public synchronized void deletePushRequests(Long... ids) { 368 public synchronized void deletePushRequests(Long... ids) {
...@@ -404,9 +376,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -404,9 +376,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
404 strFilter.append("="); 376 strFilter.append("=");
405 strFilter.append(ids[i]); 377 strFilter.append(ids[i]);
406 } 378 }
407 - new Thread(() -> {
408 getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null); 379 getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null);
409 - }).start();
410 } 380 }
411 381
412 public synchronized void deletePushAckRequests(Long... ids) { 382 public synchronized void deletePushAckRequests(Long... ids) {
...@@ -420,9 +390,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -420,9 +390,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
420 strFilter.append("="); 390 strFilter.append("=");
421 strFilter.append(ids[i]); 391 strFilter.append(ids[i]);
422 } 392 }
423 - new Thread(() -> {
424 getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null); 393 getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null);
425 - }).start();
426 } 394 }
427 395
428 public synchronized boolean isForceRequestsExist() { 396 public synchronized boolean isForceRequestsExist() {
...@@ -460,7 +428,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -460,7 +428,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
460 428
461 //------------------------------ Tags -----------------------------// 429 //------------------------------ Tags -----------------------------//
462 public synchronized void saveTags(String[] tags) { 430 public synchronized void saveTags(String[] tags) {
463 - new Thread(() -> {
464 if (tags != null && tags.length > 0) { 431 if (tags != null && tags.length > 0) {
465 432
466 try { 433 try {
...@@ -481,11 +448,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -481,11 +448,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
481 getDb().endTransaction(); 448 getDb().endTransaction();
482 } 449 }
483 } 450 }
484 - }).start();
485 } 451 }
486 452
487 public synchronized void removeTags(String[] tags) { 453 public synchronized void removeTags(String[] tags) {
488 - new Thread(() -> {
489 StringBuilder strFilter = new StringBuilder(); 454 StringBuilder strFilter = new StringBuilder();
490 for (int i = 0; i < tags.length; i++) { 455 for (int i = 0; i < tags.length; i++) {
491 if (i > 0) { 456 if (i > 0) {
...@@ -498,7 +463,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -498,7 +463,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
498 strFilter.append("'"); 463 strFilter.append("'");
499 } 464 }
500 getDb().delete(TABLE_TAGS, strFilter.toString(), null); 465 getDb().delete(TABLE_TAGS, strFilter.toString(), null);
501 - }).start();
502 } 466 }
503 467
504 public synchronized void removeAllTags() { 468 public synchronized void removeAllTags() {
......