2
* Copyright 2005-2008 the original author or authors.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
package org.springframework.ldap.transaction.compensating;
18
import javax.naming.Name;
19
import javax.naming.directory.ModificationItem;
21
import org.apache.commons.logging.Log;
22
import org.apache.commons.logging.LogFactory;
23
import org.springframework.ldap.core.LdapOperations;
24
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
27
* A {@link CompensatingTransactionOperationExecutor} to manage a
28
* <code>modifyAttributes</code> operation. Performs a
29
* <code>modifyAttributes</code> in {@link #performOperation()}, a negating
30
* modifyAttributes in {@link #rollback()}, and nothing in {@link #commit()}.
32
* @author Mattias Hellborg Arthursson
35
public class ModifyAttributesOperationExecutor implements
36
CompensatingTransactionOperationExecutor {
38
private static Log log = LogFactory
39
.getLog(ModifyAttributesOperationExecutor.class);
41
private LdapOperations ldapOperations;
45
private ModificationItem[] compensatingModifications;
47
private ModificationItem[] actualModifications;
52
* @param ldapOperations
53
* The {@link LdapOperations} to use to perform the rollback
56
* the DN of the target entry.
57
* @param actualModifications
58
* the actual modificationItems that were sent to the
59
* modifyAttributes operation.
60
* @param compensatingModifications
61
* the ModificationItems to undo the recorded operation.
63
public ModifyAttributesOperationExecutor(LdapOperations ldapOperations,
64
Name dn, ModificationItem[] actualModifications,
65
ModificationItem[] compensatingModifications) {
66
this.ldapOperations = ldapOperations;
68
this.actualModifications = (ModificationItem[]) actualModifications.clone();
69
this.compensatingModifications = (ModificationItem[]) compensatingModifications.clone();
73
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#rollback()
75
public void rollback() {
77
log.debug("Rolling back modifyAttributes operation");
78
ldapOperations.modifyAttributes(dn, compensatingModifications);
79
} catch (Exception e) {
81
.warn("Failed to rollback ModifyAttributes operation, dn: "
87
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#commit()
89
public void commit() {
90
log.debug("Nothing to do in commit for modifyAttributes");
94
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#performOperation()
96
public void performOperation() {
97
log.debug("Performing modifyAttributes operation");
98
ldapOperations.modifyAttributes(dn, actualModifications);
105
LdapOperations getLdapOperations() {
106
return ldapOperations;
109
ModificationItem[] getActualModifications() {
110
return actualModifications;
113
ModificationItem[] getCompensatingModifications() {
114
return compensatingModifications;