diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..51c63e295
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,15 @@
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.trp filter=lfs diff=lfs merge=lfs -text
+*.apk filter=lfs diff=lfs merge=lfs -text
+*.jar filter=lfs diff=lfs merge=lfs -text
+*.mp4 filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.asm filter=lfs diff=lfs merge=lfs -text
+*.8svn filter=lfs diff=lfs merge=lfs -text
+*.9svn filter=lfs diff=lfs merge=lfs -text
+*.dylib filter=lfs diff=lfs merge=lfs -text
+*.exe filter=lfs diff=lfs merge=lfs -text
+*.a filter=lfs diff=lfs merge=lfs -text
+*.so filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.dll filter=lfs diff=lfs merge=lfs -text
diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md
deleted file mode 100644
index f09d98dde..000000000
--- a/.gitee/ISSUE_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 该问题是怎么引起的?
-
-
-
-### 重现步骤
-
-
-
-### 报错信息
-
-
-
-
diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
deleted file mode 100644
index 66d433205..000000000
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,14 +0,0 @@
-### 相关的Issue
-
-
-### 原因(目的、解决的问题等)
-
-
-### 描述(做了什么,变更了什么)
-
-
-### 测试用例(新增、改动、可能影响的功能)
-
-
-
-
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..1b4f1a301
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.idea/
+*.iml
+CMakeLists.txt
+cmake-build-debug
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 7cd40e552..4947287f7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,176 +1,177 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/OAT.xml b/OAT.xml
new file mode 100644
index 000000000..aa29bc2f6
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 37c19f571..b689787ac 100644
--- a/README.md
+++ b/README.md
@@ -1,119 +1,107 @@
-# distributeddatamgr_appdatamgr
+# distributeddatamgr\_appdatamgr
-- [Introduction](#section11660541593)
-- [Directory Structure](#section1464106163817)
-- [Constraints](#section1718733212019)
-- [Architecture](#section159991817144514)
-- [Available APIs](#section11510542164514)
-- [Usage Guidelines](#section1685211117463)
-- [Repositories Involved](#section10365113863719)
+- [Introduction](#section11660541593)
+ - [RDB](#section1589234172717)
+ - [Preferences Database](#section1287582752719)
+
+- [Directory Structure](#section161941989596)
+- [Relational Database](#section101010894114)
+ - [Constraints](#section18387142613414)
+
+- [Preferences Database](#section762641474720)
+ - [Constraints](#section1944481420489)
+
+- [Repositories Involved](#section1371113476307)
## Introduction
-The distributed data management service allows you to manage data in a convenient, efficient, and secure way. It reduces development costs and creates a consistent and smooth user experience across devices.
-> Currently, it supports storage of local lightweight key-value (KV) pairs. In the future, more data types will be supported.
-Lightweight key-value pairs are structured and transaction-related (to be supported in the future). Dedicated APIs related to key-value pairs are provided.
+The **relational database \(RDB\)** manages data based on relational models. With the underlying SQLite database, the OpenHarmony RDB provides a complete mechanism for managing local databases.
-> Lightweight key-value (KV) data: The data is structured, the file is lightweight, and transactional (supported in the future), and a dedicated key-value pair interface is provided separately
+The **preferences database** provides lightweight key-value operations for local applications to store a small amount of data. As the stored data is already loaded in the memory, the faster data access speed achieves a higher work efficiency. The preferences database is non-relational, and therefore it is not suitable for storing a large amount of data. Instead, the preferences database is usually used to operate data in key-value pairs.
-![输入图片说明](https://images.gitee.com/uploads/images/2021/0422/200748_51a0cbd1_8046977.png "屏幕截图.png")
+### RDB
-The lightweight KV store is developed based on the KV storage capabilities provided by Utils, and provides key-value pair management capabilities for apps. On a platform with processes, the key-value pair management capabilities provided by the KV store can only be accessed by a specific process. On such a platform, the KV store is loaded in the app process as a basic library so that it cannot be accessed by other processes.
+With the SQLite database as the persistence engine, the OpenHarmony RDB supports all features of the SQLite database , including but not limited to transactions, indices, views, triggers, foreign keys, parameterized queries, and prepared SQL statements.
-The distributed data management service abstracts data operation APIs of different platforms into unified APIs for file operations. In this way, you do not need to pay attention to the file system differences between chip platforms.
+**Figure 1** How RDB works
+
+
+![](figures/en-us_image_0000001115980740.png)
+
+### Preferences Database
+
+1. The preferences database provides operation classes for applications to operate the database.
+2. With the **PreferencesHelper**, an app can load the content of a specified file to the **Preferences** instance. Each file has only one **Preferences** instance. The system stores the instance in the memory through a static container until the app removes the instance from the memory or deletes the file.
+3. After obtaining the **Preferences** instance, the app can use the functions in **Preferences** to read data from or write data to the **Preferences** instance, and use **flush\(\)** or **flushSync\(\)** to save the modification to the file that stores the preference data.
+
+**Figure 2** How the preferences database works
+
+
+![](figures/en-us_image_0000001162419711.png)
+
+## Directory Structure
-## Directory Structure
```
-foundation/distributeddatamgr/appdatamgr/
-└─appdatamgr_lite
- │ BUILD.gn
- │
- ├─dbm_kv_store
- │ │ BUILD.gn
- │ │
- │ ├─inc
- │ │ dbm_def.h
- │ │
- │ ├─innerkits
- │ │ dbm_kv_store.h
- │ │ dbm_kv_store_env.h
- │ │
- │ └─src
- │ ├─kv_store_impl_hal
- │ │ dbm_kv_store.c
- │ │
- │ └─kv_store_impl_posix
- │ dbm_kv_store.c
- │
- └─include
- dbm_config.h
- dbm_errno.h
+//foundation/distributeddatamgr/appdatamgr
+├── frameworks # Framework code
+│ └── innerkitsimpl # Internal API implementation
+└── interfaces # APIs
+ └── innerkits # Internal APIs
```
-## Constraints
-### Lightweight Key-Value Pairs
--The platform should have file creation, reading, writing, deletion, modification, and locking capabilities. The semantic functions of APIs should be kept the same for different platforms (such as the LiteOS Cortex-M and LiteOS Cortex-A).
--Due to the differences in platform capabilities, the KV store capabilities need to be tailored accordingly. Internal implementation may be different for different platforms.
+## Relational Database
-## Architecture
-### Lightweight Key-Value Pairs
-The KV store inherits capacities from Utils. In addition, the KV store provides data deletion and binary value reading and writing capabilities while ensuring the atomicity of operations. Capabilities specific to different platforms are abstracted separately and provided by each platform.
->- The mini system generally has poor performance and insufficient memory and computing capabilities. In data management scenarios, reading operations are much more than writing operations, and memory usage is sensitive.、
->- File operation APIs used by a platform are provided by the file system. These APIs are generallynot process-safe.
->- The mini system may have no lock capabilities or lock mechanism. In that case, concurrency is guaranteed by the service. If a lock mechanism is needed, a hook should be registered by the service.
+Some basic concepts are as follows:
-## Available APIs
-- **Lightweight KV store**
+- **Relational database \(RDB\)**
- ```
- typedef struct DBM *KVStoreHandle;
- // storeFullPath is a valid directory. The key-value pairs of the KV store will be stored in this directory.
- // If you pass an empty string, key-value pairs of the KV store will be stored in the current directory.
- int DBM_GetKVStore(const char* storeFullPath, KVStoreHandle* kvStore);
-
- int DBM_Get(KVStoreHandle db, const char* key, void* value, unsigned int count, unsigned int* realValueLen);
- int DBM_Put(KVStoreHandle db, const char* key, void* value, unsigned int len);
- int DBM_Delete(KVStoreHandle db, const char* key);
-
- int DBM_CloseKVStore(KVStoreHandle db);
- // Ensure that all KVStore objects in the specified directory are closed before you delete the KV store.
- int DBM_DeleteKVStore(const char* storeFullPath);
+ A database created on the basis of relational models. The RDB stores data in rows and columns.
-## Usage Guidelines
-- **Lightweight KV store**
+- **Result set**
- ```
- // Create or open the kvStore.
- const char storeFullPath[] = ""; // A valid directory or an empty string
- KVStoreHandle kvStore = NULL;
- int ret = DBM_GetKVStore(storeFullPath, &kvStore);
-
- // Insert or update a key-value pair.
- char key[] = "rw.sys.version";
- struct {
- int num;
- char content[200];
- } value;
- memset_s(&value, sizeof(value), 0, sizeof(value));
- value.num = 1;
- strcpy_s(value.content, sizeof(value.content), "Hello world !");
- ret = DBM_Put(kvStore, key, (void*)&value, sizeof(value));
-
- // Read a key-value pair.
- memset_s(&value, sizeof(value), 0, sizeof(value));
- unsigned int realValLen = 0;
- ret = DBM_Get(g_KVStoreHandle, key, &value, sizeof(value), &realValLen);
-
- // Delete a key-value pair.
- ret = DBM_Delete(kvStore, key);
-
- // Close the KV store.
- ret = DBM_CloseKVStore(kvStore);
-
- // Delete the KV store and remove all key-value pairs.
- ret = DBM_DeleteKVStore(storeFullPath);
-
- ```
+ A set of query results used to access the data. You can access the required data in a result set in flexible modes.
+
+- **SQLite database**
+
+ A lightweight RDB in compliance with the atomicity, consistency, isolation, and durability \(ACID\) properties. It is an open-source database.
+
+
+### Constraints
+
+The RDB can use a maximum of four connection pools to manage read and write operations.
+
+To ensure data accuracy, the RDB supports only one writ operation at a time.
+
+## Preferences Database
+
+Some basic concepts are as follows:
+
+- **Key-value database**
+
+ A database that stores data in key-value pairs. The **key** indicates keyword, and **value** indicates the corresponding value.
+
+- **Non-relational database**
+
+ A database not in compliance with the atomicity, consistency, isolation, and durability \(ACID\) database management properties of relational data transactions. Instead, the data in a non-relational database is independent and scalable.
+
+- **Preference** **data**
+
+ A type of data that is frequently accessed and used.
+
+
+### Constraints
+
+A key should be a string with a maximum of 80 characters and cannot be an empty string.
+
+A value in the format of string can have a maximum of 8192 characters. A value can be an empty string.
+
+To avoid a high memory cost, it is recommended that the preferences database store no more than ten thousand data entries.
+
+## Repositories Involved
+
+Distributed Data Management subsystem
+
+distributeddatamgr\_appdatamgr
+
+third\_party\_sqlite
-## Repositories Involved
-distributeddatamgr_appdatamgr
\ No newline at end of file
diff --git a/README_zh.md b/README_zh.md
index 9bb2d8cfc..2ff2089c2 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -1,120 +1,107 @@
-# distributeddatamgr_appdatamgr
+# 本地数据管理组件
- [简介](#section11660541593)
-- [目录](#section1464106163817)
-- [约束](#section1718733212019)
-- [软件架构](#section159991817144514)
-- [接口](#section11510542164514)
-- [使用](#section1685211117463)
-- [涉及仓](#section10365113863719)
+ - [关系型数据库(RDB)](#section1589234172717)
+ - [轻量级偏好数据库(Preferences)](#section1287582752719)
+
+- [目录](#section161941989596)
+- [关系型数据库(RDB)](#section101010894114)
+ - [约束](#section18387142613414)
+
+- [轻量级偏好数据库(Preferences)](#section762641474720)
+ - [约束](#section1944481420489)
+
+- [相关仓](#section1371113476307)
## 简介
-数据管理服务为应用程序和用户提供更加便捷、高效和安全的数据管理能力。降低开发成本,打造应用跨设备运行一致、流畅的用户体验。
-> 当前先支持轻量键值(KV)本地数据存储能力,后续会逐步支持其他更丰富的数据类型。
->
-> 轻量键值(KV)数据:数据有结构,文件轻量,具有事务性(未来支持),单独提供一套专用的键值对接口
-![输入图片说明](https://images.gitee.com/uploads/images/2021/0422/193406_a3e03a96_8046977.png "屏幕截图.png")
+**关系型数据库(Relational Database,RDB)**是一种基于关系模型来管理数据的数据库。OpenHarmony关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制。
-轻量级KV数据库依托当前公共基础库提供的KV存储能力开发,为应用提供键值对参数管理能力。在有进程的平台上,KV存储提供的参数管理,供单进程访问不能被其他进程使用。在此类平台上,KV存储作为基础库加载在应用进程,以保障不被其他进程访问。
+**轻量级偏好数据库(Preferences)**主要提供轻量级Key-Value操作,支持本地应用存储少量数据,数据存储在本地文件中,同时也加载在内存中的,所以访问速度更快,效率更高。轻量级偏好数据库属于非关系型数据库,不宜存储大量数据,经常用于操作键值对形式数据的场景。
-分布式数据管理服务在不同平台上,将数据操作接口形成抽象层用来统一进行文件操作,使厂商不需要关注不同芯片平台文件系统的差异。
+### 关系型数据库(RDB)
-目前,在轻量系统上默认关闭该特性,需要使用时请用户修改vendor_hisilicon仓配置以开启。
+OpenHarmony关系型数据库底层使用SQLite作为持久化存储引擎,支持SQLite具有的所有数据库特性,包括但不限于事务、索引、视图、触发器、外键、参数化查询和预编译SQL语句。
+
+**图 1** 关系型数据库运作机制
+
+
+![](figures/zh-cn_image_0000001115980740.png)
+
+### 轻量级偏好数据库(Preferences)
+
+1. 本模块提供偏好型数据库的操作类,应用通过这些操作类完成数据库操作。
+2. 借助PreferencesHelper,可以将指定文件的内容加载到Preferences实例,每个文件最多有一个Preferences实例,系统会通过静态容器将该实例存储在内存中,直到主动从内存中移除该实例或者删除该文件。
+3. 获取Preferences实例后,可以借助Preferences类的函数,从Preferences实例中读取数据或者将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。
+
+**图 2** 轻量级偏好数据库运行机制
+
+
+![](figures/zh-cn_image_0000001162419711.png)
+
+## 目录
-## 目录
```
-foundation/distributeddatamgr/appdatamgr/
-└─appdatamgr_lite
- │ BUILD.gn
- │
- ├─dbm_kv_store
- │ │ BUILD.gn
- │ │
- │ ├─inc
- │ │ dbm_def.h
- │ │
- │ ├─innerkits
- │ │ dbm_kv_store.h
- │ │ dbm_kv_store_env.h
- │ │
- │ └─src
- │ ├─kv_store_impl_hal
- │ │ dbm_kv_store.c
- │ │
- │ └─kv_store_impl_posix
- │ dbm_kv_store.c
- │
- └─include
- dbm_config.h
- dbm_errno.h
+//foundation/distributeddatamgr/appdatamgr
+├── frameworks # 框架层代码
+│ └── innerkitsimpl # 内部接口实现
+└── interfaces # 接口代码
+ └── innerkits # 内部接口声明
```
-## 约束
-### 轻量键值(KV)数据
-- 依赖平台具有正常的文件创建、读写删除修改、锁等能力,针对不同平台(如LiteOS-M内核、LiteOS-A内核等)尽可能表现接口语义功能的不变
-- 由于平台能力差异数据库能力需要做相应裁剪,其中不同平台内部实现可能不同
-- 对于指定路径仅支持创建数据库单例,不支持同一路径创建多数据库实例对象
-## 软件架构
-### 轻量键值(KV)数据
-KV存储能力继承自公共基础库原始设计,在原有能力基础上进行增强,新增提供数据删除及二进制value读写能力的同时,保证操作的原子性;为区别平台差异,将依赖平台差异的内容单独抽象,由对应产品平台提供。
->- 轻量系统普遍性能有限,内存及计算能力不足,对于数据管理的场景大多读多写少,且内存占用敏感;
->- 平台使用的文件操作接口是由文件系统提供,一般来说文件操作接口本身并不是进程安全的,请格外注意;
->- 轻量系统,存在不具备锁能力的情况,不提供锁的机制,并发由业务保证,若需要提供有锁机制,则需要提供hook,由业务进行注册。
+## 关系型数据库(RDB)
-## 接口
-- **轻量KV存储**
+以下是几个基本概念:
- ```
- typedef struct DBM *KVStoreHandle;
- // storeFullPath为合法目录,创建的KV将已此目录创建条目
- // 传入空串则以当前目录创建
- int DBM_GetKVStore(const char* storeFullPath, KVStoreHandle* kvStore);
-
- int DBM_Get(KVStoreHandle db, const char* key, void* value, unsigned int count, unsigned int* realValueLen);
- int DBM_Put(KVStoreHandle db, const char* key, void* value, unsigned int len);
- int DBM_Delete(KVStoreHandle db, const char* key);
-
- int DBM_CloseKVStore(KVStoreHandle db);
- // 请确保删除数据库前已关闭该目录对应的所有数据库对象
- int DBM_DeleteKVStore(const char* storeFullPath);
- ```
-## 使用
+- **关系型数据库**
-- **轻量KV存储**
+ 创建在关系模型基础上的数据库,以行和列的形式存储数据。
- ```
- // 创建或打开数据库
- const char storeFullPath[] = ""; // 目录或空字符串
- KVStoreHandle kvStore = NULL;
- int ret = DBM_GetKVStore(storeFullPath, &kvStore);
-
- // 插入或修改数据
- char key[] = "rw.sys.version";
- struct {
- int num;
- char content[200];
- } value;
- memset_s(&value, sizeof(value), 0, sizeof(value));
- value.num = 1;
- strcpy_s(value.content, sizeof(value.content), "Hello world !");
- ret = DBM_Put(kvStore, key, (void*)&value, sizeof(value));
-
- // 读取数据
- memset_s(&value, sizeof(value), 0, sizeof(value));
- unsigned int realValLen = 0;
- ret = DBM_Get(g_KVStoreHandle, key, &value, sizeof(value), &realValLen);
-
- // 删除数据
- ret = DBM_Delete(kvStore, key);
-
- // 关闭数据库
- ret = DBM_CloseKVStore(kvStore);
-
- // 删除数据库
- ret = DBM_DeleteKVStore(storeFullPath);
-
- ```
+- **结果集**
+
+ 指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。
+
+- **SQLite数据库**
+
+ 一款轻量级的数据库,是遵守ACID的关系型数据库组件。它是一个开源的项目。
+
+
+### 约束
+
+数据库中连接池的最大数量是4个,用以管理用户的读写操作。
+
+为保证数据的准确性,数据库同一时间只能支持一个写操作。
+
+## 轻量级偏好数据库(Preferences)
+
+以下是几个基本概念:
+
+- **Key-Value数据库**
+
+ 一种以键值对存储数据的一种数据库。Key是关键字,Value是值。
+
+- **非关系型数据库**
+
+ 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系,扩展性好。
+
+- **偏好数据**
+
+ 用户经常访问和使用的数据。
+
+
+### 约束
+
+Key键为String类型,要求非空且长度不超过80个字符。
+
+如果Value值为String类型,可以为空但是长度不超过8192个字符。
+
+存储的数据量应该是轻量级的,建议存储的数据不超过一万条,否则会在内存方面产生较大的开销。
+
+## 相关仓
+
+分布式数据管理子系统
+
+distributeddatamgr\_appdatamgr
+
+third\_party\_sqlite
-## 涉及仓
-distributeddatamgr_appdatamgr
\ No newline at end of file
diff --git a/figures/en-us_image_0000001115980740.png b/figures/en-us_image_0000001115980740.png
new file mode 100644
index 000000000..a3d9f28d8
Binary files /dev/null and b/figures/en-us_image_0000001115980740.png differ
diff --git a/figures/en-us_image_0000001162419711.png b/figures/en-us_image_0000001162419711.png
new file mode 100644
index 000000000..f4199c10d
Binary files /dev/null and b/figures/en-us_image_0000001162419711.png differ
diff --git a/figures/zh-cn_image_0000001115980740.png b/figures/zh-cn_image_0000001115980740.png
new file mode 100644
index 000000000..4398ed073
Binary files /dev/null and b/figures/zh-cn_image_0000001115980740.png differ
diff --git a/figures/zh-cn_image_0000001162419711.png b/figures/zh-cn_image_0000001162419711.png
new file mode 100644
index 000000000..baffe5aba
Binary files /dev/null and b/figures/zh-cn_image_0000001162419711.png differ
diff --git a/find_java_files.py b/find_java_files.py
new file mode 100755
index 000000000..6ac519f2c
--- /dev/null
+++ b/find_java_files.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import fnmatch
+
+
+def FindInDirectory(directory, filename_filter):
+ for root, _dirnames, filenames in os.walk(directory):
+ matched_files = fnmatch.filter(filenames, filename_filter)
+ for file in matched_files:
+ print(os.path.join(root, file))
+
+
+def main(args):
+ dirs = args
+ for directory in dirs:
+ if os.path.isdir(directory):
+ FindInDirectory(directory, "*.java")
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/native_preferences/include/logger.h b/frameworks/innerkitsimpl/native_preferences/include/logger.h
new file mode 100644
index 000000000..69fdd4be3
--- /dev/null
+++ b/frameworks/innerkitsimpl/native_preferences/include/logger.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NATIVE_PREFERENCES_LOGGER_H
+#define NATIVE_PREFERENCES_LOGGER_H
+
+#include "hilog/log.h"
+
+namespace OHOS {
+namespace NativePreferences {
+static const OHOS::HiviewDFX::HiLogLabel DFS_LABEL = { LOG_CORE, 0xD001650, "NativePreferences" };
+
+#define LOG_DEBUG(...) ((void)OHOS::HiviewDFX::HiLog::Debug(DFS_LABEL, __VA_ARGS__))
+#define LOG_INFO(...) ((void)OHOS::HiviewDFX::HiLog::Info(DFS_LABEL, __VA_ARGS__))
+#define LOG_WARN(...) ((void)OHOS::HiviewDFX::HiLog::Warn(DFS_LABEL, __VA_ARGS__))
+#define LOG_ERROR(...) ((void)OHOS::HiviewDFX::HiLog::Error(DFS_LABEL, __VA_ARGS__))
+#define LOG_FATAL(...) ((void)OHOS::HiviewDFX::HiLog::Fatal(DFS_LABEL, __VA_ARGS__))
+} // namespace NativePreferences
+} // namespace OHOS
+
+#endif // NATIVE_PREFERENCES_LOGGER_H
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/native_preferences/include/preferences_impl.h b/frameworks/innerkitsimpl/native_preferences/include/preferences_impl.h
new file mode 100644
index 000000000..ffdec2779
--- /dev/null
+++ b/frameworks/innerkitsimpl/native_preferences/include/preferences_impl.h
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PREFERENCES_IMPL_H
+#define PREFERENCES_IMPL_H
+
+#include
+#include
+#include
+#include
+#include