DnsQueryRepository.kt 1.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.frostnerd.smokescreen.database.repository

import androidx.room.Insert
import com.frostnerd.smokescreen.database.dao.DnsQueryDao
import com.frostnerd.smokescreen.database.entities.DnsQuery
import kotlinx.coroutines.*

/**
 * Copyright Daniel Wolf 2018
 * All rights reserved.
 * Code may NOT be used without proper permission, neither in binary nor in source form.
 * All redistributions of this software in source code must retain this copyright header
 * All redistributions of this software in binary form must visibly inform users about usage of this software
 *
 * development@frostnerd.com
 */

class DnsQueryRepository(val dnsQueryDao: DnsQueryDao) {

    fun updateAsync(dnsQuery: DnsQuery): Job {
        return GlobalScope.launch {
            dnsQueryDao.update(dnsQuery)
        }
    }

    fun insertAllAsync(dnsQueries:List<DnsQuery>): Job {
        return GlobalScope.launch {
            dnsQueryDao.insertAll(dnsQueries)
        }
    }

    fun insertAsync(dnsQuery:DnsQuery): Job {
        return GlobalScope.launch {
            dnsQueryDao.insert(dnsQuery)
        }
    }

    suspend fun getAllAsync(coroutineScope: CoroutineScope): List<DnsQuery> {
        return coroutineScope.async(start = CoroutineStart.DEFAULT) {
            dnsQueryDao.getAll()
        }.await()
    }
}