Results 1 to 6 of 6

Thread: Lookup methods and Attributes

  1. #1
    Join Date
    Feb 2006
    Location
    Nancy, France
    Posts
    145

    Default Lookup methods and Attributes

    Since I've started with LdapTemplate, I'm wondering why there's no
    "lookup(String dn, String [] attributes, AttributesMapper mapper)" method.
    Let's take a real case, each time I use the lookup method, all
    attributes of the entry are retrieved.
    In my LDAP, each entry has about 20 or 30 attributes, it's a real mess
    if I only need the uid.

    Here are the modifications to add these methods :

    LdapOperations.java :

    Code:
    public Object lookup(final String dn, final String [] attributes, final AttributesMapper mapper);
    public Object lookup(final String dn, final String [] attributes, final ContextMapper mapper);
    public Object lookup(final Name dn, final String [] attributes, final AttributesMapper mapper);
    public Object lookup(final Name dn, final String [] attributes, final ContextMapper mapper);
    LdapTemplate.java :

    Implement the new methods and modify the old ones to call these with a
    null attributes parameter.

    Tell me if it's something that could be done, I think it's a real
    performance improvement.

  2. #2
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    The thing is, we forward all method calls to corresponding methods in the DirContext interface, and there are no lookup methods there that take the Attributes to return as an argument. We could of course implement the requested functionality in LdapTemplate, but that would problably not result in any great performance improvement.

    However, there are overloaded search methods in the DirContext interface that take an array containing the attributes to return. We should probably add corresponding methods in LdapOperations/LdapTemplate, especially since using those methods are the only way to have operational attributes returned. We'll probably add that in the first release of Spring-LDAP.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  3. #3
    Join Date
    Feb 2006
    Location
    Nancy, France
    Posts
    145

    Default

    Of course there's no 'lookup' method in DirContext but there are two 'getAttributes' methods :

    Attributes getAttributes(Name name, String[] attrIds)
    Retrieves selected attributes associated with a named object.
    Attributes getAttributes(String name)
    Retrieves all of the attributes associated with a named object.

    Maybe these could be interesting ?

    Thanks for your answer.

  4. #4
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    You can call any method in DirContext using the executeReadOnly() and executeReadWrite() methods respectively. What you do is you define a ContextExecutor implementation which executes the operation of your choice and supply it to the corresponding LdapTemplate method depending on whether it's a readonly or readwrite operation.

    It's possible that the requested operations will be implemented in the Spring-LDAP release, but the above should get you on your way until then.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  5. #5
    Join Date
    Sep 2006
    Posts
    1

    Default Limiting attribute retrieval

    So, I'm a bit confused. If my goal is to not retrieve all attributes for an entry, are you saying that I can use a ContextMapper, and it will only retrieve the attributes used in the mapper?

    You also mentioned a couple times that "We'll probably release that in the first release of Spring-LDAP". Isn't it already at 1.1, and past the initial release?

    For example, in the documentation, there's a class:
    Code:
    private static class PersonContextMapper implements ContextMapper {
          public Object mapFromContext(Object ctx) {
             DirContextAdapter context = (DirContextAdapter)ctx;
             Person p = new Person();
             p.setFullName(context.getStringAttribute("cn"));
             p.setLastName(context.getStringAttribute("sn"));
             p.setDescription(context.getStringAttribute("description"));
             return p;
          }
       }
    When used in a lookup (or search) with a mapper like the above, does the framework retrieve all the attributes or just the 3 (cn, sn and description)?
    Last edited by gfreemankc; Sep 8th, 2006 at 01:24 PM.

  6. #6
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    I was suggesting a ContextExecutor, which is an interface in which you can define any operation to be executed with a DirContext instance. ContextMapper is another thing altogether.

    It's described in the reference documentation, but as a simple example, to use the getAttributes(Name name, String[] attrs), you'd use a ContextExecutor as follows:
    Code:
    public Attributes getAttributes(final Name name, final String[] attrs){
      ContextExecutor executor = new ContextExecutor(){
        public Object executeWithContext(DirContext ctx) {
          return ctx.getAttributes(name, attrs);
        }
      };
    
      return (Attributes)ldapTemplate.executeReadOnly(executor);
    }
    You can use an AttributesMapper or ContextMapper to map the returned attributes if you want.

    Well, we missed it in the release. Sorry 'bout that.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •