DataNucleus supports persisting/retrieving objects to/from LDAP datastores (using the datanucleus-ldap plugin). If you wish to help out development of this plugin either by contributing or by sponsoring particular functionality please contact us via the DataNucleus Forum.
The following persistence properties will connect to an LDAP running on your local machine
datanucleus.ConnectionDriverName=com.sun.jndi.ldap.LdapCtxFactory datanucleus.ConnectionURL=ldap://localhost:10389 datanucleus.ConnectionUserName=uid=admin,ou=system datanucleus.ConnectionPassword=secret
So you create your PersistenceManagerFactory or EntityManagerFactory with these properties. Thereafter you have the full power of the JDO or JPA APIs at your disposal, for your LDAP datastore.
Access Platform allows you to query the objects in the datastore using the following
Queries are evaluated in-memory.
When persisting a Java object to an LDAP datastore clearly the user would like some control over where and how in the LDAP DIT (directory information tree) we are persisting the object. In general Java objects are mapped to LDAP entries and fields of the Java objects are mapped to attributes of the LDAP entries.
The following Java types are supported and stored as single-valued attribute to the LDAP entry:
Arrays, Collections, Sets and Lists of these data types are stored as multi-valued attributes. Please note that when using Arrays and Lists no order could be guaranteed and no duplicate values are allowed!
By default persistable objects are stored as separate LDAP entries. There are some options how to persist relationship references between persistable objects:
It is also possible to store persistable objects embedded. Note that there is inbuilt logic for deciding which of these mapping strategies to use for a relationship. You can explicitly set this with the metadata extension for the field/property mapping-strategy and it can be set to dn or attribute.
Here's an example using JDO XML MetaData:
<jdo> <package name="org.datanucleus.samples.models.company"> <class name="Group" table="ou=Groups,dc=example,dc=com" schema="top,groupOfNames" detachable="true"> <field name="name" column="cn" primary-key="true" /> <field name="users" column="member" /> </class> <class name="Person" table="ou=Users,dc=example,dc=com" schema="top,person,organizationalPerson,inetOrgPerson" detachable="true"> <field name="personNum" column="cn" primary-key="true" /> <field name="firstName" column="givenMame" /> <field name="lastName" column="sn" /> </class> </package> </jdo>
For the class as a whole we use the table attribute to set the distinguished name of the container under which to store objects of a type. So, for example, we are mapping all objects of class Group as subordinates to "ou=Groups,dc=example,dc=com". You can also use the extension "dn" to specify the same thing.
For the class as a whole we use the schema attribute to define the object classes of the LDAP entry. So, for example, all objects of type Person are mapped to the common "top,person,organizationalPerson,inetOrgPerson" object classes in LDAP. You can also use the extension "objectClass" to specify the same thing.
For each field we use the column attribute to define the LDAP attribute that we are mapping this field to. So, for example, we map the Group "name" to "cn" in our LDAP. You can also use the extension "attribute" to specify the same thing.
Some resulting LDAP entries would look like this:
dn: cn=Sales,ou=Groups,dc=example,dc=com objectClass: top objectClass: groupOfNames cn: Sales member: cn=1,ou=Users,dc=example,dc=com dn: cn=1,ou=Users,dc=example,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: 1 givenName: Bugs sn: Bunny
Here's the same example using JDO Annotations:
@PersistenceCapable(table="ou=Groups,dc=example,dc=com", schema="top,groupOfNames") public class Group { @PrimaryKey @Column(name = "cn") String name; @Column(name = "member") protected Set<Person> users = new HashSet<Person>(); } @PersistenceCapable(table="ou=Users,dc=example,dc=com", schema="top,person,organizationalPerson,inetOrgPerson") public class Person { @PrimaryKey @Column(name = "cn") private long personNum; @Column(name = "givenName") private String firstName; @Column(name = "sn") private String lastName; }
Here's the same example using JPA Annotations:
@Entity @Table(name="ou=Groups,dc=example,dc=com", schema="top,groupOfNames") public class Group { @Id @Extension(key="attribute", value="cn") String name; @OneToMany @Extension(key="attribute", value="member") protected Set users = new HashSet(); } @Entity @Table(name="ou=Groups,dc=example,dc=com", schema="top,person,organizationalPerson,inetOrgPerson") public class Person { @Id @Extension(key="attribute", value="roomNumber") private long personNum; @Extension(key="attribute", value="cn") private String firstName; @Extension(key="attribute", value="sn") private String lastName; }
The following are known limitations of the current implementation