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(() -> {
update(TABLE_CLIENT, values);
}).start();
} else {
new Thread(() -> {
insert(TABLE_CLIENT, values);
}).start();
}
if (isTableNotEmpty(TABLE_CLIENT))
update(TABLE_CLIENT, values);
else
insert(TABLE_CLIENT, values);
}
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(() -> {
update(TABLE_AUTH, values);
}).start();
} else {
new Thread(() -> {
insert(TABLE_AUTH, values);
}).start();
}
if (isTableNotEmpty(TABLE_AUTH))
update(TABLE_AUTH, values);
else
insert(TABLE_AUTH, values);
}
@Nullable
......@@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public synchronized void deleteClient() {
new Thread(() -> {
clearTable(TABLE_CLIENT);
}).start();
clearTable(TABLE_CLIENT);
}
public synchronized void deleteAuth() {
new Thread(() -> {
clearTable(TABLE_AUTH);
}).start();
clearTable(TABLE_AUTH);
}
//------------------------------ Api requests -----------------------------//
......@@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public synchronized void deleteAllRequests() {
new Thread(() -> {
clearTable(TABLE_REQUESTS);
}).start();
clearTable(TABLE_REQUESTS);
}
public synchronized void deleteAllPushRequests() {
new Thread(() -> {
clearTable(TABLE_PUSH_REQUESTS);
}).start();
clearTable(TABLE_PUSH_REQUESTS);
}
public synchronized void deleteAllPushAckRequests() {
new Thread(() -> {
clearTable(TABLE_PUSH_ACK_REQUESTS);
}).start();
clearTable(TABLE_PUSH_ACK_REQUESTS);
}
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();
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);
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();
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);
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();
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);
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();
getDb().delete(TABLE_REQUESTS, strFilter.toString(), null);
}
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();
getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null);
}
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();
getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null);
}
public synchronized boolean isForceRequestsExist() {
......@@ -460,45 +428,41 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
//------------------------------ Tags -----------------------------//
public synchronized void saveTags(String[] tags) {
new Thread(() -> {
if (tags != null && tags.length > 0) {
try {
getDb().beginTransaction();
ContentValues values = new ContentValues();
for (String tag : tags) {
values.put(KEY_TAG, tag);
values.put(KEY_TAG_LAST_ADD_DATE, System.currentTimeMillis());
insert(TABLE_TAGS, values);
}
getDb().setTransactionSuccessful();
} catch (SQLException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
} finally {
getDb().endTransaction();
if (tags != null && tags.length > 0) {
try {
getDb().beginTransaction();
ContentValues values = new ContentValues();
for (String tag : tags) {
values.put(KEY_TAG, tag);
values.put(KEY_TAG_LAST_ADD_DATE, System.currentTimeMillis());
insert(TABLE_TAGS, values);
}
getDb().setTransactionSuccessful();
} catch (SQLException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
} finally {
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) {
strFilter.append(" OR ");
}
strFilter.append(KEY_TAG);
strFilter.append("=");
strFilter.append("'");
strFilter.append(tags[i]);
strFilter.append("'");
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < tags.length; i++) {
if (i > 0) {
strFilter.append(" OR ");
}
getDb().delete(TABLE_TAGS, strFilter.toString(), null);
}).start();
strFilter.append(KEY_TAG);
strFilter.append("=");
strFilter.append("'");
strFilter.append(tags[i]);
strFilter.append("'");
}
getDb().delete(TABLE_TAGS, strFilter.toString(), null);
}
public synchronized void removeAllTags() {
......