1 Star 0 Fork 104

hchenphd / distributeddatamgr_appdatamgr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

本地数据管理组件

简介

关系型数据库(Relational Database,RDB) 是一种基于关系模型来管理数据的数据库。OpenHarmony关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制。

轻量级偏好数据库(Preferences) 主要提供轻量级Key-Value操作,支持本地应用存储少量数据,数据存储在本地文件中,同时也加载在内存中的,所以访问速度更快,效率更高。轻量级偏好数据库属于非关系型数据库,不宜存储大量数据,经常用于操作键值对形式数据的场景。

轻量系统KV数据库(Lightweight KV store) 依托当前公共基础库提供的KV存储能力开发,为轻量系统设备应用提供键值对数据管理能力。在有进程的平台上,KV存储提供的参数管理,供单进程访问不能被其他进程使用。在此类平台上,KV存储作为基础库加载在应用进程,以保障不被其他进程访问。

关系型数据库(RDB)

OpenHarmony关系型数据库底层使用SQLite作为持久化存储引擎,支持SQLite具有的所有数据库特性,包括但不限于事务、索引、视图、触发器、外键、参数化查询和预编译SQL语句。

图 1 关系型数据库运作机制

轻量级偏好数据库(Preferences)

  1. 本模块提供偏好型数据库的操作类,应用通过这些操作类完成数据库操作。
  2. 借助PreferencesHelper,可以将指定文件的内容加载到Preferences实例,每个文件最多有一个Preferences实例,系统会通过静态容器将该实例存储在内存中,直到主动从内存中移除该实例或者删除该文件。
  3. 获取Preferences实例后,可以借助Preferences类的函数,从Preferences实例中读取数据或者将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。

图 2 轻量级偏好数据库运行机制

轻量系统KV数据库(Lightweight KV store)

当前先支持轻量键值(KV)本地数据存储能力,后续会逐步支持其他更丰富的数据类型。

轻量键值(KV)数据:数据有结构,文件轻量,具有简易事务性,单独提供一套专用的键值对接口

分布式数据管理服务在不同平台上,将数据操作接口形成抽象层用来统一进行文件操作,使厂商不需要关注不同芯片平台文件系统的差异。

目前,在轻量系统上默认关闭该特性,需要使用时请用户修改vendor_hisilicon仓配置以开启。

目录

//foundation/distributeddatamgr/appdatamgr
├── frameworks            # 框架层代码
│   └── innerkitsimpl     # 内部接口实现
└── interfaces            # 接口代码
    └── innerkits         # 内部接口声明

关系型数据库(RDB)

以下是几个基本概念:

  • 关系型数据库

    创建在关系模型基础上的数据库,以行和列的形式存储数据。

  • 结果集

    指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。

  • SQLite数据库

    一款轻量级的数据库,是遵守ACID的关系型数据库组件。它是一个开源的项目。

约束

数据库中连接池的最大数量是4个,用以管理用户的读写操作。

为保证数据的准确性,数据库同一时间只能支持一个写操作。

轻量级偏好数据库(Preferences)

以下是几个基本概念:

  • Key-Value数据库

    一种以键值对存储数据的一种数据库。Key是关键字,Value是值。

  • 非关系型数据库

    区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系,扩展性好。

  • 偏好数据

    用户经常访问和使用的数据。

约束

Key键为String类型,要求非空且长度不超过80个字符。

如果Value值为String类型,可以为空但是长度不超过8192个字符。

存储的数据量应该是轻量级的,建议存储的数据不超过一万条,否则会在内存方面产生较大的开销。

轻量系统KV数据库(Lightweight KV store)

说明

KV存储能力继承自公共基础库原始设计,在原有能力基础上进行增强,新增提供数据删除及二进制value读写能力的同时,保证操作的原子性;

  • 轻量系统普遍性能有限,内存及计算能力不足,对于数据管理的场景大多读多写少,且内存占用敏感;
  • 平台使用的文件操作接口是由文件系统提供,一般来说文件操作接口本身并不是进程安全的,请格外注意;
  • 轻量系统,存在不具备锁能力的情况,不提供锁的机制,并发由业务保证,若需要提供有锁机制,则需要提供hook,由业务进行注册。

约束

  • KV大小及可存储条目数在平台可承受内可修改配置,轻量系统默认为小于Key(32byte),Value(512byte),通过修改编译宏修改;

  • 依赖平台具有正常的文件创建、读写删除修改、锁等能力,针对不同平台(如LiteOS-M内核、LiteOS-A内核等)尽可能表现接口语义功能的不变;

  • 由于平台能力差异数据库能力需要做相应裁剪,其中不同平台内部实现可能不同;

  • 对于指定路径仅支持创建数据库单例,不支持同一路径创建多数据库实例对象。

相关仓

分布式数据管理子系统

distributeddatamgr_appdatamgr

third_party_sqlite

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-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hchenphd/distributeddatamgr_appdatamgr.git
git@gitee.com:hchenphd/distributeddatamgr_appdatamgr.git
hchenphd
distributeddatamgr_appdatamgr
distributeddatamgr_appdatamgr
master

搜索帮助