title: Upsert for LDAP directory in Java
body: <p>I'm attempting to execute an Upsert using the Novell JLDAP library, unfortunately, I'm having trouble finding an example of this. Currently, I have to:</p>
  
  <pre><code> public EObject put(EObject eObject){
  Subject s = (Subject) eObject;
  //Query and grab attributes from subject
  LDAPAttributes attr = resultsToAttributes(getLDAPConnection().get(s)); 
  
  //No modification needed - return
  if(s.getAttributes().equals(attr)){
    return eObject;
  } else {
    //Keys:
    //REPLACE,ADD,DELETE, depending on which attributes are present in the maps, I choose the operation which will be used
   Map&lt;String,LDAPAttribute&gt; operationalMap = figureOutWhichAttributesArePresent(c.getAttributes(),attr);
  
   //Add the Modifcations to a modification array
   ArrayList&lt;LDAPModification&gt; modList = new ArrayList&lt;LDAPModification&gt;();
   for(Entry entry: operationalMap.getEntrySet()){
     //Specify whether it is an update, delete, or insert here. (entry.getKey());
     modList.add(new LDAPModification(entry.getKey(),entry.getValue());
   }
   //commit
   connection.modify("directorypathhere",modList.toArray(new LDAPModification[modList.size()]));
  }
  </code></pre>
  
  <p>I'd prefer to not have to query on the customer first, which results in cycling through the subject's attributes as well. Is anyone aware if JNDI or another library is able to execute an update/insert without running multiple statements against LDAP?  </p>