mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Abstract part of the DAOs
This commit is contained in:
parent
7cbcbad40f
commit
1ec70dd1a8
@ -1,17 +1,20 @@
|
|||||||
package com.looker.droidify.database
|
package com.looker.droidify.database
|
||||||
|
|
||||||
import android.database.SQLException
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
|
|
||||||
@Dao
|
interface BaseDao<T> {
|
||||||
interface RepositoryDao {
|
|
||||||
@Insert
|
@Insert
|
||||||
@Throws(SQLException::class)
|
fun insert(vararg product: T)
|
||||||
fun insert(vararg repository: Repository)
|
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun update(vararg repository: Repository?)
|
fun update(vararg obj: T)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(obj: T)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface RepositoryDao : BaseDao<Repository> {
|
||||||
fun put(repository: Repository) {
|
fun put(repository: Repository) {
|
||||||
if (repository.id >= 0L) update(repository) else insert(repository)
|
if (repository.id >= 0L) update(repository) else insert(repository)
|
||||||
}
|
}
|
||||||
@ -25,20 +28,18 @@ interface RepositoryDao {
|
|||||||
@get:Query("SELECT _id, deleted FROM repository WHERE deleted != 0 and enabled == 0 ORDER BY _id ASC")
|
@get:Query("SELECT _id, deleted FROM repository WHERE deleted != 0 and enabled == 0 ORDER BY _id ASC")
|
||||||
val allDisabledDeleted: List<Repository.IdAndDeleted>
|
val allDisabledDeleted: List<Repository.IdAndDeleted>
|
||||||
|
|
||||||
@Delete
|
|
||||||
fun delete(repository: Repository)
|
|
||||||
|
|
||||||
@Query("DELETE FROM repository WHERE _id = :id")
|
@Query("DELETE FROM repository WHERE _id = :id")
|
||||||
fun deleteById(vararg id: Long): Int
|
fun deleteById(vararg id: Long): Int
|
||||||
|
|
||||||
|
// TODO optimize
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun markAsDeleted(id: Long) {
|
fun markAsDeleted(id: Long) {
|
||||||
update(get(id).apply { this?.deleted = 1 })
|
get(id).apply { this?.deleted = 1 }?.let { update(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ProductDao {
|
interface ProductDao : BaseDao<Product> {
|
||||||
@Query("SELECT COUNT(*) FROM product WHERE repository_id = :id")
|
@Query("SELECT COUNT(*) FROM product WHERE repository_id = :id")
|
||||||
fun countForRepository(id: Long): Long
|
fun countForRepository(id: Long): Long
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ interface ProductDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CategoryDao {
|
interface CategoryDao : BaseDao<Category> {
|
||||||
@Query(
|
@Query(
|
||||||
"""SELECT DISTINCT category.name
|
"""SELECT DISTINCT category.name
|
||||||
FROM category AS category
|
FROM category AS category
|
||||||
@ -66,11 +67,7 @@ interface CategoryDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface InstalledDao {
|
interface InstalledDao : BaseDao<Installed> {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
@Throws(SQLException::class)
|
|
||||||
fun insert(vararg installed: Installed)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM installed WHERE package_name = :packageName")
|
@Query("SELECT * FROM installed WHERE package_name = :packageName")
|
||||||
fun get(packageName: String): Installed?
|
fun get(packageName: String): Installed?
|
||||||
|
|
||||||
@ -79,11 +76,7 @@ interface InstalledDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface LockDao {
|
interface LockDao : BaseDao<Lock> {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
@Throws(SQLException::class)
|
|
||||||
fun insert(vararg lock: Lock)
|
|
||||||
|
|
||||||
@Query("DELETE FROM lock WHERE package_name = :packageName")
|
@Query("DELETE FROM lock WHERE package_name = :packageName")
|
||||||
fun delete(packageName: String)
|
fun delete(packageName: String)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user