~hudson-ubuntu/ubuntu/natty/libspring-ldap-java/hudson-fix

« back to all changes in this revision

Viewing changes to dist/module-sources/spring-ldap-core/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutor.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-04-16 20:36:56 UTC
  • Revision ID: james.westby@ubuntu.com-20100416203656-257w9tnqwmpmcgv5
Tags: upstream-1.3.0.RELEASE
ImportĀ upstreamĀ versionĀ 1.3.0.RELEASE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2005-2008 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
 *      http://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
package org.springframework.ldap.transaction.compensating;
 
17
 
 
18
import javax.naming.Name;
 
19
import javax.naming.directory.ModificationItem;
 
20
 
 
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;
 
25
 
 
26
/**
 
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()}.
 
31
 * 
 
32
 * @author Mattias Hellborg Arthursson
 
33
 * @since 1.2
 
34
 */
 
35
public class ModifyAttributesOperationExecutor implements
 
36
        CompensatingTransactionOperationExecutor {
 
37
 
 
38
    private static Log log = LogFactory
 
39
            .getLog(ModifyAttributesOperationExecutor.class);
 
40
 
 
41
    private LdapOperations ldapOperations;
 
42
 
 
43
    private Name dn;
 
44
 
 
45
    private ModificationItem[] compensatingModifications;
 
46
 
 
47
    private ModificationItem[] actualModifications;
 
48
 
 
49
    /**
 
50
     * Constructor.
 
51
     * 
 
52
     * @param ldapOperations
 
53
     *            The {@link LdapOperations} to use to perform the rollback
 
54
     *            operation.
 
55
     * @param dn
 
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.
 
62
     */
 
63
    public ModifyAttributesOperationExecutor(LdapOperations ldapOperations,
 
64
            Name dn, ModificationItem[] actualModifications,
 
65
            ModificationItem[] compensatingModifications) {
 
66
        this.ldapOperations = ldapOperations;
 
67
        this.dn = dn;
 
68
        this.actualModifications = (ModificationItem[]) actualModifications.clone();
 
69
        this.compensatingModifications = (ModificationItem[]) compensatingModifications.clone();
 
70
    }
 
71
 
 
72
    /*
 
73
     * @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#rollback()
 
74
     */
 
75
    public void rollback() {
 
76
        try {
 
77
            log.debug("Rolling back modifyAttributes operation");
 
78
            ldapOperations.modifyAttributes(dn, compensatingModifications);
 
79
        } catch (Exception e) {
 
80
            log
 
81
                    .warn("Failed to rollback ModifyAttributes operation, dn: "
 
82
                            + dn);
 
83
        }
 
84
    }
 
85
 
 
86
    /*
 
87
     * @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#commit()
 
88
     */
 
89
    public void commit() {
 
90
        log.debug("Nothing to do in commit for modifyAttributes");
 
91
    }
 
92
 
 
93
    /*
 
94
     * @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor#performOperation()
 
95
     */
 
96
    public void performOperation() {
 
97
        log.debug("Performing modifyAttributes operation");
 
98
        ldapOperations.modifyAttributes(dn, actualModifications);
 
99
    }
 
100
 
 
101
    Name getDn() {
 
102
        return dn;
 
103
    }
 
104
 
 
105
    LdapOperations getLdapOperations() {
 
106
        return ldapOperations;
 
107
    }
 
108
 
 
109
    ModificationItem[] getActualModifications() {
 
110
        return actualModifications;
 
111
    }
 
112
 
 
113
    ModificationItem[] getCompensatingModifications() {
 
114
        return compensatingModifications;
 
115
    }
 
116
}