Skip to content

Commit 12481a5

Browse files
committed
Clarify DnAttribute Role
Closes gh-459
1 parent 0ce74f5 commit 12481a5

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2005-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ldap.odm.annotations;
218

319
import java.lang.annotation.ElementType;
@@ -7,7 +23,7 @@
723

824

925
/**
10-
* This annotation describes the mapping of a Java field to an LDAP attribute.
26+
* Maps a Java field to an LDAP attribute.
1127
* <p>
1228
* The containing class must be annotated with {@link Entry}.
1329
*

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

Lines changed: 4 additions & 4 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,9 +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 values from
27-
* the distinguished names of found entries. Annotated fields must be of type <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>.
2828
* <p>
2929
* For automatic calculation of the DN of an entry to work, the {@link #index()} value
3030
* must be specified on all DnAttribute annotations in that class, and these attribute values,

src/docs/asciidoc/index.adoc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,19 +1083,28 @@ For example, assume that you have entries in your LDAP tree that have the follow
10831083
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" })`.
10841084
However, if you want to manage attributes defined in the `inetOrgPerson` objectclass, you need to use the following: `@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })`.
10851085

1086-
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`.
1086+
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.
10871087

1088-
The `@Attribute` annotation is used to map object class fields to entity fields.
1089-
`@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.
1090-
`@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.
1088+
First, the `@Id` annotation maps the distinguished name of the entry to a field. The field must be an instance of `javax.naming.Name`.
10911089

1092-
The `@DnAttribute` annotation is used to map object class fields to and from components in the distinguished name of an entry.
1093-
Fields annotated with `@DnAttribute` are automatically populated with the appropriate value from the distinguished name when an entry is read from the directory tree.
1090+
Second, the `@Attribute` annotation maps entity fields to LDAP attributes.
1091+
This is handy when the attribute name is different from the field name.
1092+
To use `@Attribute`, you must declare the name of the attribute to which the field maps.
1093+
Optionally, you can also guarantee and exact match by including the syntax OID of the LDAP attribute.
1094+
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.
1095+
1096+
Third, the `@Transient` annotation indicates that the given entity field does not map to an LDAP attribute.
1097+
1098+
Finally, the `@DnAttribute` annotation additionally maps entity fields to components of an entry's distinguished name.
10941099
Only fields of type `String` can be annotated with `@DnAttribute`. Other types are not supported.
1095-
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.
1100+
1101+
[TIP]
1102+
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.
10961103
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.
10971104

1098-
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`.
1105+
[NOTE]
1106+
Remember that all fields are mapped to LDAP attributes by default.
1107+
`@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`.
10991108

11001109
=== Execution
11011110

0 commit comments

Comments
 (0)