Merge "Bug 2820 - LLDP TLV support and testing"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / MergeModification.java
1 /*
2  * Copyright (c) 2014 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.controller.cluster.datastore.modification;
10
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;
21
22 /**
23  * MergeModification stores all the parameters required to merge data into the specified path
24  */
25 public class MergeModification extends WriteModification {
26     private static final long serialVersionUID = 1L;
27
28     public MergeModification() {
29         this(DataStoreVersions.CURRENT_VERSION);
30     }
31
32     public MergeModification(short version) {
33         super(version);
34     }
35
36     public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
37         super(path, data);
38     }
39
40     @Override
41     public void apply(final DOMStoreWriteTransaction transaction) {
42         transaction.merge(getPath(), getData());
43     }
44
45     @Override
46     public void apply(final DataTreeModification transaction) {
47         transaction.merge(getPath(), getData());
48     }
49
50     @Override
51     public byte getType() {
52         return MERGE;
53     }
54
55     @Deprecated
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());
60     }
61
62     public static MergeModification fromStream(ObjectInput in, short version)
63             throws ClassNotFoundException, IOException {
64         MergeModification mod = new MergeModification(version);
65         mod.readExternal(in);
66         return mod;
67     }
68 }