2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.mdsal.dom.store.inmemory;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableMap;
14 import java.util.Map.Entry;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
21 final class ShardDataModification extends WriteableNodeWithSubshard {
23 private final ShardRootModificationContext rootContext;
24 private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
26 ShardDataModification(final ShardRootModificationContext boundary,
27 final Map<PathArgument, WriteableModificationNode> subshards,
28 final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
30 this.rootContext = Preconditions.checkNotNull(boundary);
31 this.childShards = ImmutableMap.copyOf(childShards);
35 WriteCursorStrategy createOperation(final DOMDataTreeWriteCursor parentCursor) {
36 return new WriteableNodeOperation(this, rootContext.cursor()) {
39 throw new IllegalStateException("Can not exit data tree root");
45 public PathArgument getIdentifier() {
46 return rootContext.getIdentifier().getRootIdentifier().getLastPathArgument();
49 static ShardDataModification from(final ShardRootModificationContext root,
50 final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
52 ShardDataModificationBuilder builder = new ShardDataModificationBuilder(root);
53 for (Entry<YangInstanceIdentifier, ForeignShardModificationContext> subshard : shards.entrySet()) {
54 builder.addSubshard(subshard.getValue());
56 return builder.build();
59 DOMDataTreeIdentifier getPrefix() {
60 return rootContext.getIdentifier();
63 Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
67 DataTreeModification seal() {
68 final DataTreeModification rootModification = rootContext.ready();
69 for (ForeignShardModificationContext childShard : childShards.values()) {
73 return rootModification;
76 void closeTransactions() {
77 for (final ForeignShardModificationContext childShard : childShards.values()) {
78 childShard.closeForeignTransaction();
83 rootContext.closeCursor();