primary key

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2023-09-21 21:18:00 +02:00 committed by Andy Scherzinger
parent e926feabc7
commit 3c20251047
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
9 changed files with 164 additions and 10 deletions

View file

@ -0,0 +1,139 @@
{
"formatVersion": 1,
"database": {
"version": 9,
"identityHash": "666fcc4bbbdf3ff121b8f1ace8fcbcb8",
"entities": [
{
"tableName": "User",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `userId` TEXT, `username` TEXT, `baseUrl` TEXT, `token` TEXT, `displayName` TEXT, `pushConfigurationState` TEXT, `capabilities` TEXT, `clientCertificate` TEXT, `externalSignalingServer` TEXT, `current` INTEGER NOT NULL, `scheduledForDeletion` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "userId",
"columnName": "userId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "baseUrl",
"columnName": "baseUrl",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "token",
"columnName": "token",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "displayName",
"columnName": "displayName",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "pushConfigurationState",
"columnName": "pushConfigurationState",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "capabilities",
"columnName": "capabilities",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "clientCertificate",
"columnName": "clientCertificate",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "externalSignalingServer",
"columnName": "externalSignalingServer",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "current",
"columnName": "current",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "scheduledForDeletion",
"columnName": "scheduledForDeletion",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"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`))",
"fields": [
{
"fieldPath": "accountIdentifier",
"columnName": "accountIdentifier",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "storageObject",
"columnName": "object",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"accountIdentifier",
"key"
]
},
"indices": [],
"foreignKeys": []
}
],
"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')"
]
}
}

View file

@ -22,10 +22,11 @@ package com.nextcloud.talk.arbitrarystorage
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
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))
}
@ -36,4 +37,8 @@ class ArbitraryStorageManager(private val arbitraryStoragesRepository: Arbitrary
fun deleteAllEntriesForAccountIdentifier(accountIdentifier: Long): Int {
return arbitraryStoragesRepository.deleteArbitraryStorage(accountIdentifier)
}
fun getAll() : Maybe<List<ArbitraryStorageEntity>> {
return arbitraryStoragesRepository.getAll()
}
}

View file

@ -22,6 +22,7 @@ package com.nextcloud.talk.data.source.local
import android.content.Context
import android.util.Log
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@ -45,7 +46,7 @@ import java.util.Locale
@Database(
entities = [UserEntity::class, ArbitraryStorageEntity::class],
version = 8,
version = 9,
exportSchema = true
)
@TypeConverters(

View file

@ -41,6 +41,12 @@ abstract class ArbitraryStoragesDao {
objectString: String
): Maybe<ArbitraryStorageEntity>
@Query(
"SELECT * FROM ArbitraryStorage"
)
abstract fun getAll() : Maybe<List<ArbitraryStorageEntity>>
@Query("DELETE FROM ArbitraryStorage WHERE accountIdentifier = :accountIdentifier")
abstract fun deleteArbitraryStorage(accountIdentifier: Long): Int

View file

@ -21,10 +21,12 @@
package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
import io.reactivex.Maybe
interface ArbitraryStoragesRepository {
fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): Maybe<ArbitraryStorage>
fun deleteArbitraryStorage(accountIdentifier: Long): Int
fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long
fun getAll(): Maybe<List<ArbitraryStorageEntity>>
}

View file

@ -21,6 +21,7 @@
package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
import io.reactivex.Maybe
class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) :
@ -35,6 +36,10 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
.map { ArbitraryStorageMapper.toModel(it) }
}
override fun getAll(): Maybe<List<ArbitraryStorageEntity>> {
return arbitraryStoragesDao.getAll()
}
override fun deleteArbitraryStorage(accountIdentifier: Long): Int {
return arbitraryStoragesDao.deleteArbitraryStorage(accountIdentifier)
}

View file

@ -25,8 +25,8 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class ArbitraryStorage(
var accountIdentifier: Long = 0,
var key: String? = null,
var accountIdentifier: Long,
var key: String,
var storageObject: String? = null,
var value: String? = null
) : Parcelable

View file

@ -27,14 +27,13 @@ import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(tableName = "ArbitraryStorage")
@Entity(tableName = "ArbitraryStorage", primaryKeys = ["accountIdentifier", "key"])
data class ArbitraryStorageEntity(
@PrimaryKey
@ColumnInfo(name = "accountIdentifier")
var accountIdentifier: Long = 0,
@ColumnInfo(name = "key")
var key: String? = null,
var key: String = "",
@ColumnInfo(name = "object")
var storageObject: String? = null,

View file

@ -125,9 +125,6 @@ class FilterConversationFragment(
arbitraryStorageManager.storeStorageSetting(accountId, MENTION, mentionValue.toString(), "")
arbitraryStorageManager.storeStorageSetting(accountId, UNREAD, unreadValue.toString(), "")
val m = arbitraryStorageManager.getStorageSetting(accountId, MENTION, "")
val u = arbitraryStorageManager.getStorageSetting(accountId, UNREAD, "")
conversationsList.filterConversation()
}