クラスPagedResultsControl

java.lang.Object
javax.naming.ldap.BasicControl
javax.naming.ldap.PagedResultsControl
すべての実装されたインタフェース:
Serializable, Control

public final class PagedResultsControl extends BasicControl
検索操作の結果を、指定したサイズごとにまとめて返すようLDAPサーバーに要求します。 要求者は、検索操作を呼び出す頻度を制御することで、結果を受け取る頻度を制御できます。

このクラスの使用方法を示すコーディング例を次に示します。


    // Open an LDAP association
    LdapContext ctx = new InitialLdapContext();

    // Activate paged results
    int pageSize = 20; // 20 entries per page
    byte[] cookie = null;
    int total;
    ctx.setRequestControls(new Control[]{
        new PagedResultsControl(pageSize, Control.CRITICAL) });

    do {
        // Perform the search
        NamingEnumeration results =
            ctx.search("", "(objectclass=*)", new SearchControls());

        // Iterate over a batch of search results
        while (results != null && results.hasMore()) {
            // Display an entry
            SearchResult entry = (SearchResult)results.next();
            System.out.println(entry.getName());
            System.out.println(entry.getAttributes());

            // Handle the entry's response controls (if any)
            if (entry instanceof HasControls) {
                // ((HasControls)entry).getControls();
            }
        }
        // Examine the paged results control response
        Control[] controls = ctx.getResponseControls();
        if (controls != null) {
            for (int i = 0; i < controls.length; i++) {
                if (controls[i] instanceof PagedResultsResponseControl) {
                    PagedResultsResponseControl prrc =
                        (PagedResultsResponseControl)controls[i];
                    total = prrc.getResultSize();
                    cookie = prrc.getCookie();
                } else {
                    // Handle other response controls (if any)
                }
            }
        }

        // Re-activate paged results
        ctx.setRequestControls(new Control[]{
            new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
    } while (cookie != null);

    // Close the LDAP association
    ctx.close();
    ...

 

このクラスは、RFC 2696で定義されている、ページごとに区切られた結果のLDAPv3コントロールを実装します。 このコントロールの値のASN.1定義は次のとおりです。


    realSearchControlValue ::= SEQUENCE {
        size      INTEGER (0..maxInt),
                          -- requested page size from client
                          -- result set size estimate from server
        cookie    OCTET STRING
    }

導入されたバージョン:
1.5
関連項目:
  • フィールド詳細

    • OID

      public static final String OID
      ページごとに区切られた結果のコントロールに割り当てられているオブジェクト識別子は1.2.840.113556.1.4.319です。
      関連項目:
  • コンストラクタの詳細

    • PagedResultsControl

      public PagedResultsControl(int pageSize, boolean criticality) throws IOException
      1ページ当たりに取得する結果のエントリ数を設定するためのコントロールを構築します。
      パラメータ:
      pageSize - 1ページで返すエントリの数。
      criticality - trueの場合、サーバーはこのコントロールに従い、pageSizeで示されたとおりに検索結果を返すか、または検索の実行を拒否する必要がある。 falseの場合、サーバーはこのコントロールに従う必要はない。
      スロー:
      IOException - 指定された引数のコントロールへのエンコード中にエラーが検出された場合。
    • PagedResultsControl

      public PagedResultsControl(int pageSize, byte[] cookie, boolean criticality) throws IOException
      1ページ当たりに取得する結果のエントリ数を設定するためのコントロールを構築します。 Cookieはサーバーによって提供され、ページごとに区切られた結果の応答コントロールから取得できます。

      一連の結果ページを途中で放棄するには、pageSizeを0に設定し、Cookieをサーバーから最後に受け取ったCookieに設定します。

      パラメータ:
      pageSize - 1ページで返すエントリの数。
      cookie - サーバーで生成されたCookie。nullの場合もある。
      criticality - trueの場合、サーバーはこのコントロールに従い、pageSizeで示されたとおりに検索結果を返すか、または検索の実行を拒否する必要がある。 falseの場合、サーバーはこのコントロールに従う必要はない。
      スロー:
      IOException - 指定された引数のコントロールへのエンコード中にエラーが検出された場合。