From a74f188b3b55981e3846a0bfd07c85073f7e7414 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 16 Oct 2019 11:15:11 +0300 Subject: [PATCH] requery: use our own data store class. --- app/build.gradle | 1 + app/src/main/java/com/etesync/syncadapter/App.kt | 6 +++--- .../com/etesync/syncadapter/model/CollectionInfo.kt | 2 +- .../com/etesync/syncadapter/model/JournalModel.java | 12 ++++++------ .../etesync/syncadapter/model/MyEntityDataStore.kt | 9 +++++++++ .../etesync/syncadapter/syncadapter/SyncManager.kt | 4 +--- .../syncadapter/ui/CollectionMembersListFragment.kt | 5 ++--- .../ui/journalviewer/ListEntriesFragment.kt | 4 +--- 8 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/etesync/syncadapter/model/MyEntityDataStore.kt diff --git a/app/build.gradle b/app/build.gradle index 582df60d..7ef7a8a7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -152,6 +152,7 @@ dependencies { implementation "io.requery:requery-android:$requeryVersion" implementation "io.requery:requery-kotlin:$requeryVersion" kapt "io.requery:requery-processor:$requeryVersion" + implementation 'com.google.code.findbugs:jsr305:3.0.2' def spongyCastleVersion = "1.54.0.0" implementation "com.madgag.spongycastle:core:$spongyCastleVersion" diff --git a/app/src/main/java/com/etesync/syncadapter/App.kt b/app/src/main/java/com/etesync/syncadapter/App.kt index 1ca66da9..16508870 100644 --- a/app/src/main/java/com/etesync/syncadapter/App.kt +++ b/app/src/main/java/com/etesync/syncadapter/App.kt @@ -51,13 +51,13 @@ class App : Application() { * `@Provides @Singleton`. */ // override onUpgrade to handle migrating to a new version - val data: EntityDataStore + val data: MyEntityDataStore get() = initDataStore() - fun initDataStore(): EntityDataStore { + fun initDataStore(): MyEntityDataStore { val source = MyDatabaseSource(this, Models.DEFAULT, 4) val configuration = source.configuration - return EntityDataStore(configuration) + return MyEntityDataStore(configuration) } @SuppressLint("HardwareIds") diff --git a/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.kt b/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.kt index 7a1bff40..130b2900 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.kt +++ b/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.kt @@ -65,7 +65,7 @@ class CollectionInfo : Serializable { return service == type.toString() } - fun getServiceEntity(data: EntityDataStore): ServiceEntity { + fun getServiceEntity(data: MyEntityDataStore): ServiceEntity { return data.findByKey(ServiceEntity::class.java, serviceID) } diff --git a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java index a37fd74f..f68b8980 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java +++ b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java @@ -60,14 +60,14 @@ public class JournalModel { this.deleted = false; } - public Journal(EntityDataStore data, CollectionInfo info) { + public Journal(MyEntityDataStore data, CollectionInfo info) { this(); this.info = info; this.uid = info.getUid(); this.serviceModel = info.getServiceEntity(data); } - public static List getJournals(EntityDataStore data, ServiceEntity serviceEntity) { + public static List getJournals(MyEntityDataStore data, ServiceEntity serviceEntity) { List ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.DELETED.eq(false))).get().toList(); for (JournalEntity journal : ret) { // FIXME: For some reason this isn't always being called, manually do it here. @@ -76,7 +76,7 @@ public class JournalModel { return ret; } - public static JournalEntity fetch(EntityDataStore data, ServiceEntity serviceEntity, String uid) { + public static JournalEntity fetch(MyEntityDataStore data, ServiceEntity serviceEntity, String uid) { JournalEntity ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.UID.eq(uid))).limit(1).get().firstOrNull(); if (ret != null) { // FIXME: For some reason this isn't always being called, manually do it here. @@ -85,7 +85,7 @@ public class JournalModel { return ret; } - public static JournalEntity fetchOrCreate(EntityDataStore data, CollectionInfo collection) { + public static JournalEntity fetchOrCreate(MyEntityDataStore data, CollectionInfo collection) { JournalEntity journalEntity = fetch(data, collection.getServiceEntity(data), collection.getUid()); if (journalEntity == null) { journalEntity = new JournalEntity(data, collection); @@ -95,7 +95,7 @@ public class JournalModel { return journalEntity; } - public String getLastUid(EntityDataStore data) { + public String getLastUid(MyEntityDataStore data) { EntryEntity last = data.select(EntryEntity.class).where(EntryEntity.JOURNAL.eq(this)).orderBy(EntryEntity.ID.desc()).limit(1).get().firstOrNull(); if (last != null) { return last.getUid(); @@ -144,7 +144,7 @@ public class JournalModel { @Index(value = "service_unique_together") CollectionInfo.Type type; - public static ServiceEntity fetchOrCreate(EntityDataStore data, String account, CollectionInfo.Type type) { + public static ServiceEntity fetchOrCreate(MyEntityDataStore data, String account, CollectionInfo.Type type) { ServiceEntity service = data.select(ServiceEntity.class).where(ServiceEntity.ACCOUNT.eq(account).and(ServiceEntity.TYPE.eq(type))).limit(1).get().firstOrNull(); if (service == null) { // If our first time, create service and a journal diff --git a/app/src/main/java/com/etesync/syncadapter/model/MyEntityDataStore.kt b/app/src/main/java/com/etesync/syncadapter/model/MyEntityDataStore.kt new file mode 100644 index 00000000..4df62d15 --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/model/MyEntityDataStore.kt @@ -0,0 +1,9 @@ +package com.etesync.syncadapter.model + +import io.requery.Persistable +import io.requery.sql.Configuration +import io.requery.sql.EntityDataStore + +class MyEntityDataStore(configuration: Configuration): EntityDataStore(configuration) { + +} \ No newline at end of file diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt index c8a32245..9fea8c84 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt @@ -28,8 +28,6 @@ import com.etesync.syncadapter.resource.* import com.etesync.syncadapter.ui.AccountsActivity import com.etesync.syncadapter.ui.DebugInfoActivity import com.etesync.syncadapter.ui.ViewCollectionActivity -import io.requery.Persistable -import io.requery.sql.EntityDataStore import org.jetbrains.anko.defaultSharedPreferences import java.io.Closeable import java.io.FileNotFoundException @@ -54,7 +52,7 @@ constructor(protected val context: Context, protected val account: Account, prot private val crypto: Crypto.CryptoManager - private val data: EntityDataStore + private val data: MyEntityDataStore /** * remote CTag (uuid of the last entry on the server). We update it when we fetch/push and save when everything works. diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt index 76830b14..2628245f 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/CollectionMembersListFragment.kt @@ -16,15 +16,14 @@ import com.etesync.syncadapter.journalmanager.JournalManager import com.etesync.syncadapter.model.CollectionInfo import com.etesync.syncadapter.model.JournalEntity import com.etesync.syncadapter.model.JournalModel -import io.requery.Persistable -import io.requery.sql.EntityDataStore +import com.etesync.syncadapter.model.MyEntityDataStore import okhttp3.HttpUrl import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread import java.util.concurrent.Future class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickListener, Refreshable { - private lateinit var data: EntityDataStore + private lateinit var data: MyEntityDataStore private lateinit var account: Account private lateinit var info: CollectionInfo private lateinit var journalEntity: JournalEntity diff --git a/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.kt index 4fa3c060..d971bb53 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/journalviewer/ListEntriesFragment.kt @@ -24,15 +24,13 @@ import com.etesync.syncadapter.R import com.etesync.syncadapter.model.* import com.etesync.syncadapter.ui.JournalItemActivity import com.etesync.syncadapter.ui.ViewCollectionActivity -import io.requery.Persistable -import io.requery.sql.EntityDataStore import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread import java.util.concurrent.Future class ListEntriesFragment : ListFragment(), AdapterView.OnItemClickListener { - private lateinit var data: EntityDataStore + private lateinit var data: MyEntityDataStore private lateinit var account: Account private lateinit var info: CollectionInfo private var journalEntity: JournalEntity? = null