Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-dom-spi / src / main / java / org / opendaylight / controller / sal / core / spi / data / AbstractDOMStoreTransaction.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.core.spi.data;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Abstract DOM Store Transaction.
20  *
21  * <p>
22  * Convenience super implementation of DOM Store transaction which provides
23  * common implementation of {@link #toString()} and {@link #getIdentifier()}.
24  *
25  * <p>
26  * It can optionally capture the context where it was allocated.
27  *
28  * @param <T> identifier type
29  * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTransaction} instead.
30  */
31 @Deprecated
32 @Beta
33 public abstract class AbstractDOMStoreTransaction<T> implements DOMStoreTransaction {
34     private final Throwable debugContext;
35     private final @NonNull T identifier;
36
37     protected AbstractDOMStoreTransaction(final @NonNull T identifier) {
38         this(identifier, false);
39     }
40
41     protected AbstractDOMStoreTransaction(final @NonNull T identifier, final boolean debug) {
42         this.identifier = requireNonNull(identifier, "Identifier must not be null.");
43         this.debugContext = debug ? new Throwable().fillInStackTrace() : null;
44     }
45
46     @Override
47     public final T getIdentifier() {
48         return identifier;
49     }
50
51     /**
52      * Return the context in which this transaction was allocated.
53      *
54      * @return The context in which this transaction was allocated, or null if the context was not recorded.
55      */
56     public final @Nullable Throwable getDebugContext() {
57         return debugContext;
58     }
59
60     @Override
61     public final String toString() {
62         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
63     }
64
65     /**
66      * Add class-specific toString attributes.
67      *
68      * @param toStringHelper
69      *            ToStringHelper instance
70      * @return ToStringHelper instance which was passed in
71      */
72     protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
73         return toStringHelper.add("id", identifier);
74     }
75 }