aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-09-29 11:57:16 +0200
committersteckbrief <steckbrief@chefmail.de>2016-09-29 11:57:16 +0200
commit34fcdda53fa8ae1174909b62860534d2d874eb72 (patch)
tree50564c1d946ef1779567c67ad25a646b446a6403 /src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
parent297bed106efdfa619d700ae44ce047d7f2663c93 (diff)
Implements FS#235: Deletion of remote files uploaded via httpupload
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
index 7c2583ae..e721afbb 100644
--- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
+++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
@@ -35,6 +35,7 @@ import org.json.JSONException;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlServiceImpl;
import de.thedevstack.conversationsplus.crypto.axolotl.SQLiteAxolotlStore;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
@@ -44,6 +45,8 @@ import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.Roster;
import de.thedevstack.conversationsplus.entities.ServiceDiscoveryResult;
+import de.thedevstack.conversationsplus.persistance.db.access.CursorHelper;
+import de.thedevstack.conversationsplus.persistance.db.access.MessageDatabaseAccess;
import de.thedevstack.conversationsplus.utils.SimpleCryptoUtil;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -55,7 +58,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 25;
private static final int C_TO_CPLUS_VERSION_OFFSET = 1000;
- private static final int CPLUS_DATABASE_VERSION = 2;
+ private static final int CPLUS_DATABASE_VERSION = 3;
private static final int CPLUS_DATABASE_VERSION_MULTIPLIER = 100;
private static final int PHYSICAL_DATABASE_VERSION = DATABASE_VERSION + C_TO_CPLUS_VERSION_OFFSET + (CPLUS_DATABASE_VERSION * CPLUS_DATABASE_VERSION_MULTIPLIER);
@@ -191,18 +194,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL(CREATE_SIGNED_PREKEYS_STATEMENT);
db.execSQL(CREATE_IDENTITIES_STATEMENT);
- // Create Conversations+ related tables
- db.execSQL(MessageDatabaseAccess.TABLE_ADDITIONAL_PARAMETERS_CREATE_V0);
+ MessageDatabaseAccess.create(db);
}
protected void onUpgradeCPlusDatabase(SQLiteDatabase db, int oldVersion, int newVersion) {
Logging.d("db.upgrade.cplus", "Updating Conversations+ database from version '" + oldVersion + "' to '" + newVersion + "'");
if (oldVersion < newVersion) {
if (oldVersion < 1 && newVersion >= 1) {
- Logging.d("db.upgrade.cplus", "Creating additional parameters table for messages.");
- db.execSQL(MessageDatabaseAccess.TABLE_ADDITIONAL_PARAMETERS_CREATE_V0);
- db.execSQL("INSERT INTO " + MessageDatabaseAccess.TABLE_NAME_ADDITIONAL_PARAMETERS + "(" + MessageDatabaseAccess.COLUMN_NAME_MSG_PARAMS_MSGUUID + ") "
- + " SELECT " + Message.UUID + " FROM " + Message.TABLENAME);
+ MessageDatabaseAccess.upgrade(db, oldVersion, newVersion);
}
if (oldVersion < 2 && newVersion >= 2) {
Logging.d("db.upgrade.cplus", "Encrypt all passwords for the first time");
@@ -217,6 +216,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
cursor.close();
}
+
+ if (oldVersion < 3 && newVersion >= 3) {
+ MessageDatabaseAccess.upgrade(db, oldVersion, newVersion);
+ }
}
}
@@ -434,6 +437,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
}
+ public static synchronized DatabaseBackend getInstance() {
+ return getInstance(ConversationsPlusApplication.getAppContext());
+ }
+
public static synchronized DatabaseBackend getInstance(Context context) {
if (instance == null) {
instance = new DatabaseBackend(context);
@@ -657,15 +664,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public void updateMessage(Message message) {
- Logging.d("db.msg.update", "Updating message with uuid '" + message.getUuid() + "', isRead: " + message.isRead());
- SQLiteDatabase db = this.getWritableDatabase();
- String[] args = {message.getUuid()};
- db.beginTransaction();
- db.update(Message.TABLENAME, message.getContentValues(), Message.UUID
- + "=?", args);
- db.update(MessageDatabaseAccess.TABLE_NAME_ADDITIONAL_PARAMETERS, MessageDatabaseAccess.getAdditionalParametersContentValues(message), MessageDatabaseAccess.COLUMN_NAME_MSG_PARAMS_MSGUUID + "=?", args);
- db.setTransactionSuccessful();
- db.endTransaction();
+ this.updateMessage(message, message.getUuid());
}
public void updateMessage(Message message, String uuid) {
@@ -676,7 +675,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.beginTransaction();
db.update(Message.TABLENAME, message.getContentValues(), Message.UUID
+ "=?", args);
- db.update(MessageDatabaseAccess.TABLE_NAME_ADDITIONAL_PARAMETERS, MessageDatabaseAccess.getAdditionalParametersContentValues(message), MessageDatabaseAccess.COLUMN_NAME_MSG_PARAMS_MSGUUID + "=?", args);
+ MessageDatabaseAccess.updateMessageParameters(db, message, uuid);
db.setTransactionSuccessful();
db.endTransaction();
}