如何URI的系统应设计? [英] How the system of URIs should be designed?

查看:120
本文介绍了如何URI的系统应设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的ListView 应显示产品的相当长的code-列表的内容(比如高达100万,即没有什么小)。由于这个原因,有效的和交互式搜索是重要的。对于此处没有解释原因,过滤器值应为URI的一部分...

我使用SQLite表和 LoadManager CursorLoader 办法。每当过滤字符串的变化,装载机光标复位,而 onCursorLoader 被称为反过来。我现在用的是code是这样的:

  @覆盖
公共装载机<&光标GT; onCreateLoader(INT ID,捆绑参数){    //撰写基于所述内容是否应该过滤或不的URI。
    // mCurFilter包含过滤器值。
    乌里URI;
    如果(mCurFilter.isEmpty()){
        URI = DemoContentProvider.PRODUCTS_CONTENT_URI;
    }其他{
        URI = Uri.withAppendedPath(DemoContentProvider.PRODUCTS_CONTENT_FILTER_URI,
                                   Uri.en code(mCurFilter));
    }    的String [] =投影{ProductTable.COLUMN_ID,
                            ProductTable.COLUMN_ code,
                            ProductTable.COLUMN_NAME,
                            ProductTable.COLUMN_STOCK,
                            ProductTable.COLUMN_PRICE};    CursorLoader cursorLoader =新CursorLoader(这一点,
            URI,投影,
            NULL,NULL,//没有选择和selargs - URI的过滤器内的价值
            订单信息); //分拣信息    返回cursorLoader;
}

请,专注于 URI 组成。在这里, PRODUCTS_CONTENT_FILTER_URI 定义为:

 公共静态最终乌里PRODUCTS_CONTENT_FILTER_URI =
        Uri.parse(内容://+ AUTHORITY
                   +/+ ProductTable.CONTENT_PATH +/过滤器);

这个例子可能看起来像

 内容://cz.xxx.android.yyydemo.contentprovider/product/filter/abc

其中, ABC 是由用户输入的过滤值。我觉得这个URI的设计可能不正确(即在该地区的初学者)。对我来说,下面的例子是确定:

 内容:// AUTHORITY /产品/ ......让所有的产品
内容:// AUTHORITY /产品/ 123 ...与_id = 123,以获得产品

然而,就像过滤器/值后缀的路很好走?

更新:我终于有几个相互关联的活动。在角度来考虑的客户产品为了头订单列表笔记列表。我是新来adressing数据的网状系统(即到URI系统如何应设计)。我想设计规则为我的URI,这样它可能是一种广义。我知道他们只是字符串,我可以做到这一点whathever方式。但我想这样做的很好的:)

例如:如果客户名单变得大了,用户可能要筛选列表。我可能要前preSS过滤作为URI的一部分。产品列表已经的的大。我想用塔相同的URI结构的产品。现在,订单把客户和产品在一起。

我说,我想展示的产品为客户和订单(订单头)列表中提供有关产品,包括产品数量为零的订购量的信息加入(以便能够将它们添加到命令)。这样的产品具有的数量的组合列表是一种类似的产品纯列表(至少相同数量的列表中的项目的) - 用户可能希望过滤,改变顺序等。但是,在URI应该包含客户ID和订单ID。当加入过滤,应当也添加到URI。我知道我可以简单地使用像 /客户/ 123 /顺序/ 456 /过滤/苹果,其中苹果是路径过滤器值,数字 123 456 是ID的由$ pssed表前$ p $路径的对$ pvious部分...

从另一个角度来看 - 为previous例子 - 客户ID,订单ID和过滤器值可以作为键值对的键是'custome 秩序,分别和'过滤器'。此外,我不知道将在未来增加。

我想正常启动与applicatios URI的系统。我想这必须由别人做了很多次。你可以分享你的经验吗?我想,以避免以后neccessity重新设计它。


