Remove public keyword
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / ShardDataModification.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.ImmutableMap;
13 import java.util.Map;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
19
20 final class ShardDataModification extends WriteableNodeWithSubshard {
21
22     private final ShardRootModificationContext rootContext;
23     private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
24
25     ShardDataModification(final ShardRootModificationContext boundary,
26             final Map<PathArgument, WriteableModificationNode> subshards,
27             final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
28         super(subshards);
29         this.rootContext = Preconditions.checkNotNull(boundary);
30         this.childShards = ImmutableMap.copyOf(childShards);
31     }
32
33     @Override
34     WriteCursorStrategy createOperation(final DOMDataTreeWriteCursor parentCursor) {
35         return new WriteableNodeOperation(this, rootContext.cursor()) {
36             @Override
37             public void exit() {
38                 throw new IllegalStateException("Can not exit data tree root");
39             }
40         };
41     }
42
43     @Override
44     public PathArgument getIdentifier() {
45         return rootContext.getIdentifier().getRootIdentifier().getLastPathArgument();
46     }
47
48     static ShardDataModification from(final ShardRootModificationContext root,
49             final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
50
51         ShardDataModificationBuilder builder = new ShardDataModificationBuilder(root);
52         for (ForeignShardModificationContext subshard : shards.values()) {
53             builder.addSubshard(subshard);
54         }
55         return builder.build();
56     }
57
58     DOMDataTreeIdentifier getPrefix() {
59         return rootContext.getIdentifier();
60     }
61
62     Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
63         return childShards;
64     }
65
66     DataTreeModification seal() {
67         final DataTreeModification rootModification = rootContext.ready();
68         for (ForeignShardModificationContext childShard : childShards.values()) {
69             childShard.ready();
70         }
71
72         return rootModification;
73     }
74
75     void closeTransactions() {
76         for (final ForeignShardModificationContext childShard : childShards.values()) {
77             childShard.closeForeignTransaction();
78         }
79     }
80
81     void closeCursor() {
82         rootContext.closeCursor();
83     }
84 }