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 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;
20 final class ShardDataModification extends WriteableNodeWithSubshard {
22 private final ShardRootModificationContext rootContext;
23 private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
25 ShardDataModification(ShardRootModificationContext boundary,
26 Map<PathArgument, WriteableModificationNode> subshards,
27 Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
29 this.rootContext = Preconditions.checkNotNull(boundary);
30 this.childShards = ImmutableMap.copyOf(childShards);
34 WriteCursorStrategy createOperation(DOMDataTreeWriteCursor parentCursor) {
35 return new WriteableNodeOperation(this, rootContext.cursor()) {
38 throw new IllegalStateException("Can not exit data tree root");
44 public PathArgument getIdentifier() {
45 return rootContext.getIdentifier().getRootIdentifier().getLastPathArgument();
48 static ShardDataModification from(ShardRootModificationContext root,
49 Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
51 ShardDataModificationBuilder builder = new ShardDataModificationBuilder(root);
52 for (ForeignShardModificationContext subshard : shards.values()) {
53 builder.addSubshard(subshard);
55 return builder.build();
58 public DOMDataTreeIdentifier getPrefix() {
59 return rootContext.getIdentifier();
62 public Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
66 public DataTreeModification seal() {
67 final DataTreeModification rootModification = rootContext.ready();
68 for (ForeignShardModificationContext childShard : childShards.values()) {
72 return rootModification;
75 public void closeTransactions() {
76 for (final ForeignShardModificationContext childShard : childShards.values()) {
77 childShard.closeForeignTransaction();
82 rootContext.closeCursor();