Bug 1081 - Deprecate non-asynchronous Data Broker API
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / data / SynchronizedTransaction.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.binding.api.data;
9
10 import java.util.Map;
11 import java.util.Set;
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.yangtools.concepts.Delegator;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20
21 import com.google.common.base.Preconditions;
22
23 /**
24  * Synchronized wrapper for DataModificationTransaction.
25  *
26  * To get instance of synchronized wrapper use {@link #from(DataModificationTransaction)}
27  *
28  * @deprecated Replaced by more specific transaction types. Please use
29  *          {@link org.opendaylight.controller.md.sal.binding.api.DataBroker#newReadOnlyTransaction(),
30  *          {@link org.opendaylight.controller.md.sal.binding.api.DataBroker#newReadWriteTransaction()
31  *          or
32  *          {@link org.opendaylight.controller.md.sal.binding.api.DataBroker#newWriteOnlyTransaction().
33  *
34  */
35 @Deprecated
36 public final class SynchronizedTransaction implements DataModificationTransaction,Delegator<DataModificationTransaction> {
37
38     private final DataModificationTransaction delegate;
39
40     private SynchronizedTransaction(final DataModificationTransaction delegate) {
41         this.delegate = delegate;
42     }
43
44     /**
45      * Returns synchronized wrapper on supplied transaction.
46      *
47      * @param transaction Transaction for which synchronized wrapper should be created.
48      * @return Synchronized wrapper over transaction.
49      */
50     public static final SynchronizedTransaction from(final DataModificationTransaction transaction) {
51         Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
52         if (transaction instanceof SynchronizedTransaction) {
53             return (SynchronizedTransaction) transaction;
54         }
55         return new SynchronizedTransaction(transaction);
56     }
57
58     @Override
59     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getCreatedOperationalData() {
60         return delegate.getCreatedOperationalData();
61     }
62
63     @Override
64     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getCreatedConfigurationData() {
65         return delegate.getCreatedConfigurationData();
66     }
67
68     @Override
69     public synchronized DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
70         return delegate.readOperationalData(path);
71     }
72
73     @Override
74     public synchronized TransactionStatus getStatus() {
75         return delegate.getStatus();
76     }
77
78     @Override
79     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getUpdatedOperationalData() {
80         return delegate.getUpdatedOperationalData();
81     }
82
83     @Override
84     public synchronized Object getIdentifier() {
85         return delegate.getIdentifier();
86     }
87
88     @Override
89     public synchronized DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
90         return delegate.readConfigurationData(path);
91     }
92
93     @Override
94     public synchronized Future<RpcResult<TransactionStatus>> commit() {
95         return delegate.commit();
96     }
97
98     @Override
99     public synchronized void putOperationalData(final InstanceIdentifier<? extends DataObject> path, final DataObject data) {
100         delegate.putOperationalData(path, data);
101     }
102
103     @Override
104     public synchronized void putConfigurationData(final InstanceIdentifier<? extends DataObject> path, final DataObject data) {
105         delegate.putConfigurationData(path, data);
106     }
107
108     @Override
109     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getUpdatedConfigurationData() {
110         return delegate.getUpdatedConfigurationData();
111     }
112
113     @Override
114     public synchronized void removeOperationalData(final InstanceIdentifier<? extends DataObject> path) {
115         delegate.removeOperationalData(path);
116     }
117
118     @Override
119     public synchronized void removeConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
120         delegate.removeConfigurationData(path);
121     }
122
123     @Override
124     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedConfigurationData() {
125         return delegate.getRemovedConfigurationData();
126     }
127
128     @Override
129     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedOperationalData() {
130         return delegate.getRemovedOperationalData();
131     }
132
133     @Override
134     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalConfigurationData() {
135         return delegate.getOriginalConfigurationData();
136     }
137
138     @Override
139     public synchronized ListenerRegistration<DataTransactionListener> registerListener(final DataTransactionListener listener) {
140         return delegate.registerListener(listener);
141     }
142
143     @Override
144     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalOperationalData() {
145         return delegate.getOriginalOperationalData();
146     }
147
148     @Override
149     public synchronized DataModificationTransaction getDelegate() {
150         return delegate;
151     }
152
153     @Override
154     public int hashCode() {
155         final int prime = 31;
156         int result = 1;
157         result = prime * result + ((delegate == null) ? 0 : delegate.hashCode());
158         return result;
159     }
160
161     @Override
162     public boolean equals(final Object obj) {
163         if (this == obj) {
164             return true;
165         }
166         if (obj == null) {
167             return false;
168         }
169         if (getClass() != obj.getClass()){
170             return false;
171         }
172         SynchronizedTransaction other = (SynchronizedTransaction) obj;
173         if (delegate == null) {
174             if (other.delegate != null) {
175                 return false;
176             }
177         } else if (!delegate.equals(other.delegate)) {
178             return false;
179         }
180         return true;
181     }
182 }
183

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.