[ 
https://issues.apache.org/jira/browse/DIRAPI-184?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13948976#comment-13948976
 ] 

Robert Hou commented on DIRAPI-184:
-----------------------------------

I tested available() method before, no matter SearchCursor has element in it or 
not, it always return false. Following is my test code:
 @Test
                public void testSearchCursor()
                {
                        LdapNetworkConnection connection = new 
LdapNetworkConnection(
                                        "192.168.80.223", 50001);
                        DefaultConfigurableBinaryAttributeDetector bad = new 
DefaultConfigurableBinaryAttributeDetector();
                        bad.addBinaryAttribute("objectSid","objectGUID");
                        connection.setBinaryAttributeDetector(bad);
                        try {
                                
connection.bind("cn=robert,cn=roles,dc=tibco,dc=com", "robert");
                        } catch (LdapException e1) {
                                e1.printStackTrace();
                        }
                        SearchRequest sr = new SearchRequestImpl();
                        try {
                                sr.setBase(new Dn("cn=roles1,dc=tibco,dc=com"));
                        } catch (LdapInvalidDnException e1) {
                                e1.printStackTrace();
                        }
                        try {
                                sr.setFilter("(objectClass=inetorgperson)");
                        } catch (LdapException e1) {
                                e1.printStackTrace();
                        }
                        sr.setScope(SearchScope.SUBTREE);
//                      sr.addControl(new PersistentSearchImpl());
                        SearchCursor cursor = null;
                        try{
                                cursor = connection.search(sr);
                        }catch(LdapException e){
                                e.printStackTrace();
                        }
//                      SearchCursor cursorBackup = cursor;
                        boolean done = cursor.isDone();
                        System.out.println("done = " + done);
                        done = cursor.available();
                        System.out.println("done = " + done);
                        SearchResultDone searchResultDone= 
cursor.getSearchResultDone();
                        String str = (searchResultDone == null) ? null: 
searchResultDone.toString();
                        System.out.println(str);
                        try {
                                cursor.getEntry();
                        } catch (LdapException e2) {
                                e2.printStackTrace();
                        }
                        MessageTypeEnum messageTypeEnum = null;
                        try {
                                Response response = cursor.get();
                                messageTypeEnum = response.getType();
                        } catch (CursorException e2) {
                                e2.printStackTrace();
                        }
                        try {
//                              done = cursor.isFirst();
//                              System.out.println("bdone = " + done);
                                if(cursor.next()){
//                                      done = cursor.isFirst();
//                                      System.out.println("ndone = " + done);
                                }
                        } catch (LdapException e1) {
                                e1.printStackTrace();
                        } catch (CursorException e1) {
                                e1.printStackTrace();
                        }
                        int i = 0;
                        try {
                                while(cursor.next()){
                                        i++;
                                        Entry entry = cursor.getEntry();
                                        Dn dn = entry.getDn();
                                        System.out.println("dn = " + dn);
                                        Collection<Attribute> colAttribute = 
entry.getAttributes();
                                        Iterator<Attribute> itAttribute = 
colAttribute.iterator();
                                        while(itAttribute.hasNext()){
                                                Attribute attribute = 
itAttribute.next();
                                                String attributeName = 
attribute.getUpId();
                                                Iterator<Value<?>> itValue = 
attribute.iterator();
                                                while(itValue.hasNext()){
                                                        Value<?> value = 
itValue.next();
                                                        
if(value.isHumanReadable()){
                                                                String strValue 
= value.getString();
                                                                
System.out.println("\t" + attributeName + "=" + strValue);
                                                        }else{
                                                                
System.out.println("\t" + attributeName + "withBinary=" + 
value.getValue().toString());
                                                        }
                                                                
                                                }
                                        }
                                }
                        } catch (LdapException e) {
                                e.printStackTrace();
                        } catch (CursorException e) {
                                e.printStackTrace();
                        }
                        done = cursor.isDone();
                        System.out.println("itfinish = " + done);
                        System.out.println("output " + i + "entries");
                        
                }

> Supply one method in SearchCursor to judge it has element or not.
> -----------------------------------------------------------------
>
>                 Key: DIRAPI-184
>                 URL: https://issues.apache.org/jira/browse/DIRAPI-184
>             Project: Directory Client API
>          Issue Type: Improvement
>    Affects Versions: 1.0.0-M21
>            Reporter: Robert Hou
>
> In some case, I need one method in 
> org.apache.directory.api.ldap.model.cursor.SearchCursor to judge it has 
> element or not. If not, I would not process the later logic.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to