| author | Da Risk <da_risk@geekorum.com> |
| Thu, 09 May 2019 17:53:48 -0700 | |
| changeset 137 | 5464f07a306c |
| parent 61 | 4c99647b9a58 |
| child 611 | 91b8d76c03cd |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
61
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
61
diff
changeset
|
4 |
* Copyright (C) 2017-2019 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
package com.geekorum.ttrss.data |
|
22 |
||
23 |
import androidx.room.Dao |
|
24 |
import androidx.room.Delete |
|
25 |
import androidx.room.Insert |
|
26 |
import androidx.room.OnConflictStrategy |
|
27 |
import androidx.room.Query |
|
|
61
4c99647b9a58
Make Room DAO functions suspendable when possible
Da Risk <da_risk@geekorum.com>
parents:
38
diff
changeset
|
28 |
import kotlinx.coroutines.runBlocking |
| 0 | 29 |
|
30 |
/** |
|
31 |
* Dao to read/modify transactions. |
|
32 |
*/ |
|
33 |
@Dao |
|
34 |
abstract class TransactionsDao {
|
|
35 |
@Insert(onConflict = OnConflictStrategy.REPLACE) |
|
|
61
4c99647b9a58
Make Room DAO functions suspendable when possible
Da Risk <da_risk@geekorum.com>
parents:
38
diff
changeset
|
36 |
abstract suspend fun insertTransaction(transaction: Transaction) |
| 0 | 37 |
|
38 |
@Delete |
|
|
61
4c99647b9a58
Make Room DAO functions suspendable when possible
Da Risk <da_risk@geekorum.com>
parents:
38
diff
changeset
|
39 |
abstract suspend fun deleteTransactions(transactions: Collection<Transaction>) |
| 0 | 40 |
|
41 |
||
42 |
@Query("SELECT * FROM transactions WHERE article_id=:articleId AND field=:field")
|
|
|
61
4c99647b9a58
Make Room DAO functions suspendable when possible
Da Risk <da_risk@geekorum.com>
parents:
38
diff
changeset
|
43 |
abstract suspend fun getTransactionForArticleAndType(articleId: Long, field: String): List<Transaction> |
| 0 | 44 |
|
45 |
/** |
|
46 |
* Insert a unique transaction for a [Transaction.articleId] [Transaction.field] pair. |
|
47 |
* |
|
48 |
* @param transaction |
|
49 |
*/ |
|
50 |
@androidx.room.Transaction |
|
|
61
4c99647b9a58
Make Room DAO functions suspendable when possible
Da Risk <da_risk@geekorum.com>
parents:
38
diff
changeset
|
51 |
open fun insertUniqueTransaction(transaction: Transaction) = runBlocking {
|
| 0 | 52 |
val existingTransactions = getTransactionForArticleAndType(transaction.articleId, transaction.field) |
53 |
deleteTransactions(existingTransactions) |
|
54 |
insertTransaction(transaction) |
|
55 |
} |
|
56 |
||
57 |
} |