Package org.springframework.ldap.control

Examples of org.springframework.ldap.control.PagedResultsDirContextProcessor


    }
   
    public NamingEnumeration<SearchResult> executeSearch(DirContext ctx) throws NamingException
    {
        NamingEnumeration<SearchResult> results = null;
        PagedResultsDirContextProcessor processor = null;
        boolean noExceptions = false;
        try
        {
            PagedResultsCookie cookie = null;
            int index = 0;
            boolean doNext = true;
            if (handler.getMaxCount() > 0 && controls.getCountLimit() <= 0 || handler.getMaxCount()+1 < controls.getCountLimit())
            {
                controls.setCountLimit(handler.getMaxCount()+1);
            }
            int pageSize = handler.getSearchPageSize() < 0 ? this.pageSize : handler.getSearchPageSize();
            if (pageSize > 0)
            {
                do
                {
                    processor = new PagedResultsDirContextProcessor(pageSize, cookie);
                    processor.preProcess(ctx);
                    results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName, filter, controls);
                    int pageIndex = 0;
                    while (doNext && results.hasMore())
                    {
                        doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++, index++);
                    }               
                    processor.postProcess(ctx);
                    cookie = processor.getCookie();
                }
                while (doNext && cookie != null && cookie.getCookie() != null && cookie.getCookie().length != 0);
            }
            else
            {
                results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName, filter, controls);
                int pageIndex = 0;
                while (doNext && results.hasMore())
                {
                    doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++, index++);
                }               
            }
            noExceptions = true;
        }
        finally
        {
            if (results != null)
            {
                try
                {
                    results.close();
                }
                catch (Exception e)
                {
                    // Never mind
                }
            }
            if (processor != null)
            {
                try
                {
                    processor.postProcess(ctx);
                }
                catch (NamingException e)
                {
                    if (noExceptions)
                    {  
View Full Code Here


     */
    @Override
    public void searchLdap(final LdapTemplate inLdapTemplate, final String inEncodedFilter,
            final SearchControls inSearchControls, final CollectingNameClassPairCallbackHandler inHandler)
    {
        PagedResultsDirContextProcessor pager = new PagedResultsDirContextProcessor(resultsPerPage);

        if (logger.isTraceEnabled())
        {
            logger.trace("Beginning paged ldap search with " + resultsPerPage + " results per page.  Filter: "
                    + inEncodedFilter + " using dc: "
                + ((LdapContextSource) inLdapTemplate.getContextSource()).getUrls()[0] + " using baseLdapPath: "
                + ((LdapContextSource) inLdapTemplate.getContextSource()).getBaseLdapPathAsString());
        }

        do
        {
            // Although the SearchControls object contains a limit on the max results for the
            // search, the paging processor works over the entire result set so the loop is
            // cut short manually.
            inLdapTemplate.search("", inEncodedFilter, inSearchControls, inHandler, pager);

            pager = new PagedResultsDirContextProcessor(resultsPerPage, pager.getCookie());
        }
        while (pager.getCookie() != null && pager.getCookie().getCookie() != null
                && inHandler.getList().size() < inSearchControls.getCountLimit());

        if (logger.isTraceEnabled())
        {
            logger.trace("Paged ldap search complete with " + inHandler.getList().size() + " results retrieved");
View Full Code Here

    }
   
    public NamingEnumeration<SearchResult> executeSearch(DirContext ctx) throws NamingException
    {
        NamingEnumeration<SearchResult> results = null;
        PagedResultsDirContextProcessor processor = null;
        boolean noExceptions = false;
        try
        {
            PagedResultsCookie cookie = null;
            int index = 0;
            boolean doNext = true;
            if (handler.getMaxCount() > 0 && controls.getCountLimit() <= 0 || handler.getMaxCount()+1 < controls.getCountLimit())
            {
                controls.setCountLimit(handler.getMaxCount()+1);
            }
            int pageSize = handler.getSearchPageSize() < 0 ? this.pageSize : handler.getSearchPageSize();
            if (pageSize > 0)
            {
                do
                {
                    processor = new PagedResultsDirContextProcessor(pageSize, cookie);
                    processor.preProcess(ctx);
                    results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName, filter, controls);
                    int pageIndex = 0;
                    while (doNext && results.hasMore())
                    {
                        doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++, index++);
                    }               
                    processor.postProcess(ctx);
                    cookie = processor.getCookie();
                }
                while (doNext && cookie != null && cookie.getCookie() != null && cookie.getCookie().length != 0);
            }
            else
            {
                results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName, filter, controls);
                int pageIndex = 0;
                while (doNext && results.hasMore())
                {
                    doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++, index++);
                }               
            }
            noExceptions = true;
        }
        finally
        {
            if (results != null)
            {
                try
                {
                    results.close();
                }
                catch (Exception e)
                {
                    // Never mind
                }
            }
            if (processor != null)
            {
                try
                {
                    // Make sure the Paging RequestControls are cleared again!
                    LdapContext ldapContext = (LdapContext)ctx;
                    ldapContext.setRequestControls(null);
                    processor.postProcess(ctx);
                }
                catch (NamingException e)
                {
                    if (noExceptions)
                    {  
View Full Code Here

TOP

Related Classes of org.springframework.ldap.control.PagedResultsDirContextProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.