Skip to content

Commit

Permalink
- Fixed bug with Room Overwriting old data
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Linus <[email protected]>
  • Loading branch information
rapterjet2004 committed Dec 12, 2023
1 parent 35c6b62 commit f963e51
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 9,
"identityHash": "666fcc4bbbdf3ff121b8f1ace8fcbcb8",
"identityHash": "250a3a56f3943f0d72f7ca0aac08fd1e",
"entities": [
{
"tableName": "User",
Expand Down Expand Up @@ -92,7 +92,7 @@
},
{
"tableName": "ArbitraryStorage",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountIdentifier` INTEGER NOT NULL, `key` TEXT NOT NULL, `object` TEXT, `value` TEXT, PRIMARY KEY(`accountIdentifier`, `key`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountIdentifier` INTEGER NOT NULL, `key` TEXT NOT NULL, `object` TEXT NOT NULL, `value` TEXT, PRIMARY KEY(`accountIdentifier`, `key`, `object`))",
"fields": [
{
"fieldPath": "accountIdentifier",
Expand All @@ -110,7 +110,7 @@
"fieldPath": "storageObject",
"columnName": "object",
"affinity": "TEXT",
"notNull": false
"notNull": true
},
{
"fieldPath": "value",
Expand All @@ -123,7 +123,8 @@
"autoGenerate": false,
"columnNames": [
"accountIdentifier",
"key"
"key",
"object"
]
},
"indices": [],
Expand All @@ -133,7 +134,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '666fcc4bbbdf3ff121b8f1ace8fcbcb8')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '250a3a56f3943f0d72f7ca0aac08fd1e')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import io.reactivex.Maybe

class ArbitraryStorageManager(private val arbitraryStoragesRepository: ArbitraryStoragesRepository) {
fun storeStorageSetting(accountIdentifier: Long, key: String, value: String?, objectString: String?) {
fun storeStorageSetting(accountIdentifier: Long, key: String, value: String?, objectString: String) {
arbitraryStoragesRepository.saveArbitraryStorage(ArbitraryStorage(accountIdentifier, key, objectString, value))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class ConversationInfoActivity :

override fun onResume() {
super.onResume()

if (databaseStorageModule == null) {
databaseStorageModule = DatabaseStorageModule(conversationUser, conversationToken)
}
Log.d("Julius", "DatabaseModule is $databaseStorageModule")
setUpNotificationSettings(databaseStorageModule!!)
binding.deleteConversationAction.setOnClickListener { showDeleteConversationDialog() }
binding.leaveConversationAction.setOnClickListener { leaveConversation() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ abstract class TalkDatabase : RoomDatabase() {

return Room
.databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName)
// comment out openHelperFactory to view the database entries in Android Studio for debugging
.openHelperFactory(factory)
// NOTE: comment out openHelperFactory to view the database entries in Android Studio for debugging
// .openHelperFactory(factory)
.addMigrations(Migrations.MIGRATION_6_8, Migrations.MIGRATION_7_8, Migrations.MIGRATION_8_9)
.allowMainThreadQueries()
.addCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
): Maybe<ArbitraryStorage> {
return arbitraryStoragesDao
.getStorageSetting(accountIdentifier, key, objectString)
.map { ArbitraryStorageMapper.toModel(it) }
.map {
ArbitraryStorageMapper.toModel(it)
}
}

override fun getAll(): Maybe<List<ArbitraryStorageEntity>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import kotlinx.parcelize.Parcelize
data class ArbitraryStorage(
var accountIdentifier: Long,
var key: String,
var storageObject: String? = null,
var storageObject: String,
var value: String? = null
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.room.Entity
import kotlinx.parcelize.Parcelize

@Parcelize
@Entity(tableName = "ArbitraryStorage", primaryKeys = ["accountIdentifier", "key"])
@Entity(tableName = "ArbitraryStorage", primaryKeys = ["accountIdentifier", "key", "object"])
data class ArbitraryStorageEntity(
@ColumnInfo(name = "accountIdentifier")
var accountIdentifier: Long = 0,
Expand All @@ -35,7 +35,7 @@ data class ArbitraryStorageEntity(
var key: String = "",

@ColumnInfo(name = "object")
var storageObject: String? = null,
var storageObject: String = "",

@ColumnInfo(name = "value")
var value: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,10 @@ public String getString(String key, String defaultVal) {
public void setMessageExpiration(int messageExpiration) {
this.messageExpiration = messageExpiration;
}

@androidx.annotation.NonNull
public String toString() {
return "Conversation token: " + conversationToken
+ "\nAccount Number: " + accountIdentifier;
}
}

0 comments on commit f963e51

Please sign in to comment.