DnsQueryDao.kt 3.03 KB
Newer Older
1
2
package com.frostnerd.smokescreen.database.dao

3
import androidx.lifecycle.LiveData
4
5
6
import androidx.room.*
import com.frostnerd.smokescreen.database.entities.DnsQuery

Daniel Wolf's avatar
Daniel Wolf committed
7
8
/*
 * Copyright (C) 2019 Daniel Wolf (Ch4t4r)
9
 *
Daniel Wolf's avatar
Daniel Wolf committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You can contact the developer at daniel.wolf@frostnerd.com.
24
25
26
27
28
29
 */
@Dao
interface DnsQueryDao {
    @Query("SELECT * FROM DnsQuery")
    fun getAll(): List<DnsQuery>

30
31
32
    @Query("SELECT * FROM DnsQuery LIMIT :limit OFFSET :offset")
    fun getAll(limit:Long, offset:Long):List<DnsQuery>

33
34
35
    @Query("SELECT * FROM DnsQuery")
    fun getAllLive(): LiveData<List<DnsQuery>>

36
37
38
    @Query("SELECT * FROM DnsQuery WHERE name LIKE '%' ||:hostPart || '%'")
    fun getAllWithHostLive(hostPart:String): LiveData<List<DnsQuery>>

Daniel Wolf's avatar
Daniel Wolf committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    @Query("SELECT * FROM DnsQuery WHERE (responseSource='UPSTREAM' AND (:showForwarded=1 OR (:showBlockedByServer=1 AND responseTime>0))) " +
            "OR (responseSource='CACHE' AND :showCache=1) " +
            "OR (responseSource='LOCALRESOLVER' AND :showDnsRules=1) " +
            "OR (responseSource='CACHE_AND_LOCALRESOLVER' AND (:showCache=1 OR :showDnsRules=1)) " +
            "OR (responseSource='OTHER' AND :showForwarded=1)")
    fun getAllWithFilterLive(showForwarded:Boolean, showCache:Boolean, showDnsRules:Boolean, showBlockedByServer:Boolean):LiveData<List<DnsQuery>>

    @Query("SELECT * FROM DnsQuery WHERE (responseSource='UPSTREAM' AND (:showForwarded=1 OR (:showBlockedByServer=1 AND responseTime>0)) " +
            "OR (responseSource='CACHE' AND :showCache=1) " +
            "OR (responseSource='LOCALRESOLVER' AND :showDnsRules=1) " +
            "OR (responseSource='CACHE_AND_LOCALRESOLVER' AND (:showCache=1 OR :showDnsRules=1)) " +
            "OR (responseSource='OTHER' AND :showForwarded=1)) " +
            "AND name LIKE '%' ||:hostPart || '%'")
    fun getAllWithHostAndFilterLive(hostPart:String, showForwarded:Boolean, showCache:Boolean, showDnsRules:Boolean, showBlockedByServer:Boolean):LiveData<List<DnsQuery>>

54
55
56
    @Query("SELECT MAX(id) FROM DnsQuery")
    fun getLastInsertedId():Long

57
58
59
    @Query("SELECT COUNT(*) FROM DnsQuery")
    fun getCount():Int

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    @Insert
    fun insertAll(vararg dnsQueries: DnsQuery)

    @Insert
    fun insertAll(dnsQueries: List<DnsQuery>)

    @Insert
    fun insert(dnsQuery: DnsQuery)

    @Update
    fun update(dnsQuery: DnsQuery)

    @Delete
    fun delete(dnsQuery: DnsQuery)

    @Query("DELETE FROM DnsQuery")
    fun deleteAll()
}