免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 12873 | 回复: 11
打印 上一主题 下一主题

[ldap] 有人在这里讨论一下,javax.naming.ldap.PagedResultsControl ,ldap分页的问题吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-06 16:20 |只看该作者 |倒序浏览
sun的jndi中提供的分页功能javax.naming.ldap.PagedResultsControl ,好像用起来不太爽,不知道大家怎么处理的,
比如,我是在b/s模式中进行分页,可能是我理解的错误,这个接口的分页好像是从一个上一个查询中返回的结果中取得cookie才能翻到下一页,但是在b/s模式中,从第一页直接翻到第N页,哪不是要先得到N-1个cookie??这样每次从头翻到尾还有什么意义呢? 哪位仁兄,达人,可以切磋一下?

[ 本帖最后由 wangbaohua 于 2007-1-23 19:01 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-11-06 16:37 |只看该作者
自己先顶一个,目前好像目录的分页功能并不是所有的服务器都技持,
大家知道技持分页功能的目录服务有哪些??

虽然同为sun自己的东西,netscape.ldap.controls.LDAPVirtualListControl,跟他自己标准的
javax.naming.ldap.PagedResultsControl 用法好像就完全不一样,前者只要用
LDAPVirtualListControl(int startIndex, int beforeCount, int afterCount, int contentCount)
就可以了,

论坛徽章:
0
3 [报告]
发表于 2006-11-06 17:24 |只看该作者
关注!!

论坛徽章:
0
4 [报告]
发表于 2006-11-06 17:35 |只看该作者
http://www3.ietf.org/proceedings ... t-ldapv3-vlv-09.txt
       LDAP Extensions for Scrolling View Browsing of Search Results
http://www.ietf.org/rfc/rfc2696.txt
     LDAP Control Extension for Simple Paged Results Manipulation

显然这两个东西是不一样的,前一个简称vlv,这样来看sun的标准接口对于开发来说提供的支持还不是很全面,我想各个目录服务自己提供的sdk应该都有类似这样功能的实现吧! 比较了一下,实现了vlv的接口可能在功能上更好用, 但是sun提供的提接口从方向上来说,更可能是一种标准,只是不知道他们什么时候提供vlv功能。

论坛徽章:
0
5 [报告]
发表于 2006-11-06 18:16 |只看该作者
下载了所有的jndi的扩展包下来,一个一个看过,终于发现sun的vlv接口在ldapbp-1_0.zip(LDAP Booster Pack 1.0 Release)中

论坛徽章:
0
6 [报告]
发表于 2006-11-08 09:16 |只看该作者
做一个分页的例子,运行成功,但是速度是非常的慢,我在50000条数据中做分页,每页大小才20,
但是每查询一次好像要48875ms,基本上属于不可用的状态。

服务器环境是sun one directory server 5.2 ,win2003,

暂时不知道是什么原因,导致慢,因为就算我把50000条记录全部输出花的时间也只有这个时间的零头。
有人懂这个原理的么??

import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;
import java.io.IOException;
import java.util.*;
import com.sun.jndi.ldap.ctl.*;

public class PageMain {

        public static void main(String[] args) {


                Hashtable m_env = new Hashtable(5, 0.75f);
                LdapContext m_Ctx;
                m_env.put(Context.INITIAL_CONTEXT_FACTORY,
                                "com.sun.jndi.ldap.LdapCtxFactory");
                m_env.put("java.naming.ldap.version", "3");
                m_env.put(Context.PROVIDER_URL, "ldap://192.168.1.153:12345");
                m_env.put(Context.SECURITY_AUTHENTICATION, "simple");
                m_env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
                m_env.put(Context.SECURITY_CREDENTIALS,"12345678");

                try{
                        m_Ctx = new InitialLdapContext(m_env, null);
                        boolean b = true;
                        int counter = 0;
                        int listSize = 0;
                        int i = 0;
                        int nTargetOffset = 1;
                        int nPageSize = 20;
                        while (b) {
                               
                                VirtualListViewControl vctl
                                = new VirtualListViewControl(nTargetOffset, 0, 0, nPageSize, Control.CRITICAL);
                                javax.naming.ldap.SortControl sctl
                                =new javax.naming.ldap.SortControl(new String[] { "cn" },Control.CRITICAL);
                               
                                m_Ctx.setRequestControls(new Control[] { sctl, vctl });

                                SearchControls constraints = new SearchControls();
                                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
                                String[] retAtt = { "cn" };
                                constraints.setReturningAttributes(retAtt);
                               
                                String searchCondition = "(objectclass=inetOrgPerson)";
                               
                                System.out.println("-----------"+i+"-----------");

                                i++;
                                NamingEnumeration results =
                                        m_Ctx.search("dc=com", searchCondition,constraints);
                                System.out.println(m_Ctx);
                                int subcounter = 0;
                                if (results != null) {
                                        System.out.println("---------println results-----------");
                                        while (results.hasMoreElements()) {
                                                subcounter++;
                                                SearchResult si = (SearchResult) results.nextElement();
                                                counter++;
                                                System.out.println(si.getName());
                                        }
                                        System.out.println(searchCondition + " returned "+ subcounter);
                                        if (subcounter == 0){
                                                b = false;
                                                }
                                } else{
                                        System.out.println(searchCondition+ " did not match with any!!!");
                                }

                                System.out.println("------------------NEW PAGE NO. " + i);
                                nTargetOffset += subcounter; // nPageSize; //subcounter;
                        }
               
                } catch (NamingException e) {
                        e.printStackTrace();
                        System.out.println(e);
                }catch (IOException ex) {
                        System.out.print(ex);
                }
               
        }

}

论坛徽章:
0
7 [报告]
发表于 2006-11-08 10:26 |只看该作者
上面同样的分页功能在 openldap 2.2.*中,执行不能成功,
报错:
javax.naming.OperationNotSupportedException: [LDAP: error code 12 - critical extension is not recognized]; remaining name ……
我没有看到openldap说支持vlv,是不是它就不支持。

论坛徽章:
0
8 [报告]
发表于 2006-11-10 17:54 |只看该作者
终于采用在 netscape.ldap 的sdk中提供的vlv方法分页成功,速度还不错,

只是留下几个疑问,如果把jndi比作jdbc,哪么看来各个目录对jndi的支持还不够,

包括sun自己。如果真要做什么开发如果不用jndi可能使程序失去复用性。

目前我在做一个目录的应用,在选择目录服务器上,和采用的开发接口上,正在犹豫中……

现在我的基本想法,就是基本netscape 和它自己的sdk来做,因为我不是做产品,

专用也就专用了,我现在想做一些基本的封装,把逻辑层和目录操作区分一下。

也试过spring的ldap,没多看,基为它是基于jndi的所以还是不太放心,

   另:第一次发帖,发现好像自言自语,好不凄凉……,希望对大家有些帮助

论坛徽章:
0
9 [报告]
发表于 2007-02-06 19:35 |只看该作者

回复 8楼 wangbaohua 的帖子

我也有同感,之前写了一个spring ldap分页的测试用例,可是怎么都跑不起来,郁闷。
现将代码贴出来,请大侠指点一下:
package com.cvicse.sso.console.dao;

import javax.naming.directory.SearchControls;

import junit.framework.TestCase;

import org.springframework.ldap.CollectingNameClassPairCallbackHandler;
import org.springframework.ldap.support.control.PagedResultsCookie;
import org.springframework.ldap.support.control.PagedResultsRequestControl;

import com.cvicse.sso.console.dao.ldap.LdapTemplateExtend;
import com.cvicse.sso.console.dao.ldap.CAASUserAttributesMapper;

public class LdapTemplatePagedSearchITest extends TestCase {

        private LdapTemplateExtend tested;

        // LDAP contains 5 persons matching the filter. Page size is 3.
        // Expects two batches of 3 and 2 persons respectively.
        public void testPagedResult() {
                SearchControls searchControls = new SearchControls();
                searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                String base = "dc=cvicse,dc=com";
                String filter = "(&(objectclass=person)(cn=zhouzhou))";
                CAASUserAttributesMapper mapper = new CAASUserAttributesMapper();
                CollectingNameClassPairCallbackHandler handler = tested.new AttributesMapperCallbackHandler(
                                mapper);

                PagedResultsRequestControl requestControl;
                requestControl = new PagedResultsRequestControl(3);
                tested.search(base, filter, searchControls, handler, requestControl);
                PagedResultsCookie cookie = requestControl.getCookie();
                assertNotNull("Cookie should not be null yet", cookie.getCookie());
                assertEquals(3, handler.getList().size());

                // Prepare for second and last search
                requestControl = new PagedResultsRequestControl(3, cookie);
                tested.search(base, filter, searchControls, handler, requestControl);
                cookie = requestControl.getCookie();
                assertNull("Cookie should be null now", cookie.getCookie());
                assertEquals(5, handler.getList().size());
        }

}

论坛徽章:
0
10 [报告]
发表于 2007-02-27 09:39 |只看该作者
关注中.....
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP