From 2fe57dd577b1c32431b12a16579af44ea4b4de02 Mon Sep 17 00:00:00 2001 From: Shaurya Rehan Date: Tue, 3 Dec 2024 17:24:57 +0530 Subject: [PATCH] NTP-7545 | clean slate | delete specific rows of a table (#13844) --- .../db/NaviModuleDatabaseCleanerExecutor.kt | 22 ++++++++++-- .../firebase/NaviFirebaseMessagingService.kt | 14 ++++++++ .../bbps/db/cleaner/BbpsModuleTableCleaner.kt | 20 +++++++++++ .../feature/billerlist/dao/BillerListDao.kt | 4 +++ .../feature/mybills/db/DismissedBillDao.kt | 4 +++ .../bbps/feature/mybills/db/MyBillsDao.kt | 4 +++ .../prepaidrecharge/dao/AllPrepaidPlansDao.kt | 4 +++ .../PhoneNumberToOperatorCircleMappingDao.kt | 4 +++ .../PhoneSeriesOperatorCircleMappingDao.kt | 4 +++ .../ModuleDatabaseCleanerExecutor.kt | 23 +++++++++++- .../dbcleaner/NaviModuleTableCleaner.kt | 2 ++ .../pushnotification/NotificationConstants.kt | 3 ++ .../common/bankuptime/dao/BankUptimeDao.kt | 4 +++ .../butler/dao/VpaTransactionInsightsDao.kt | 4 +++ .../com/navi/pay/common/sync/dao/SyncDao.kt | 4 +++ .../common/validatevpa/dao/ValidateVpaDao.kt | 4 +++ .../db/cleaner/NaviPayModuleTableCleaner.kt | 36 +++++++++++++++++++ .../repository/SavedBeneficiaryDao.kt | 4 +++ .../transactionhistory/dao/TransactionDao.kt | 2 ++ .../upinumber/list/dao/UpiNumbersDao.kt | 4 +++ .../pay/onboarding/account/add/dao/BankDao.kt | 4 +++ .../account/common/dao/AccountDao.kt | 4 +++ .../onboarding/account/common/dao/VpaDao.kt | 4 +++ .../navi/pay/tstore/list/db/dao/OrderDao.kt | 2 ++ .../tstore/list/db/dao/OrderTagSummaryDao.kt | 4 +++ 25 files changed, 184 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/naviapp/app/db/NaviModuleDatabaseCleanerExecutor.kt b/android/app/src/main/java/com/naviapp/app/db/NaviModuleDatabaseCleanerExecutor.kt index 6e4fbacdc8..142d0ea6d2 100644 --- a/android/app/src/main/java/com/naviapp/app/db/NaviModuleDatabaseCleanerExecutor.kt +++ b/android/app/src/main/java/com/naviapp/app/db/NaviModuleDatabaseCleanerExecutor.kt @@ -47,12 +47,28 @@ constructor( } } - override fun cleanTable(moduleName: String, tableName: String) { + override fun cleanTable( + moduleName: String, + tableName: String, + keys: List?, + columnName: String? + ) { coroutineScope.launch { - getTableCleaner(moduleName = moduleName)?.cleanTable(tableName = tableName) + if (columnName.isNullOrBlank() || keys.isNullOrEmpty()) { + getTableCleaner(moduleName = moduleName)?.cleanTable(tableName = tableName) + } else { + getTableCleaner(moduleName = moduleName) + ?.cleanTableRows(tableName = tableName, keys = keys, columnName = columnName) + } NaviTrackEvent.trackEventOnClickStream( eventName = "CacheCleaner_cleanTable", - eventValues = mapOf("moduleName" to moduleName, "tableName" to tableName) + eventValues = + mapOf( + "moduleName" to moduleName, + "tableName" to tableName, + "keys" to keys.toString(), + "columnName" to columnName.orEmpty() + ) ) } } diff --git a/android/app/src/main/java/com/naviapp/pushnotification/firebase/NaviFirebaseMessagingService.kt b/android/app/src/main/java/com/naviapp/pushnotification/firebase/NaviFirebaseMessagingService.kt index c14120f039..94fda9708a 100644 --- a/android/app/src/main/java/com/naviapp/pushnotification/firebase/NaviFirebaseMessagingService.kt +++ b/android/app/src/main/java/com/naviapp/pushnotification/firebase/NaviFirebaseMessagingService.kt @@ -38,6 +38,7 @@ import com.navi.common.pushnotification.CustomNotificationHandler import com.navi.common.pushnotification.NotificationCancelBroadcastReceiver import com.navi.common.pushnotification.NotificationConstants import com.navi.common.pushnotification.NotificationReceiverActivity +import com.navi.common.utils.COMMA import com.navi.common.utils.log import com.navi.pay.common.utils.NaviPayNotificationHandler import com.naviapp.R @@ -206,6 +207,19 @@ class NaviFirebaseMessagingService : FirebaseMessagingService() { type = data[NotificationConstants.PREFERENCE_TYPE].orEmpty() ) } + NotificationConstants.ACTION_CLEAN_DATABASE_MODULE_TABLE_KEYS -> { + moduleDatabaseCleanerExecutor + .get() + .cleanTable( + moduleName = data[NotificationConstants.MODULE_NAME].orEmpty(), + tableName = data[NotificationConstants.TABLE_NAME].orEmpty(), + keys = + data[NotificationConstants.COMMA_SEPARATED_TABLE_KEYS] + .orEmpty() + .split(COMMA), + columnName = data[NotificationConstants.COLUMN_NAME].orEmpty() + ) + } } NaviTrackEvent.trackEventOnClickStream( Constants.SILENT_PN_ACTION, diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/db/cleaner/BbpsModuleTableCleaner.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/db/cleaner/BbpsModuleTableCleaner.kt index 45a018ea2f..7dc3b210df 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/db/cleaner/BbpsModuleTableCleaner.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/db/cleaner/BbpsModuleTableCleaner.kt @@ -7,6 +7,7 @@ package com.navi.bbps.db.cleaner +import androidx.sqlite.db.SimpleSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_ALL_PREPAID_PLANS_TABLE import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_DATABASE_BILLERS @@ -33,4 +34,23 @@ constructor(private val naviBbpsAppDatabase: NaviBbpsAppDatabase) : NaviModuleTa NAVI_BBPS_TABLE_MY_SAVED_BILLS -> naviBbpsAppDatabase.myBillsDao().deleteAll() } } + + override suspend fun cleanTableRows(tableName: String, keys: List, columnName: String) { + val placeholders = keys.joinToString(",") { "?" } + val query = "DELETE FROM $tableName WHERE $columnName IN ($placeholders)" + val sqlQuery = SimpleSQLiteQuery(query, keys.toTypedArray()) + + when (tableName) { + NAVI_BBPS_DATABASE_BILLERS -> naviBbpsAppDatabase.billerListDao().deleteRows(sqlQuery) + NAVI_BBPS_ALL_PREPAID_PLANS_TABLE -> + naviBbpsAppDatabase.allPrepaidPlansDao().deleteRows(sqlQuery) + NAVI_BBPS_TABLE_DISMISSED_BILLS -> + naviBbpsAppDatabase.dismissedBillDao().deleteRows(sqlQuery) + NAVI_BBPS_MOBILE_SERIES_TO_OPERATOR_CIRCLE_MAPPING_TABLE -> + naviBbpsAppDatabase.phoneSeriesOperatorCircleMappingDao().deleteRows(sqlQuery) + NAVI_BBPS_MOBILE_NUMBER_TO_OPERATOR_CIRCLE_MAPPING_TABLE -> + naviBbpsAppDatabase.phoneNumberToOperatorCircleMappingDao().deleteRows(sqlQuery) + NAVI_BBPS_TABLE_MY_SAVED_BILLS -> naviBbpsAppDatabase.myBillsDao().deleteRows(sqlQuery) + } + } } diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/billerlist/dao/BillerListDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/billerlist/dao/BillerListDao.kt index 279471553e..7e62b6d24c 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/billerlist/dao/BillerListDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/billerlist/dao/BillerListDao.kt @@ -9,8 +9,10 @@ package com.navi.bbps.feature.billerlist.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_DATABASE_BILLERS import com.navi.bbps.feature.billerlist.model.view.BillerItemEntity @@ -31,4 +33,6 @@ interface BillerListDao { suspend fun getBillersByCategory(categoryId: String): List @Query("DELETE FROM $NAVI_BBPS_DATABASE_BILLERS") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/DismissedBillDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/DismissedBillDao.kt index aae64e4007..51db50f496 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/DismissedBillDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/DismissedBillDao.kt @@ -9,7 +9,9 @@ package com.navi.bbps.feature.mybills.db import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_TABLE_DISMISSED_BILLS import com.navi.bbps.feature.mybills.model.view.DismissedBillEntity @@ -24,4 +26,6 @@ interface DismissedBillDao { @Upsert fun insert(dismissedBillEntity: DismissedBillEntity) @Query("DELETE FROM $NAVI_BBPS_TABLE_DISMISSED_BILLS") fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/MyBillsDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/MyBillsDao.kt index 4d35b04353..cae8be334e 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/MyBillsDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/mybills/db/MyBillsDao.kt @@ -11,7 +11,9 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_TABLE_MY_SAVED_BILLS import com.navi.bbps.feature.mybills.model.view.MyBillEntity import kotlinx.coroutines.flow.Flow @@ -29,6 +31,8 @@ interface MyBillsDao { @Query("DELETE FROM $NAVI_BBPS_TABLE_MY_SAVED_BILLS") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Transaction suspend fun refresh(myBills: List) { deleteAll() diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/AllPrepaidPlansDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/AllPrepaidPlansDao.kt index abb9753c98..18fd4e6401 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/AllPrepaidPlansDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/AllPrepaidPlansDao.kt @@ -9,8 +9,10 @@ package com.navi.bbps.feature.prepaidrecharge.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_ALL_PREPAID_PLANS_TABLE import com.navi.bbps.feature.prepaidrecharge.model.view.PrepaidRechargeEntity @@ -27,6 +29,8 @@ interface AllPrepaidPlansDao { @Query("DELETE FROM $NAVI_BBPS_ALL_PREPAID_PLANS_TABLE") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query( "SELECT * FROM $NAVI_BBPS_ALL_PREPAID_PLANS_TABLE WHERE operatorCode = :operatorCode AND circleId = :circleId" ) diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneNumberToOperatorCircleMappingDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneNumberToOperatorCircleMappingDao.kt index 20a7593111..a3bd733b55 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneNumberToOperatorCircleMappingDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneNumberToOperatorCircleMappingDao.kt @@ -9,7 +9,9 @@ package com.navi.bbps.feature.prepaidrecharge.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_MOBILE_NUMBER_TO_OPERATOR_CIRCLE_MAPPING_TABLE import com.navi.bbps.feature.prepaidrecharge.model.view.PhoneNumberToOperatorCircleMappingEntity @@ -29,4 +31,6 @@ interface PhoneNumberToOperatorCircleMappingDao { @Query("DELETE FROM $NAVI_BBPS_MOBILE_NUMBER_TO_OPERATOR_CIRCLE_MAPPING_TABLE") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneSeriesOperatorCircleMappingDao.kt b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneSeriesOperatorCircleMappingDao.kt index 90be3897ec..bc5ea19514 100644 --- a/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneSeriesOperatorCircleMappingDao.kt +++ b/android/navi-bbps/src/main/kotlin/com/navi/bbps/feature/prepaidrecharge/dao/PhoneSeriesOperatorCircleMappingDao.kt @@ -9,7 +9,9 @@ package com.navi.bbps.feature.prepaidrecharge.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.bbps.db.NaviBbpsAppDatabase.Companion.NAVI_BBPS_MOBILE_SERIES_TO_OPERATOR_CIRCLE_MAPPING_TABLE import com.navi.bbps.feature.prepaidrecharge.model.view.OperatorCircleSeriesMappingItemEntity @@ -19,6 +21,8 @@ interface PhoneSeriesOperatorCircleMappingDao { @Query("DELETE FROM $NAVI_BBPS_MOBILE_SERIES_TO_OPERATOR_CIRCLE_MAPPING_TABLE") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Upsert suspend fun upsertMapping(mapping: List) @Query( diff --git a/android/navi-common/src/main/java/com/navi/common/dbcleaner/ModuleDatabaseCleanerExecutor.kt b/android/navi-common/src/main/java/com/navi/common/dbcleaner/ModuleDatabaseCleanerExecutor.kt index ea08be29e6..32adb9139b 100644 --- a/android/navi-common/src/main/java/com/navi/common/dbcleaner/ModuleDatabaseCleanerExecutor.kt +++ b/android/navi-common/src/main/java/com/navi/common/dbcleaner/ModuleDatabaseCleanerExecutor.kt @@ -7,8 +7,29 @@ package com.navi.common.dbcleaner +/** Interface for executing database cleaning tasks in different modules. */ interface ModuleDatabaseCleanerExecutor { + /** + * Cleans the entire database in the specified module. + * + * @param moduleName the name of the module. + * @param dbName the name of the database to clean. + */ fun cleanDatabase(moduleName: String, dbName: String) - fun cleanTable(moduleName: String, tableName: String) + /** + * Cleans a table in the specified module. + * + * @param moduleName the name of the module. + * @param tableName the name of the table to clean. + * @param keys optional list of keys to filter the rows to be cleaned. + * @param columnName optional column name to match the keys. If both keys and columnName are + * null, the entire table will be cleaned. + */ + fun cleanTable( + moduleName: String, + tableName: String, + keys: List? = null, + columnName: String? = null + ) } diff --git a/android/navi-common/src/main/java/com/navi/common/dbcleaner/NaviModuleTableCleaner.kt b/android/navi-common/src/main/java/com/navi/common/dbcleaner/NaviModuleTableCleaner.kt index fe6e68dd71..58b6eb5634 100644 --- a/android/navi-common/src/main/java/com/navi/common/dbcleaner/NaviModuleTableCleaner.kt +++ b/android/navi-common/src/main/java/com/navi/common/dbcleaner/NaviModuleTableCleaner.kt @@ -9,4 +9,6 @@ package com.navi.common.dbcleaner interface NaviModuleTableCleaner { suspend fun cleanTable(tableName: String) + + suspend fun cleanTableRows(tableName: String, keys: List, columnName: String) } diff --git a/android/navi-common/src/main/java/com/navi/common/pushnotification/NotificationConstants.kt b/android/navi-common/src/main/java/com/navi/common/pushnotification/NotificationConstants.kt index 66d82a2593..5cc6e654d6 100644 --- a/android/navi-common/src/main/java/com/navi/common/pushnotification/NotificationConstants.kt +++ b/android/navi-common/src/main/java/com/navi/common/pushnotification/NotificationConstants.kt @@ -47,7 +47,10 @@ object NotificationConstants { const val COMMA_SEPARATED_PREFERENCE_KEYS = "comma_separated_preference_keys" const val PREFERENCE_TYPE = "preference_type" const val ACTION_CLEAN_PREFERENCE_KEYS = "actionCleanPreferenceKeys" + const val ACTION_CLEAN_DATABASE_MODULE_TABLE_KEYS = "actionCleanDatabaseModuleTableKeys" const val DB_NAME = "db_name" const val TABLE_NAME = "table_name" const val MODULE_NAME = "module_name" + const val COLUMN_NAME = "column_name" + const val COMMA_SEPARATED_TABLE_KEYS = "comma_separated_table_keys" } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/common/bankuptime/dao/BankUptimeDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/common/bankuptime/dao/BankUptimeDao.kt index 35974218d1..c6333fd9b3 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/common/bankuptime/dao/BankUptimeDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/common/bankuptime/dao/BankUptimeDao.kt @@ -9,8 +9,10 @@ package com.navi.pay.common.bankuptime.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.common.bankuptime.model.view.BankUptimeEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_UPTIME_TABLE @@ -21,6 +23,8 @@ interface BankUptimeDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_BANK_UPTIME_TABLE") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query("SELECT * FROM $NAVI_PAY_DATABASE_BANK_UPTIME_TABLE WHERE ifsc IN (:ifscList)") suspend fun getBankUptimeEntitiesForIfscList(ifscList: List): List diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/common/butler/dao/VpaTransactionInsightsDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/common/butler/dao/VpaTransactionInsightsDao.kt index 498a09382b..ec5d4672da 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/common/butler/dao/VpaTransactionInsightsDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/common/butler/dao/VpaTransactionInsightsDao.kt @@ -9,7 +9,9 @@ package com.navi.pay.common.butler.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.common.butler.model.view.VpaTransactionsInsightEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME @@ -34,4 +36,6 @@ interface VpaTransactionInsightsDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/common/sync/dao/SyncDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/common/sync/dao/SyncDao.kt index af5b6d2b2c..17adb78e89 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/common/sync/dao/SyncDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/common/sync/dao/SyncDao.kt @@ -11,6 +11,8 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import androidx.room.RawQuery +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.common.sync.model.view.SyncEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_SYNC_TABLE_NAME @@ -23,4 +25,6 @@ interface SyncDao { suspend fun get(key: String): SyncEntity? @Query("DELETE FROM $NAVI_PAY_DATABASE_SYNC_TABLE_NAME") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/common/validatevpa/dao/ValidateVpaDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/common/validatevpa/dao/ValidateVpaDao.kt index bfe0643197..ef971d5e9c 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/common/validatevpa/dao/ValidateVpaDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/common/validatevpa/dao/ValidateVpaDao.kt @@ -11,6 +11,8 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import androidx.room.RawQuery +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.common.validatevpa.model.view.ValidateVpaEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_VALIDATE_VPA_CACHE_TABLE_NAME @@ -27,4 +29,6 @@ interface ValidateVpaDao { suspend fun delete(vpa: String) @Query("DELETE FROM $NAVI_PAY_DATABASE_VALIDATE_VPA_CACHE_TABLE_NAME") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/db/cleaner/NaviPayModuleTableCleaner.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/db/cleaner/NaviPayModuleTableCleaner.kt index fce47a12a7..36b2e4a1e3 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/db/cleaner/NaviPayModuleTableCleaner.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/db/cleaner/NaviPayModuleTableCleaner.kt @@ -7,6 +7,7 @@ package com.navi.pay.db.cleaner +import androidx.sqlite.db.SimpleSQLiteQuery import com.navi.common.dbcleaner.NaviModuleTableCleaner import com.navi.pay.db.NaviPayAppDatabase import com.navi.pay.db.NaviPayAppEncryptedDatabase @@ -54,4 +55,39 @@ constructor( naviPayAppDatabase.orderTagSummaryDao().deleteAll() } } + + override suspend fun cleanTableRows(tableName: String, keys: List, columnName: String) { + // Trim spaces from keys + val sanitizedKeys = keys.map { it.trim() } + // Generate placeholders for each key + val placeholders = sanitizedKeys.joinToString(",") { "?" } + // Construct the SQL query with placeholders + val query = "DELETE FROM $tableName WHERE $columnName IN ($placeholders)" + val sqlQuery = SimpleSQLiteQuery(query, sanitizedKeys.toTypedArray()) + + when (tableName) { + NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME -> + naviPayAppEncryptedDatabase.orderDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_TRANSACTION_HISTORY_TABLE_NAME -> + naviPayAppEncryptedDatabase.transactionHistoryDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_ACCOUNTS_TABLE_NAME -> + naviPayAppEncryptedDatabase.accountDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_VPA_TABLE_NAME -> + naviPayAppEncryptedDatabase.vpaDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_SAVED_BENEFICIARY_TABLE -> + naviPayAppEncryptedDatabase.savedBeneficiaryDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_VALIDATE_VPA_CACHE_TABLE_NAME -> + naviPayAppEncryptedDatabase.validateVpaDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_SYNC_TABLE_NAME -> naviPayAppDatabase.syncDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_BANK_UPTIME_TABLE -> + naviPayAppDatabase.bankUptimeDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_BANK_TABLE_NAME -> naviPayAppDatabase.bankDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_UPI_NUMBERS_TABLE_NAME -> + naviPayAppDatabase.upiNumbersDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME -> + naviPayAppDatabase.vpaTransactionInsightsDao().deleteRows(sqlQuery) + NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME -> + naviPayAppDatabase.orderTagSummaryDao().deleteRows(sqlQuery) + } + } } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/management/savedbeneficiary/repository/SavedBeneficiaryDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/management/savedbeneficiary/repository/SavedBeneficiaryDao.kt index 5e222bc11c..c575f3a6cf 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/management/savedbeneficiary/repository/SavedBeneficiaryDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/management/savedbeneficiary/repository/SavedBeneficiaryDao.kt @@ -10,7 +10,9 @@ package com.navi.pay.management.savedbeneficiary.repository import androidx.paging.PagingSource import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.management.savedbeneficiary.model.view.SavedBeneficiaryEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_SAVED_BENEFICIARY_TABLE @@ -57,4 +59,6 @@ interface SavedBeneficiaryDao { suspend fun deleteAllPartiallyDeletedBeneficiaries() @Query("DELETE FROM $NAVI_PAY_DATABASE_SAVED_BENEFICIARY_TABLE") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/management/transactionhistory/dao/TransactionDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/management/transactionhistory/dao/TransactionDao.kt index 04d5c36ba0..a96e62716a 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/management/transactionhistory/dao/TransactionDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/management/transactionhistory/dao/TransactionDao.kt @@ -71,4 +71,6 @@ interface TransactionDao { fun getOldestTransactionTimestamp(): Flow @Query("DELETE FROM $NAVI_PAY_DATABASE_TRANSACTION_HISTORY_TABLE_NAME") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int } diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/management/upinumber/list/dao/UpiNumbersDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/management/upinumber/list/dao/UpiNumbersDao.kt index 8c1041d5de..bd87796a20 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/management/upinumber/list/dao/UpiNumbersDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/management/upinumber/list/dao/UpiNumbersDao.kt @@ -9,8 +9,10 @@ package com.navi.pay.management.upinumber.list.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.management.upinumber.list.model.view.UpiNumberEntity import com.navi.pay.management.upinumber.list.model.view.UpiNumberStatus import com.navi.pay.utils.NAVI_PAY_DATABASE_UPI_NUMBERS_TABLE_NAME @@ -22,6 +24,8 @@ interface UpiNumbersDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_UPI_NUMBERS_TABLE_NAME") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Transaction suspend fun refreshUpiNumbersTable(upiNumberEntities: List) { deleteAll() diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/add/dao/BankDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/add/dao/BankDao.kt index 310df974d7..ed2100761b 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/add/dao/BankDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/add/dao/BankDao.kt @@ -12,7 +12,9 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Transaction +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.onboarding.account.add.model.view.BankEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_TABLE_NAME @@ -49,6 +51,8 @@ interface BankDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_BANK_TABLE_NAME") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query("SELECT * FROM $NAVI_PAY_DATABASE_BANK_TABLE_NAME WHERE code IN (:bankCodeList)") suspend fun getBankEntityListFromBankCodeList(bankCodeList: List): List diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/AccountDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/AccountDao.kt index 2a5b77125f..2b112c7f14 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/AccountDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/AccountDao.kt @@ -10,6 +10,8 @@ package com.navi.pay.onboarding.account.common.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query +import androidx.room.RawQuery +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.management.lite.models.view.UPILiteEntity import com.navi.pay.onboarding.account.common.model.view.AccountEntity import com.navi.pay.onboarding.account.common.model.view.AccountStatus @@ -23,6 +25,8 @@ interface AccountDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_ACCOUNTS_TABLE_NAME") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query("SELECT * FROM $NAVI_PAY_DATABASE_ACCOUNTS_TABLE_NAME WHERE status = :status") fun getAllAccountByStatusAsFlow(status: AccountStatus): Flow> diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/VpaDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/VpaDao.kt index d86ea91f3d..a92d91ced7 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/VpaDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/common/dao/VpaDao.kt @@ -10,6 +10,8 @@ package com.navi.pay.onboarding.account.common.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query +import androidx.room.RawQuery +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.onboarding.account.common.model.view.VpaEntity import com.navi.pay.onboarding.account.common.model.view.VpaStatus import com.navi.pay.utils.NAVI_PAY_DATABASE_VPA_TABLE_NAME @@ -20,6 +22,8 @@ interface VpaDao { @Query("DELETE FROM $NAVI_PAY_DATABASE_VPA_TABLE_NAME") suspend fun deleteAll() + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query( "SELECT * FROM $NAVI_PAY_DATABASE_VPA_TABLE_NAME WHERE bankAccountUniqueId IN (:bankAccountUniqueIds) AND status = :status" ) diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderDao.kt index bcaf7f0208..9a6fd4217a 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderDao.kt @@ -61,6 +61,8 @@ interface OrderDao { @RawQuery(observedEntities = [OrderEntity::class]) suspend fun getOrderHistoryCountForFilters(query: SupportSQLiteQuery): Int + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int + @Query( "SELECT " + "orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " + diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderTagSummaryDao.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderTagSummaryDao.kt index 95e6decd8c..dd88d98449 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderTagSummaryDao.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/tstore/list/db/dao/OrderTagSummaryDao.kt @@ -9,7 +9,9 @@ package com.navi.pay.tstore.list.db.dao import androidx.room.Dao import androidx.room.Query +import androidx.room.RawQuery import androidx.room.Upsert +import androidx.sqlite.db.SupportSQLiteQuery import com.navi.pay.tstore.list.model.view.OrderTagSummaryEntity import com.navi.pay.utils.NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME import kotlinx.coroutines.flow.Flow @@ -23,4 +25,6 @@ interface OrderTagSummaryDao { fun getAll(): Flow> @Query("DELETE FROM $NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME") suspend fun deleteAll() + + @RawQuery suspend fun deleteRows(query: SupportSQLiteQuery): Int }