UnboundID LDAP SDK for Java

LDAP SDK Home Page
Product Information
Using the UnboundID LDAP SDK Persistence Framework

The LDAPPersister Class

The com.unboundid.ldap.sdk.persist.LDAPPersister class provides a set of methods that may be used to perform most of the real work of encoding and decoding entries and communicating with an LDAP directory server in the context of the LDAP SDK persistence framework. It uses the Java generics framework, and each instance of an LDAPPersister class may be used for one type of object marked with the @LDAPObject annotation type.

The getInstance method may be used to obtain an instance of the LDAPPersister class for use with a particular type of object. The class provided as an argument to the getInstance method must be marked with the @LDAPObject annotation type, and the process of initializing the LDAPPersister instance will validate that class to ensure that it does not violate any of the constraints imposed by the LDAP SDK persistence framework.

Key methods provided by the LDAPPersister class include:

  • constructAttributeTypes -- This method may be used to construct LDAP attribute type definitions for all attributes that may be used in the encoding or decoding process. This is primarily used for the purpose of generating LDAP schema definitions from properly-annotated source files.

  • constructObjectClasses -- This method may be used to construct LDAP object class definitions for the structural and any auxiliary classes referenced in the @LDAPObject annotation type.

  • encode -- This method may be used to encode a Java object of the associated class to an LDAP entry.

  • decode -- This method may be used to create and initialize a Java object from the contents of an LDAP entry.

  • add -- This method may be used to add an entry created from a Java object to an LDAP directory server. It invokes the encode method to generate an entry, and then adds that entry to the directory server via LDAP.

  • delete -- This method may be used to delete the LDAP entry that corresponds to a provided Java object. The provided object must have been obtained using the persistence framework, and it must have a field marked with either the @LDAPDNField or @LDAPEntryField annotation types.

  • getModifications -- This method may be used to retrieve a set of modifications that may be applied to an entry in order to update it based on the information in a provided object instance. If the Java class has a field marked with the @LDAPEntryField annotation type and a non-null value, then the information in that entry will be used to help refine the set of modifications to be applied. Otherwise, modifications will be generated from all fields and getter methods marked for inclusion in modify operations.

  • modify -- This method may be used to modify an LDAP entry to match the content of a provided Java object. It uses the getModifications method to obtain the set of modifications.

  • get -- This method may be used to retrieve a single instance of the associated object from an LDAP directory. There are two variants of this method: one that takes the DN of the LDAP entry to retrieve, and a second that takes an object instance to use to construct the DN. If the variant that takes an object instance is used, then that object must include values for all fields and/or getter methods included in the entry RDN.

  • search -- This method may be used to perform an LDAP search to retrieve object instances that match a provided object. All non-null fields and getter methods marked for inclusion in search filters will be used to generate the filter, and all entries returned from the search will be decoded as instances of the associated object type.