Move checking/logging out of executeModification() 97/90697/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Jun 2020 13:58:43 +0000 (15:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Jun 2020 13:59:06 +0000 (15:59 +0200)
We will need specialized methods to deal with modifications,
similar to what we are doing for read(). As a first step, split
out common bits. This inlining has the added benefit of not touching
class reflection data.

JIRA: CONTROLLER-1950
Change-Id: I88030331ad8fe9299e8e824e18571047c87c90c6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java

index b4934e7e62a449cdc5b3789f9551426c9944836c..02ccb81c898a2201c0b5042a8f55fe15592bc8ea 100644 (file)
@@ -138,26 +138,27 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
 
     @Override
     public void delete(final YangInstanceIdentifier path) {
+        checkModificationState("delete", path);
+
         executeModification(new DeleteModification(path));
     }
 
     @Override
     public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+        checkModificationState("merge", path);
+
         executeModification(new MergeModification(path, data));
     }
 
     @Override
     public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+        checkModificationState("write", path);
+
         executeModification(new WriteModification(path, data));
     }
 
     private void executeModification(final AbstractModification modification) {
-        checkModificationState();
-
-        LOG.trace("Tx {} executeModification {} {}", getIdentifier(), modification.getClass().getSimpleName(),
-                modification.getPath());
-
-        TransactionContextWrapper contextWrapper = getContextWrapper(modification.getPath());
+        final TransactionContextWrapper contextWrapper = getContextWrapper(modification.getPath());
         contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() {
             @Override
             protected void invoke(final TransactionContext transactionContext, final Boolean havePermit) {
@@ -166,9 +167,10 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         });
     }
 
-    private void checkModificationState() {
+    private void checkModificationState(final String opName, final YangInstanceIdentifier path) {
         checkState(type != TransactionType.READ_ONLY, "Modification operation on read-only transaction is not allowed");
         checkState(state == TransactionState.OPEN, "Transaction is sealed - further modifications are not allowed");
+        LOG.trace("Tx {} {} {}", getIdentifier(), opName, path);
     }
 
     private boolean seal(final TransactionState newState) {