2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.core.spi.data;
10 import static java.util.Objects.requireNonNull;
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;
19 * Abstract DOM Store Transaction.
22 * Convenience super implementation of DOM Store transaction which provides
23 * common implementation of {@link #toString()} and {@link #getIdentifier()}.
26 * It can optionally capture the context where it was allocated.
28 * @param <T> identifier type
29 * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTransaction} instead.
31 @Deprecated(forRemoval = true)
33 public abstract class AbstractDOMStoreTransaction<T> implements DOMStoreTransaction {
34 private final Throwable debugContext;
35 private final @NonNull T identifier;
37 protected AbstractDOMStoreTransaction(final @NonNull T identifier) {
38 this(identifier, false);
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;
47 public final T getIdentifier() {
52 * Return the context in which this transaction was allocated.
54 * @return The context in which this transaction was allocated, or null if the context was not recorded.
56 public final @Nullable Throwable getDebugContext() {
61 public final String toString() {
62 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
66 * Add class-specific toString attributes.
68 * @param toStringHelper
69 * ToStringHelper instance
70 * @return ToStringHelper instance which was passed in
72 protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
73 return toStringHelper.add("id", identifier);