Create transaction on the backend datastore only when neccessary
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ReadWriteShardDataTreeTransaction.java
1 /*
2  * Copyright (c) 2015 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.cluster.datastore;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
12 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
13
14 final class ReadWriteShardDataTreeTransaction extends AbstractShardDataTreeTransaction<DataTreeModification> {
15     private final ShardDataTreeTransactionParent parent;
16
17     protected ReadWriteShardDataTreeTransaction(final ShardDataTreeTransactionParent parent, final String id, final DataTreeModification modification) {
18         super(id, modification);
19         this.parent = Preconditions.checkNotNull(parent);
20     }
21
22     @Override
23     void abort() {
24         Preconditions.checkState(close(), "Transaction is already closed");
25
26         parent.abortTransaction(this);
27     }
28
29     DOMStoreThreePhaseCommitCohort ready() {
30         Preconditions.checkState(close(), "Transaction is already closed");
31
32         return parent.finishTransaction(this);
33     }
34 }