Panagiotis Triantafyllou

minor db revert

......@@ -35,7 +35,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
private static final String DB_NAME = "warply.db";
private static final int DB_VERSION = 6;
private static final int DB_VERSION = 7;
private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W";
//------------------------------ Fields -----------------------------//
......@@ -222,15 +222,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
values.put(KEY_CLIENT_ID, clientId);
if (!TextUtils.isEmpty(clientSecret))
values.put(KEY_CLIENT_SECRET, clientSecret);
if (isTableNotEmpty(TABLE_CLIENT)) {
new Thread(() -> {
if (isTableNotEmpty(TABLE_CLIENT))
update(TABLE_CLIENT, values);
}).start();
} else {
new Thread(() -> {
else
insert(TABLE_CLIENT, values);
}).start();
}
}
public synchronized void saveAuthAccess(String accessToken, String refreshToken) {
......@@ -239,15 +234,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
values.put(KEY_ACCESS_TOKEN, accessToken);
if (!TextUtils.isEmpty(refreshToken))
values.put(KEY_REFRESH_TOKEN, refreshToken);
if (isTableNotEmpty(TABLE_AUTH)) {
new Thread(() -> {
if (isTableNotEmpty(TABLE_AUTH))
update(TABLE_AUTH, values);
}).start();
} else {
new Thread(() -> {
else
insert(TABLE_AUTH, values);
}).start();
}
}
@Nullable
......@@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public synchronized void deleteClient() {
new Thread(() -> {
clearTable(TABLE_CLIENT);
}).start();
}
public synchronized void deleteAuth() {
new Thread(() -> {
clearTable(TABLE_AUTH);
}).start();
}
//------------------------------ Api requests -----------------------------//
......@@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public synchronized void deleteAllRequests() {
new Thread(() -> {
clearTable(TABLE_REQUESTS);
}).start();
}
public synchronized void deleteAllPushRequests() {
new Thread(() -> {
clearTable(TABLE_PUSH_REQUESTS);
}).start();
}
public synchronized void deleteAllPushAckRequests() {
new Thread(() -> {
clearTable(TABLE_PUSH_ACK_REQUESTS);
}).start();
}
public synchronized long addRequest(String microapp, String entity, boolean force) {
new Thread(() -> {
ContentValues values = new ContentValues();
values.put(KEY_REQUESTS_MICROAPP, microapp);
values.put(KEY_REQUESTS_ENTITY, entity);
values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
insert(TABLE_REQUESTS, values);
}).start();
return getRequestsInQueueCount();
}
public synchronized long addPushRequest(String microapp, String entity, boolean force) {
new Thread(() -> {
ContentValues values = new ContentValues();
values.put(KEY_REQUESTS_MICROAPP, microapp);
values.put(KEY_REQUESTS_ENTITY, entity);
values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
insert(TABLE_PUSH_REQUESTS, values);
}).start();
return getPushRequestsInQueueCount();
}
public synchronized long addPushAckRequest(String microapp, String entity, boolean force) {
new Thread(() -> {
ContentValues values = new ContentValues();
values.put(KEY_REQUESTS_MICROAPP, microapp);
values.put(KEY_REQUESTS_ENTITY, entity);
values.put(KEY_REQUESTS_FORCE, force ? 1 : 0);
values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis());
insert(TABLE_PUSH_ACK_REQUESTS, values);
}).start();
return getPushAckRequestsInQueueCount();
}
......@@ -388,9 +362,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append("=");
strFilter.append(ids[i]);
}
new Thread(() -> {
getDb().delete(TABLE_REQUESTS, strFilter.toString(), null);
}).start();
}
public synchronized void deletePushRequests(Long... ids) {
......@@ -404,9 +376,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append("=");
strFilter.append(ids[i]);
}
new Thread(() -> {
getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null);
}).start();
}
public synchronized void deletePushAckRequests(Long... ids) {
......@@ -420,9 +390,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append("=");
strFilter.append(ids[i]);
}
new Thread(() -> {
getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null);
}).start();
}
public synchronized boolean isForceRequestsExist() {
......@@ -460,7 +428,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
//------------------------------ Tags -----------------------------//
public synchronized void saveTags(String[] tags) {
new Thread(() -> {
if (tags != null && tags.length > 0) {
try {
......@@ -481,11 +448,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
getDb().endTransaction();
}
}
}).start();
}
public synchronized void removeTags(String[] tags) {
new Thread(() -> {
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < tags.length; i++) {
if (i > 0) {
......@@ -498,7 +463,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append("'");
}
getDb().delete(TABLE_TAGS, strFilter.toString(), null);
}).start();
}
public synchronized void removeAllTags() {
......