diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp index a6f613f1b955fca36855b3cbe2f9ed7533807b2b..6967950aab1e73a66d4e41b5feb9447fd1be422c 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp @@ -16,19 +16,22 @@ #include "log_table_manager_factory.h" #include "cloud_sync_log_table_manager.h" #include "collaboration_log_table_manager.h" +#include "device_tracker_log_table_manager.h" #include "split_device_log_table_manager.h" namespace DistributedDB { -std::unique_ptr LogTableManagerFactory::GetTableManager(DistributedTableMode mode, - TableSyncType syncType) +std::unique_ptr LogTableManagerFactory::GetTableManager(const TableInfo &tableInfo, + DistributedTableMode mode, TableSyncType syncType) { if (syncType == CLOUD_COOPERATION) { return std::make_unique(); - } else { - if (mode == DistributedTableMode::COLLABORATION) { - return std::make_unique(); - } + } + if (!tableInfo.GetTrackerTable().IsEmpty()) { + return std::make_unique(); + } + if (mode == DistributedTableMode::SPLIT_BY_DEVICE) { return std::make_unique(); } + return std::make_unique(); } } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h index b31f9d508ad5e186774eb301005ec540a6d03ea1..623f7852b16c8ed57ffa7739647e8a2505b6a259 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h @@ -24,7 +24,8 @@ namespace DistributedDB { class LogTableManagerFactory final { public: - static std::unique_ptr GetTableManager(DistributedTableMode mode, TableSyncType syncType); + static std::unique_ptr GetTableManager(const TableInfo &tableInfo, + DistributedTableMode mode, TableSyncType syncType); private: LogTableManagerFactory() {} diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp index 9c25c59b2ad67485bfafb258109a39d6fbb254c9..5f6d1d8d489098805a63028d6dcb355e47d5c7af 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp @@ -128,7 +128,7 @@ int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTable TableInfo tableInfo = table.second; tableInfo.SetTrackerTable(trackerSchemaObj.GetTrackerTable(table.first)); tableInfo.SetDistributedTable(schemaObj.GetDistributedTable(table.first)); - auto manager = LogTableManagerFactory::GetTableManager(mode, tableInfo.GetTableSyncType()); + auto manager = LogTableManagerFactory::GetTableManager(tableInfo, mode, tableInfo.GetTableSyncType()); errCode = manager->AddRelationalLogTableTrigger(db_, tableInfo, ""); if (errCode != E_OK) { LOGE("[Relational][Upgrade] recreate distributed trigger failed. err:%d", errCode); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp index d75cb372593f5a36c21376834e26fddde130d021..195205e110ec5936d15be3551bb48a6327397302 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp @@ -1165,6 +1165,7 @@ int SQLiteSingleRelationalStorageEngine::SetDistributedSchemaInTraction(Relation continue; } TableInfo tableInfo = schemaObj.GetTable(table.tableName); + tableInfo.SetTrackerTable(GetTrackerSchema().GetTrackerTable(table.tableName)); if (tableInfo.Empty()) { continue; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h index 4e82a5899b909383e512f58f950952aec73ff38a..7f98adb6e1dcbad2e522d8ae93453c690266ce17 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h @@ -128,7 +128,7 @@ private: int SetDistributedSchemaInner(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, const std::string &localIdentity, bool isForceUpgrade); - static int SetDistributedSchemaInTraction(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, + int SetDistributedSchemaInTraction(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, const std::string &localIdentity, bool isForceUpgrade, SQLiteSingleVerRelationalStorageExecutor &handle); RelationalSchemaObject schema_; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp index ece7e590b35c8a1af7885ccde13b218eed272364..1ac223e29733283fdd80dab2bd30909b4ed7514d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp @@ -220,11 +220,7 @@ int SQLiteSingleVerRelationalStorageExecutor::CreateRelationalLogTable(Distribut { // create log table std::unique_ptr tableManager; - if (!table.GetTrackerTable().IsEmpty() && table.GetTableSyncType() == TableSyncType::DEVICE_COOPERATION) { - tableManager = std::make_unique(); - } else { - tableManager = LogTableManagerFactory::GetTableManager(mode, table.GetTableSyncType()); - } + tableManager = LogTableManagerFactory::GetTableManager(table, mode, table.GetTableSyncType()); if (tableManager == nullptr) { LOGE("[CreateRelationalLogTable] get table manager failed"); return -E_INVALID_DB; @@ -1910,7 +1906,7 @@ int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKey(DistributedTableMode if (tableInfo.GetIdentifyKey().size() == 1u && tableInfo.GetIdentifyKey().at(0) == "rowid") { return UpdateHashKeyWithOutPk(mode, tableInfo, syncType, localIdentity); } - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); auto logName = DBCommon::GetLogTableName(tableInfo.GetTableName()); std::string sql = "UPDATE OR REPLACE " + logName + " SET hash_key = hash_key || '_old' where data_key in " + "(select _rowid_ from '" + tableInfo.GetTableName() + "') AND device IS NULL;"; @@ -1928,7 +1924,7 @@ int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKey(DistributedTableMode int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKeyWithOutPk( DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType, const std::string &localIdentity) { - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); auto logName = DBCommon::GetLogTableName(tableInfo.GetTableName()); std::string extendStr = "_tmp"; std::string tmpTable = logName + extendStr; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp index 7e1ee410f7a0930a81077cc29c0aef8252f0dbc0..d3ec3f3a3e15eae641818f49571fe6930a19acd4 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp @@ -1124,7 +1124,7 @@ int SQLiteSingleVerRelationalStorageExecutor::BindStmtWithCloudGidInner(const st int SQLiteSingleVerRelationalStorageExecutor::RenewTableTrigger(DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType, const std::string &localIdentity) { - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); return tableManager->AddRelationalLogTableTrigger(dbHandle_, tableInfo, localIdentity); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp index c64cfb6ca2d1beaa72bc0d2ee6d301b5729d83f0..b07666e671c844d58676420f2317490f478f3000 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp @@ -60,7 +60,8 @@ HWTEST_F(DistributedDBInterfacesLogTest, DBFactoryTest001, TestSize.Level1) { DistributedTableMode mode = DistributedTableMode::COLLABORATION; TableSyncType tableSyncType = TableSyncType::DEVICE_COOPERATION; - auto tableManager = LogTableManagerFactory::GetTableManager(mode, tableSyncType); + TableInfo tableInfo; + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, tableSyncType); EXPECT_TRUE(tableManager != nullptr); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp index 6ac776f9d110664f5abade13a76e0992473e000d..390ae38414412c4c1e9d483b00d2ba42fd5da326 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp @@ -95,7 +95,8 @@ void CreateLogTable(const std::string &tableName) sqlite3 *db = nullptr; ASSERT_EQ(sqlite3_open(g_storePath.c_str(), &db), SQLITE_OK); auto tableManager = - LogTableManagerFactory::GetTableManager(DistributedTableMode::COLLABORATION, TableSyncType::CLOUD_COOPERATION); + LogTableManagerFactory::GetTableManager(table, DistributedTableMode::COLLABORATION, + TableSyncType::CLOUD_COOPERATION); int errCode = tableManager->CreateRelationalLogTable(db, table); EXPECT_EQ(errCode, E_OK); sqlite3_close(db);