LDAP-235, LDAP-228: Update with ODM.

ODM update now uses modifyAttributes rather than rebind.
This commit is contained in:
Mattias Hellborg Arthursson
2013-08-12 11:18:45 +02:00
parent 540ae86136
commit f8b979d5e6
4 changed files with 58 additions and 48 deletions

View File

@@ -1,21 +1,5 @@
package org.springframework.ldap.odm.core.impl;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.ContextSource;
@@ -31,6 +15,21 @@ import org.springframework.ldap.odm.core.OdmException;
import org.springframework.ldap.odm.core.OdmManager;
import org.springframework.ldap.odm.typeconversion.ConverterManager;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* An implementation of {@link org.springframework.ldap.odm.core.OdmManager} which
* uses {@link org.springframework.ldap.odm.typeconversion.ConverterManager} to
@@ -189,9 +188,9 @@ public final class OdmManagerImpl implements OdmManager {
LOG.debug(String.format("Updating entry - %s$1", entry));
}
DirContextAdapter context = new DirContextAdapter(getId(entry));
DirContextOperations context = ldapTemplate.lookupContext(getId(entry));
mapToContext(entry, context);
ldapTemplate.rebind(context);
ldapTemplate.modifyAttributes(context);
}
/*

View File

@@ -1,21 +1,20 @@
package org.springframework.ldap.odm.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import javax.naming.Name;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import javax.naming.Name;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
/**
* Automatically generated to represent the LDAP object classes
* "organizationalunit", "top".
*/
@Entry(objectClasses = { "organizationalunit", "top" })
@Entry(objectClasses = { "organizationalUnit", "top" })
public final class OrganizationalUnit {
@Id
@@ -74,6 +73,10 @@ public final class OrganizationalUnit {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getDescription() {
return description;
}

View File

@@ -1,20 +1,19 @@
package org.springframework.ldap.odm.test;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Attribute.Type;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.odm.annotations.Transient;
import javax.naming.Name;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import javax.naming.Name;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.odm.annotations.Transient;
import org.springframework.ldap.odm.annotations.Attribute.Type;
// Simple LDAP entry for testing
@Entry(objectClasses = { "inetorgperson", "organizationalperson", "person", "top" })
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
public final class Person {
public Person() {
}

View File

@@ -1,18 +1,5 @@
package org.springframework.ldap.odm.test;
import static org.junit.Assert.assertEquals;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -50,6 +37,18 @@ import org.springframework.ldap.odm.typeconversion.impl.converters.FromStringCon
import org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter;
import org.springframework.ldap.test.LdapTestUtils;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
// Tests all OdmManager functions
public final class TestLdap {
private static final Log LOG = LogFactory.getLog(TestLdap.class);
@@ -520,6 +519,16 @@ public final class TestLdap {
((OdmManagerImpl)odmManager).read(Integer.class, baseName);
}
@Test
public void updateWithChildren_Ldap235() throws Exception {
OrganizationalUnit organizationalUnit = odmManager.read(OrganizationalUnit.class, ouTestData[0].getDn());
organizationalUnit.setStreet("new street");
odmManager.update(organizationalUnit);
OrganizationalUnit updated = odmManager.read(OrganizationalUnit.class, organizationalUnit.getDn());
assertEquals(organizationalUnit, updated);
}
private enum Flag {
URL("l", "url"),
USERNAME("u", "username"),