解决方案

  1. 这是你如何构建它的便利性的问题。我想补充的过滤器的URI来降低查询的复杂性(例如多个WHERE条件,加入S)


  2. ListView控件被重用子视图,以便它可以处理了。适配器滤波器被设计以减少什么已经在适配器。当我们在谈论大数据我想美元,不把它摆在首位加载p $ PFER。


The ListView should display the content of the rather long code-list of products (say up to 100 thousands, i.e. nothing small). Because of that, effective and interactive searching is important. For the reasons not explained here, the filter value should be the part of URI...

I am using SQLite table, and the LoadManager and CursorLoader approach. Whenever the filter string changes, the cursor loader is reset, and the onCursorLoader is called, in turn. I am using the code like this:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    // Compose the URI based on whether the content should be filtered or not.
    // mCurFilter contains the filter value.
    Uri uri;
    if (mCurFilter.isEmpty()) {
        uri = DemoContentProvider.PRODUCTS_CONTENT_URI;
    } else {
        uri = Uri.withAppendedPath(DemoContentProvider.PRODUCTS_CONTENT_FILTER_URI,
                                   Uri.encode(mCurFilter));
    }

    String[] projection = { ProductTable.COLUMN_ID,
                            ProductTable.COLUMN_CODE,
                            ProductTable.COLUMN_NAME,
                            ProductTable.COLUMN_STOCK,
                            ProductTable.COLUMN_PRICE };

    CursorLoader cursorLoader = new CursorLoader(this,
            uri, projection,
            null, null,     // no selection and selargs - filter value inside the URI
            orderInfo);     // info for sorting

    return cursorLoader;
}

Please, focus on the uri composition. Here the PRODUCTS_CONTENT_FILTER_URI was defined as:

public static final Uri PRODUCTS_CONTENT_FILTER_URI =
        Uri.parse("content://" + AUTHORITY
                   + "/" + ProductTable.CONTENT_PATH + "/filter");

The example may look like

content://cz.xxx.android.yyydemo.contentprovider/product/filter/abc

Where abc is the filter value entered by the user. I feel this URI design may not be correct (being a beginner in the area). For me, the following examples are OK:

content://AUTHORITY/product/     ... to get all products
content://AUTHORITY/product/123  ... to get the product with _id = 123

However, is the suffix like filter/value the good way to go?

Update: I will finally have several interrelated activities. Think in terms customer, product, order head, order list, list of notes. I am new to web-like system of adressing the data (i.e. to how the URI system should be designed). I would like to design the rules for my URIs so that it could be a kind of generalized. I know they are just strings, and I could do it whathever way. But I would like to do it nicely :)

For example: If the list of customers becomes big, the user may want to filter that list. I probably want to express filtering as a part of the URI. The list of products already is big. I would like to use tha same URI structure for the products. Now, the orders put customers and products together.

Say, I would like to display the list of products for the customer and for the order (order head) joined with the information about the ordered quantity of the products including the products with zero quantity (to be able to add them into the order). This way the combined list of products with the quantity is a kind of similar to the plain list of products (at least the same number of items in the list)-- the user may want to filter, change ordering, etc. However, the URI should contain the customer id, and the order id. When filtering is added, it should be also added to the URI. I know I can simply use the path like /customer/123/order/456/filter/apple where apple is the filter value, and the numbers 123 and 456 are the id's for the tables expressed by the previous part of the path...

From another point of view--for the previous example--the customer id, order id, and the filter value may be used as key-value pairs for keys being 'custome', 'order', and 'filter' respectively. Moreover, I do not know what will be added in future.

I would like to start with the system of the applicatios URIs correctly. I guess it had to be done many times by the others. Can you share your experience? I would like to avoid the neccessity to redesign it later.

解决方案

  1. it is a matter of convenience how you structure it. I add "filter" URIs to reduce complexity of queries (e.g. multiple "WHERE" conditions, "JOIN"s)

  2. ListView is reusing child views so it can handle much. Adapter filter is designed to reduce what is already in the adapter. As we are talking about large data I would prefer to not get it loaded in the first place.

这篇关于如何URI的系统应设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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