Move transaction-invariants into producer
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / ShardDataModificationFactory.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 package org.opendaylight.mdsal.dom.store.inmemory;
9
10 import com.google.common.annotations.VisibleForTesting;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Map;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
17
18 final class ShardDataModificationFactory {
19     private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
20     private final Map<PathArgument, WriteableModificationNode> children;
21     private final DOMDataTreeIdentifier root;
22
23     ShardDataModificationFactory(final DOMDataTreeIdentifier root,
24         final Map<PathArgument, WriteableModificationNode> children,
25         final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
26         this.root = Preconditions.checkNotNull(root);
27         this.children = ImmutableMap.copyOf(children);
28         this.childShards = ImmutableMap.copyOf(childShards);
29     }
30
31     @VisibleForTesting
32     Map<PathArgument, WriteableModificationNode> getChildren() {
33         return children;
34     }
35
36     @VisibleForTesting
37     Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
38         return childShards;
39     }
40
41     ShardDataModification createModification(final CursorAwareDataTreeSnapshot snapshot) {
42         return new ShardDataModification(new ShardRootModificationContext(root, snapshot), children, childShards);
43     }
44 }