6c0d2775c6c694299ed21edad103b6a5866f7456
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataTreeShardProducer.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.mdsal.dom.store.inmemory;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.Collection;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15
16 final class InMemoryDOMDataTreeShardProducer implements DOMDataTreeShardProducer {
17
18     private final InMemoryDOMDataTreeShard parentShard;
19     private final Collection<DOMDataTreeIdentifier> prefixes;
20
21     private InmemoryDOMDataTreeShardWriteTransaction currentTx;
22     private InmemoryDOMDataTreeShardWriteTransaction lastSubmittedTx;
23
24     InMemoryDOMDataTreeShardProducer(final InMemoryDOMDataTreeShard parentShard,
25             final Collection<DOMDataTreeIdentifier> prefixes) {
26         this.parentShard = Preconditions.checkNotNull(parentShard);
27         this.prefixes = ImmutableSet.copyOf(prefixes);
28     }
29
30     @Override
31     public InmemoryDOMDataTreeShardWriteTransaction createTransaction() {
32 //      Preconditions.checkState(currentTx == null || currentTx.isFinished(), "Previous transaction not finished yet.");
33         if (lastSubmittedTx != null) {
34             currentTx = parentShard.createTransaction(lastSubmittedTx);
35         } else {
36             currentTx = parentShard.createTransaction(prefixes);
37         }
38         return currentTx;
39     }
40
41     @Override
42     public Collection<DOMDataTreeIdentifier> getPrefixes() {
43         return prefixes;
44     }
45 }