ForwardingRead[Only]/WriteTransaction implementations 68/63468/2
authorMichael Vorburger <vorburger@redhat.com>
Fri, 22 Sep 2017 22:27:29 +0000 (00:27 +0200)
committerStephen Kitt <skitt@redhat.com>
Mon, 25 Sep 2017 08:33:04 +0000 (08:33 +0000)
this came up during https://git.opendaylight.org/gerrit/#/c/63372/

a bit similar (but otherwise unrelated) to my earlier
https://git.opendaylight.org/gerrit/#/c/63135/

Change-Id: If669f94b47bf41f49e54c66c6024aeff9805f8d6
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadOnlyTransaction.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadWriteTransaction.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingWriteTransaction.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadOnlyTransaction.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadOnlyTransaction.java
new file mode 100644 (file)
index 0000000..bc7d18c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.api;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ForwardingObject;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Utility {@link ReadOnlyTransaction} implementation which forwards all interface method
+ * invocation to a delegate instance.
+ */
+@SuppressWarnings("deprecation") // due to CheckedFuture
+public class ForwardingReadOnlyTransaction extends ForwardingObject implements ReadOnlyTransaction {
+
+    private final ReadOnlyTransaction delegate;
+
+    protected ForwardingReadOnlyTransaction(ReadOnlyTransaction delegate) {
+        super();
+        this.delegate = delegate;
+    }
+
+    @Override
+    protected ReadTransaction delegate() {
+        return delegate;
+    }
+
+    @Override
+    public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store,
+            InstanceIdentifier<T> path) {
+        return delegate.read(store, path);
+    }
+
+    @Override
+    public Object getIdentifier() {
+        return delegate.getIdentifier();
+    }
+
+    @Override
+    public void close() {
+        delegate.close();
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadWriteTransaction.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadWriteTransaction.java
new file mode 100644 (file)
index 0000000..ae7446b
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.api;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ForwardingObject;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+/**
+ * Utility {@link ReadWriteTransaction} implementation which forwards all interface method
+ * invocation to a delegate instance.
+ */
+@SuppressWarnings("deprecation") // due to CheckedFuture & TransactionStatus
+public class ForwardingReadWriteTransaction extends ForwardingObject implements ReadWriteTransaction {
+
+    private final ReadWriteTransaction delegate;
+
+    protected ForwardingReadWriteTransaction(ReadWriteTransaction delegate) {
+        super();
+        this.delegate = delegate;
+    }
+
+    @Override
+    protected ReadWriteTransaction delegate() {
+        return delegate;
+    }
+
+    @Override
+    public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        delegate.put(store, path, data);
+    }
+
+    @Override
+    public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
+            boolean createMissingParents) {
+        delegate.put(store, path, data, createMissingParents);
+    }
+
+    @Override
+    public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store,
+            InstanceIdentifier<T> path) {
+        return delegate.read(store, path);
+    }
+
+    @Override
+    public Object getIdentifier() {
+        return delegate.getIdentifier();
+    }
+
+    @Override
+    public boolean cancel() {
+        return delegate.cancel();
+    }
+
+    @Override
+    public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        delegate.merge(store, path, data);
+    }
+
+    @Override
+    public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
+            boolean createMissingParents) {
+        delegate.merge(store, path, data, createMissingParents);
+    }
+
+    @Override
+    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
+        return delegate.submit();
+    }
+
+    @Override
+    public void delete(LogicalDatastoreType store, InstanceIdentifier<?> path) {
+        delegate.delete(store, path);
+    }
+
+    @Override
+    public ListenableFuture<RpcResult<TransactionStatus>> commit() {
+        return delegate.commit();
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingWriteTransaction.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingWriteTransaction.java
new file mode 100644 (file)
index 0000000..81193af
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.api;
+
+import com.google.common.collect.ForwardingObject;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+/**
+ * Utility {@link WriteTransaction} implementation which forwards all interface method
+ * invocation to a delegate instance.
+ */
+@SuppressWarnings("deprecation") // due to CheckedFuture & TransactionStatus
+public class ForwardingWriteTransaction extends ForwardingObject implements WriteTransaction {
+
+    private final WriteTransaction delegate;
+
+    protected ForwardingWriteTransaction(WriteTransaction delegate) {
+        super();
+        this.delegate = delegate;
+    }
+
+    @Override
+    protected WriteTransaction delegate() {
+        return delegate;
+    }
+
+    @Override
+    public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        delegate.put(store, path, data);
+    }
+
+    @Override
+    public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
+            boolean createMissingParents) {
+        delegate.put(store, path, data, createMissingParents);
+    }
+
+    @Override
+    public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        delegate.merge(store, path, data);
+    }
+
+    @Override
+    public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
+            boolean createMissingParents) {
+        delegate.merge(store, path, data, createMissingParents);
+    }
+
+    @Override
+    public void delete(LogicalDatastoreType store, InstanceIdentifier<?> path) {
+        delegate.delete(store, path);
+    }
+
+    @Override
+    public boolean cancel() {
+        return delegate.cancel();
+    }
+
+    @Override
+    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
+        return delegate.submit();
+    }
+
+    @Override
+    public ListenableFuture<RpcResult<TransactionStatus>> commit() {
+        return delegate.commit();
+    }
+
+    @Override
+    public Object getIdentifier() {
+        return delegate.getIdentifier();
+    }
+
+}

©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.