两个内容提供者访问同一个数据库 [英] Two content providers accessing the very same database

查看:28
本文介绍了两个内容提供者访问同一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

如果想要两个完全不同的 Android 应用程序访问和操作同一个数据库,我想知道是否有一种普遍首选的实现范式来尊重?是否建议甚至在技术上完全可以这样做?这样的架构会是什么样子?

I wonder if there is a generally preferred implementation paradigm to respect if one want's two completely different Android applications to access and operate on the same database? Is it recommended or even technically possible to do this at all? What would such an architecture look like?

到目前为止,我正在考虑让两个应用程序实现自己的 ContentProviders(两个 ContentProviders 将访问同一个数据库,但保证永远不会同时访问).我还考虑过构建一个通用的内容提供程序,并让两个应用程序在访问数据库时都使用该提供程序.我更喜欢第一个例子,但没有完全舍弃后者.

As of now I'm considering to let the two applications implement their own ContentProviders (both ContentProviders will access the same database, guaranteed never simultaneously, though). I have also thought of building one common content provider and let both applications use that one when accessing the database. I prefer the first example but haven't completely discarded the later.

理由:
我有两个需要访问公共数据库的应用程序.数据库本身存储数据的同时也描述了数据行之间的关系,通常描述了一组表单"所在的表单内容;UI 元素,如文本框、按钮和不同类型的列表,是可定制的.两个应用程序都使用数据库中的描述数据"在运行时生成各自应用程序 UI 的部分.

RATIONALE:
I have two applications which need to access a common database. The database itself stores data but also describes the relationship between the data rows, typically describing a set of "forms" where the form content; UI elements like text boxes, buttons and different kinds of lists, is customizable. Both applications use this "description data" in the database to generate parts of the respective application UI during runtime.

因此,这两个应用程序有两个方面:一个管理"方面(管理数据行之间的数据结构和关系)和一个通用用户"方面(读取/修改实际数据值).在单独的应用程序中将这两个方面分开是一种深思熟虑的选择.

Hence, there are two aspects of the two applications: one "administrative" aspect (managing the data structure and relationship between the data rows) and one "generic user" aspect (reading/modifying the actual data values). It's a deliberate choice to separate these two aspects in separate applications.

注意! 数据值与数据结构分离,即存储在一个单独的表中,并描述了结构在另一张桌子上.这意味着两个应用程序本质上将修改同一个数据库中的两个不同的表,他们永远不会修改另一个表",可以这么说.

NOTE! The data values are separated from the data structure, i.e. the values are stored in one separate table and the structure is described in another table. This means that the two applications will essentially modify two different tables in the same database and they will never modify "the other table", so to speak.

任何想法都非常感谢.该应用程序尚处于规划阶段,因此现在是进行根本性更改的时候了.

推荐答案

Dbm,

是的,它被接受、鼓励并且可以在 Android 上进行.您确实有第三个选项(这无疑会给我带来一些灼热的评论),那就是将 ContentProvider (1) 放在一个完全属于它自己的 APK 中.但是,鉴于您只有 2 种类型,您可以翻转它所托管的 apk 的四分之一.我会选择管理应用,但这对我来说是主观的.

Yes, it is accepted, encouraged and possible to do on Android. You do have a 3rd option (that will no doubt get me some burning commentary) and that's to put the ContentProvider (1) in an APK all of it's own. But, given that you only have 2 types, you can flip a quarter over which apk it is hosted by. I would choose the admin app, but that is subjective on my part.

如果您要麻烦地创建两个应用程序,那么您对每个应用程序的行为以及每个应用程序可以操作的数据类型都有先验"知识.因此,我会总结出一个单一的 CP 接口,并根据您所描述的行为来限制每个应用程序调用的内容.

If you are going to the trouble of creating two applications then you have "a priori" knowledge of what the behavior of each will do, and what kind of data that each can operate. Therefore I would conclude a single CP interface and just constrain what each app calls given the behavior you've described.

弗兰克

这篇关于两个内容提供者访问同一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