• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "connection.h"
16 
17 #include "gdb_errors.h"
18 
19 namespace OHOS::DistributedDataAip {
20 static Connection::Creator g_creators[static_cast<int32_t>(DBType::DB_BUTT)] = { nullptr, nullptr };
21 
Create(const StoreConfig & config,const bool isWriter)22 std::pair<int, std::shared_ptr<Connection>> Connection::Create(const StoreConfig &config, const bool isWriter)
23 {
24     auto dbType = config.GetDbType();
25     if (dbType < DBType::DB_GRAPH || dbType >= DBType::DB_BUTT) {
26         return { E_NOT_SUPPORT, nullptr };
27     }
28 
29     auto creator = g_creators[static_cast<int32_t>(dbType)];
30     if (creator == nullptr) {
31         return { E_NOT_SUPPORT, nullptr };
32     }
33 
34     return creator(config, isWriter);
35 }
36 
RegisterCreator(DBType dbType,Creator creator)37 int32_t Connection::RegisterCreator(DBType dbType, Creator creator)
38 {
39     if (dbType < DBType::DB_GRAPH || dbType >= DBType::DB_BUTT) {
40         return E_NOT_SUPPORT;
41     }
42 
43     if (g_creators[static_cast<int32_t>(dbType)] != nullptr) {
44         return E_OK;
45     }
46 
47     g_creators[static_cast<int32_t>(dbType)] = creator;
48     return E_OK;
49 }
50 
SetId(int id)51 int Connection::SetId(int id)
52 {
53     id_ = id;
54     return id_;
55 }
56 
GetId() const57 int Connection::GetId() const
58 {
59     return id_;
60 }
61 
62 } // namespace OHOS::DistributedDataAip
63