2 * Copyright (c) 2014 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.controller.cluster.datastore.modification;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
14 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
15 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
16 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
23 * MergeModification stores all the parameters required to merge data into the specified path
25 public class MergeModification extends WriteModification {
26 private static final long serialVersionUID = 1L;
28 public MergeModification() {
29 this(DataStoreVersions.CURRENT_VERSION);
32 public MergeModification(short version) {
36 public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
41 public void apply(final DOMStoreWriteTransaction transaction) {
42 transaction.merge(getPath(), getData());
46 public void apply(final DataTreeModification transaction) {
47 transaction.merge(getPath(), getData());
51 public byte getType() {
56 public static MergeModification fromSerializable(final Object serializable) {
57 PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
58 Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(o.getPath(), o.getData());
59 return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode());
62 public static MergeModification fromStream(ObjectInput in, short version)
63 throws ClassNotFoundException, IOException {
64 MergeModification mod = new MergeModification(version);