From 44585914cf89964ade5cfb589f8c786498f2a1c1 Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Wed, 26 Jan 2022 17:22:11 +0800 Subject: [PATCH 1/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/Readme-EN.md | 7 + .../figure/en-us_image_0000001192123772.png | Bin 0 -> 13119 bytes .../subsys-data-relational-database.md | 5 + .../subsystems/subsys-data-storage-guide.md | 193 ++++++++++++++++++ .../subsys-data-storage-overview.md | 31 +++ .../subsystems/subsys-data-storage.md | 5 + en/device-dev/subsystems/subsys-data.md | 4 + en/device-dev/subsystems/subsys.md | 2 + 8 files changed, 247 insertions(+) create mode 100644 en/device-dev/subsystems/figure/en-us_image_0000001192123772.png create mode 100644 en/device-dev/subsystems/subsys-data-relational-database.md create mode 100644 en/device-dev/subsystems/subsys-data-storage-guide.md create mode 100644 en/device-dev/subsystems/subsys-data-storage-overview.md create mode 100644 en/device-dev/subsystems/subsys-data-storage.md create mode 100644 en/device-dev/subsystems/subsys-data.md diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 393e36646fa..9e3d89ce67a 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -39,6 +39,13 @@ - [KWS SDK](subsys-aiframework-demo-sdk.md) - [KWS Plug-in](subsys-aiframework-demo-plugin.md) - [KWS Configuration File](subsys-aiframework-demo-conf.md) +- [Data Management](subsys-data.md) + - [RDB](subsys-data-relational-database.md) + - [RDB Overview](subsys-data-relational-database-overview.md) + - [RDB Development](subsys-data-relational-database-guide.md) + - [Lightweight Data Store](subsys-data-storage.md) + - [Lightweight Data Store Overview](subsys-data-storage-overview.md) + - [Lightweight Data Store Development](subsys-data-storage-guide.md) - [Sensors](subsys-sensor.md) - [Sensors Overview](subsys-sensor-overview.md) - [Sensors Usage Guidelines](subsys-sensor-guide.md) diff --git a/en/device-dev/subsystems/figure/en-us_image_0000001192123772.png b/en/device-dev/subsystems/figure/en-us_image_0000001192123772.png new file mode 100644 index 0000000000000000000000000000000000000000..8d1dabae78c438928544864ca2cada41260aa2f5 GIT binary patch literal 13119 zcmd6N1yoes+wTy9DDf(xf^jJtaB=o0Wu@>I>t3j`wn za`A_k#6wO80tt<%E8RDGX0DgHo9B8Y6jAjYPRpeuT3%<&3w6_&)5mW zG5DnFLGH$4f)uO~KcQgF2VWnyx`DxgY)mP&0*Lj+u@3d9&?+#~dy?n~@rH@%$x&{F zgz#$3Pdy{HmxFC?&B!|H#099x(Dn`WK4v(#9_89w*&H4g?rmFI+w#`6`NB*i=Kdr} z?rd8ZcJW0_IYEoUIW%iFc}S$y^YT({GN4jk)~VSqiz?L~xCg0SZX>)Xc?f}Z0D;Q> z(7GtzD+u5L#m6iEt$s9gT@LfVo_eMZfA;ObK|6s|hL?JHN&Q%F#8Zg0g=uE9G6CWW zk{@GA1%-0$1x_60TdVK=$S81JAwav0aae9|R2?tx8koDTzRi99a@XAcqtV*{po0lB z&;eevh6fK^;4piSmF7y}EbvM(qX5a%{2FWI6idl+BZrf{-L&V^D`m;-;5Ju}55q4R ziid~ac{i*-A{pR_sh@G_H7c0XJhq3u;jRy~G95Y&tdmmK{fst?4lGm+X7^bN9Mi^r z-9$FA#97aijToS)=*kbn>&FfZda4q?%s%m zJ%V#-w>If^FDN)2&jeN-Z+dCdnPMxmyl`;{)k{4667E#~Xs`8Hmo znQ;aWE5yM={3{@o5+D%*#=aYg)1>V;O4rp}CBL_1UFtWSJn z>mjdmm%yDoIs)&p+|@t0Cl*O3>n-g{6srq|%>7>Um+KOBNLARv+ zB$TAgZ4&A++r?ROdo>?eF9!;-3=o5$w=Q#lY+{zVbY3lG$bbAUKB~@_h>i;LsZ8ub z6!1&`jIE#P94tjs%Gexm%ZiH(&MlrvSv898KcCh<+AfbyhpcR%&{BRGbZXwUkBi@*W>*$+B<}$DNOy0e$dlU^!Dpl(~ zmFVf}k7MxQ@dwkazSMW7!7Ng&{aiX6Y_LHr553XP0v-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{nsA6H3wb~0J~f6{1)H%F}GHT|s8 z&i{?E2h2LP58Q4b&L{TGaZPd;lcU^i&Cv~APTD*V4zfNu0_MCK(#o}5k9Y0p9Am+9 UC9jqfeIWqq$~sCF3O3LG2dZe#?EnA( literal 0 HcmV?d00001 diff --git a/en/device-dev/subsystems/subsys-data-relational-database.md b/en/device-dev/subsystems/subsys-data-relational-database.md new file mode 100644 index 00000000000..b1b3c1b1550 --- /dev/null +++ b/en/device-dev/subsystems/subsys-data-relational-database.md @@ -0,0 +1,5 @@ +# RDB + +- **[RDB Overview](subsys-data-relational-database-overview.md)** + +- **[RDB Development](subsys-data-relational-database-guide.md)** diff --git a/en/device-dev/subsystems/subsys-data-storage-guide.md b/en/device-dev/subsystems/subsys-data-storage-guide.md new file mode 100644 index 00000000000..152935dc1a6 --- /dev/null +++ b/en/device-dev/subsystems/subsys-data-storage-guide.md @@ -0,0 +1,193 @@ +# Lightweight Data Store Development + +## When to Use + +The lightweight data store is ideal for storing lightweight and frequently used data, but not for storing a large amount of data or data with frequent changes. The application data is persistently stored on a device in the form of files. Note that the instance accessed by an application contains all data of the file. The data is always loaded to the memory of the device until the application removes it from the memory. The application can perform data operations using the Preferences APIs. + +## Available APIs + +The lightweight data store provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value pairs. Keys are of the string type, and values can be of the string, Boolean, integer, long integer, float, double, or string array type. + +**Creating a Preferences Instance** + +Create a **Preferences** instance for data operations. A **Preferences** instance is created after data is read from a specified file and loaded to the instance. + +**Table 1** API for creating a Preferences instance + +| Class| Method| Description| +| --- | ----- | ----| +| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | Creates a **Preferences** instance.
**path**: storage path of the application data.
**errCode**: error code.
Return value: **Preferences** instance created.| + +**Writing Data** + +Call the **put()** method to add or modify data in a **Preferences** instance. + +**Table 2** APIs for writing data + +| Class| Method| Description| +| --- | ----- | ----| +| Preferences | int PutInt(const std::string &key, int value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutString(const std::string &key, const std::string &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutBool(const std::string &key, bool value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutLong(const std::string &key, int64_t value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutFloat(const std::string &key, float value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutDouble(const std::string &key, double value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| + +**Reading Data** + +Call the **get()** method to read data from a **Preferences** instance. + +**Table 3** APIs for reading data + +| Class| Method| Description| +| --- | ----- | ----| +| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | float GetFloat(const std::string &key, float defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | double GetDouble(const std::string &key, double defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| + +**Storing Data Persistently** + +Call the **flush()** or **flushSync** method to write the cached data back to its text file for persistent storage. + +**Table 4** APIs for data persistence + +| Class| Method| Description| +| --- | ----- | ----| +| Preferences | void Flush(); | Writes data in the **Preferences** instance back to its file through an asynchronous thread.| +| Preferences | int FlushSync(); | Writes data in the **Preferences** instance back to its file through a synchronous thread.| + +**Observing Data Changes** + +Specify **PreferencesObserver** as the callback to subscribe to data changes. When the value of the subscribed key is changed and the **flush()** method is executed, **PreferencesObserver** will be invoked. + +**Table 5** APIs for subscribing to data changes + +| Class| Method| Description| +| --- | ----- | ----| +| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | Subscribes to data changes.
**preferencesObserver**: callback invoked to return the data changes.| +| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | Unsubscribes from data changes.
**preferencesObserver**: callback used to report data changes.| + +**Deleting Data** + +Use the following APIs to delete a **Preferences** instance or data file. + +**Table 6** APIs for deleting data + +| Class| Method| Description| +| --- | ----- | ----| +| PreferencesHelper | int DeletePreferences(const std::string &path); | Deletes a **Preferences** instance from the memory and deletes its file from the device.
**path**: storage path of the application data.
Return value: error code.| +| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | Deletes a **Preferences** instance from the memory.
**path**: storage path of the application data.
Return value: error code.| + +## How to Develop + +1. Import the Preferences module and related header files to the development environment. + + ``` C++ + Header file path: //distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include + ``` + +2. Create a **Preferences** instance. + + Read the specified file and load its data to the **Preferences** instance for data operations. + + ``` C++ + int errCode = E_OK; + Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH must be the application sandbox path. + EXPECT_EQ(errCode, E_OK); + ``` + + +3. Write data. + + Use the **put()** method of the **Preferences** class to write data to the cached **Preferences** instance. + + ```C++ + pref->PutString("test", "remove"); + ``` + +4. Read data. + + Use the **get()** method of the **Preferences** class to read data. + + ``` C++ + std::string ret = pref->GetString("test", "defaultValue"); + EXPECT_EQ(ret, "remove"); + ``` + + +5. Store data persistently. + + Use the **flush()** or **flushSync()** method to flush data in the **Preferences** instance to its file. + + ```C++ + int err = pref->FlushSync(); + EXPECT_EQ(ret, E_OK); + ``` + + +6. Subscribe to data changes. + + Specify **PreferencesObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush()** or **flushSync()** method is executed, **PreferencesObserver** will be invoked. Unregister the **PreferencesObserver** when it is no longer required. + + Customize a class to implement the **PreferencesObserver**: + ``` C++ + class PreferencesObserverCounter : public PreferencesObserver { + public: + virtual ~PreferencesObserverCounter(); + void OnChange(Preferences &preferences, const std::string &key) override; + + std::atomic_int notifyTimes; + static const std::vector NOTIFY_KEYS_VECTOR; + }; + + PreferencesObserverCounter::~PreferencesObserverCounter() {} + + void PreferencesObserverCounter::OnChange(Preferences &preferences, const std::string &key) + { + for (auto it = NOTIFY_KEYS_VECTOR.cbegin(); it != NOTIFY_KEYS_VECTOR.cend(); it++) { + if (key.compare(*it)) { + notifyTimes++; + break; + } + } + } + + const std::vector PreferencesObserverCounter::NOTIFY_KEYS_VECTOR = { PreferencesTest::KEY_TEST_INT_ELEMENT, + PreferencesTest::KEY_TEST_LONG_ELEMENT, PreferencesTest::KEY_TEST_FLOAT_ELEMENT, + PreferencesTest::KEY_TEST_BOOL_ELEMENT, PreferencesTest::KEY_TEST_STRING_ELEMENT }; + ``` + + Subscribe to data changes and invoke the callback: + ``` C++ + std::shared_ptr counter = + std::shared_ptr(new PreferencesObserverCounter()); + pref->RegisterObserver(counter); // Register a callback to return data changes. + + pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); + pref->Flush(); // Trigger the onChanged callback of the counter. + EXPECT_EQ(static_cast(counter.get())->notifyTimes, 1); + + /* same value */ + pref->PutInt(PreferencesTest::KEY_TEST_INT_ELEMENT, 2); + pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); + pref->Flush(); + EXPECT_EQ(static_cast(counter.get())->notifyTimes, 2); + + pref->UnRegisterObserver(counter); // Unregister the callback for data changes. + ``` + + +7. Delete the specified file. + + Delete the **Preferences** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored. + + ``` C++ + pref = nullptr; + int ret = PreferencesHelper::DeletePreferences("/data/test/test"); + EXPECT_EQ(ret, E_OK); + ``` diff --git a/en/device-dev/subsystems/subsys-data-storage-overview.md b/en/device-dev/subsystems/subsys-data-storage-overview.md new file mode 100644 index 00000000000..fee188e4483 --- /dev/null +++ b/en/device-dev/subsystems/subsys-data-storage-overview.md @@ -0,0 +1,31 @@ +# Lightweight Data Store Overview + +The lightweight data store is applicable to access and persistence operations on the data in key-value pairs. When an application accesses a lightweight store instance, the data in the instance will be cached in the memory for faster access. The cached data can also be written back to the text file for persistent storage. Since file read and write consume system resources, you are advised to minimize the frequency of reading and writing persistent files. + +## Basic Concepts + +- **Key-Value data structure** + + A type of data structure. The key is the unique identifier for a piece of data, and the value is the specific data being identified. + +- **Non-relational databases** + + A database not in compliance with the atomicity, consistency, isolation, and durability (ACID) database management properties of relational data transactions. The data in a non-relational database is independent. + + +## Working Principles + +When an application loads data from a specified Preferences file to a **Preferences** instance, the system stores the instance in the memory through a static container. Each file of an application or process has only one **Preferences** instance in the memory, till the application removes the instance from the memory or deletes the **Preferences** file. + +When obtaining a **Preferences** instance, the application can read data from or write data to the instance. The data in the instance can be flushed to its **Preferences** file by calling the **flush()** or **flushSync()** method. + +**Figure 1** How lightweight data store works + + +![](figure/en-us_image_0000001192123772.png) + +## Constraints + +- **Preferences** instances are loaded to the memory. To minimize non-memory overhead, the number of data records stored in a Preferences instance cannot exceed 10,000. Delete the instances that are no longer used in a timely manner. +- The key in the key-value pairs is of the string type. It cannot be empty or exceed 80 characters. +- If the value in the key-value pairs is of the string type, it can be empty or contain a maximum of 8192 characters. diff --git a/en/device-dev/subsystems/subsys-data-storage.md b/en/device-dev/subsystems/subsys-data-storage.md new file mode 100644 index 00000000000..2c6e163303a --- /dev/null +++ b/en/device-dev/subsystems/subsys-data-storage.md @@ -0,0 +1,5 @@ +# Lightweight Data Store + +- **[Lightweight Data Store Overview](subsys-data-storage-overview.md)** + +- **[Lightweight Data Store Development] (subsys-data-storage-guide.md)** diff --git a/en/device-dev/subsystems/subsys-data.md b/en/device-dev/subsystems/subsys-data.md new file mode 100644 index 00000000000..f74c8f5cf30 --- /dev/null +++ b/en/device-dev/subsystems/subsys-data.md @@ -0,0 +1,4 @@ +# Data Management + +- **[RDB](subsys-data-relational-database.md)** +- **[Lightweight Data Store](subsys-data-storage.md)** diff --git a/en/device-dev/subsystems/subsys.md b/en/device-dev/subsystems/subsys.md index 74cc4fa005d..06318d2b2ab 100644 --- a/en/device-dev/subsystems/subsys.md +++ b/en/device-dev/subsystems/subsys.md @@ -8,6 +8,8 @@ - **[Multimedia](subsys-multimedia.md)** +- **[Data Management](subsys-data.md)** + - **[Utils](subsys-utils.md)** - **[AI Framework](subsys-aiframework.md)** -- Gitee From 371901c32da0e0927f1ac15fc6eb887112dd7507 Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Thu, 27 Jan 2022 14:12:54 +0800 Subject: [PATCH 2/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/Readme-EN.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 9e3d89ce67a..393e36646fa 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -39,13 +39,6 @@ - [KWS SDK](subsys-aiframework-demo-sdk.md) - [KWS Plug-in](subsys-aiframework-demo-plugin.md) - [KWS Configuration File](subsys-aiframework-demo-conf.md) -- [Data Management](subsys-data.md) - - [RDB](subsys-data-relational-database.md) - - [RDB Overview](subsys-data-relational-database-overview.md) - - [RDB Development](subsys-data-relational-database-guide.md) - - [Lightweight Data Store](subsys-data-storage.md) - - [Lightweight Data Store Overview](subsys-data-storage-overview.md) - - [Lightweight Data Store Development](subsys-data-storage-guide.md) - [Sensors](subsys-sensor.md) - [Sensors Overview](subsys-sensor-overview.md) - [Sensors Usage Guidelines](subsys-sensor-guide.md) -- Gitee From 19cda1eccb7acc830a372bfdb1c47c4bd47a9d7f Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Thu, 27 Jan 2022 14:16:27 +0800 Subject: [PATCH 3/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/Readme-EN.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 02a632ffc5f..9e3d89ce67a 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -39,10 +39,21 @@ - [KWS SDK](subsys-aiframework-demo-sdk.md) - [KWS Plug-in](subsys-aiframework-demo-plugin.md) - [KWS Configuration File](subsys-aiframework-demo-conf.md) +- [Data Management](subsys-data.md) + - [RDB](subsys-data-relational-database.md) + - [RDB Overview](subsys-data-relational-database-overview.md) + - [RDB Development](subsys-data-relational-database-guide.md) + - [Lightweight Data Store](subsys-data-storage.md) + - [Lightweight Data Store Overview](subsys-data-storage-overview.md) + - [Lightweight Data Store Development](subsys-data-storage-guide.md) - [Sensors](subsys-sensor.md) - [Sensors Overview](subsys-sensor-overview.md) - [Sensors Usage Guidelines](subsys-sensor-guide.md) - [Sensors Usage Example](subsys-sensor-demo.md) +- [USB](subsys-usbservice.md) + - [[USB Overview](subsys-usbservice-overview.md) + - [USB Usage Guidelines](subsys-usbservice-guide.md) + - [USB Usage Example](subsys-usbservice-demo.md) - [Application Framework](subsys-application-framework.md) - [Overview](subsys-application-framework-overview.md) - [Setting Up a Development Environment](subsys-application-framework-envbuild.md) -- Gitee From 3269ef288737a83ce8503c83b50f36fab602663e Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Thu, 27 Jan 2022 15:31:13 +0800 Subject: [PATCH 4/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/Readme-EN.md | 7 - .../subsystems/subsys-data-storage-guide.md | 144 +++++++++--------- .../subsys-data-storage-overview.md | 32 ++-- .../subsystems/subsys-data-storage.md | 6 +- en/device-dev/subsystems/subsys-data.md | 8 +- 5 files changed, 97 insertions(+), 100 deletions(-) diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 9e3d89ce67a..393e36646fa 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -39,13 +39,6 @@ - [KWS SDK](subsys-aiframework-demo-sdk.md) - [KWS Plug-in](subsys-aiframework-demo-plugin.md) - [KWS Configuration File](subsys-aiframework-demo-conf.md) -- [Data Management](subsys-data.md) - - [RDB](subsys-data-relational-database.md) - - [RDB Overview](subsys-data-relational-database-overview.md) - - [RDB Development](subsys-data-relational-database-guide.md) - - [Lightweight Data Store](subsys-data-storage.md) - - [Lightweight Data Store Overview](subsys-data-storage-overview.md) - - [Lightweight Data Store Development](subsys-data-storage-guide.md) - [Sensors](subsys-sensor.md) - [Sensors Overview](subsys-sensor-overview.md) - [Sensors Usage Guidelines](subsys-sensor-guide.md) diff --git a/en/device-dev/subsystems/subsys-data-storage-guide.md b/en/device-dev/subsystems/subsys-data-storage-guide.md index 152935dc1a6..8d3f4e2725e 100644 --- a/en/device-dev/subsystems/subsys-data-storage-guide.md +++ b/en/device-dev/subsystems/subsys-data-storage-guide.md @@ -1,118 +1,118 @@ -# Lightweight Data Store Development +# 轻量级数据存储开发指导 -## When to Use +## 场景介绍 -The lightweight data store is ideal for storing lightweight and frequently used data, but not for storing a large amount of data or data with frequent changes. The application data is persistently stored on a device in the form of files. Note that the instance accessed by an application contains all data of the file. The data is always loaded to the memory of the device until the application removes it from the memory. The application can perform data operations using the Preferences APIs. +轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Preferences的API进行数据操作。 -## Available APIs +## 接口说明 -The lightweight data store provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value pairs. Keys are of the string type, and values can be of the string, Boolean, integer, long integer, float, double, or string array type. +轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括字符串型、布尔型、整数型、长整型、浮点型、双精度类型和字符串数组。 -**Creating a Preferences Instance** +**创建存储实例** -Create a **Preferences** instance for data operations. A **Preferences** instance is created after data is read from a specified file and loaded to the instance. +读取指定文件,将数据加载到Preferences实例,即可创建一个存储实例,用于数据操作。 -**Table 1** API for creating a Preferences instance +**表 1** 轻量级数据存储实例创建接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | Creates a **Preferences** instance.
**path**: storage path of the application data.
**errCode**: error code.
Return value: **Preferences** instance created.| +| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | path:应用程序内部数据存储路径。
errCode:错误码。
返回值:轻量级存储实例。 | -**Writing Data** +**存入数据** -Call the **put()** method to add or modify data in a **Preferences** instance. +通过Put系列方法,可以增加或修改Preferences实例中的数据。 -**Table 2** APIs for writing data +**表 2** 轻量级偏好数据库存入接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| Preferences | int PutInt(const std::string &key, int value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutString(const std::string &key, const std::string &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutBool(const std::string &key, bool value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutLong(const std::string &key, int64_t value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutFloat(const std::string &key, float value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutDouble(const std::string &key, double value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutInt(const std::string &key, int value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutString(const std::string &key, const std::string &value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutBool(const std::string &key, bool value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutLong(const std::string &key, int64_t value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutFloat(const std::string &key, float value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutDouble(const std::string &key, double value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | +| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | key:将要存储的key名称,不能为空。
value:将要存储的。
返回值:错误码。 | -**Reading Data** +**读取数据** -Call the **get()** method to read data from a **Preferences** instance. +通过调用Get系列方法,可以读取Preferences中的数据。 -**Table 3** APIs for reading data +**表 3** 轻量级数据读取接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | float GetFloat(const std::string &key, float defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | double GetDouble(const std::string &key, double defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | float GetFloat(const std::string &key, float defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | double GetDouble(const std::string &key, double defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -**Storing Data Persistently** +**数据持久化** -Call the **flush()** or **flushSync** method to write the cached data back to its text file for persistent storage. +通过执行flush或者flushSync方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。 -**Table 4** APIs for data persistence +**表 5** 轻量级数据数据持久化接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| Preferences | void Flush(); | Writes data in the **Preferences** instance back to its file through an asynchronous thread.| -| Preferences | int FlushSync(); | Writes data in the **Preferences** instance back to its file through a synchronous thread.| +| Preferences | void Flush(); | 将Preferences实例通过异步线程回写入文件中。 | +| Preferences | int FlushSync(); | 将Preferences实例通过同步线程回写入文件中,并返回错误码。 | -**Observing Data Changes** +**订阅数据变化** -Specify **PreferencesObserver** as the callback to subscribe to data changes. When the value of the subscribed key is changed and the **flush()** method is executed, **PreferencesObserver** will be invoked. +订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,PreferencesObserver被回调。 -**Table 5** APIs for subscribing to data changes +**表 5** 轻量级数据变化订阅接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | Subscribes to data changes.
**preferencesObserver**: callback invoked to return the data changes.| -| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | Unsubscribes from data changes.
**preferencesObserver**: callback used to report data changes.| +| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要订阅的回调对象实例。 | +| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要注销订阅的回调对象实例。 | -**Deleting Data** +**删除数据文件** -Use the following APIs to delete a **Preferences** instance or data file. +通过调用以下两种接口,可以删除数据实例或对应的文件。 -**Table 6** APIs for deleting data +**表 6** 轻量级数据存储删除接口 -| Class| Method| Description| +| 类名 | 方法名 | 描述 | | --- | ----- | ----| -| PreferencesHelper | int DeletePreferences(const std::string &path); | Deletes a **Preferences** instance from the memory and deletes its file from the device.
**path**: storage path of the application data.
Return value: error code.| -| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | Deletes a **Preferences** instance from the memory.
**path**: storage path of the application data.
Return value: error code.| +| PreferencesHelper | int DeletePreferences(const std::string &path); | 将Preferences实例从内存中移除,同时删除其在设备上的持久化文件。path:应用程序内部数据存储路径。
返回值:错误码。 | +| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | 仅将Preferences实例从内存中移除。path:应用程序内部数据存储路径。
返回值:错误码。 | -## How to Develop +## 开发步骤 -1. Import the Preferences module and related header files to the development environment. +1. 准备工作,引入preferences以及相关的头文件到开发环境。 ``` C++ - Header file path: //distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include + 头文件路径://distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include ``` -2. Create a **Preferences** instance. +2. 获取Preferences实例。 - Read the specified file and load its data to the **Preferences** instance for data operations. + 读取指定文件,将数据加载到Preferences实例,用于数据操作。 ``` C++ int errCode = E_OK; - Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH must be the application sandbox path. + Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH须为应用沙箱路径。 EXPECT_EQ(errCode, E_OK); ``` -3. Write data. +3. 存入数据。 - Use the **put()** method of the **Preferences** class to write data to the cached **Preferences** instance. + 使用Preferences put方法保存数据到缓存的实例中。 ```C++ pref->PutString("test", "remove"); ``` -4. Read data. +4. 读取数据。 - Use the **get()** method of the **Preferences** class to read data. + 使用Preferences get方法读取数据。 ``` C++ std::string ret = pref->GetString("test", "defaultValue"); @@ -120,9 +120,9 @@ Use the following APIs to delete a **Preferences** instance or data file. ``` -5. Store data persistently. +5. 数据持久化。 - Use the **flush()** or **flushSync()** method to flush data in the **Preferences** instance to its file. + 应用存入数据到Preferences实例后,可以通过flush或者flushSync方法将Preferences实例回写到文件中。 ```C++ int err = pref->FlushSync(); @@ -130,11 +130,11 @@ Use the following APIs to delete a **Preferences** instance or data file. ``` -6. Subscribe to data changes. +6. 订阅数据变化。 - Specify **PreferencesObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush()** or **flushSync()** method is executed, **PreferencesObserver** will be invoked. Unregister the **PreferencesObserver** when it is no longer required. + 应用订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush或者flushSync方法时,PreferencesObserver被触发回调。不再需要PreferencesObserver时请注销。 - Customize a class to implement the **PreferencesObserver**: + 自定义类,实现PreferencesObserver接口: ``` C++ class PreferencesObserverCounter : public PreferencesObserver { public: @@ -162,14 +162,14 @@ Use the following APIs to delete a **Preferences** instance or data file. PreferencesTest::KEY_TEST_BOOL_ELEMENT, PreferencesTest::KEY_TEST_STRING_ELEMENT }; ``` - Subscribe to data changes and invoke the callback: + 订阅数据变化,并触发执行回调方法: ``` C++ std::shared_ptr counter = std::shared_ptr(new PreferencesObserverCounter()); - pref->RegisterObserver(counter); // Register a callback to return data changes. + pref->RegisterObserver(counter); // 注册数据变化的回调。 pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); - pref->Flush(); // Trigger the onChanged callback of the counter. + pref->Flush(); // 触发执行counter的onChanged回调方法。 EXPECT_EQ(static_cast(counter.get())->notifyTimes, 1); /* same value */ @@ -178,16 +178,18 @@ Use the following APIs to delete a **Preferences** instance or data file. pref->Flush(); EXPECT_EQ(static_cast(counter.get())->notifyTimes, 2); - pref->UnRegisterObserver(counter); // Unregister the callback for data changes. + pref->UnRegisterObserver(counter); // 注销注册数据变化的回调。 ``` -7. Delete the specified file. +7. 删除指定文件。 - Delete the **Preferences** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored. + 从使用PreferencesHelper内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。 ``` C++ pref = nullptr; int ret = PreferencesHelper::DeletePreferences("/data/test/test"); EXPECT_EQ(ret, E_OK); ``` + + diff --git a/en/device-dev/subsystems/subsys-data-storage-overview.md b/en/device-dev/subsystems/subsys-data-storage-overview.md index fee188e4483..a4830a9c807 100644 --- a/en/device-dev/subsystems/subsys-data-storage-overview.md +++ b/en/device-dev/subsystems/subsys-data-storage-overview.md @@ -1,31 +1,31 @@ -# Lightweight Data Store Overview +# 轻量级数据存储概述 -The lightweight data store is applicable to access and persistence operations on the data in key-value pairs. When an application accesses a lightweight store instance, the data in the instance will be cached in the memory for faster access. The cached data can also be written back to the text file for persistent storage. Since file read and write consume system resources, you are advised to minimize the frequency of reading and writing persistent files. +轻量级数据存储适用于对Key-Value结构的数据进行存取和持久化操作。应用获取某个轻量级存储对象后,该存储对象中的数据将会被缓存在内存中,以便应用获得更快的数据存取速度。应用也可以将缓存的数据再次写回文本文件中进行持久化存储,由于文件读写将产生不可避免的系统资源开销,建议应用减少对持久化文件的读写频率。 -## Basic Concepts +## 基本概念 -- **Key-Value data structure** +- **Key-Value数据结构** - A type of data structure. The key is the unique identifier for a piece of data, and the value is the specific data being identified. + 一种键值结构数据类型。Key是不重复的关键字,Value是数据值。 -- **Non-relational databases** +- **非关系型数据库** - A database not in compliance with the atomicity, consistency, isolation, and durability (ACID) database management properties of relational data transactions. The data in a non-relational database is independent. + 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系。 -## Working Principles +## 运作机制 -When an application loads data from a specified Preferences file to a **Preferences** instance, the system stores the instance in the memory through a static container. Each file of an application or process has only one **Preferences** instance in the memory, till the application removes the instance from the memory or deletes the **Preferences** file. +1. 应用通过指定Preferences文件将其中的数据加载到Preferences实例,系统会通过静态容器将该实例存储在内存中,同一应用或进程中每个文件仅存在一个Preferences实例,直到应用主动从内存中移除该实例或者删除该Preferences文件。 +2. 应用获取到Preferences文件对应的实例后,可以从Preferences实例中读取数据,或者将数据存入Preferences实例中。通过调用flush或者flushSync方法可以将Preferences实例中的数据回写到文件里。 -When obtaining a **Preferences** instance, the application can read data from or write data to the instance. The data in the instance can be flushed to its **Preferences** file by calling the **flush()** or **flushSync()** method. +**图 1** 轻量级数据存储运作机制 -**Figure 1** How lightweight data store works +![](figure/zh-cn_image_0000001192123772.png) -![](figure/en-us_image_0000001192123772.png) +## 约束与限制 -## Constraints +- 因Preferences实例会加载到内存中,建议存储的数据不超过一万条,并及时清理不再使用的实例,以便减少非内存开销。 +- 数据中的key为string类型,要求非空且字符长度不超过80个。 +- 当数据中的value为string类型时,允许为空,字符长度不超过8192个。 -- **Preferences** instances are loaded to the memory. To minimize non-memory overhead, the number of data records stored in a Preferences instance cannot exceed 10,000. Delete the instances that are no longer used in a timely manner. -- The key in the key-value pairs is of the string type. It cannot be empty or exceed 80 characters. -- If the value in the key-value pairs is of the string type, it can be empty or contain a maximum of 8192 characters. diff --git a/en/device-dev/subsystems/subsys-data-storage.md b/en/device-dev/subsystems/subsys-data-storage.md index 2c6e163303a..62031452c5b 100644 --- a/en/device-dev/subsystems/subsys-data-storage.md +++ b/en/device-dev/subsystems/subsys-data-storage.md @@ -1,5 +1,5 @@ -# Lightweight Data Store +# 轻量级数据存储 -- **[Lightweight Data Store Overview](subsys-data-storage-overview.md)** +- **[轻量级数据存储概述](subsys-data-storage-overview.md)** -- **[Lightweight Data Store Development] (subsys-data-storage-guide.md)** +- **[轻量级数据存储开发指导](subsys-data-storage-guide.md)** diff --git a/en/device-dev/subsystems/subsys-data.md b/en/device-dev/subsystems/subsys-data.md index f74c8f5cf30..5e1f5fb2764 100644 --- a/en/device-dev/subsystems/subsys-data.md +++ b/en/device-dev/subsystems/subsys-data.md @@ -1,4 +1,6 @@ -# Data Management +# 数据管理 + +- **[关系型数据库](subsys-data-relational-database.md)** +- **[轻量级数据存储](subsys-data-storage.md)** + -- **[RDB](subsys-data-relational-database.md)** -- **[Lightweight Data Store](subsys-data-storage.md)** -- Gitee From 886736baefe39b91457e330c254ead1725714f9a Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Thu, 27 Jan 2022 15:32:28 +0800 Subject: [PATCH 5/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/Readme-EN.md | 7 + .../subsystems/subsys-data-storage-guide.md | 144 +++++++++--------- .../subsys-data-storage-overview.md | 32 ++-- .../subsystems/subsys-data-storage.md | 6 +- en/device-dev/subsystems/subsys-data.md | 8 +- 5 files changed, 100 insertions(+), 97 deletions(-) diff --git a/en/device-dev/subsystems/Readme-EN.md b/en/device-dev/subsystems/Readme-EN.md index 393e36646fa..9e3d89ce67a 100644 --- a/en/device-dev/subsystems/Readme-EN.md +++ b/en/device-dev/subsystems/Readme-EN.md @@ -39,6 +39,13 @@ - [KWS SDK](subsys-aiframework-demo-sdk.md) - [KWS Plug-in](subsys-aiframework-demo-plugin.md) - [KWS Configuration File](subsys-aiframework-demo-conf.md) +- [Data Management](subsys-data.md) + - [RDB](subsys-data-relational-database.md) + - [RDB Overview](subsys-data-relational-database-overview.md) + - [RDB Development](subsys-data-relational-database-guide.md) + - [Lightweight Data Store](subsys-data-storage.md) + - [Lightweight Data Store Overview](subsys-data-storage-overview.md) + - [Lightweight Data Store Development](subsys-data-storage-guide.md) - [Sensors](subsys-sensor.md) - [Sensors Overview](subsys-sensor-overview.md) - [Sensors Usage Guidelines](subsys-sensor-guide.md) diff --git a/en/device-dev/subsystems/subsys-data-storage-guide.md b/en/device-dev/subsystems/subsys-data-storage-guide.md index 8d3f4e2725e..152935dc1a6 100644 --- a/en/device-dev/subsystems/subsys-data-storage-guide.md +++ b/en/device-dev/subsystems/subsys-data-storage-guide.md @@ -1,118 +1,118 @@ -# 轻量级数据存储开发指导 +# Lightweight Data Store Development -## 场景介绍 +## When to Use -轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Preferences的API进行数据操作。 +The lightweight data store is ideal for storing lightweight and frequently used data, but not for storing a large amount of data or data with frequent changes. The application data is persistently stored on a device in the form of files. Note that the instance accessed by an application contains all data of the file. The data is always loaded to the memory of the device until the application removes it from the memory. The application can perform data operations using the Preferences APIs. -## 接口说明 +## Available APIs -轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括字符串型、布尔型、整数型、长整型、浮点型、双精度类型和字符串数组。 +The lightweight data store provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value pairs. Keys are of the string type, and values can be of the string, Boolean, integer, long integer, float, double, or string array type. -**创建存储实例** +**Creating a Preferences Instance** -读取指定文件,将数据加载到Preferences实例,即可创建一个存储实例,用于数据操作。 +Create a **Preferences** instance for data operations. A **Preferences** instance is created after data is read from a specified file and loaded to the instance. -**表 1** 轻量级数据存储实例创建接口 +**Table 1** API for creating a Preferences instance -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | path:应用程序内部数据存储路径。
errCode:错误码。
返回值:轻量级存储实例。 | +| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | Creates a **Preferences** instance.
**path**: storage path of the application data.
**errCode**: error code.
Return value: **Preferences** instance created.| -**存入数据** +**Writing Data** -通过Put系列方法,可以增加或修改Preferences实例中的数据。 +Call the **put()** method to add or modify data in a **Preferences** instance. -**表 2** 轻量级偏好数据库存入接口 +**Table 2** APIs for writing data -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| Preferences | int PutInt(const std::string &key, int value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutString(const std::string &key, const std::string &value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutBool(const std::string &key, bool value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutLong(const std::string &key, int64_t value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutFloat(const std::string &key, float value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutDouble(const std::string &key, double value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | key:将要存储的key名称,不能为空。
value:将要存储的。
返回值:错误码。 | +| Preferences | int PutInt(const std::string &key, int value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutString(const std::string &key, const std::string &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutBool(const std::string &key, bool value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutLong(const std::string &key, int64_t value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutFloat(const std::string &key, float value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutDouble(const std::string &key, double value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| +| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | **key**: key of the data to write. It cannot be empty.
**value**: value of the data to write.
Return value: error code.| -**读取数据** +**Reading Data** -通过调用Get系列方法,可以读取Preferences中的数据。 +Call the **get()** method to read data from a **Preferences** instance. -**表 3** 轻量级数据读取接口 +**Table 3** APIs for reading data -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | float GetFloat(const std::string &key, float defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | double GetDouble(const std::string &key, double defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | +| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | bool GetBool(const std::string &key, bool defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | float GetFloat(const std::string &key, float defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | double GetDouble(const std::string &key, double defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| +| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | **key**: key of the data to read. It cannot be empty.
**defValue**: default value to return if the operation fails or the value does not exist.
Return value: Returns the value read if the operation is successful; returns **defValue** otherwise.| -**数据持久化** +**Storing Data Persistently** -通过执行flush或者flushSync方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。 +Call the **flush()** or **flushSync** method to write the cached data back to its text file for persistent storage. -**表 5** 轻量级数据数据持久化接口 +**Table 4** APIs for data persistence -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| Preferences | void Flush(); | 将Preferences实例通过异步线程回写入文件中。 | -| Preferences | int FlushSync(); | 将Preferences实例通过同步线程回写入文件中,并返回错误码。 | +| Preferences | void Flush(); | Writes data in the **Preferences** instance back to its file through an asynchronous thread.| +| Preferences | int FlushSync(); | Writes data in the **Preferences** instance back to its file through a synchronous thread.| -**订阅数据变化** +**Observing Data Changes** -订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,PreferencesObserver被回调。 +Specify **PreferencesObserver** as the callback to subscribe to data changes. When the value of the subscribed key is changed and the **flush()** method is executed, **PreferencesObserver** will be invoked. -**表 5** 轻量级数据变化订阅接口 +**Table 5** APIs for subscribing to data changes -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要订阅的回调对象实例。 | -| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要注销订阅的回调对象实例。 | +| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | Subscribes to data changes.
**preferencesObserver**: callback invoked to return the data changes.| +| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | Unsubscribes from data changes.
**preferencesObserver**: callback used to report data changes.| -**删除数据文件** +**Deleting Data** -通过调用以下两种接口,可以删除数据实例或对应的文件。 +Use the following APIs to delete a **Preferences** instance or data file. -**表 6** 轻量级数据存储删除接口 +**Table 6** APIs for deleting data -| 类名 | 方法名 | 描述 | +| Class| Method| Description| | --- | ----- | ----| -| PreferencesHelper | int DeletePreferences(const std::string &path); | 将Preferences实例从内存中移除,同时删除其在设备上的持久化文件。path:应用程序内部数据存储路径。
返回值:错误码。 | -| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | 仅将Preferences实例从内存中移除。path:应用程序内部数据存储路径。
返回值:错误码。 | +| PreferencesHelper | int DeletePreferences(const std::string &path); | Deletes a **Preferences** instance from the memory and deletes its file from the device.
**path**: storage path of the application data.
Return value: error code.| +| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | Deletes a **Preferences** instance from the memory.
**path**: storage path of the application data.
Return value: error code.| -## 开发步骤 +## How to Develop -1. 准备工作,引入preferences以及相关的头文件到开发环境。 +1. Import the Preferences module and related header files to the development environment. ``` C++ - 头文件路径://distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include + Header file path: //distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include ``` -2. 获取Preferences实例。 +2. Create a **Preferences** instance. - 读取指定文件,将数据加载到Preferences实例,用于数据操作。 + Read the specified file and load its data to the **Preferences** instance for data operations. ``` C++ int errCode = E_OK; - Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH须为应用沙箱路径。 + Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH must be the application sandbox path. EXPECT_EQ(errCode, E_OK); ``` -3. 存入数据。 +3. Write data. - 使用Preferences put方法保存数据到缓存的实例中。 + Use the **put()** method of the **Preferences** class to write data to the cached **Preferences** instance. ```C++ pref->PutString("test", "remove"); ``` -4. 读取数据。 +4. Read data. - 使用Preferences get方法读取数据。 + Use the **get()** method of the **Preferences** class to read data. ``` C++ std::string ret = pref->GetString("test", "defaultValue"); @@ -120,9 +120,9 @@ ``` -5. 数据持久化。 +5. Store data persistently. - 应用存入数据到Preferences实例后,可以通过flush或者flushSync方法将Preferences实例回写到文件中。 + Use the **flush()** or **flushSync()** method to flush data in the **Preferences** instance to its file. ```C++ int err = pref->FlushSync(); @@ -130,11 +130,11 @@ ``` -6. 订阅数据变化。 +6. Subscribe to data changes. - 应用订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush或者flushSync方法时,PreferencesObserver被触发回调。不再需要PreferencesObserver时请注销。 + Specify **PreferencesObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush()** or **flushSync()** method is executed, **PreferencesObserver** will be invoked. Unregister the **PreferencesObserver** when it is no longer required. - 自定义类,实现PreferencesObserver接口: + Customize a class to implement the **PreferencesObserver**: ``` C++ class PreferencesObserverCounter : public PreferencesObserver { public: @@ -162,14 +162,14 @@ PreferencesTest::KEY_TEST_BOOL_ELEMENT, PreferencesTest::KEY_TEST_STRING_ELEMENT }; ``` - 订阅数据变化,并触发执行回调方法: + Subscribe to data changes and invoke the callback: ``` C++ std::shared_ptr counter = std::shared_ptr(new PreferencesObserverCounter()); - pref->RegisterObserver(counter); // 注册数据变化的回调。 + pref->RegisterObserver(counter); // Register a callback to return data changes. pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); - pref->Flush(); // 触发执行counter的onChanged回调方法。 + pref->Flush(); // Trigger the onChanged callback of the counter. EXPECT_EQ(static_cast(counter.get())->notifyTimes, 1); /* same value */ @@ -178,18 +178,16 @@ pref->Flush(); EXPECT_EQ(static_cast(counter.get())->notifyTimes, 2); - pref->UnRegisterObserver(counter); // 注销注册数据变化的回调。 + pref->UnRegisterObserver(counter); // Unregister the callback for data changes. ``` -7. 删除指定文件。 +7. Delete the specified file. - 从使用PreferencesHelper内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。 + Delete the **Preferences** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored. ``` C++ pref = nullptr; int ret = PreferencesHelper::DeletePreferences("/data/test/test"); EXPECT_EQ(ret, E_OK); ``` - - diff --git a/en/device-dev/subsystems/subsys-data-storage-overview.md b/en/device-dev/subsystems/subsys-data-storage-overview.md index a4830a9c807..fee188e4483 100644 --- a/en/device-dev/subsystems/subsys-data-storage-overview.md +++ b/en/device-dev/subsystems/subsys-data-storage-overview.md @@ -1,31 +1,31 @@ -# 轻量级数据存储概述 +# Lightweight Data Store Overview -轻量级数据存储适用于对Key-Value结构的数据进行存取和持久化操作。应用获取某个轻量级存储对象后,该存储对象中的数据将会被缓存在内存中,以便应用获得更快的数据存取速度。应用也可以将缓存的数据再次写回文本文件中进行持久化存储,由于文件读写将产生不可避免的系统资源开销,建议应用减少对持久化文件的读写频率。 +The lightweight data store is applicable to access and persistence operations on the data in key-value pairs. When an application accesses a lightweight store instance, the data in the instance will be cached in the memory for faster access. The cached data can also be written back to the text file for persistent storage. Since file read and write consume system resources, you are advised to minimize the frequency of reading and writing persistent files. -## 基本概念 +## Basic Concepts -- **Key-Value数据结构** +- **Key-Value data structure** - 一种键值结构数据类型。Key是不重复的关键字,Value是数据值。 + A type of data structure. The key is the unique identifier for a piece of data, and the value is the specific data being identified. -- **非关系型数据库** +- **Non-relational databases** - 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系。 + A database not in compliance with the atomicity, consistency, isolation, and durability (ACID) database management properties of relational data transactions. The data in a non-relational database is independent. -## 运作机制 +## Working Principles -1. 应用通过指定Preferences文件将其中的数据加载到Preferences实例,系统会通过静态容器将该实例存储在内存中,同一应用或进程中每个文件仅存在一个Preferences实例,直到应用主动从内存中移除该实例或者删除该Preferences文件。 -2. 应用获取到Preferences文件对应的实例后,可以从Preferences实例中读取数据,或者将数据存入Preferences实例中。通过调用flush或者flushSync方法可以将Preferences实例中的数据回写到文件里。 +When an application loads data from a specified Preferences file to a **Preferences** instance, the system stores the instance in the memory through a static container. Each file of an application or process has only one **Preferences** instance in the memory, till the application removes the instance from the memory or deletes the **Preferences** file. -**图 1** 轻量级数据存储运作机制 +When obtaining a **Preferences** instance, the application can read data from or write data to the instance. The data in the instance can be flushed to its **Preferences** file by calling the **flush()** or **flushSync()** method. +**Figure 1** How lightweight data store works -![](figure/zh-cn_image_0000001192123772.png) -## 约束与限制 +![](figure/en-us_image_0000001192123772.png) -- 因Preferences实例会加载到内存中,建议存储的数据不超过一万条,并及时清理不再使用的实例,以便减少非内存开销。 -- 数据中的key为string类型,要求非空且字符长度不超过80个。 -- 当数据中的value为string类型时,允许为空,字符长度不超过8192个。 +## Constraints +- **Preferences** instances are loaded to the memory. To minimize non-memory overhead, the number of data records stored in a Preferences instance cannot exceed 10,000. Delete the instances that are no longer used in a timely manner. +- The key in the key-value pairs is of the string type. It cannot be empty or exceed 80 characters. +- If the value in the key-value pairs is of the string type, it can be empty or contain a maximum of 8192 characters. diff --git a/en/device-dev/subsystems/subsys-data-storage.md b/en/device-dev/subsystems/subsys-data-storage.md index 62031452c5b..2c6e163303a 100644 --- a/en/device-dev/subsystems/subsys-data-storage.md +++ b/en/device-dev/subsystems/subsys-data-storage.md @@ -1,5 +1,5 @@ -# 轻量级数据存储 +# Lightweight Data Store -- **[轻量级数据存储概述](subsys-data-storage-overview.md)** +- **[Lightweight Data Store Overview](subsys-data-storage-overview.md)** -- **[轻量级数据存储开发指导](subsys-data-storage-guide.md)** +- **[Lightweight Data Store Development] (subsys-data-storage-guide.md)** diff --git a/en/device-dev/subsystems/subsys-data.md b/en/device-dev/subsystems/subsys-data.md index 5e1f5fb2764..f74c8f5cf30 100644 --- a/en/device-dev/subsystems/subsys-data.md +++ b/en/device-dev/subsystems/subsys-data.md @@ -1,6 +1,4 @@ -# 数据管理 - -- **[关系型数据库](subsys-data-relational-database.md)** -- **[轻量级数据存储](subsys-data-storage.md)** - +# Data Management +- **[RDB](subsys-data-relational-database.md)** +- **[Lightweight Data Store](subsys-data-storage.md)** -- Gitee From ee3828e9bdd61c1c31ebafeb096d33c0fcb0b10b Mon Sep 17 00:00:00 2001 From: annie_wangli Date: Thu, 27 Jan 2022 17:20:05 +0800 Subject: [PATCH 6/6] update docs Signed-off-by: annie_wangli --- en/device-dev/subsystems/subsys-data-storage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/device-dev/subsystems/subsys-data-storage.md b/en/device-dev/subsystems/subsys-data-storage.md index 2c6e163303a..504f220b7b8 100644 --- a/en/device-dev/subsystems/subsys-data-storage.md +++ b/en/device-dev/subsystems/subsys-data-storage.md @@ -2,4 +2,4 @@ - **[Lightweight Data Store Overview](subsys-data-storage-overview.md)** -- **[Lightweight Data Store Development] (subsys-data-storage-guide.md)** +- **[Lightweight Data Store Development](subsys-data-storage-guide.md)** -- Gitee