From 990ab81c2bd8ae82a0d8b01d27419ad0a683c35a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 16 Oct 2019 10:35:53 +0300 Subject: [PATCH] ServiceEntity: rename fetch to fetchOrCreate. This is what it was doing anyway. --- .../main/java/com/etesync/syncadapter/model/JournalModel.java | 2 +- .../syncadapter/syncadapter/AddressBooksSyncAdapterService.kt | 2 +- .../syncadapter/syncadapter/CalendarsSyncAdapterService.kt | 2 +- .../com/etesync/syncadapter/syncadapter/SyncAdapterService.kt | 2 +- .../java/com/etesync/syncadapter/syncadapter/SyncManager.kt | 2 +- .../etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt | 2 +- .../java/com/etesync/syncadapter/ui/CreateCollectionFragment.kt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) 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 b856388f..a37fd74f 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java +++ b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java @@ -144,7 +144,7 @@ public class JournalModel { @Index(value = "service_unique_together") CollectionInfo.Type type; - public static ServiceEntity fetch(EntityDataStore data, String account, CollectionInfo.Type type) { + public static ServiceEntity fetchOrCreate(EntityDataStore 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/syncadapter/AddressBooksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt index cdb9d723..9233eaab 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt @@ -74,7 +74,7 @@ class AddressBooksSyncAdapterService : SyncAdapterService() { private fun updateLocalAddressBooks(provider: ContentProviderClient, account: Account) { val context = context val data = (getContext().applicationContext as App).data - val service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.ADDRESS_BOOK) + val service = JournalModel.Service.fetchOrCreate(data, account.name, CollectionInfo.Type.ADDRESS_BOOK) val remote = HashMap() val remoteJournals = JournalEntity.getJournals(data, service) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt index 84efe374..930aab6e 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt @@ -59,7 +59,7 @@ class CalendarsSyncAdapterService : SyncAdapterService() { @Throws(CalendarStorageException::class) private fun updateLocalCalendars(provider: ContentProviderClient, account: Account, settings: AccountSettings) { val data = (context.applicationContext as App).data - val service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.CALENDAR) + val service = JournalModel.Service.fetchOrCreate(data, account.name, CollectionInfo.Type.CALENDAR) val remote = HashMap() val remoteJournals = JournalEntity.getJournals(data, service) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt index 4c5b0ad5..ad9d63c6 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt @@ -229,7 +229,7 @@ abstract class SyncAdapterService : Service() { private fun saveCollections(journals: Iterable>) { val data = (context.applicationContext as App).data - val service = JournalModel.Service.fetch(data, account.name, serviceType) + val service = JournalModel.Service.fetchOrCreate(data, account.name, serviceType) val existing = HashMap() for (journalEntity in JournalEntity.getJournals(data, service)) { 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 f5fdb259..c8a32245 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt @@ -89,7 +89,7 @@ constructor(protected val context: Context, protected val account: Account, prot httpClient = HttpClient.Builder(context, settings).setForeground(false).build() data = (context.applicationContext as App).data - val serviceEntity = JournalModel.Service.fetch(data, accountName, serviceType) + val serviceEntity = JournalModel.Service.fetchOrCreate(data, accountName, serviceType) info = JournalEntity.fetch(data, serviceEntity, journalUid)!!.info // dismiss previous error notifications diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt index c72790fa..a9257bd7 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt @@ -78,7 +78,7 @@ class TasksSyncAdapterService: SyncAdapterService() { private fun updateLocalTaskLists(provider: TaskProvider, account: Account, settings: AccountSettings) { val data = (context.applicationContext as App).data - var service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.TASKS) + var service = JournalModel.Service.fetchOrCreate(data, account.name, CollectionInfo.Type.TASKS) val remote = HashMap() val remoteJournals = JournalEntity.getJournals(data, service) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.kt index 389c135c..5522f295 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.kt @@ -95,7 +95,7 @@ class CreateCollectionFragment : DialogFragment(), LoaderManager.LoaderCallbacks CollectionInfo.Type.TASKS -> authority = TaskProvider.ProviderName.OpenTasks.authority } - val serviceEntity = JournalModel.Service.fetch(data, account.name, info.type) + val serviceEntity = JournalModel.Service.fetchOrCreate(data, account.name, info.type) info.serviceID = serviceEntity.id val settings = AccountSettings(context, account)