Skip to content

Commit 3089966

Browse files
committed
Clarify DnAttribute Role
Closes gh-459
1 parent bdaad6d commit 3089966

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

core/src/main/java/org/springframework/ldap/odm/annotations/Attribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* This annotation describes the mapping of a Java field to an LDAP attribute.
25+
* Maps a Java field to an LDAP attribute.
2626
* <p>
2727
* The containing class must be annotated with {@link Entry}.
2828
*

core/src/main/java/org/springframework/ldap/odm/annotations/DnAttribute.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,10 +22,9 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* Indicates that a field is to be automatically populated to/from the distinguished name
26-
* of an entry. Fields annotated with this annotation will be automatically populated with
27-
* values from the distinguished names of found entries. Annotated fields must be of type
28-
* <code>String</code>.
25+
* Maps a Java field to a component of an entry's distinguished name. Fields annotated
26+
* with this annotation will be automatically populated with values from the distinguished
27+
* names of found entries. Annotated fields must be of type <code>String</code>.
2928
* <p>
3029
* For automatic calculation of the DN of an entry to work, the {@link #index()} value
3130
* must be specified on all DnAttribute annotations in that class, and these attribute

src/docs/asciidoc/index.adoc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,19 +1073,28 @@ For example, assume that you have entries in your LDAP tree that have the follow
10731073
If you are interested only in changing the attributes defined in the `person` object class, you can annotate your `@Entry` with `@Entry(objectClasses = { "person", "top" })`.
10741074
However, if you want to manage attributes defined in the `inetOrgPerson` objectclass, you need to use the following: `@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })`.
10751075

1076-
The `@Id` annotation is used to map the distinguished name of the entry to a field. The field must be an instance of `javax.naming.Name`.
1076+
All entity fields are mapped by their field name to LDAP attributes. The remaining annotations -- `@Id`, `@Attribute`, `@Transient`, and `@DnAttribute` -- affect how that mapping occurs.
10771077

1078-
The `@Attribute` annotation is used to map object class fields to entity fields.
1079-
`@Attribute` is required to declare the name of the object class property to which the field maps and may optionally declare the syntax OID of the LDAP attribute, to guarantee exact matching.
1080-
`@Attribute` also provides the type declaration, which lets you indicate whether the attribute is regarded as binary-based or string-based by the LDAP JNDI provider.
1078+
First, the `@Id` annotation maps the distinguished name of the entry to a field. The field must be an instance of `javax.naming.Name`.
10811079

1082-
The `@DnAttribute` annotation is used to map object class fields to and from components in the distinguished name of an entry.
1083-
Fields annotated with `@DnAttribute` are automatically populated with the appropriate value from the distinguished name when an entry is read from the directory tree.
1080+
Second, the `@Attribute` annotation maps entity fields to LDAP attributes.
1081+
This is handy when the attribute name is different from the field name.
1082+
To use `@Attribute`, you must declare the name of the attribute to which the field maps.
1083+
Optionally, you can also guarantee and exact match by including the syntax OID of the LDAP attribute.
1084+
Finally, `@Attribute` also provides the type declaration, which lets you indicate whether the attribute is regarded as binary- or string-based by the LDAP JNDI provider.
1085+
1086+
Third, the `@Transient` annotation indicates that the given entity field does not map to an LDAP attribute.
1087+
1088+
Finally, the `@DnAttribute` annotation additionally maps entity fields to components of an entry's distinguished name.
10841089
Only fields of type `String` can be annotated with `@DnAttribute`. Other types are not supported.
1085-
If the `index` attribute of all `@DnAttribute` annotations in a class is specified, the DN can also be automatically calculated when creating and updating entries.
1090+
1091+
[TIP]
1092+
When the `index` attribute of all `@DnAttribute` annotations in a class is specified, the DN can also be automatically calculated when creating and updating entries.
10861093
For update scenarios, this also automatically takes care of moving entries in the tree if attributes that are part of the distinguished name have changed.
10871094

1088-
The `@Transient` annotation indicates that the field should be ignored by the object directory mapping and not mapped to an underlying LDAP property. Note that if a `@DnAttribute` is not to be bound to an `Attribute`. That is, it is only part of the Distinguished Name and not represented by an object attribute. It must also be annotated with `@Transient`.
1095+
[NOTE]
1096+
Remember that all fields are mapped to LDAP attributes by default.
1097+
`@DnAttribute` does not change this; in other words, fields annotated with `@DnAttribute` will also map to an LDAP attribute, unless you also annotate the field with `@Transient`.
10891098

10901099
=== Execution
10911100

0 commit comments

Comments
 (0)